@@ -69,40 +69,57 @@ def __init__(self, coder_worker, output_queue, input_queue, args):
6969 )
7070
7171 self .bind (
72- self .tui_config ["key_bindings" ]["newline" ], "noop" , description = "New Line" , show = True
72+ self ._encode_keys (self .get_keys_for ("newline" )),
73+ "noop" ,
74+ description = "New Line" ,
75+ show = True ,
7376 )
7477 self .bind (
75- self .tui_config [ "key_bindings" ][ " submit"] , "noop" , description = "Submit" , show = True
78+ self ._encode_keys ( self . get_keys_for ( " submit")) , "noop" , description = "Submit" , show = True
7679 )
7780 self .bind (
78- self .tui_config ["key_bindings" ]["cycle_forward" ],
81+ self ._encode_keys (self .get_keys_for ("completion" )),
82+ "noop" ,
83+ description = "Accept Completion" ,
84+ show = True ,
85+ )
86+ self .bind (
87+ self ._encode_keys (self .get_keys_for ("cycle_forward" )),
7988 "noop" ,
8089 description = "Cycle Forward" ,
8190 show = True ,
8291 )
8392 self .bind (
84- self .tui_config [ "key_bindings" ][ " cycle_backward"] ,
93+ self ._encode_keys ( self . get_keys_for ( " cycle_backward")) ,
8594 "noop" ,
8695 description = "Cycle Backward" ,
8796 show = True ,
8897 )
8998 self .bind (
90- self .tui_config [ "key_bindings" ][ " cancel"] , "noop" , description = "Cancel" , show = True
99+ self ._encode_keys ( self . get_keys_for ( " cancel")) , "noop" , description = "Cancel" , show = True
91100 )
92101
93102 self .bind (
94- self .tui_config [ "key_bindings" ][ " focus"] ,
103+ self ._encode_keys ( self . get_keys_for ( " focus")) ,
95104 "focus_input" ,
96105 description = "Focus Input" ,
97106 show = True ,
98107 )
99108 self .bind (
100- self .tui_config ["key_bindings" ]["stop" ], "interrupt" , description = "Interrupt" , show = True
109+ self ._encode_keys (self .get_keys_for ("stop" )),
110+ "interrupt" ,
111+ description = "Interrupt" ,
112+ show = True ,
101113 )
102114 self .bind (
103- self .tui_config ["key_bindings" ]["clear" ], "clear_output" , description = "Clear" , show = True
115+ self ._encode_keys (self .get_keys_for ("clear" )),
116+ "clear_output" ,
117+ description = "Clear" ,
118+ show = True ,
119+ )
120+ self .bind (
121+ self ._encode_keys (self .get_keys_for ("focus" )), "quit" , description = "Quit" , show = True
104122 )
105- self .bind (self .tui_config ["key_bindings" ]["focus" ], "quit" , description = "Quit" , show = True )
106123
107124 self .register_theme (BASE_THEME )
108125 self .theme = "aider"
@@ -166,9 +183,10 @@ def _get_config(self):
166183 default_key_bindings = {
167184 "newline" : "enter" if is_multiline else "shift+enter" ,
168185 "submit" : "shift+enter" if is_multiline else "enter" ,
186+ "completion" : "tab" ,
169187 "stop" : "escape" ,
170- "cycle_forward" : "tab " ,
171- "cycle_backward" : "shift+tab " ,
188+ "cycle_forward" : "right " ,
189+ "cycle_backward" : "left " ,
172190 "focus" : "ctrl+f" ,
173191 "cancel" : "ctrl+c" ,
174192 "clear" : "ctrl+l" ,
@@ -267,10 +285,10 @@ def update_key_hints(self, generating=False):
267285 try :
268286 hints = self .query_one (KeyHints )
269287 if generating :
270- stop = self .app ._decode_keys ( self . app . tui_config [ "key_bindings" ][ " stop"] )
288+ stop = self .app .get_keys_for ( " stop" )
271289 hints .update (f"{ stop } to cancel" )
272290 else :
273- submit = self .app ._decode_keys ( self . app . tui_config [ "key_bindings" ][ " submit"] )
291+ submit = self .app .get_keys_for ( " submit" )
274292 hints .update (f"{ submit } to submit" )
275293 except Exception :
276294 pass
@@ -486,17 +504,26 @@ def action_noop(self):
486504 pass
487505
488506 def _encode_keys (self , key ):
489- if key == "shift+enter" :
490- return "ctrl+j"
507+ key = key .replace ("shift+enter" , "ctrl+j" )
491508
492509 return key
493510
494511 def _decode_keys (self , key ):
495- if key == "ctrl+j" :
496- return "shift+enter"
512+ key = key .replace ("ctrl+j" , "shift+enter" )
497513
498514 return key
499515
516+ def is_key_for (self , type , key ):
517+ allowed_keys = self .tui_config ["key_bindings" ][type ].split ("," )
518+ if key in allowed_keys :
519+ return True
520+
521+ return False
522+
523+ def get_keys_for (self , type ):
524+ allowed_keys = self .tui_config ["key_bindings" ][type ]
525+ return self ._decode_keys (allowed_keys )
526+
500527 def _do_quit (self ):
501528 """Perform the actual quit after UI updates."""
502529 self .worker .stop ()
0 commit comments