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.
This commit is contained in:
Andrew Hamilton 2022-01-04 17:50:36 +10:00
parent dd5aa524a7
commit ae07f1cab3
3 changed files with 8 additions and 10 deletions

View file

@ -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()

View file

@ -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)

View file

@ -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