From 7f34cd86eb4c0d649042a1b5127bee90447b8e4e Mon Sep 17 00:00:00 2001 From: "n loewen (aider)" Date: Sun, 8 Jun 2025 00:38:04 +0100 Subject: [PATCH] fix: Prevent terminal-specific mouse handling crash for nsterm --- gtm2.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/gtm2.py b/gtm2.py index 150abf8..abeaba4 100755 --- a/gtm2.py +++ b/gtm2.py @@ -649,10 +649,12 @@ 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 - try: - print("\033[?1003h", end="", flush=True) - except: - pass + # This escape code is not supported by all terminals (e.g., nsterm) + if os.environ.get("TERM") != "nsterm": + try: + print("\033[?1003h", end="", flush=True) + except Exception: + pass 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 if state.enable_mouse: - try: - print("\033[?1003l", end="", flush=True) - except: - pass + # This escape code is not supported by all terminals (e.g., nsterm) + if os.environ.get("TERM") != "nsterm": + try: + print("\033[?1003l", end="", flush=True) + except Exception: + pass if __name__ == "__main__": parser = argparse.ArgumentParser(description="A \"Git Time Machine\" for viewing file history")