From dea1a46759debe00c7e4503b0bd1122eb39aaf8b Mon Sep 17 00:00:00 2001 From: "n loewen (aider)" Date: Sun, 8 Jun 2025 16:38:51 +0100 Subject: [PATCH] refactor: Improve terminal type support detection using curses setupterm --- gtm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gtm b/gtm index 74b393f..c9cc132 100755 --- a/gtm +++ b/gtm @@ -1625,10 +1625,20 @@ def set_warning_message(state: AppState, message: str) -> AppState: """Set a warning message to be displayed in the status bar""" return replace(state, warning_message=message) +def is_terminal_supported(term_name): + """Check if a terminal type is supported by curses.""" + import _curses + try: + # Try to set up the terminal without actually initializing the screen + curses.setupterm(term=term_name, fd=-1) + return True + except _curses.error: + return False + if __name__ == "__main__": - # Set a fallback terminal type if the current one isn't recognized - original_term = os.environ.get("TERM") - if original_term in ["xterm-ghostty", "unknown"]: + # Check if current terminal is supported, use fallback if needed + original_term = os.environ.get("TERM", "") + if original_term and not is_terminal_supported(original_term): # We'll show this warning in the UI instead of console terminal_warning = f"Terminal type '{original_term}' not recognized. Using 'xterm-256color'." os.environ["TERM"] = "xterm-256color"