From 77eca03be3f67e8934c51ad09092b4a60ebf7b2c Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Tue, 4 Jan 2022 08:28:07 +1000 Subject: [PATCH] Raw mode for ctrl-c and ctrl-z. - No special behaviour for ctrl-c and ctrl-z by default. --- eris/eris/__main__.py | 2 +- fill3/fill3/__init__.py | 5 +++-- fill3/fill3/terminal.py | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/eris/eris/__main__.py b/eris/eris/__main__.py index 1402d6b..516bf6a 100755 --- a/eris/eris/__main__.py +++ b/eris/eris/__main__.py @@ -1047,7 +1047,7 @@ async def main(title, root_path, worker_count=None, editor_command=None, theme=N loop.create_task(worker_.future) try: if sys.stdout.isatty() or is_being_tested: - await fill3.tui(title, screen) + await fill3.tui(title, screen, raw_ctrl_c_and_z=False) log.log_message("Program stopped.") else: shutdown_event = asyncio.Event() diff --git a/fill3/fill3/__init__.py b/fill3/fill3/__init__.py index 9f64b23..98e9902 100755 --- a/fill3/fill3/__init__.py +++ b/fill3/fill3/__init__.py @@ -455,7 +455,7 @@ def signal_handler(loop, signal_, func): loop.remove_signal_handler(signal_) -async def tui(title, screen_widget): +async def tui(title, screen_widget, raw_ctrl_c_and_z=True): global APPEARANCE_CHANGED_EVENT global SHUTDOWN_EVENT APPEARANCE_CHANGED_EVENT = asyncio.Event() @@ -464,7 +464,8 @@ async def tui(title, screen_widget): with (signal_handler(loop, signal.SIGWINCH, lambda: draw_screen(screen_widget)), signal_handler(loop, signal.SIGINT, SHUTDOWN_EVENT.set), signal_handler(loop, signal.SIGTERM, SHUTDOWN_EVENT.set), terminal.title(title), - terminal.alternate_buffer(), terminal.interactive(), terminal.mouse_tracking()): + terminal.alternate_buffer(), terminal.interactive(raw_ctrl_c_and_z=raw_ctrl_c_and_z), + terminal.mouse_tracking()): update_task = asyncio.create_task(update_screen(screen_widget)) try: loop.add_reader(sys.stdin, on_terminal_input, screen_widget) diff --git a/fill3/fill3/terminal.py b/fill3/fill3/terminal.py index fbe9086..d6f2c29 100644 --- a/fill3/fill3/terminal.py +++ b/fill3/fill3/terminal.py @@ -67,11 +67,13 @@ def alternate_buffer(): @contextlib.contextmanager -def interactive(): +def interactive(raw_ctrl_c_and_z=True): old_termios_settings = termios.tcgetattr(sys.stdin) new_settings = termios.tcgetattr(sys.stdin) new_settings[0] = new_settings[0] & ~termios.IXON new_settings[3] = new_settings[3] & ~termios.ECHO & ~termios.ICANON + if raw_ctrl_c_and_z: + new_settings[3] = new_settings[3] & ~termios.ISIG new_settings[6][termios.VMIN] = 0 termios.tcsetattr(sys.stdin, termios.TCSADRAIN, new_settings) sys.stdout.write(ESC + "[?1l") # Ensure normal cursor key codes