refactor: Simplify commit details drawing by removing unnecessary try-except block

This commit is contained in:
n loewen 2025-06-08 09:26:52 +01:00 committed by n loewen (aider)
parent ecb59fa6c4
commit 328f0de01d
1 changed files with 31 additions and 34 deletions

57
gtm
View File

@ -931,41 +931,38 @@ def draw_commit_details(stdscr, state: AppState, layout: StatusBarLayout):
if not message_lines: if not message_lines:
message_lines = [""] message_lines = [""]
try: # Draw on the second line of the status bar (layout.commit_detail_start_y)
# Draw on the second line of the status bar (layout.commit_detail_start_y) second_line = layout.commit_detail_start_y
second_line = layout.commit_detail_start_y
# Draw the commit hash with bold at the start # Draw the commit hash with bold at the start
commit_info = f" {state.commit_hash} " commit_info = f" {state.commit_hash} "
stdscr.addstr(second_line, 0, commit_info, curses.A_REVERSE | curses.A_BOLD) stdscr.addstr(second_line, 0, commit_info, curses.A_REVERSE | curses.A_BOLD)
# Draw the author and branch on the right # Draw the author and branch on the right
author_branch_info = f" {state.commit_author} [{state.commit_branch}] " author_branch_info = f" {state.commit_author} [{state.commit_branch}] "
right_x = layout.screen_width - len(author_branch_info) right_x = layout.screen_width - len(author_branch_info)
if right_x >= 0: if right_x >= 0:
stdscr.addstr(second_line, right_x, author_branch_info, curses.A_REVERSE) stdscr.addstr(second_line, right_x, author_branch_info, curses.A_REVERSE)
# Draw the first line of the commit message in between # Draw the first line of the commit message in between
available_width = layout.screen_width - len(commit_info) - len(author_branch_info) - 1 available_width = layout.screen_width - len(commit_info) - len(author_branch_info) - 1
first_line = message_lines[0] if message_lines else "" first_line = message_lines[0] if message_lines else ""
if len(first_line) > available_width: if len(first_line) > available_width:
first_line = first_line[:available_width-3] + "..." first_line = first_line[:available_width-3] + "..."
stdscr.addstr(second_line, len(commit_info), first_line, curses.A_REVERSE) stdscr.addstr(second_line, len(commit_info), first_line, curses.A_REVERSE)
# Draw additional lines of the commit message if we have more space # Draw additional lines of the commit message if we have more space
for i, line in enumerate(message_lines[1:], 1): for i, line in enumerate(message_lines[1:], 1):
line_y = layout.commit_detail_start_y + i line_y = layout.commit_detail_start_y + i
if line_y >= layout.start_y + layout.total_height: if line_y >= layout.start_y + layout.total_height:
break # No more space break # No more space
# For continuation lines, indent them # For continuation lines, indent them
line_available_width = layout.screen_width - 4 # Leave some margin line_available_width = layout.screen_width - 4 # Leave some margin
if len(line) > line_available_width: if len(line) > line_available_width:
line = line[:line_available_width-3] + "..." line = line[:line_available_width-3] + "..."
stdscr.addstr(line_y, 4, line, curses.A_REVERSE) stdscr.addstr(line_y, 4, line, curses.A_REVERSE)
except curses.error:
pass
def draw_search_mode(stdscr, state: AppState, layout: StatusBarLayout): def draw_search_mode(stdscr, state: AppState, layout: StatusBarLayout):
"""Draw search input interface""" """Draw search input interface"""
@ -1206,7 +1203,7 @@ def handle_mouse_input(stdscr, state: AppState) -> AppState:
# or very close to the same position (within 1-2 pixels) # or very close to the same position (within 1-2 pixels)
if (state.click_position and if (state.click_position and
abs(state.click_position[0] - mx) <= 2 and abs(state.click_position[0] - mx) <= 2 and
abs(state.click_position[1] - my) <= 2): abs(state.click_position[1] - my) <= 2): # TODO don't do this <= 2 thing
# This was a click, so switch panes (only if sidebar is visible) # This was a click, so switch panes (only if sidebar is visible)
focus = "right" focus = "right"
if state.show_sidebar: if state.show_sidebar: