refactor: Simplify warning message drawing and error handling in curses

This commit is contained in:
n loewen 2025-06-08 16:38:47 +01:00 committed by n loewen (aider)
parent 6b84f1fc2b
commit 3b01821ed4
1 changed files with 15 additions and 21 deletions

36
gtm
View File

@ -911,27 +911,21 @@ def draw_warning_message(stdscr, state: AppState, layout: StatusBarLayout):
if not state.warning_message: if not state.warning_message:
return return
try: # Initialize color pair for warning if not already done
# Initialize color pair for warning if not already done if curses.has_colors():
if curses.has_colors(): curses.init_pair(8, curses.COLOR_RED, -1) # Red text on default background
try:
curses.init_pair(8, curses.COLOR_RED, -1) # Red text on default background # Use red text with bold for warning
except: warning_attr = curses.color_pair(8) | curses.A_BOLD
pass # Silently fail if we can't set the color
# Draw the warning message and dismiss instruction all in red
# Use red text with bold for warning warning_text = f" WARNING: {state.warning_message} "
warning_attr = curses.color_pair(8) | curses.A_BOLD stdscr.addstr(layout.main_status_y, 0, warning_text, warning_attr)
# Draw the warning message and dismiss instruction all in red # Add instruction to dismiss, also in red
warning_text = f" WARNING: {state.warning_message} " dismiss_text = " (Press any key to dismiss) "
stdscr.addstr(layout.main_status_y, 0, warning_text, warning_attr) if len(warning_text) + len(dismiss_text) < layout.screen_width:
stdscr.addstr(layout.main_status_y, len(warning_text), dismiss_text, warning_attr)
# Add instruction to dismiss, also in red
dismiss_text = " (Press any key to dismiss) "
if len(warning_text) + len(dismiss_text) < layout.screen_width:
stdscr.addstr(layout.main_status_y, len(warning_text), dismiss_text, warning_attr)
except curses.error:
pass # Silently fail if we can't draw the warning
def draw_main_status_line(stdscr, state: AppState, layout: StatusBarLayout): def draw_main_status_line(stdscr, state: AppState, layout: StatusBarLayout):
"""Draw the main status line (percentages, indicators, etc.)""" """Draw the main status line (percentages, indicators, etc.)"""