fix: Add error handling for terminal control sequences to prevent crashes

This commit is contained in:
n loewen (aider) 2025-06-07 23:16:43 +01:00
parent e9b806aeb8
commit 6aa6881f0b
1 changed files with 15 additions and 3 deletions

18
gtm2.py
View File

@ -542,7 +542,10 @@ def handle_keyboard_input(key, state):
# --- Main Application ---
def main(stdscr, filename, show_diff, show_add, show_del, mouse):
curses.curs_set(0)
try:
curses.curs_set(0)
except:
pass
stdscr.keypad(True)
stdscr.timeout(50) # Less aggressive timeout (50ms instead of 10ms)
@ -559,7 +562,10 @@ def main(stdscr, filename, show_diff, show_add, show_del, mouse):
if state.enable_mouse:
curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
# Enable mouse motion events for better drag tracking
print("\033[?1003h", end="", flush=True)
try:
print("\033[?1003h", end="", flush=True)
except:
pass
state.load_commit_content()
@ -586,11 +592,17 @@ def main(stdscr, filename, show_diff, show_add, show_del, mouse):
draw_ui(stdscr, state)
except Exception as e:
# Prevent crashes by catching exceptions
# Uncomment for debugging:
# with open("/tmp/gtm_error.log", "a") as f:
# f.write(f"{str(e)}\n")
pass
# Disable mouse motion events when exiting
if state.enable_mouse:
print("\033[?1003l", end="", flush=True)
try:
print("\033[?1003l", end="", flush=True)
except:
pass
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="A \"Git Time Machine\" for viewing file history")