fix: Add bounds checking and error handling for curses drawing
This commit is contained in:
parent
328f0de01d
commit
dcf892a8ea
30
gtm
30
gtm
|
|
@ -941,15 +941,31 @@ def draw_commit_details(stdscr, state: AppState, layout: StatusBarLayout):
|
|||
# Draw the author and branch on the right
|
||||
author_branch_info = f" {state.commit_author} [{state.commit_branch}] "
|
||||
right_x = layout.screen_width - len(author_branch_info)
|
||||
if right_x >= 0:
|
||||
stdscr.addstr(second_line, right_x, author_branch_info, curses.A_REVERSE)
|
||||
if right_x >= len(commit_info) and right_x >= 0:
|
||||
try:
|
||||
stdscr.addstr(second_line, right_x, author_branch_info, curses.A_REVERSE)
|
||||
except curses.error:
|
||||
# If it still fails, truncate the author info to fit
|
||||
max_author_width = layout.screen_width - len(commit_info) - 4 # Leave some margin
|
||||
if max_author_width > 10: # Only show if we have reasonable space
|
||||
truncated_info = f" {state.commit_author[:max_author_width-10]}... "
|
||||
try:
|
||||
stdscr.addstr(second_line, layout.screen_width - len(truncated_info), truncated_info, curses.A_REVERSE)
|
||||
except curses.error:
|
||||
pass # Give up if we still can't fit it
|
||||
|
||||
# Draw the first line of the commit message in between
|
||||
available_width = layout.screen_width - len(commit_info) - len(author_branch_info) - 1
|
||||
first_line = message_lines[0] if message_lines else ""
|
||||
if len(first_line) > available_width:
|
||||
first_line = first_line[:available_width-3] + "..."
|
||||
stdscr.addstr(second_line, len(commit_info), first_line, curses.A_REVERSE)
|
||||
# Only draw if we have space and the author info was successfully placed
|
||||
if right_x >= len(commit_info):
|
||||
available_width = right_x - len(commit_info) - 1
|
||||
first_line = message_lines[0] if message_lines else ""
|
||||
if available_width > 0:
|
||||
if len(first_line) > available_width:
|
||||
first_line = first_line[:available_width-3] + "..."
|
||||
try:
|
||||
stdscr.addstr(second_line, len(commit_info), first_line, curses.A_REVERSE)
|
||||
except curses.error:
|
||||
pass # Silently fail if we can't draw the message
|
||||
|
||||
# Draw additional lines of the commit message if we have more space
|
||||
for i, line in enumerate(message_lines[1:], 1):
|
||||
|
|
|
|||
Loading…
Reference in New Issue