From 3b01821ed4a6e7cf587a49ce5909730ca8e528df Mon Sep 17 00:00:00 2001 From: n loewen Date: Sun, 8 Jun 2025 16:38:47 +0100 Subject: [PATCH] refactor: Simplify warning message drawing and error handling in curses --- gtm | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/gtm b/gtm index 8850faf..74b393f 100755 --- a/gtm +++ b/gtm @@ -911,27 +911,21 @@ def draw_warning_message(stdscr, state: AppState, layout: StatusBarLayout): if not state.warning_message: return - try: - # Initialize color pair for warning if not already done - if curses.has_colors(): - try: - curses.init_pair(8, curses.COLOR_RED, -1) # Red text on default background - except: - pass # Silently fail if we can't set the color - - # Use red text with bold for warning - warning_attr = curses.color_pair(8) | curses.A_BOLD - - # Draw the warning message and dismiss instruction all in red - warning_text = f" WARNING: {state.warning_message} " - stdscr.addstr(layout.main_status_y, 0, warning_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 + # Initialize color pair for warning if not already done + if curses.has_colors(): + curses.init_pair(8, curses.COLOR_RED, -1) # Red text on default background + + # Use red text with bold for warning + warning_attr = curses.color_pair(8) | curses.A_BOLD + + # Draw the warning message and dismiss instruction all in red + warning_text = f" WARNING: {state.warning_message} " + stdscr.addstr(layout.main_status_y, 0, warning_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) def draw_main_status_line(stdscr, state: AppState, layout: StatusBarLayout): """Draw the main status line (percentages, indicators, etc.)"""