1313from prompt_toolkit .completion import NestedCompleter
1414from prompt_toolkit .history import FileHistory
1515from prompt_toolkit .formatted_text import ANSI
16+ from prompt_toolkit .key_binding import KeyBindings
1617
1718from meshcore import TCPConnection , BLEConnection , SerialConnection
1819from meshcore import MeshCore , EventType , logger
@@ -227,6 +228,13 @@ async def interactive_loop(mc, to=None) :
227228 mouse_support = True ,
228229 complete_style = CompleteStyle .MULTI_COLUMN )
229230
231+ bindings = KeyBindings ()
232+
233+ # Add our own key binding.
234+ @bindings .add ("escape" )
235+ def _ (event ):
236+ event .app .current_buffer .cancel_completion ()
237+
230238 last_ack = True
231239 while True :
232240 prompt = ""
@@ -237,7 +245,11 @@ async def interactive_loop(mc, to=None) :
237245 if not process_event_message .color :
238246 prompt = escape_ansi (prompt )
239247
240- line = await session .prompt_async (ANSI (prompt ), complete_while_typing = False )
248+ session .app .ttimeoutlen = 0.2
249+ session .app .timeoutlen = 0.2
250+
251+ line = await session .prompt_async (ANSI (prompt ), complete_while_typing = False ,
252+ key_bindings = bindings )
241253
242254 if line == "" : # blank line
243255 pass
0 commit comments