Skip to content

Commit 19e7117

Browse files
committed
fix(tui): add arrow and behind count for branches behind main
show an arrow pointing up to the commit and a (-N) indicator showing how many commits behind main the branch is.
1 parent 39a1833 commit 19e7117

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

src/tui/app.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub struct BranchAtCommit {
4747
pub name: String,
4848
/// position in main_track (0 = oldest shown, higher = newer)
4949
pub position: usize,
50+
/// number of commits behind main
51+
pub behind: usize,
5052
}
5153

5254
/// Git graph data for visualization.
@@ -419,9 +421,14 @@ impl App {
419421
})
420422
.unwrap_or(0);
421423

424+
// count how many commits behind main
425+
let behind =
426+
crate::git::commit_count(&wt.path, "HEAD", &main_branch_name).unwrap_or(0);
427+
422428
labels_behind.push(BranchAtCommit {
423429
name: branch_name.clone(),
424430
position,
431+
behind,
425432
});
426433
}
427434
} else {

src/tui/ui.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -961,20 +961,37 @@ fn draw_git_graph(f: &mut Frame, area: Rect, app: &App) {
961961
lines.push(Line::from(main_spans));
962962

963963
// render behind branch labels below main track at their positions
964+
// show arrow pointing up to the commit and (-N) indicator
964965
if !graph.labels_behind.is_empty() {
965-
let mut behind_str = String::new();
966+
// first line: arrows pointing up to the commits
967+
let mut arrow_str = String::new();
966968
for label in &graph.labels_behind {
967-
// position label under its commit
968-
// position is in oldest-first indexing (0 = leftmost)
969969
let offset = label.position * chars_per_commit;
970-
while behind_str.len() < offset {
971-
behind_str.push(' ');
970+
while arrow_str.len() < offset {
971+
arrow_str.push(' ');
972972
}
973-
behind_str.push_str(&label.name);
974-
behind_str.push(' ');
973+
arrow_str.push('↑');
975974
}
976975
lines.push(Line::from(Span::styled(
977-
behind_str,
976+
arrow_str,
977+
Style::default().fg(Color::Yellow),
978+
)));
979+
980+
// second line: branch names with behind count
981+
let mut label_str = String::new();
982+
for label in &graph.labels_behind {
983+
let offset = label.position * chars_per_commit;
984+
// try to center the label under the arrow
985+
let label_text = format!("{} (-{})", label.name, label.behind);
986+
let label_start = offset.saturating_sub(label_text.len() / 2);
987+
while label_str.len() < label_start {
988+
label_str.push(' ');
989+
}
990+
label_str.push_str(&label_text);
991+
label_str.push(' ');
992+
}
993+
lines.push(Line::from(Span::styled(
994+
label_str,
978995
Style::default().fg(Color::Yellow),
979996
)));
980997
}

0 commit comments

Comments
 (0)