fix: Prevent terminal-specific mouse handling crash for nsterm

This commit is contained in:
n loewen (aider) 2025-06-08 00:38:04 +01:00
parent 96f7b80226
commit 7f34cd86eb
1 changed files with 12 additions and 8 deletions

20
gtm2.py
View File

@ -649,10 +649,12 @@ 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
try: # This escape code is not supported by all terminals (e.g., nsterm)
print("\033[?1003h", end="", flush=True) if os.environ.get("TERM") != "nsterm":
except: try:
pass print("\033[?1003h", end="", flush=True)
except Exception:
pass
state.load_commit_content() state.load_commit_content()
@ -686,10 +688,12 @@ def main(stdscr, filename, show_diff, show_add, show_del, mouse):
# Disable mouse motion events when exiting # Disable mouse motion events when exiting
if state.enable_mouse: if state.enable_mouse:
try: # This escape code is not supported by all terminals (e.g., nsterm)
print("\033[?1003l", end="", flush=True) if os.environ.get("TERM") != "nsterm":
except: try:
pass print("\033[?1003l", end="", flush=True)
except Exception:
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")