refactor: Improve terminal type support detection using curses setupterm

This commit is contained in:
n loewen (aider) 2025-06-08 16:38:51 +01:00
parent 3b01821ed4
commit dea1a46759
1 changed files with 13 additions and 3 deletions

16
gtm
View File

@ -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"