From 7db93d4af36bc9ea8f1c143a4269177a9137fd8e Mon Sep 17 00:00:00 2001 From: "n loewen (aider)" Date: Sat, 7 Jun 2025 23:28:53 +0100 Subject: [PATCH] fix: Handle curses drawing errors in status bar rendering --- gtm2.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/gtm2.py b/gtm2.py index d277561..69ec260 100755 --- a/gtm2.py +++ b/gtm2.py @@ -361,8 +361,14 @@ def draw_status_bars(stdscr, state): # Draw full-width status bar with commit message status_attr = curses.color_pair(5) # New color pair for status bar - for x in range(state.width): - stdscr.addch(state.height - 1, x, ' ', status_attr) + + # Fill the status bar with spaces, avoiding the last character position + # which can cause curses errors on some terminals + for x in range(state.width - 1): + try: + stdscr.addch(state.height - 1, x, ' ', status_attr) + except curses.error: + pass # Add commit message centered in status bar if commit_message: @@ -371,14 +377,26 @@ def draw_status_bars(stdscr, state): commit_message = commit_message[:max_msg_width-3] + "..." msg_x = (state.width - len(commit_message)) // 2 - stdscr.addstr(state.height - 1, msg_x, commit_message, status_attr) + try: + stdscr.addstr(state.height - 1, msg_x, commit_message, status_attr) + except curses.error: + pass # Add percentage indicators on left and right sides left_attr = status_attr | (curses.A_REVERSE if state.focus == "left" else 0) right_attr = status_attr | (curses.A_REVERSE if state.focus == "right" else 0) - stdscr.addstr(state.height - 1, 1, left_status, left_attr) - stdscr.addstr(state.height - 1, state.width - len(right_status) - 1, right_status, right_attr) + try: + stdscr.addstr(state.height - 1, 1, left_status, left_attr) + except curses.error: + pass + + try: + right_x = state.width - len(right_status) - 1 + if right_x >= 0: + stdscr.addstr(state.height - 1, right_x, right_status, right_attr) + except curses.error: + pass def draw_ui(stdscr, state): stdscr.erase()