Raw mode for ctrl-c and ctrl-z.
- No special behaviour for ctrl-c and ctrl-z by default.
This commit is contained in:
parent
2dc9c0f71a
commit
77eca03be3
3 changed files with 7 additions and 4 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue