@@ -88,105 +88,120 @@ def fill_config_with_default_values(
8888
8989
9090class Config :
91- def __init__ (self , config_path : Path ):
91+ default_colors = {
92+ "keyword" : "y" ,
93+ "name" : "c" ,
94+ "comment" : "b" ,
95+ "string" : "m" ,
96+ "error" : "r" ,
97+ "number" : "G" ,
98+ "operator" : "Y" ,
99+ "punctuation" : "y" ,
100+ "token" : "C" ,
101+ "background" : "d" ,
102+ "output" : "w" ,
103+ "main" : "c" ,
104+ "paren" : "R" ,
105+ "prompt" : "c" ,
106+ "prompt_more" : "g" ,
107+ "right_arrow_suggestion" : "K" ,
108+ }
109+
110+ defaults : Dict [str , Dict [str , Any ]] = {
111+ "general" : {
112+ "arg_spec" : True ,
113+ "auto_display_list" : True ,
114+ "autocomplete_mode" : default_completion ,
115+ "color_scheme" : "default" ,
116+ "complete_magic_methods" : True ,
117+ "dedent_after" : 1 ,
118+ "default_autoreload" : False ,
119+ "editor" : default_editor (),
120+ "flush_output" : True ,
121+ "import_completion_skiplist" : ":" .join (
122+ (
123+ # version tracking
124+ ".git" ,
125+ ".svn" ,
126+ ".hg"
127+ # XDG
128+ ".config" ,
129+ ".local" ,
130+ ".share" ,
131+ # nodejs
132+ "node_modules" ,
133+ # PlayOnLinux
134+ "PlayOnLinux's virtual drives" ,
135+ # wine
136+ "dosdevices" ,
137+ # Python byte code cache
138+ "__pycache__" ,
139+ )
140+ ),
141+ "highlight_show_source" : True ,
142+ "hist_duplicates" : True ,
143+ "hist_file" : "~/.pythonhist" ,
144+ "hist_length" : 1000 ,
145+ "paste_time" : 0.02 ,
146+ "pastebin_confirm" : True ,
147+ "pastebin_expiry" : "1week" ,
148+ "pastebin_helper" : "" ,
149+ "pastebin_url" : "https://bpaste.net" ,
150+ "save_append_py" : False ,
151+ "single_undo_time" : 1.0 ,
152+ "syntax" : True ,
153+ "tab_length" : 4 ,
154+ "unicode_box" : True ,
155+ },
156+ "keyboard" : {
157+ "backspace" : "C-h" ,
158+ "beginning_of_line" : "C-a" ,
159+ "clear_line" : "C-u" ,
160+ "clear_screen" : "C-l" ,
161+ "clear_word" : "C-w" ,
162+ "copy_clipboard" : "F10" ,
163+ "cut_to_buffer" : "C-k" ,
164+ "delete" : "C-d" ,
165+ "down_one_line" : "C-n" ,
166+ "edit_config" : "F3" ,
167+ "edit_current_block" : "C-x" ,
168+ "end_of_line" : "C-e" ,
169+ "exit" : "" ,
170+ "external_editor" : "F7" ,
171+ "help" : "F1" ,
172+ "incremental_search" : "M-s" ,
173+ "last_output" : "F9" ,
174+ "left" : "C-b" ,
175+ "pastebin" : "F8" ,
176+ "redo" : "C-g" ,
177+ "reimport" : "F6" ,
178+ "reverse_incremental_search" : "M-r" ,
179+ "right" : "C-f" ,
180+ "save" : "C-s" ,
181+ "search" : "C-o" ,
182+ "show_source" : "F2" ,
183+ "suspend" : "C-z" ,
184+ "toggle_file_watch" : "F5" ,
185+ "transpose_chars" : "C-t" ,
186+ "undo" : "C-r" ,
187+ "up_one_line" : "C-p" ,
188+ "yank_from_buffer" : "C-y" ,
189+ },
190+ "cli" : {
191+ "suggestion_width" : 0.8 ,
192+ "trim_prompts" : False ,
193+ },
194+ "curtsies" : {
195+ "list_above" : False ,
196+ "right_arrow_completion" : True ,
197+ },
198+ }
199+
200+ def __init__ (self , config_path : Path ) -> None :
92201 """Loads .ini configuration file and stores its values."""
93202
94203 config = ConfigParser ()
95- defaults : Dict [str , Dict [str , Any ]] = {
96- "general" : {
97- "arg_spec" : True ,
98- "auto_display_list" : True ,
99- "autocomplete_mode" : default_completion ,
100- "color_scheme" : "default" ,
101- "complete_magic_methods" : True ,
102- "dedent_after" : 1 ,
103- "default_autoreload" : False ,
104- "editor" : default_editor (),
105- "flush_output" : True ,
106- "import_completion_skiplist" : ":" .join (
107- (
108- # version tracking
109- ".git" ,
110- ".svn" ,
111- ".hg"
112- # XDG
113- ".config" ,
114- ".local" ,
115- ".share" ,
116- # nodejs
117- "node_modules" ,
118- # PlayOnLinux
119- "PlayOnLinux's virtual drives" ,
120- # wine
121- "dosdevices" ,
122- # Python byte code cache
123- "__pycache__" ,
124- )
125- ),
126- "highlight_show_source" : True ,
127- "hist_duplicates" : True ,
128- "hist_file" : "~/.pythonhist" ,
129- "hist_length" : 1000 ,
130- "paste_time" : 0.02 ,
131- "pastebin_confirm" : True ,
132- "pastebin_expiry" : "1week" ,
133- "pastebin_helper" : "" ,
134- "pastebin_url" : "https://bpaste.net" ,
135- "save_append_py" : False ,
136- "single_undo_time" : 1.0 ,
137- "syntax" : True ,
138- "tab_length" : 4 ,
139- "unicode_box" : True ,
140- },
141- "keyboard" : {
142- "backspace" : "C-h" ,
143- "beginning_of_line" : "C-a" ,
144- "clear_line" : "C-u" ,
145- "clear_screen" : "C-l" ,
146- "clear_word" : "C-w" ,
147- "copy_clipboard" : "F10" ,
148- "cut_to_buffer" : "C-k" ,
149- "delete" : "C-d" ,
150- "down_one_line" : "C-n" ,
151- "edit_config" : "F3" ,
152- "edit_current_block" : "C-x" ,
153- "end_of_line" : "C-e" ,
154- "exit" : "" ,
155- "external_editor" : "F7" ,
156- "help" : "F1" ,
157- "incremental_search" : "M-s" ,
158- "last_output" : "F9" ,
159- "left" : "C-b" ,
160- "pastebin" : "F8" ,
161- "redo" : "C-g" ,
162- "reimport" : "F6" ,
163- "reverse_incremental_search" : "M-r" ,
164- "right" : "C-f" ,
165- "save" : "C-s" ,
166- "search" : "C-o" ,
167- "show_source" : "F2" ,
168- "suspend" : "C-z" ,
169- "toggle_file_watch" : "F5" ,
170- "transpose_chars" : "C-t" ,
171- "undo" : "C-r" ,
172- "up_one_line" : "C-p" ,
173- "yank_from_buffer" : "C-y" ,
174- },
175- "cli" : {
176- "suggestion_width" : 0.8 ,
177- "trim_prompts" : False ,
178- },
179- "curtsies" : {
180- "list_above" : False ,
181- "right_arrow_completion" : True ,
182- },
183- }
184-
185- default_keys_to_commands = {
186- value : key for (key , value ) in defaults ["keyboard" ].items ()
187- }
188-
189- fill_config_with_default_values (config , defaults )
204+ fill_config_with_default_values (config , self .defaults )
190205 try :
191206 config .read (config_path )
192207 except UnicodeDecodeError as e :
@@ -199,8 +214,12 @@ def __init__(self, config_path: Path):
199214 )
200215 sys .exit (1 )
201216
202- def get_key_no_doublebind (command ):
203- default_commands_to_keys = defaults ["keyboard" ]
217+ default_keys_to_commands = {
218+ value : key for (key , value ) in self .defaults ["keyboard" ].items ()
219+ }
220+
221+ def get_key_no_doublebind (command : str ) -> str :
222+ default_commands_to_keys = self .defaults ["keyboard" ]
204223 requested_key = config .get ("keyboard" , command )
205224
206225 try :
@@ -209,7 +228,7 @@ def get_key_no_doublebind(command):
209228 if default_commands_to_keys [default_command ] == config .get (
210229 "keyboard" , default_command
211230 ):
212- setattr (self , "%s_key" % default_command , "" )
231+ setattr (self , f" { default_command } _key" , "" )
213232 except KeyError :
214233 pass
215234
@@ -307,34 +326,14 @@ def get_key_no_doublebind(command):
307326 self .unicode_box = config .getboolean ("general" , "unicode_box" )
308327
309328 color_scheme_name = config .get ("general" , "color_scheme" )
310-
311- default_colors = {
312- "keyword" : "y" ,
313- "name" : "c" ,
314- "comment" : "b" ,
315- "string" : "m" ,
316- "error" : "r" ,
317- "number" : "G" ,
318- "operator" : "Y" ,
319- "punctuation" : "y" ,
320- "token" : "C" ,
321- "background" : "d" ,
322- "output" : "w" ,
323- "main" : "c" ,
324- "paren" : "R" ,
325- "prompt" : "c" ,
326- "prompt_more" : "g" ,
327- "right_arrow_suggestion" : "K" ,
328- }
329-
330329 if color_scheme_name == "default" :
331- self .color_scheme = default_colors
330+ self .color_scheme = self . default_colors
332331 else :
333332 self .color_scheme = dict ()
334333
335334 path = get_config_home () / f"{ color_scheme_name } .theme"
336335 try :
337- load_theme (path , self .color_scheme , default_colors )
336+ load_theme (path , self .color_scheme , self . default_colors )
338337 except OSError :
339338 sys .stderr .write (
340339 f"Could not load theme '{ color_scheme_name } ' from { path } .\n "
0 commit comments