Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat(list): Align arrow columns for consistent display

Maximilian Roos7570f22b0ef6
diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rs
index e8e9e3cc4..e3f657c79 100644
--- a/src/commands/list/layout.rs
+++ b/src/commands/list/layout.rs
@@ -31,12 +31,14 @@ fn try_allocate(
ideal_width // Return just the column width
}
-/// Width information for diff columns (e.g., "+128 -147")
+/// Width information for two-part columns: diffs ("+128 -147") and arrows ("↑6 ↓1")
+/// - For diff columns: added_digits/deleted_digits refer to line change counts
+/// - For arrow columns: added_digits/deleted_digits refer to ahead/behind commit counts
#[derive(Clone, Copy, Debug)]
pub struct DiffWidths {
pub total: usize,
- pub added_digits: usize,
- pub deleted_digits: usize,
+ pub added_digits: usize, // First part: + for diffs, ↑ for arrows
+ pub deleted_digits: usize, // Second part: - for diffs, ↓ for arrows
}
impl DiffWidths {
diff --git a/src/commands/list/render.rs b/src/commands/list/render.rs
index 80e8b88a5..af3cff413 100644
--- a/src/commands/list/render.rs
+++ b/src/commands/list/render.rs
@@ -579,4 +579,40 @@ mod tests {
"Unicode and ASCII branches should pad to same visual width"
);
}
+
+ #[test]
+ fn test_arrow_column_alignment_invariant() {
+ // Test that arrow columns maintain consistent width regardless of values
+ // This ensures down arrows always appear at the same horizontal position
+ use super::super::layout::DiffWidths;
+ use super::format_arrow_column;
+ use worktrunk::styling::{ADDITION, DELETION};
+
+ let widths = DiffWidths {
+ total: 7, // "↑99 ↓99" = 1+2+1+1+2 = 7
+ added_digits: 2,
+ deleted_digits: 2,
+ };
+
+ let dim_deletion = DELETION.dimmed();
+
+ // All these cases should produce identical width (vertical alignment)
+ let test_cases = vec![
+ (0, 0, "both zero"),
+ (1, 0, "only ahead"),
+ (0, 1, "only behind"),
+ (1, 1, "both single digit"),
+ (99, 99, "both max digits"),
+ (5, 44, "mixed digits"),
+ ];
+
+ for (ahead, behind, description) in test_cases {
+ let result = format_arrow_column(ahead, behind, &widths, ADDITION, dim_deletion);
+ assert_eq!(
+ result.width(),
+ 7,
+ "Arrow column ({ahead}, {behind}) [{description}] should always be width 7"
+ );
+ }
+ }
}