refactor: Improve commit details display with author name truncation
This commit is contained in:
parent
dcf892a8ea
commit
50e4401399
38
gtm
38
gtm
|
|
@ -26,8 +26,8 @@ def get_commits(filename):
|
||||||
|
|
||||||
def get_commit_details(commit_hash):
|
def get_commit_details(commit_hash):
|
||||||
"""Get detailed information about a specific commit."""
|
"""Get detailed information about a specific commit."""
|
||||||
# Get commit author
|
# Get commit author (name only, no email)
|
||||||
author_cmd = ['git', 'show', '-s', '--format=%an <%ae>', commit_hash]
|
author_cmd = ['git', 'show', '-s', '--format=%an', commit_hash]
|
||||||
author_result = subprocess.run(author_cmd, capture_output=True, text=True)
|
author_result = subprocess.run(author_cmd, capture_output=True, text=True)
|
||||||
author = author_result.stdout.strip()
|
author = author_result.stdout.strip()
|
||||||
|
|
||||||
|
|
@ -938,25 +938,31 @@ def draw_commit_details(stdscr, state: AppState, layout: StatusBarLayout):
|
||||||
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
|
# Calculate the author and branch info, ensuring it always fits
|
||||||
author_branch_info = f" {state.commit_author} [{state.commit_branch}] "
|
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)
|
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:
|
try:
|
||||||
stdscr.addstr(second_line, right_x, author_branch_info, curses.A_REVERSE)
|
stdscr.addstr(second_line, right_x, author_branch_info, curses.A_REVERSE)
|
||||||
except curses.error:
|
except curses.error:
|
||||||
# If it still fails, truncate the author info to fit
|
pass
|
||||||
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
|
# Draw the commit message in the remaining 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
|
|
||||||
# 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
|
available_width = right_x - len(commit_info) - 1
|
||||||
first_line = message_lines[0] if message_lines else ""
|
first_line = message_lines[0] if message_lines else ""
|
||||||
if available_width > 0:
|
if available_width > 0:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue