From ae07f1cab3310523012b67e3502ee8cc60bc2eca Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Tue, 4 Jan 2022 17:50:36 +1000 Subject: [PATCH] fill3: Always put ctrl-c and ctrl-z in raw mode. - Rename interactive context to raw. - Explicitly handle ctrl-c. - Ctrl-z for backgrounding is always disabled. --- eris/eris/__main__.py | 7 ++++--- fill3/fill3/__init__.py | 5 ++--- fill3/fill3/terminal.py | 6 ++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/eris/eris/__main__.py b/eris/eris/__main__.py index 516bf6a..e624ba2 100755 --- a/eris/eris/__main__.py +++ b/eris/eris/__main__.py @@ -965,8 +965,9 @@ class Screen: terminal.RIGHT: cursor_right, terminal.PAGE_DOWN: cursor_page_down, terminal.PAGE_UP: cursor_page_up, "s": toggle_order, terminal.HOME: cursor_home, terminal.END: cursor_end, "n": move_to_next_issue, "N": move_to_next_issue_of_tool, - "e": edit_file, "q": quit_, terminal.ESC: quit_, "r": refresh, "R": refresh_tool, - "\t": toggle_focus, "f": toggle_fullscreen, "o": xdg_open} + "e": edit_file, "q": quit_, terminal.ESC: quit_, terminal.CTRL_C: quit_, + "r": refresh, "R": refresh_tool, "\t": toggle_focus, "f": toggle_fullscreen, + "o": xdg_open} def setup_inotify(root_path, loop, on_filesystem_event, exclude_filter): @@ -1047,7 +1048,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, raw_ctrl_c_and_z=False) + await fill3.tui(title, screen) log.log_message("Program stopped.") else: shutdown_event = asyncio.Event() diff --git a/fill3/fill3/__init__.py b/fill3/fill3/__init__.py index 3273705..44bc657 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, raw_ctrl_c_and_z=True): +async def tui(title, screen_widget): global APPEARANCE_CHANGED_EVENT global SHUTDOWN_EVENT APPEARANCE_CHANGED_EVENT = asyncio.Event() @@ -464,8 +464,7 @@ async def tui(title, screen_widget, raw_ctrl_c_and_z=True): 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(raw_ctrl_c_and_z=raw_ctrl_c_and_z), - terminal.mouse_tracking()): + terminal.alternate_buffer(), terminal.raw(), 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 d6f2c29..9ea641d 100644 --- a/fill3/fill3/terminal.py +++ b/fill3/fill3/terminal.py @@ -67,13 +67,11 @@ def alternate_buffer(): @contextlib.contextmanager -def interactive(raw_ctrl_c_and_z=True): +def raw(): 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[3] = new_settings[3] & ~termios.ECHO & ~termios.ICANON & ~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