Nicer fix for #5469

This commit is contained in:
Kovid Goyal 2022-09-04 22:15:17 +05:30
parent b60d9f73ce
commit 5bf5454dbe
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 13 additions and 9 deletions

View File

@ -45,7 +45,6 @@ class Handler:
mouse_tracking = MouseTracking.none
terminal_io_ended = False
overlay_ready_report_needed = False
perform_default_key_actions = True # ctrl-c/ctrl-d will call on_interrupt and on_eot
def _initialize(
self,
@ -122,11 +121,22 @@ class Handler:
self._tui_loop.quit(1)
def on_key_event(self, key_event: KeyEventType, in_bracketed_paste: bool = False) -> None:
' Override this method and perform_default_key_action() to handle all key events '
if key_event.text:
self.on_text(key_event.text, in_bracketed_paste)
else:
self.on_key(key_event)
def perform_default_key_action(self, key_event: KeyEventType) -> bool:
' Override in sub-class if you want to handle these key events yourself '
if key_event.matches('ctrl+c'):
self.on_interrupt()
return True
if key_event.matches('ctrl+d'):
self.on_eot()
return True
return False
def on_text(self, text: str, in_bracketed_paste: bool = False) -> None:
pass

View File

@ -330,14 +330,8 @@ class Loop:
except Exception:
pass
else:
if self.handler.perform_default_key_actions:
if k.matches('ctrl+c'):
self.handler.on_interrupt()
return
if k.matches('ctrl+d'):
self.handler.on_eot()
return
self.handler.on_key_event(k)
if not self.handler.perform_default_key_action(k):
self.handler.on_key_event(k)
def _on_pm(self, pm: str) -> None:
pass