refactor: Improve commit details display with author name truncation

This commit is contained in:
n loewen (aider) 2025-06-08 09:29:34 +01:00
parent dcf892a8ea
commit 50e4401399
1 changed files with 22 additions and 16 deletions

36
gtm
View File

@ -26,8 +26,8 @@ def get_commits(filename):
def get_commit_details(commit_hash):
"""Get detailed information about a specific commit."""
# Get commit author
author_cmd = ['git', 'show', '-s', '--format=%an <%ae>', commit_hash]
# Get commit author (name only, no email)
author_cmd = ['git', 'show', '-s', '--format=%an', commit_hash]
author_result = subprocess.run(author_cmd, capture_output=True, text=True)
author = author_result.stdout.strip()
@ -938,25 +938,31 @@ def draw_commit_details(stdscr, state: AppState, layout: StatusBarLayout):
commit_info = f" {state.commit_hash} "
stdscr.addstr(second_line, 0, commit_info, curses.A_REVERSE | curses.A_BOLD)
# Draw the author and branch on the right
# Calculate the author and branch info, ensuring it always fits
author_branch_info = f" {state.commit_author} [{state.commit_branch}] "
# Reserve space for author/branch info and ensure it fits
min_author_space = 20 # Minimum space to reserve for author info
max_author_width = max(min_author_space, len(author_branch_info))
# If the author info is too long, truncate it but keep the branch
if len(author_branch_info) > layout.screen_width // 3: # Don't let it take more than 1/3 of screen
max_author_name_width = (layout.screen_width // 3) - len(f" [{state.commit_branch}] ")
if max_author_name_width > 5: # Only truncate if we have reasonable space
truncated_author = state.commit_author[:max_author_name_width-3] + "..."
author_branch_info = f" {truncated_author} [{state.commit_branch}] "
# Calculate positions
right_x = layout.screen_width - len(author_branch_info)
if right_x >= len(commit_info) and right_x >= 0:
# Always draw the author/branch info (it should fit now)
if right_x >= len(commit_info):
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
pass
# Draw the first line of the commit message in between
# Only draw if we have space and the author info was successfully placed
if right_x >= len(commit_info):
# Draw the commit message in the remaining space
available_width = right_x - len(commit_info) - 1
first_line = message_lines[0] if message_lines else ""
if available_width > 0: