fix: Add error handling for terminal control sequences to prevent crashes
This commit is contained in:
parent
e9b806aeb8
commit
6aa6881f0b
18
gtm2.py
18
gtm2.py
|
|
@ -542,7 +542,10 @@ def handle_keyboard_input(key, state):
|
||||||
# --- Main Application ---
|
# --- Main Application ---
|
||||||
|
|
||||||
def main(stdscr, filename, show_diff, show_add, show_del, mouse):
|
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.keypad(True)
|
||||||
stdscr.timeout(50) # Less aggressive timeout (50ms instead of 10ms)
|
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:
|
if state.enable_mouse:
|
||||||
curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
|
curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
|
||||||
# Enable mouse motion events for better drag tracking
|
# 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()
|
state.load_commit_content()
|
||||||
|
|
||||||
|
|
@ -586,11 +592,17 @@ def main(stdscr, filename, show_diff, show_add, show_del, mouse):
|
||||||
draw_ui(stdscr, state)
|
draw_ui(stdscr, state)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Prevent crashes by catching exceptions
|
# Prevent crashes by catching exceptions
|
||||||
|
# Uncomment for debugging:
|
||||||
|
# with open("/tmp/gtm_error.log", "a") as f:
|
||||||
|
# f.write(f"{str(e)}\n")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Disable mouse motion events when exiting
|
# Disable mouse motion events when exiting
|
||||||
if state.enable_mouse:
|
if state.enable_mouse:
|
||||||
print("\033[?1003l", end="", flush=True)
|
try:
|
||||||
|
print("\033[?1003l", end="", flush=True)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description="A \"Git Time Machine\" for viewing file history")
|
parser = argparse.ArgumentParser(description="A \"Git Time Machine\" for viewing file history")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue