feat: Add new status bar below existing panes with commit message

This commit is contained in:
n loewen (aider) 2025-06-07 23:30:20 +01:00
parent 7db93d4af3
commit 4053001591
1 changed files with 49 additions and 30 deletions

79
gtm2.py
View File

@ -205,10 +205,10 @@ class AppState:
def draw_left_pane(stdscr, state):
if state.selected_commit_idx < state.left_scroll_offset:
state.left_scroll_offset = state.selected_commit_idx
elif state.selected_commit_idx >= state.left_scroll_offset + state.height - 1:
state.left_scroll_offset = state.selected_commit_idx - (state.height - 2)
elif state.selected_commit_idx >= state.left_scroll_offset + state.height - 2:
state.left_scroll_offset = state.selected_commit_idx - (state.height - 3)
visible_commits = state.commits[state.left_scroll_offset:state.left_scroll_offset + state.height - 1]
visible_commits = state.commits[state.left_scroll_offset:state.left_scroll_offset + state.height - 2]
for i, line in enumerate(visible_commits):
display_index = i + state.left_scroll_offset
if display_index == state.selected_commit_idx:
@ -220,10 +220,10 @@ def draw_left_pane(stdscr, state):
def draw_right_pane(stdscr, state):
right_width = state.width - state.divider_col - 3
max_scroll = max(0, len(state.file_lines) - (state.height - 1))
max_scroll = max(0, len(state.file_lines) - (state.height - 2))
state.right_scroll_offset = min(state.right_scroll_offset, max_scroll)
visible_lines = state.file_lines[state.right_scroll_offset:state.right_scroll_offset + state.height - 1]
visible_lines = state.file_lines[state.right_scroll_offset:state.right_scroll_offset + state.height - 2]
display_lines = []
deleted_line_map = {}
@ -250,7 +250,7 @@ def draw_right_pane(stdscr, state):
display_row = 0
for line_info in display_lines:
if display_row >= state.height - 1:
if display_row >= state.height - 2:
break
line_type = line_info['type']
@ -274,7 +274,7 @@ def draw_right_pane(stdscr, state):
def draw_divider(stdscr, state):
divider_char = "" if state.dragging_divider else ""
for y in range(state.height):
for y in range(state.height - 1): # Don't draw through the commit message bar
try:
stdscr.addch(y, state.divider_col, divider_char)
except curses.error:
@ -326,7 +326,8 @@ def draw_selection(stdscr, state):
pass
def draw_status_bars(stdscr, state):
visible_height = state.height - 1
# We'll use height-2 for the original status bars and height-1 for the commit message bar
visible_height = state.height - 2
# Get commit message for the selected commit
commit_message = ""
@ -359,20 +360,54 @@ def draw_status_bars(stdscr, state):
mouse_status += " SEL"
left_status += mouse_status
# Draw full-width status bar with commit message
status_attr = curses.color_pair(5) # New color pair for status bar
# Draw original status bars for left and right panes
left_attr = curses.color_pair(1) if state.focus == "left" else curses.color_pair(2)
right_attr = curses.color_pair(1) if state.focus == "right" else curses.color_pair(2)
# Fill the status bar with spaces, avoiding the last character position
# which can cause curses errors on some terminals
# Fill the original status bar with spaces
for x in range(state.divider_col):
try:
stdscr.addch(state.height - 2, x, ' ', left_attr)
except curses.error:
pass
for x in range(state.divider_col + 1, state.width - 1):
try:
stdscr.addch(state.height - 2, x, ' ', right_attr)
except curses.error:
pass
# Add percentage indicators on left and right sides of original status bar
try:
stdscr.addstr(state.height - 2, 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 - 2, right_x, right_status, right_attr)
except curses.error:
pass
# Draw divider in status bar
try:
stdscr.addch(state.height - 2, state.divider_col, "")
except curses.error:
pass
# Draw new full-width status bar with commit message below the original status bars
status_attr = curses.color_pair(5) # Color pair for commit message bar
# Fill the commit message bar with spaces
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
# Add commit message centered in the commit message bar
if commit_message:
max_msg_width = state.width - 20 # Leave space for percentages
max_msg_width = state.width - 4 # Leave a small margin
if len(commit_message) > max_msg_width:
commit_message = commit_message[:max_msg_width-3] + "..."
@ -381,22 +416,6 @@ def draw_status_bars(stdscr, state):
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)
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()