refactor: Merge status bars into single white-on-black bar with scroll percentages and commit message
This commit is contained in:
parent
022b27474f
commit
e6249a29e6
116
gtm2.py
116
gtm2.py
|
|
@ -215,10 +215,10 @@ 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 - 2:
|
||||
state.left_scroll_offset = state.selected_commit_idx - (state.height - 3)
|
||||
elif state.selected_commit_idx >= state.left_scroll_offset + state.height - 1:
|
||||
state.left_scroll_offset = state.selected_commit_idx - (state.height - 2)
|
||||
|
||||
visible_commits = state.commits[state.left_scroll_offset:state.left_scroll_offset + state.height - 2]
|
||||
visible_commits = state.commits[state.left_scroll_offset:state.left_scroll_offset + state.height - 1]
|
||||
for i, line in enumerate(visible_commits):
|
||||
display_index = i + state.left_scroll_offset
|
||||
if display_index == state.selected_commit_idx:
|
||||
|
|
@ -232,10 +232,10 @@ def draw_right_pane(stdscr, state):
|
|||
right_start = 0 if not state.show_sidebar else state.divider_col + 2
|
||||
right_width = state.width - right_start - 1
|
||||
|
||||
max_scroll = max(0, len(state.file_lines) - (state.height - 2))
|
||||
max_scroll = max(0, len(state.file_lines) - (state.height - 1))
|
||||
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 - 2]
|
||||
visible_lines = state.file_lines[state.right_scroll_offset:state.right_scroll_offset + state.height - 1]
|
||||
|
||||
display_lines = []
|
||||
deleted_line_map = {}
|
||||
|
|
@ -289,7 +289,7 @@ def draw_divider(stdscr, state):
|
|||
return
|
||||
|
||||
divider_char = "║" if state.dragging_divider else "│"
|
||||
for y in range(state.height - 1): # Don't draw through the commit message bar
|
||||
for y in range(state.height - 1): # Don't draw through the status bar
|
||||
try:
|
||||
stdscr.addch(y, state.divider_col, divider_char)
|
||||
except curses.error:
|
||||
|
|
@ -347,8 +347,8 @@ def draw_selection(stdscr, state):
|
|||
pass
|
||||
|
||||
def draw_status_bars(stdscr, state):
|
||||
# We'll use height-2 for the original status bars and height-1 for the commit message bar
|
||||
visible_height = state.height - 2
|
||||
# We'll use height-1 for the single status bar
|
||||
visible_height = state.height - 1
|
||||
|
||||
# Get commit message for the selected commit
|
||||
commit_message = ""
|
||||
|
|
@ -369,59 +369,47 @@ def draw_status_bars(stdscr, state):
|
|||
right_percent = 0
|
||||
right_status = f"{right_percent}%"
|
||||
|
||||
if len(state.commits) > 0:
|
||||
if len(state.commits) > 0 and state.show_sidebar:
|
||||
last_visible_commit = state.left_scroll_offset + visible_height
|
||||
left_percent = int((last_visible_commit / len(state.commits)) * 100)
|
||||
left_percent = 100 if last_visible_commit >= len(state.commits) else left_percent
|
||||
else:
|
||||
left_percent = 0
|
||||
left_status = f"{left_percent}%"
|
||||
if state.enable_mouse:
|
||||
mouse_status = f" [M] {state.mouse_x},{state.mouse_y} b:{state.last_bstate}"
|
||||
if state.dragging_divider:
|
||||
mouse_status += " DIV"
|
||||
elif state.is_selecting:
|
||||
mouse_status += " SEL"
|
||||
left_status += mouse_status
|
||||
|
||||
# Draw original status bars for left and right panes
|
||||
# Both active and inactive panes now use their respective color pairs
|
||||
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)
|
||||
# Use white on black for the status bar
|
||||
status_attr = curses.color_pair(2) # white on black
|
||||
|
||||
if state.show_sidebar:
|
||||
# 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
|
||||
|
||||
# Add percentage indicators on left side of original status bar
|
||||
try:
|
||||
stdscr.addstr(state.height - 2, 1, left_status, left_attr)
|
||||
except curses.error:
|
||||
pass
|
||||
|
||||
# Draw divider in status bar with left and right colors
|
||||
try:
|
||||
# Use the half block character "▐" which can show both colors
|
||||
# First draw with left side color
|
||||
stdscr.addch(state.height - 2, state.divider_col, "▐", left_attr)
|
||||
except curses.error:
|
||||
pass
|
||||
|
||||
# Fill right side of status bar
|
||||
for x in range(state.divider_col + 1, state.width - 1):
|
||||
try:
|
||||
stdscr.addch(state.height - 2, x, ' ', right_attr)
|
||||
except curses.error:
|
||||
pass
|
||||
else:
|
||||
# When sidebar is hidden, fill the entire status bar with right pane color
|
||||
# Fill the status bar with spaces
|
||||
for x in range(state.width - 1):
|
||||
try:
|
||||
stdscr.addch(state.height - 2, x, ' ', right_attr)
|
||||
stdscr.addch(state.height - 1, x, ' ', status_attr)
|
||||
except curses.error:
|
||||
pass
|
||||
|
||||
# Add left percentage indicator (only if sidebar is visible)
|
||||
if state.show_sidebar:
|
||||
try:
|
||||
stdscr.addstr(state.height - 1, 1, left_status, status_attr)
|
||||
except curses.error:
|
||||
pass
|
||||
|
||||
# Add commit message in the middle
|
||||
if commit_message:
|
||||
# Calculate available space
|
||||
left_margin = len(left_status) + 3 if state.show_sidebar else 1
|
||||
right_margin = len(right_status) + 1
|
||||
available_width = state.width - left_margin - right_margin
|
||||
|
||||
# Truncate message if needed
|
||||
if len(commit_message) > available_width:
|
||||
commit_message = commit_message[:available_width-3] + "..."
|
||||
|
||||
# Center the message in the available space
|
||||
message_x = left_margin
|
||||
|
||||
try:
|
||||
stdscr.addstr(state.height - 1, message_x, commit_message, status_attr)
|
||||
except curses.error:
|
||||
pass
|
||||
|
||||
|
|
@ -429,28 +417,7 @@ def draw_status_bars(stdscr, state):
|
|||
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 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 in the commit message bar
|
||||
if commit_message:
|
||||
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] + "..."
|
||||
|
||||
try:
|
||||
stdscr.addstr(state.height - 1, 1, commit_message, status_attr)
|
||||
stdscr.addstr(state.height - 1, right_x, right_status, status_attr)
|
||||
except curses.error:
|
||||
pass
|
||||
|
||||
|
|
@ -582,7 +549,7 @@ def handle_mouse_input(stdscr, state):
|
|||
state.focus = "right" # When sidebar is hidden, focus is always right
|
||||
|
||||
# If clicking in the left pane on a commit entry, select that commit
|
||||
if state.show_sidebar and mx < state.divider_col and my < len(state.commits) - state.left_scroll_offset:
|
||||
if state.show_sidebar and mx < state.divider_col and my < min(state.height - 1, len(state.commits) - state.left_scroll_offset):
|
||||
new_commit_idx = my + state.left_scroll_offset
|
||||
if 0 <= new_commit_idx < len(state.commits):
|
||||
state.selected_commit_idx = new_commit_idx
|
||||
|
|
@ -668,7 +635,6 @@ def main(stdscr, filename, show_diff, show_add, show_del, mouse):
|
|||
curses.init_pair(2, curses.COLOR_WHITE, 0) # Inactive pane: white on black
|
||||
curses.init_pair(3, curses.COLOR_GREEN, -1)
|
||||
curses.init_pair(4, curses.COLOR_RED, -1)
|
||||
curses.init_pair(5, curses.COLOR_BLACK, 7) # Status bar color (white background)
|
||||
|
||||
height, width = stdscr.getmaxyx()
|
||||
state = AppState(filename, width, height, show_diff, show_add, show_del, mouse)
|
||||
|
|
|
|||
Loading…
Reference in New Issue