fix: Improve error handling and reduce timeout in main event loop

This commit is contained in:
n loewen (aider) 2025-06-07 23:15:22 +01:00
parent d22b9ff5b9
commit c1605e99cd
1 changed files with 19 additions and 12 deletions

31
gtm2.py
View File

@ -544,6 +544,7 @@ def handle_keyboard_input(key, state):
def main(stdscr, filename, show_diff, show_add, show_del, mouse):
curses.curs_set(0)
stdscr.keypad(True)
stdscr.timeout(50) # Less aggressive timeout (50ms instead of 10ms)
if curses.has_colors():
curses.use_default_colors()
@ -566,20 +567,26 @@ def main(stdscr, filename, show_diff, show_add, show_del, mouse):
draw_ui(stdscr, state)
while not state.should_exit:
key = stdscr.getch()
# Process input and update the application state
if key == curses.KEY_RESIZE:
try:
key = stdscr.getch()
# Process input and update the application state
if key == -1: # No input available (timeout)
pass # Just redraw the UI and continue
elif key == curses.KEY_RESIZE:
h, w = stdscr.getmaxyx()
state.update_dimensions(h, w)
elif state.enable_mouse and key == curses.KEY_MOUSE:
handle_mouse_input(stdscr, state)
else:
handle_keyboard_input(key, state)
# After every action, redraw the UI to reflect changes immediately.
# This is crucial for real-time feedback during mouse drags.
draw_ui(stdscr, state)
elif state.enable_mouse and key == curses.KEY_MOUSE:
handle_mouse_input(stdscr, state)
else:
handle_keyboard_input(key, state)
# After every action, redraw the UI to reflect changes immediately.
# This is crucial for real-time feedback during mouse drags.
draw_ui(stdscr, state)
except Exception as e:
# Prevent crashes by catching exceptions
pass
# Disable mouse motion events when exiting
if state.enable_mouse: