Skip to content

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

refactor: Use centralized COLUMN_SPECS registry for list columns

Maximilian Roos867e4c5e29c9
diff --git a/src/commands/list/columns.rs b/src/commands/list/columns.rs
index 49889da8e..cd135089c 100644
--- a/src/commands/list/columns.rs
+++ b/src/commands/list/columns.rs
@@ -1,5 +1,4 @@
/// Logical identifier for each column rendered by `wt list`.
-#[allow(dead_code)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ColumnKind {
Branch,
@@ -16,7 +15,6 @@ pub enum ColumnKind {
}
/// Differentiates between diff-style columns with plus/minus symbols and those with arrows.
-#[allow(dead_code)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DiffVariant {
Signs,
@@ -24,7 +22,6 @@ pub enum DiffVariant {
}
/// Static metadata describing a column's behavior in both layout and rendering.
-#[allow(dead_code)]
#[derive(Clone, Copy, Debug)]
pub struct ColumnSpec {
pub kind: ColumnKind,
@@ -56,7 +53,6 @@ impl ColumnSpec {
}
/// Static registry of all possible columns in display order.
-#[allow(dead_code)]
pub const COLUMN_SPECS: &[ColumnSpec] = &[
ColumnSpec::new(
ColumnKind::Branch,
diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rs
index b91c42256..2123573db 100644
--- a/src/commands/list/layout.rs
+++ b/src/commands/list/layout.rs
@@ -107,7 +107,10 @@ use crate::display::{find_common_prefix, get_terminal_width};
use std::path::{Path, PathBuf};
use unicode_width::UnicodeWidthStr;
-use super::model::ListItem;
+use super::{
+ columns::{COLUMN_SPECS, ColumnKind, ColumnSpec, DiffVariant},
+ model::ListItem,
+};
/// Width of short commit hash display (first 8 hex characters)
const COMMIT_HASH_WIDTH: usize = 8;
@@ -195,16 +198,6 @@ pub struct DiffWidths {
pub deleted_digits: usize, // Second part: - for diffs, ↓ for arrows
}
-impl DiffWidths {
- pub fn zero() -> Self {
- Self {
- total: 0,
- added_digits: 0,
- deleted_digits: 0,
- }
- }
-}
-
pub struct ColumnWidths {
pub branch: usize,
pub time: usize,
@@ -215,8 +208,6 @@ pub struct ColumnWidths {
pub branch_diff: DiffWidths,
pub upstream: DiffWidths,
pub states: usize,
- pub commit: usize,
- pub path: usize,
}
/// Tracks which columns have actual data (vs just headers)
@@ -230,64 +221,130 @@ pub struct ColumnDataFlags {
pub ci_status: bool,
}
-/// Column types for allocation
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-enum ColumnType {
- Branch,
- WorkingDiff,
- AheadBehind,
- BranchDiff,
- States,
- Path,
- Upstream,
- Time,
- CiStatus,
- Commit,
- Message,
+const EMPTY_PENALTY: u8 = 10;
+
+fn column_has_data(kind: ColumnKind, flags: &ColumnDataFlags) -> bool {
+ match kind {
+ ColumnKind::Branch => true,
+ ColumnKind::WorkingDiff => flags.working_diff,
+ ColumnKind::AheadBehind => flags.ahead_behind,
+ ColumnKind::BranchDiff => flags.branch_diff,
+ ColumnKind::States => flags.states,
+ ColumnKind::Path => true,
+ ColumnKind::Upstream => flags.upstream,
+ ColumnKind::Time => true,
+ ColumnKind::CiStatus => flags.ci_status,
+ ColumnKind::Commit => true,
+ ColumnKind::Message => true,
+ }
}
-/// Describes a column for priority-based allocation
-struct ColumnDescriptor {
- column_type: ColumnType,
- base_priority: u8,
- has_data: bool,
+#[derive(Clone, Copy, Debug)]
+pub struct DiffDigits {
+ pub added: usize,
+ pub deleted: usize,
}
-impl ColumnDescriptor {
- /// Calculate final priority: base_priority + empty_penalty
- fn priority(&self) -> u8 {
- const EMPTY_PENALTY: u8 = 10;
- if self.has_data {
- self.base_priority
- } else {
- self.base_priority + EMPTY_PENALTY
+impl From<DiffWidths> for DiffDigits {
+ fn from(widths: DiffWidths) -> Self {
+ Self {
+ added: widths.added_digits,
+ deleted: widths.deleted_digits,
}
}
}
-/// Absolute column positions for guaranteed alignment
#[derive(Clone, Copy, Debug)]
-pub struct ColumnPositions {
- pub branch: usize,
- pub working_diff: usize,
- pub ahead_behind: usize,
- pub branch_diff: usize,
- pub states: usize,
- pub path: usize,
- pub ci_status: usize,
- pub upstream: usize,
- pub time: usize,
- pub commit: usize,
- pub message: usize,
+pub enum ColumnFormat {
+ Text,
+ Diff {
+ digits: DiffDigits,
+ variant: DiffVariant,
+ },
+}
+
+#[derive(Clone, Debug)]
+pub struct ColumnLayout {
+ pub kind: ColumnKind,
+ pub header: &'static str,
+ pub start: usize,
+ pub width: usize,
+ pub format: ColumnFormat,
}
pub struct LayoutConfig {
- pub widths: ColumnWidths,
- pub positions: ColumnPositions,
+ pub columns: Vec<ColumnLayout>,
pub common_prefix: PathBuf,
pub max_message_len: usize,
}
+#[derive(Clone, Copy, Debug)]
+struct ColumnIdeal {
+ width: usize,
+ format: ColumnFormat,
+}
+
+impl ColumnIdeal {
+ fn text(width: usize) -> Option<Self> {
+ if width == 0 {
+ None
+ } else {
+ Some(Self {
+ width,
+ format: ColumnFormat::Text,
+ })
+ }
+ }
+
+ fn diff(widths: DiffWidths, variant: DiffVariant) -> Option<Self> {
+ if widths.total == 0 {
+ None
+ } else {
+ Some(Self {
+ width: widths.total,
+ format: ColumnFormat::Diff {
+ digits: widths.into(),
+ variant,
+ },
+ })
+ }
+ }
+}
+
+#[derive(Clone, Copy)]
+struct ColumnCandidate<'a> {
+ spec: &'a ColumnSpec,
+ priority: u8,
+}
+
+#[derive(Clone, Copy)]
+struct PendingColumn<'a> {
+ spec: &'a ColumnSpec,
+ width: usize,
+ format: ColumnFormat,
+}
+
+fn ideal_for_column(
+ spec: &ColumnSpec,
+ widths: &ColumnWidths,
+ max_path_width: usize,
+ commit_width: usize,
+) -> Option<ColumnIdeal> {
+ match spec.kind {
+ ColumnKind::Branch => ColumnIdeal::text(widths.branch),
+ ColumnKind::States => ColumnIdeal::text(widths.states),
+ ColumnKind::Path => ColumnIdeal::text(max_path_width),
+ ColumnKind::Time => ColumnIdeal::text(widths.time),
+ ColumnKind::CiStatus => ColumnIdeal::text(widths.ci_status),
+ ColumnKind::Commit => ColumnIdeal::text(commit_width),
+ ColumnKind::Message => None,
+ ColumnKind::WorkingDiff => ColumnIdeal::diff(widths.working_diff, DiffVariant::Signs),
+ ColumnKind::AheadBehind => ColumnIdeal::diff(widths.ahead_behind, DiffVariant::Arrows),
+ ColumnKind::BranchDiff => ColumnIdeal::diff(widths.branch_diff, DiffVariant::Signs),
+ ColumnKind::Upstream => ColumnIdeal::diff(widths.upstream, DiffVariant::Arrows),
+ }
+}
+
pub fn calculate_column_widths(
items: &[ListItem],
fetch_ci: bool,
@@ -404,8 +461,6 @@ pub fn calculate_column_widths(
branch_diff,
upstream,
states: final_states,
- commit: fit_header(HEADER_COMMIT, COMMIT_HASH_WIDTH),
- path: 0, // Path width calculated later in responsive layout
};
let data_flags = ColumnDataFlags {
@@ -449,244 +504,127 @@ pub fn calculate_responsive_layout(
.unwrap_or(0);
let max_path_width = fit_header(HEADER_PATH, path_data_width);
- let spacing = 2;
let commit_width = fit_header(HEADER_COMMIT, COMMIT_HASH_WIDTH);
- // Priority-based allocation using scoring model: final_priority = base_priority + modifiers
- // Base priorities (1-11) defined by user need hierarchy
- // Empty penalty (+10) pushes empty columns to priorities 12-21
- //
- // Priority order (from high to low):
- // 1. branch - identity (what is this?)
- // 2. working_diff - uncommitted changes (CRITICAL: do I need to commit?)
- // 3. ahead_behind - commits difference (CRITICAL: am I ahead/behind?)
- // 4. branch_diff - line diff in commits (work volume in those commits)
- // 5. states - special states like [rebasing], (conflicts) (rare but urgent when present)
- // 6. path - location (where is this?)
- // 7. ci_status - CI status (contextual when available)
- // 8. upstream - tracking configuration (sync context)
- // 9. time - recency (nice-to-have context)
- // 10. commit - hash (reference info, rarely needed)
- // 11. message - description (nice-to-have, space-hungry)
-
+ let spacing = 2;
let mut remaining = terminal_width;
- let mut widths = ColumnWidths {
- branch: 0,
- time: 0,
- ci_status: 0,
- message: 0,
- ahead_behind: DiffWidths::zero(),
- working_diff: DiffWidths::zero(),
- branch_diff: DiffWidths::zero(),
- upstream: DiffWidths::zero(),
- states: 0,
- commit: 0,
- path: 0,
- };
- // Build column allocation list with priorities
- let mut columns = [
- ColumnDescriptor {
- column_type: ColumnType::Branch,
- base_priority: 1,
- has_data: true,
- },
- ColumnDescriptor {
- column_type: ColumnType::WorkingDiff,
- base_priority: 2,
- has_data: data_flags.working_diff,
- },
- ColumnDescriptor {
- column_type: ColumnType::AheadBehind,
- base_priority: 3,
- has_data: data_flags.ahead_behind,
- },
- ColumnDescriptor {
- column_type: ColumnType::BranchDiff,
- base_priority: 4,
- has_data: data_flags.branch_diff,
- },
- ColumnDescriptor {
- column_type: ColumnType::States,
- base_priority: 5,
- has_data: data_flags.states,
- },
- ColumnDescriptor {
- column_type: ColumnType::Path,
- base_priority: 6,
- has_data: true,
- },
- ColumnDescriptor {
- column_type: ColumnType::CiStatus,
- base_priority: 7,
- has_data: data_flags.ci_status,
- },
- ColumnDescriptor {
- column_type: ColumnType::Upstream,
- base_priority: 8,
- has_data: data_flags.upstream,
- },
- ColumnDescriptor {
- column_type: ColumnType::Time,
- base_priority: 9,
- has_data: true,
- },
- ColumnDescriptor {
- column_type: ColumnType::Commit,
- base_priority: 10,
- has_data: true,
- },
- ColumnDescriptor {
- column_type: ColumnType::Message,
- base_priority: 11,
- has_data: true,
- },
- ];
-
- // Sort by final priority (includes empty penalty)
- columns.sort_by_key(|col| col.priority());
-
- // Message width constants (used in allocation and expansion)
+ let mut candidates: Vec<ColumnCandidate> = COLUMN_SPECS
+ .iter()
+ .filter(|spec| {
+ (!spec.requires_show_full || show_full) && (!spec.requires_fetch_ci || fetch_ci)
+ })
+ .map(|spec| ColumnCandidate {
+ spec,
+ priority: if column_has_data(spec.kind, &data_flags) {
+ spec.base_priority
+ } else {
+ spec.base_priority + EMPTY_PENALTY
+ },
+ })
+ .collect();
+
+ candidates.sort_by_key(|candidate| candidate.priority);
+
const MIN_MESSAGE: usize = 20;
const PREFERRED_MESSAGE: usize = 50;
const MAX_MESSAGE: usize = 100;
- // Allocate columns in priority order
- for (idx, col) in columns.iter().enumerate() {
- let is_first = idx == 0;
+ let mut pending: Vec<PendingColumn> = Vec::new();
- match col.column_type {
- ColumnType::Branch => {
- widths.branch =
- try_allocate(&mut remaining, ideal_widths.branch, spacing, is_first);
- }
- ColumnType::WorkingDiff => {
- let allocated = try_allocate(
- &mut remaining,
- ideal_widths.working_diff.total,
- spacing,
- is_first,
- );
- if allocated > 0 {
- widths.working_diff = ideal_widths.working_diff;
- }
- }
- ColumnType::AheadBehind => {
- let allocated = try_allocate(
- &mut remaining,
- ideal_widths.ahead_behind.total,
- spacing,
- is_first,
- );
- if allocated > 0 {
- widths.ahead_behind = ideal_widths.ahead_behind;
- }
- }
- ColumnType::BranchDiff if show_full => {
- let allocated = try_allocate(
- &mut remaining,
- ideal_widths.branch_diff.total,
- spacing,
- is_first,
- );
- if allocated > 0 {
- widths.branch_diff = ideal_widths.branch_diff;
- }
- }
- ColumnType::States => {
- widths.states =
- try_allocate(&mut remaining, ideal_widths.states, spacing, is_first);
- }
- ColumnType::Path => {
- widths.path = try_allocate(&mut remaining, max_path_width, spacing, is_first);
- }
- ColumnType::Upstream => {
- let allocated = try_allocate(
- &mut remaining,
- ideal_widths.upstream.total,
- spacing,
- is_first,
- );
- if allocated > 0 {
- widths.upstream = ideal_widths.upstream;
- }
- }
- ColumnType::Time => {
- widths.time = try_allocate(&mut remaining, ideal_widths.time, spacing, is_first);
- }
- ColumnType::CiStatus if fetch_ci => {
- widths.ci_status =
- try_allocate(&mut remaining, ideal_widths.ci_status, spacing, is_first);
+ for candidate in candidates {
+ let spec = candidate.spec;
+
+ if spec.kind == ColumnKind::Message {
+ let is_first = pending.is_empty();
+ let spacing_cost = if is_first { 0 } else { spacing };
+
+ if remaining <= spacing_cost {
+ continue;
}
- ColumnType::Commit => {
- widths.commit = try_allocate(&mut remaining, commit_width, spacing, is_first);
+
+ let available = remaining - spacing_cost;
+ let mut message_width = 0;
+
+ if available >= PREFERRED_MESSAGE {
+ message_width = PREFERRED_MESSAGE.min(ideal_widths.message);
+ } else if available >= MIN_MESSAGE {
+ message_width = available.min(ideal_widths.message);
}
- ColumnType::Message => {
- let message_width = if remaining >= PREFERRED_MESSAGE + spacing {
- PREFERRED_MESSAGE
- } else if remaining >= MIN_MESSAGE + spacing {
- remaining.saturating_sub(spacing).min(ideal_widths.message)
- } else {
- 0
- };
-
- if message_width > 0 {
- remaining = remaining.saturating_sub(message_width + spacing);
- widths.message = message_width.min(ideal_widths.message);
- }
+
+ if message_width > 0 {
+ remaining = remaining.saturating_sub(message_width + spacing_cost);
+ pending.push(PendingColumn {
+ spec,
+ width: message_width,
+ format: ColumnFormat::Text,
+ });
}
- _ => {} // Skip columns that don't meet visibility conditions (show_full, fetch_ci)
+
+ continue;
+ }
+
+ let Some(ideal) = ideal_for_column(spec, &ideal_widths, max_path_width, commit_width)
+ else {
+ continue;
+ };
+
+ let allocated = try_allocate(&mut remaining, ideal.width, spacing, pending.is_empty());
+ if allocated > 0 {
+ pending.push(PendingColumn {
+ spec,
+ width: allocated,
+ format: ideal.format,
+ });
}
}
- // Expand message with any leftover space (up to MAX_MESSAGE total)
- if widths.message > 0 && widths.message < MAX_MESSAGE && remaining > 0 {
- let expansion = remaining.min(MAX_MESSAGE - widths.message);
- widths.message += expansion;
+ let mut max_message_len = 0;
+ if let Some(message_col) = pending
+ .iter_mut()
+ .find(|col| col.spec.kind == ColumnKind::Message)
+ {
+ if message_col.width < MAX_MESSAGE && remaining > 0 {
+ let expansion = remaining.min(MAX_MESSAGE - message_col.width);
+ message_col.width += expansion;
+ }
+ max_message_len = message_col.width;
}
- let final_max_message_len = widths.message;
+ pending.sort_by_key(|col| col.spec.display_index);
- // Calculate absolute column positions (with 2-space gaps between columns)
let gap = 2;
- let mut pos = 0;
-
- // Helper closure to advance position for a column
- // Returns the column's start position, or 0 if column is hidden (width=0)
- let mut advance = |width: usize| -> usize {
- if width == 0 {
- return 0;
- }
- let column_pos = if pos == 0 { 0 } else { pos + gap };
- pos = column_pos + width;
- column_pos
- };
+ let mut position = 0;
+ let mut columns = Vec::new();
- let positions = ColumnPositions {
- branch: advance(widths.branch),
- working_diff: advance(widths.working_diff.total),
- ahead_behind: advance(widths.ahead_behind.total),
- branch_diff: advance(widths.branch_diff.total),
- states: advance(widths.states),
- path: advance(widths.path),
- ci_status: advance(widths.ci_status),
- upstream: advance(widths.upstream.total),
- time: advance(widths.time),
- commit: advance(widths.commit),
- message: advance(widths.message),
- };
+ for col in pending {
+ let start = if columns.is_empty() {
+ 0
+ } else {
+ position + gap
+ };
+ position = start + col.width;
+
+ columns.push(ColumnLayout {
+ kind: col.spec.kind,
+ header: col.spec.header,
+ start,
+ width: col.width,
+ format: col.format,
+ });
+ }
LayoutConfig {
- widths,
- positions,
+ columns,
common_prefix,
- max_message_len: final_max_message_len,
+ max_message_len,
}
}
#[cfg(test)]
mod tests {
use super::*;
+ use crate::commands::list::columns::ColumnKind;
use std::path::PathBuf;
#[test]
@@ -802,49 +740,46 @@ mod tests {
let items = vec![super::ListItem::Worktree(info)];
let layout = calculate_responsive_layout(&items, false, false);
- let pos = &layout.positions;
- let widths = &layout.widths;
-
- // Test key invariants of position calculation
- // 1. Branch always starts at position 0
- assert_eq!(pos.branch, 0, "Branch must start at position 0");
-
- // 2. States may be visible in Phase 2 (empty but shown if space allows)
- // Since we have plenty of space in wide terminal, states should be visible
assert!(
- pos.states > 0,
- "States column should be visible in Phase 2 (empty but shown if space)"
+ !layout.columns.is_empty(),
+ "At least one column should be visible"
);
- // 3. For visible columns, verify correct spacing
- // Each visible column should be at: previous_position + previous_width + gap(2)
- let gap = 2;
+ let mut columns_iter = layout.columns.iter();
+ let first = columns_iter.next().expect("branch column should exist");
+ assert_eq!(
+ first.kind,
+ ColumnKind::Branch,
+ "Branch column should be first"
+ );
+ assert_eq!(first.start, 0, "Branch should begin at position 0");
- if widths.working_diff.total > 0 && pos.working_diff > 0 {
+ let mut previous_end = first.start + first.width;
+ for column in columns_iter {
assert_eq!(
- pos.working_diff,
- pos.branch + widths.branch + gap,
- "Working diff position should follow branch with 2-space gap"
+ column.start,
+ previous_end + 2,
+ "Columns should be separated by a 2-space gap"
);
+ previous_end = column.start + column.width;
}
- if widths.ahead_behind.total > 0 && pos.ahead_behind > 0 {
- let prev_col_end = if pos.working_diff > 0 {
- pos.working_diff + widths.working_diff.total
- } else {
- pos.branch + widths.branch
- };
- assert_eq!(
- pos.ahead_behind,
- prev_col_end + gap,
- "Ahead/behind position should follow previous visible column with 2-space gap"
- );
- }
+ let states_visible = layout
+ .columns
+ .iter()
+ .any(|col| col.kind == ColumnKind::States);
+ assert!(
+ states_visible,
+ "States column should be visible in wide layout"
+ );
- // 4. Path must be visible and have position > 0 (it's always shown)
- assert!(pos.path > 0, "Path column must be visible");
- assert!(widths.path > 0, "Path column must have width > 0");
+ let path_column = layout
+ .columns
+ .iter()
+ .find(|col| col.kind == ColumnKind::Path)
+ .expect("Path column must be present");
+ assert!(path_column.width > 0, "Path column must have width > 0");
}
#[test]
@@ -887,39 +822,36 @@ mod tests {
let items = vec![super::ListItem::Worktree(info)];
let layout = calculate_responsive_layout(&items, false, false);
- let pos = &layout.positions;
- // Branch should be at 0
- assert_eq!(pos.branch, 0, "Branch always starts at position 0");
-
- // With new two-phase allocation, empty columns are shown in Phase 2 if space allows
- // Since we have a wide terminal (80 chars default) and minimal data, at least some empty columns should be visible
-
- // Early Phase 2 columns should be visible (highest priority empty columns)
assert!(
- pos.working_diff > 0,
- "Working diff should be visible in Phase 2 (empty but shown if space)"
- );
- assert!(
- pos.ahead_behind > 0,
- "Ahead/behind should be visible in Phase 2 (empty but shown if space)"
+ layout
+ .columns
+ .first()
+ .map(|col| col.kind == ColumnKind::Branch && col.start == 0)
+ .unwrap_or(false),
+ "Branch column should start at position 0"
);
- // Later Phase 2 columns might not fit (depending on terminal width)
- // Just verify that at least some empty columns are visible
- let empty_columns_visible = pos.working_diff > 0
- || pos.ahead_behind > 0
- || pos.branch_diff > 0
- || pos.states > 0
- || pos.upstream > 0;
+ let empty_columns_visible = [
+ ColumnKind::WorkingDiff,
+ ColumnKind::AheadBehind,
+ ColumnKind::BranchDiff,
+ ColumnKind::States,
+ ColumnKind::Upstream,
+ ]
+ .iter()
+ .any(|kind| layout.columns.iter().any(|col| &col.kind == kind));
assert!(
empty_columns_visible,
"At least some empty columns should be visible in Phase 2"
);
- // Path should be visible (always has data)
- assert!(pos.path > 0, "Path should be visible");
+ let path_visible = layout
+ .columns
+ .iter()
+ .any(|col| col.kind == ColumnKind::Path);
+ assert!(path_visible, "Path should always be visible");
}
#[test]
@@ -953,9 +885,9 @@ mod tests {
working_tree_diff: (0, 0), // Hidden: no dirty changes
working_tree_diff_with_main: (0, 0),
branch_diff: BranchDiffTotals { diff: (0, 0) }, // Hidden: no diff
- is_primary: true, // Hidden: no ahead/behind for primary
- upstream: UpstreamStatus::default(), // Hidden: no upstream
- worktree_state: None, // Hidden: no state
+ is_primary: true, // Hidden: no ahead/behind for primary
+ upstream: UpstreamStatus::default(), // Hidden: no upstream
+ worktree_state: None, // Hidden: no state
pr_status: None,
has_conflicts: false,
display: DisplayFields::default(),
@@ -964,36 +896,26 @@ mod tests {
let items = vec![super::ListItem::Worktree(info)];
let layout = calculate_responsive_layout(&items, false, false);
- let pos = &layout.positions;
- let widths = &layout.widths;
-
- // With two-phase allocation, empty columns are allocated in Phase 2 (after data columns)
- // Phase 1: branch (data), path (data), time (data), commit (data), message (data)
- // Phase 2: working_diff (empty), ahead_behind (empty), branch_diff (empty), states (empty), upstream (empty), ci_status (empty)
- // In Phase 1, path comes after branch immediately (since all middle columns have no data)
- // Branch, path, time, commit, message are allocated first
-
- // Path should come early since it has data and is allocated in Phase 1
+ let path_visible = layout
+ .columns
+ .iter()
+ .any(|col| col.kind == ColumnKind::Path);
assert!(
- pos.path > 0,
+ path_visible,
"Path should be visible (allocated in Phase 1)"
);
- // With the corrected Phase 2 allocation, empty columns only show if space remains AFTER message
- // In this test with 80 character width and minimal data:
- // - Branch, path, time, commit get allocated in Phase 1
- // - Message gets allocated next (before empty columns)
- // - Empty columns only allocated if space remains after message
-
- // Message should be allocated (it comes before empty columns now)
+ let message_visible = layout
+ .columns
+ .iter()
+ .any(|col| col.kind == ColumnKind::Message);
assert!(
- widths.message > 0,
+ message_visible,
"Message should be allocated before empty columns"
);
- // Empty columns may or may not be visible depending on space remaining after message
- // This is acceptable - message has priority over empty columns
- // No assertion needed here - it's correct for empty columns to not show if message takes the space
+ // Empty columns may or may not be visible depending on space remaining after message.
+ // This is acceptable - message has priority over empty columns.
}
}
diff --git a/src/commands/list/render.rs b/src/commands/list/render.rs
index f0eea638d..5c272b6f9 100644
--- a/src/commands/list/render.rs
+++ b/src/commands/list/render.rs
@@ -3,11 +3,8 @@ use anstyle::{AnsiColor, Color, Style};
use worktrunk::styling::{ADDITION, CURRENT, DELETION, StyledLine, println};
use super::ci_status::{CiStatus, PrStatus};
-use super::layout::{
- DiffWidths, HEADER_AGE, HEADER_AHEAD_BEHIND, HEADER_BRANCH, HEADER_BRANCH_DIFF, HEADER_CI,
- HEADER_COMMIT, HEADER_MESSAGE, HEADER_PATH, HEADER_STATE, HEADER_UPSTREAM, HEADER_WORKING_DIFF,
- LayoutConfig,
-};
+use super::columns::{ColumnKind, DiffVariant};
+use super::layout::{ColumnFormat, DiffDigits, LayoutConfig};
use super::model::ListItem;
/// Format ahead/behind counts as plain text with ANSI colors (for json-pretty)
@@ -89,114 +86,93 @@ pub fn format_ci_status_plain(pr_status: &PrStatus) -> String {
format!("{}● {}{}", style, status_str, style.render_reset())
}
-/// Format arrow-based counts (e.g., "↑6 ↓1") with alignment
-/// Down arrows always appear at the same column position by reserving space for ahead part
-fn format_arrow_column(
- ahead: usize,
- behind: usize,
- widths: &DiffWidths,
- green: Style,
- red: Style,
-) -> StyledLine {
- let mut segment = StyledLine::new();
-
- if ahead > 0 || behind > 0 {
- // Always reserve full width for ahead part (↑ + max_digits)
- if ahead > 0 {
- let ahead_str = format!("↑{}", ahead);
- segment.push_styled(&ahead_str, green);
- // Pad ahead part to fixed width
- let ahead_padding = widths.added_digits.saturating_sub(ahead.to_string().len());
- if ahead_padding > 0 {
- segment.push_raw(" ".repeat(ahead_padding));
- }
- } else {
- // Reserve full space when ahead is zero
- segment.push_raw(" ".repeat(1 + widths.added_digits));
- }
+#[derive(Clone, Copy)]
+enum ValueAlign {
+ Left,
+ Right,
+}
- // Always add separator space
- segment.push_raw(" ");
-
- // Always reserve full width for behind part (↓ + max_digits)
- if behind > 0 {
- let behind_str = format!("↓{}", behind);
- segment.push_styled(&behind_str, red);
- // Pad behind part to fixed width
- let behind_padding = widths
- .deleted_digits
- .saturating_sub(behind.to_string().len());
- if behind_padding > 0 {
- segment.push_raw(" ".repeat(behind_padding));
- }
- } else {
- // Reserve full space when behind is zero
- segment.push_raw(" ".repeat(1 + widths.deleted_digits));
- }
+#[derive(Clone, Copy)]
+struct DiffRenderConfig {
+ positive_symbol: &'static str,
+ negative_symbol: &'static str,
+ align: ValueAlign,
+}
- // Pad to total width if header is wider than data
- // (e.g., "Commits" header = 7, but data "↓50" = 5)
- segment.pad_to(widths.total);
- } else {
- segment.push_raw(" ".repeat(widths.total));
+fn diff_render_config(variant: DiffVariant) -> DiffRenderConfig {
+ match variant {
+ DiffVariant::Signs => DiffRenderConfig {
+ positive_symbol: "+",
+ negative_symbol: "-",
+ align: ValueAlign::Right,
+ },
+ DiffVariant::Arrows => DiffRenderConfig {
+ positive_symbol: "↑",
+ negative_symbol: "↓",
+ align: ValueAlign::Left,
+ },
}
-
- segment
}
-/// Format diff values as styled segments (right-aligned with attached signs)
-fn format_diff_column(
- added: usize,
- deleted: usize,
- widths: &DiffWidths,
- green: Style,
- red: Style,
+fn format_diff_like_column(
+ positive: usize,
+ negative: usize,
+ digits: DiffDigits,
+ total_width: usize,
+ variant: DiffVariant,
+ positive_style: Style,
+ negative_style: Style,
) -> StyledLine {
- let mut diff_segment = StyledLine::new();
+ let config = diff_render_config(variant);
+ let mut segment = StyledLine::new();
- if added > 0 || deleted > 0 {
- // Always maintain full column width for alignment
- // Format: [padding] [+nnn] [ ] [-nnn]
- let content_width = (1 + widths.added_digits) + 1 + (1 + widths.deleted_digits);
- let left_padding = widths.total.saturating_sub(content_width);
+ if positive == 0 && negative == 0 {
+ segment.push_raw(" ".repeat(total_width));
+ return segment;
+ }
- if left_padding > 0 {
- diff_segment.push_raw(" ".repeat(left_padding));
- }
+ let positive_width = 1 + digits.added;
+ let negative_width = 1 + digits.deleted;
+ let content_width = positive_width + 1 + negative_width;
+ let extra_padding = total_width.saturating_sub(content_width);
- // Added part: show value or spaces
- if added > 0 {
- let added_part = format!(
- "{:>width$}",
- format!("+{}", added),
- width = 1 + widths.added_digits
- );
- diff_segment.push_styled(added_part, green);
- } else {
- // Blank space to maintain alignment
- diff_segment.push_raw(" ".repeat(1 + widths.added_digits));
- }
+ if matches!(config.align, ValueAlign::Right) && extra_padding > 0 {
+ segment.push_raw(" ".repeat(extra_padding));
+ }
- // Space between added and deleted
- diff_segment.push_raw(" ");
+ if positive > 0 {
+ let value = format!("{}{}", config.positive_symbol, positive);
+ let formatted = match config.align {
+ ValueAlign::Right => format!("{:>width$}", value, width = positive_width),
+ ValueAlign::Left => format!("{:<width$}", value, width = positive_width),
+ };
+ segment.push_styled(formatted, positive_style);
+ } else {
+ segment.push_raw(" ".repeat(positive_width));
+ }
- // Deleted part: show value or spaces
- if deleted > 0 {
- let deleted_part = format!(
- "{:>width$}",
- format!("-{}", deleted),
- width = 1 + widths.deleted_digits
- );
- diff_segment.push_styled(deleted_part, red);
- } else {
- // Blank space to maintain alignment
- diff_segment.push_raw(" ".repeat(1 + widths.deleted_digits));
- }
+ segment.push_raw(" ");
+
+ if negative > 0 {
+ let value = format!("{}{}", config.negative_symbol, negative);
+ let formatted = match config.align {
+ ValueAlign::Right => format!("{:>width$}", value, width = negative_width),
+ ValueAlign::Left => format!("{:<width$}", value, width = negative_width),
+ };
+ segment.push_styled(formatted, negative_style);
} else {
- diff_segment.push_raw(" ".repeat(widths.total));
+ segment.push_raw(" ".repeat(negative_width));
+ }
+
+ if matches!(config.align, ValueAlign::Left) && extra_padding > 0 {
+ segment.pad_to(segment.width() + extra_padding);
}
- diff_segment
+ if segment.width() < total_width {
+ segment.pad_to(total_width);
+ }
+
+ segment
}
fn append_line(target: &mut StyledLine, source: StyledLine) {
@@ -211,13 +187,6 @@ fn push_blank(line: &mut StyledLine, width: usize) {
}
}
-fn push_diff(line: &mut StyledLine, added: usize, deleted: usize, widths: &DiffWidths) {
- append_line(
- line,
- format_diff_column(added, deleted, widths, ADDITION, DELETION),
- );
-}
-
/// Format CI status indicator using the statusline.sh color scheme
fn format_ci_status(pr_status: &PrStatus) -> StyledLine {
let mut segment = StyledLine::new();
@@ -236,16 +205,6 @@ pub fn format_all_states(item: &ListItem) -> String {
// Worktree-specific states
if let Some(info) = item.worktree_info() {
- // Check for "no commits" state - no commits ahead AND no uncommitted changes
- if !info.is_primary && item.counts().ahead == 0 && info.working_tree_diff == (0, 0) {
- states.push("(no commits)".to_string());
- }
-
- // Check for "matches main" state - working tree contents identical to main branch
- if !info.is_primary && info.working_tree_diff_with_main == (0, 0) {
- states.push("(matches main)".to_string());
- }
-
if let Some(state) = info.worktree_state.as_ref() {
states.push(format!("[{}]", state));
}
@@ -266,77 +225,14 @@ pub fn format_all_states(item: &ListItem) -> String {
}
pub fn format_header_line(layout: &LayoutConfig) {
- let widths = &layout.widths;
- let positions = &layout.positions;
let style = Style::new();
let mut line = StyledLine::new();
- // Use absolute positions for guaranteed alignment
- push_header_at(
- &mut line,
- HEADER_BRANCH,
- widths.branch,
- positions.branch,
- style,
- );
- push_header_at(
- &mut line,
- HEADER_WORKING_DIFF,
- widths.working_diff.total,
- positions.working_diff,
- style,
- );
- push_header_at(
- &mut line,
- HEADER_AHEAD_BEHIND,
- widths.ahead_behind.total,
- positions.ahead_behind,
- style,
- );
- push_header_at(
- &mut line,
- HEADER_BRANCH_DIFF,
- widths.branch_diff.total,
- positions.branch_diff,
- style,
- );
- push_header_at(
- &mut line,
- HEADER_STATE,
- widths.states,
- positions.states,
- style,
- );
- push_header_at(&mut line, HEADER_PATH, widths.path, positions.path, style);
- push_header_at(
- &mut line,
- HEADER_CI,
- widths.ci_status,
- positions.ci_status,
- style,
- );
- push_header_at(
- &mut line,
- HEADER_UPSTREAM,
- widths.upstream.total,
- positions.upstream,
- style,
- );
- push_header_at(&mut line, HEADER_AGE, widths.time, positions.time, style);
- push_header_at(
- &mut line,
- HEADER_COMMIT,
- widths.commit,
- positions.commit,
- style,
- );
- push_header_at(
- &mut line,
- HEADER_MESSAGE,
- widths.message,
- positions.message,
- style,
- );
+ for column in &layout.columns {
+ line.pad_to(column.start);
+ let header = format!("{:width$}", column.header, width = column.width);
+ line.push_styled(header, style);
+ }
println!("{}", line.render());
}
@@ -351,48 +247,16 @@ fn optional_reason_state(label: &str, reason: Option<&str>) -> Option<String> {
})
}
-fn push_header_at(line: &mut StyledLine, label: &str, width: usize, position: usize, style: Style) {
- if width > 0 {
- // Pad to absolute position
- line.pad_to(position);
- // Add header content padded to width
- let header = format!("{:width$}", label, width = width);
- line.push_styled(header, style);
- }
-}
-
-/// Check if a worktree/branch has marginal information (dim the line)
-///
-/// Dimming principle: A line is dimmed when it provides no marginal information
-/// beyond what's already in the main branch. This helps focus attention on
-/// worktrees that contain work.
-///
-/// Dims when (using OR logic):
-/// - No commits AND clean working tree (ahead == 0 AND working_tree_diff == (0, 0)):
-/// The worktree has no commits ahead and no uncommitted changes
-/// - Working tree matches main (working_tree_diff_with_main == (0, 0)):
-/// The working tree contents are identical to main, regardless of commit history
-///
-/// Either condition alone is sufficient to dim, as both indicate "no unique work here".
+/// Push a header at an absolute column position
+/// Check if a branch is potentially removable (nothing ahead, no uncommitted changes)
fn is_potentially_removable(item: &ListItem) -> bool {
- if item.is_primary() {
- return false;
- }
-
let counts = item.counts();
+ let wt_diff = item
+ .worktree_info()
+ .map(|info| info.working_tree_diff)
+ .unwrap_or((0, 0));
- if let Some(info) = item.worktree_info() {
- // Condition 1: No commits ahead AND no uncommitted changes
- let no_commits_and_clean = counts.ahead == 0 && info.working_tree_diff == (0, 0);
-
- // Condition 2: Working tree matches main (regardless of commit history)
- let matches_main = info.working_tree_diff_with_main == (0, 0);
-
- no_commits_and_clean || matches_main
- } else {
- // For branches without worktrees, just check if no commits ahead
- counts.ahead == 0
- }
+ !item.is_primary() && counts.ahead == 0 && wt_diff == (0, 0)
}
/// Render a list item (worktree or branch) as a formatted line
@@ -401,8 +265,6 @@ pub fn format_list_item_line(
layout: &LayoutConfig,
current_worktree_path: Option<&std::path::PathBuf>,
) {
- let widths = &layout.widths;
-
let head = item.head();
let commit = item.commit_details();
let counts = item.counts();
@@ -433,151 +295,142 @@ pub fn format_list_item_line(
text_style
};
- // Start building the line using absolute column positions
let mut line = StyledLine::new();
- let positions = &layout.positions;
-
- // Branch name (dimmed if removable)
- if widths.branch > 0 {
- line.pad_to(positions.branch);
- let branch_text = format!("{:width$}", item.branch_name(), width = widths.branch);
- if let Some(style) = text_style {
- line.push_styled(branch_text, style);
- } else {
- line.push_raw(branch_text);
- }
- }
-
- // Working tree diff (worktrees only)
- if widths.working_diff.total > 0 {
- line.pad_to(positions.working_diff);
- if let Some(info) = worktree_info {
- let (wt_added, wt_deleted) = info.working_tree_diff;
- push_diff(&mut line, wt_added, wt_deleted, &widths.working_diff);
- } else {
- push_blank(&mut line, widths.working_diff.total);
- }
- }
-
- // Ahead/behind (commits difference) - green ahead, dim red behind
- if widths.ahead_behind.total > 0 {
- line.pad_to(positions.ahead_behind);
- if !item.is_primary() && (counts.ahead > 0 || counts.behind > 0) {
- let dim_deletion = DELETION.dimmed();
- append_line(
- &mut line,
- format_arrow_column(
- counts.ahead,
- counts.behind,
- &widths.ahead_behind,
- ADDITION,
- dim_deletion,
- ),
- );
- } else {
- push_blank(&mut line, widths.ahead_behind.total);
- }
- }
-
- // Branch diff (line diff in commits)
- if widths.branch_diff.total > 0 {
- line.pad_to(positions.branch_diff);
- if !item.is_primary() {
- push_diff(&mut line, branch_diff.0, branch_diff.1, &widths.branch_diff);
- } else {
- push_blank(&mut line, widths.branch_diff.total);
- }
- }
-
- // States (includes conflicts)
- if widths.states > 0 {
- line.pad_to(positions.states);
- let states = format_all_states(item);
- if !states.is_empty() {
- let states_text = format!("{:width$}", states, width = widths.states);
- line.push_raw(states_text);
- } else {
- push_blank(&mut line, widths.states);
- }
- }
-
- // Path (worktrees only)
- if widths.path > 0 {
- line.pad_to(positions.path);
- if let Some(info) = worktree_info {
- let path_str = shorten_path(&info.worktree.path, &layout.common_prefix);
- let path_text = format!("{:width$}", path_str, width = widths.path);
- if let Some(style) = text_style {
- line.push_styled(path_text, style);
- } else {
- line.push_raw(path_text);
+ for column in &layout.columns {
+ line.pad_to(column.start);
+
+ match (column.kind, column.format) {
+ (ColumnKind::Branch, _) => {
+ let branch_text = format!("{:width$}", item.branch_name(), width = column.width);
+ if let Some(style) = text_style {
+ line.push_styled(branch_text, style);
+ } else {
+ line.push_raw(branch_text);
+ }
+ }
+ (ColumnKind::WorkingDiff, ColumnFormat::Diff { digits, variant }) => {
+ if let Some(info) = worktree_info {
+ let (wt_added, wt_deleted) = info.working_tree_diff;
+ let segment = format_diff_like_column(
+ wt_added,
+ wt_deleted,
+ digits,
+ column.width,
+ variant,
+ ADDITION,
+ DELETION,
+ );
+ append_line(&mut line, segment);
+ } else {
+ push_blank(&mut line, column.width);
+ }
+ }
+ (ColumnKind::AheadBehind, ColumnFormat::Diff { digits, variant }) => {
+ if !item.is_primary() && (counts.ahead > 0 || counts.behind > 0) {
+ let dim_deletion = DELETION.dimmed();
+ let segment = format_diff_like_column(
+ counts.ahead,
+ counts.behind,
+ digits,
+ column.width,
+ variant,
+ ADDITION,
+ dim_deletion,
+ );
+ append_line(&mut line, segment);
+ } else {
+ push_blank(&mut line, column.width);
+ }
+ }
+ (ColumnKind::BranchDiff, ColumnFormat::Diff { digits, variant }) => {
+ if !item.is_primary() {
+ let segment = format_diff_like_column(
+ branch_diff.0,
+ branch_diff.1,
+ digits,
+ column.width,
+ variant,
+ ADDITION,
+ DELETION,
+ );
+ append_line(&mut line, segment);
+ } else {
+ push_blank(&mut line, column.width);
+ }
+ }
+ (ColumnKind::States, _) => {
+ let states = format_all_states(item);
+ if !states.is_empty() {
+ let states_text = format!("{:width$}", states, width = column.width);
+ line.push_raw(states_text);
+ } else {
+ push_blank(&mut line, column.width);
+ }
+ }
+ (ColumnKind::Path, _) => {
+ if let Some(info) = worktree_info {
+ let path_str = shorten_path(&info.worktree.path, &layout.common_prefix);
+ let path_text = format!("{:width$}", path_str, width = column.width);
+ if let Some(style) = text_style {
+ line.push_styled(path_text, style);
+ } else {
+ line.push_raw(path_text);
+ }
+ } else {
+ push_blank(&mut line, column.width);
+ }
+ }
+ (ColumnKind::Upstream, ColumnFormat::Diff { digits, variant }) => {
+ if let Some((_remote_name, upstream_ahead, upstream_behind)) = upstream.active() {
+ let dim_deletion = DELETION.dimmed();
+ let segment = format_diff_like_column(
+ upstream_ahead,
+ upstream_behind,
+ digits,
+ column.width,
+ variant,
+ ADDITION,
+ dim_deletion,
+ );
+ append_line(&mut line, segment);
+ } else {
+ push_blank(&mut line, column.width);
+ }
+ }
+ (ColumnKind::Time, _) => {
+ let time_str = format!(
+ "{:width$}",
+ format_relative_time(commit.timestamp),
+ width = column.width
+ );
+ line.push_styled(time_str, Style::new().dimmed());
+ }
+ (ColumnKind::CiStatus, _) => {
+ if let Some(pr_status) = item.pr_status() {
+ let mut ci_segment = format_ci_status(pr_status);
+ ci_segment.pad_to(column.width);
+ append_line(&mut line, ci_segment);
+ } else {
+ push_blank(&mut line, column.width);
+ }
+ }
+ (ColumnKind::Commit, _) => {
+ let commit_text = format!("{:width$}", short_head, width = column.width);
+ line.push_styled(commit_text, Style::new().dimmed());
+ }
+ (ColumnKind::Message, _) => {
+ let msg = truncate_at_word_boundary(&commit.commit_message, layout.max_message_len);
+ let msg_start = line.width();
+ line.push_styled(msg, Style::new().dimmed());
+ line.pad_to(msg_start + column.width);
+ }
+ // Fallback for diff columns when format is unexpectedly Text
+ (_, _) => {
+ push_blank(&mut line, column.width);
}
- } else {
- push_blank(&mut line, widths.path);
- }
- }
-
- // CI status
- if widths.ci_status > 0 {
- line.pad_to(positions.ci_status);
- if let Some(pr_status) = item.pr_status() {
- let mut ci_segment = format_ci_status(pr_status);
- ci_segment.pad_to(widths.ci_status);
- append_line(&mut line, ci_segment);
- } else {
- push_blank(&mut line, widths.ci_status);
- }
- }
-
- // Upstream tracking
- if widths.upstream.total > 0 {
- line.pad_to(positions.upstream);
- if let Some((_remote_name, upstream_ahead, upstream_behind)) = upstream.active() {
- let dim_deletion = DELETION.dimmed();
- // TODO: Handle show_remote_names when implemented
- append_line(
- &mut line,
- format_arrow_column(
- upstream_ahead,
- upstream_behind,
- &widths.upstream,
- ADDITION,
- dim_deletion,
- ),
- );
- } else {
- // No remote tracking - show blank
- push_blank(&mut line, widths.upstream.total);
}
}
- // Commit (short HEAD) - always dimmed (reference info)
- if widths.commit > 0 {
- line.pad_to(positions.commit);
- line.push_styled(short_head, Style::new().dimmed());
- }
-
- // Age (Time)
- if widths.time > 0 {
- line.pad_to(positions.time);
- let time_str = format!(
- "{:width$}",
- format_relative_time(commit.timestamp),
- width = widths.time
- );
- line.push_styled(time_str, Style::new().dimmed());
- }
-
- // Message
- if widths.message > 0 {
- line.pad_to(positions.message);
- let msg = truncate_at_word_boundary(&commit.commit_message, layout.max_message_len);
- let msg_start = line.width();
- line.push_styled(msg, Style::new().dimmed());
- // Pad to correct visual width (not character count - important for unicode!)
- line.pad_to(msg_start + widths.message);
- }
-
println!("{}", line.render());
}
@@ -588,67 +441,88 @@ mod tests {
#[test]
fn test_format_diff_column_pads_to_total_width() {
- // Test that diff column is padded to total width when content is smaller
+ use super::super::columns::DiffVariant;
// Case 1: Single-digit diffs with total=6 (to fit "WT +/-" header)
- let widths = DiffWidths {
- total: 6,
- added_digits: 1,
- deleted_digits: 1,
+ let digits = DiffDigits {
+ added: 1,
+ deleted: 1,
};
- let result = format_diff_column(1, 1, &widths, ADDITION, DELETION);
+ let total = 6;
+ let result =
+ format_diff_like_column(1, 1, digits, total, DiffVariant::Signs, ADDITION, DELETION);
assert_eq!(
result.width(),
- 6,
+ total,
"Diff '+1 -1' should be padded to 6 chars"
);
// Case 2: Two-digit diffs with total=8
- let widths = DiffWidths {
- total: 8,
- added_digits: 2,
- deleted_digits: 2,
+ let digits = DiffDigits {
+ added: 2,
+ deleted: 2,
};
- let result = format_diff_column(10, 50, &widths, ADDITION, DELETION);
+ let total = 8;
+ let result = format_diff_like_column(
+ 10,
+ 50,
+ digits,
+ total,
+ DiffVariant::Signs,
+ ADDITION,
+ DELETION,
+ );
assert_eq!(
result.width(),
- 8,
+ total,
"Diff '+10 -50' should be padded to 8 chars"
);
// Case 3: Asymmetric digit counts with total=9
- let widths = DiffWidths {
- total: 9,
- added_digits: 3,
- deleted_digits: 2,
+ let digits = DiffDigits {
+ added: 3,
+ deleted: 2,
};
- let result = format_diff_column(100, 50, &widths, ADDITION, DELETION);
+ let total = 9;
+ let result = format_diff_like_column(
+ 100,
+ 50,
+ digits,
+ total,
+ DiffVariant::Signs,
+ ADDITION,
+ DELETION,
+ );
assert_eq!(
result.width(),
- 9,
+ total,
"Diff '+100 -50' should be padded to 9 chars"
);
// Case 4: Zero diff should also pad to total width
- let widths = DiffWidths {
- total: 6,
- added_digits: 1,
- deleted_digits: 1,
+ let digits = DiffDigits {
+ added: 1,
+ deleted: 1,
};
- let result = format_diff_column(0, 0, &widths, ADDITION, DELETION);
- assert_eq!(result.width(), 6, "Empty diff should be 6 spaces");
+ let total = 6;
+ let result =
+ format_diff_like_column(0, 0, digits, total, DiffVariant::Signs, ADDITION, DELETION);
+ assert_eq!(result.width(), total, "Empty diff should be 6 spaces");
}
#[test]
fn test_format_diff_column_right_alignment() {
// Test that diff values are right-aligned within the total width
- let widths = DiffWidths {
- total: 6,
- added_digits: 1,
- deleted_digits: 1,
+ use super::super::columns::DiffVariant;
+
+ let digits = DiffDigits {
+ added: 1,
+ deleted: 1,
};
+ let total = 6;
- let result = format_diff_column(1, 1, &widths, ADDITION, DELETION);
+ let result =
+ format_diff_like_column(1, 1, digits, total, DiffVariant::Signs, ADDITION, DELETION);
let rendered = result.render();
// Strip ANSI codes to check alignment
@@ -769,72 +643,66 @@ mod tests {
}
#[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;
+ fn test_arrow_variant_alignment_invariant() {
+ use super::super::columns::DiffVariant;
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 digits = DiffDigits {
+ added: 2,
+ deleted: 2,
};
+ let total = 7;
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"
+ let cases = [(0, 0), (1, 0), (0, 1), (1, 1), (99, 99), (5, 44)];
+
+ for (ahead, behind) in cases {
+ let result = format_diff_like_column(
+ ahead,
+ behind,
+ digits,
+ total,
+ DiffVariant::Arrows,
+ ADDITION,
+ dim_deletion,
);
+ assert_eq!(result.width(), total);
}
}
#[test]
- fn test_arrow_column_with_header_wider_than_data() {
- // Reproduces the actual bug: when header is wider than data
- // - No ahead values (max_ahead_digits = 0)
- // - Max behind is 50 (max_behind_digits = 2)
- // - data_width = 1 + 0 + 1 + 1 + 2 = 5
- // - header "Commits" = 7
- // - total = max(5, 7) = 7
- use super::super::layout::DiffWidths;
- use super::format_arrow_column;
+ fn test_arrow_variant_respects_header_width() {
+ use super::super::columns::DiffVariant;
use worktrunk::styling::{ADDITION, DELETION};
- let widths = DiffWidths {
- total: 7, // To fit "Commits" header
- added_digits: 0, // No ahead values
- deleted_digits: 2, // Max behind is 50
+ let digits = DiffDigits {
+ added: 0,
+ deleted: 2,
};
+ let total = 7;
let dim_deletion = DELETION.dimmed();
- // Empty column should be 7 spaces
- let empty = format_arrow_column(0, 0, &widths, ADDITION, dim_deletion);
- assert_eq!(empty.width(), 7, "Empty column should be 7 spaces");
-
- // Column with only behind should also be 7!
- let behind_only = format_arrow_column(0, 50, &widths, ADDITION, dim_deletion);
- assert_eq!(
- behind_only.width(),
- 7,
- "Column with behind=50 should be 7 chars (currently {} - THIS IS THE BUG)",
- behind_only.width()
+ let empty = format_diff_like_column(
+ 0,
+ 0,
+ digits,
+ total,
+ DiffVariant::Arrows,
+ ADDITION,
+ dim_deletion,
+ );
+ assert_eq!(empty.width(), total);
+
+ let behind_only = format_diff_like_column(
+ 0,
+ 50,
+ digits,
+ total,
+ DiffVariant::Arrows,
+ ADDITION,
+ dim_deletion,
);
+ assert_eq!(behind_only.width(), total);
}
}
diff --git a/tests/snapshots/integration__integration_tests__list__detached_head.snap b/tests/snapshots/integration__integration_tests__list__detached_head.snap
index 521973547..6bad3a530 100644
--- a/tests/snapshots/integration__integration_tests__list__detached_head.snap
+++ b/tests/snapshots/integration__integration_tests__list__detached_head.snap
@@ -15,13 +15,13 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp71BEYU/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp5MUqjf/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Remote ↕ Age Commit Message
-(detached) .  b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+(detached) .  b834638e 10 months ago Initial commit
Showing 1 worktree
diff --git a/tests/snapshots/integration__integration_tests__list__locked_no_reason.snap b/tests/snapshots/integration__integration_tests__list__locked_no_reason.snap
index 6dd5df9f3..66711c05e 100644
--- a/tests/snapshots/integration__integration_tests__list__locked_no_reason.snap
+++ b/tests/snapshots/integration__integration_tests__list__locked_no_reason.snap
@@ -15,14 +15,14 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpYuerRp/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpTH2RWN/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Remote ↕ Age Commit Message
-main  ./test-repo  b834638e10 months agoInitial commit
-locked-no-reason (no commits) (matches main) (locked) ./locked-no-reason b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo  b834638e 10 months ago Initial commit
+locked-no-reason (locked) ./locked-no-reason b834638e 10 months ago Initial commit
Showing 2 worktrees
diff --git a/tests/snapshots/integration__integration_tests__list__locked_worktree.snap b/tests/snapshots/integration__integration_tests__list__locked_worktree.snap
index 29e9ba169..3fbc05a06 100644
--- a/tests/snapshots/integration__integration_tests__list__locked_worktree.snap
+++ b/tests/snapshots/integration__integration_tests__list__locked_worktree.snap
@@ -15,14 +15,14 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpp40ZYn/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpfwWO3y/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± State Path Age Commit Message
-main  ./test-repo  b834638e10 months agoInitial commit
-locked-feature (no commits) (matches main) (locked: Testing lock functionality) ./locked-feature b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo  b834638e 10 months ago Initial commit
+locked-feature (locked: Testing lock functionality) ./locked-feature b834638e 10 months ago Initial commit
Showing 2 worktrees
diff --git a/tests/snapshots/integration__integration_tests__list__long_commit_message.snap b/tests/snapshots/integration__integration_tests__list__long_commit_message.snap
index f02d4c6f6..4efc86fd5 100644
--- a/tests/snapshots/integration__integration_tests__list__long_commit_message.snap
+++ b/tests/snapshots/integration__integration_tests__list__long_commit_message.snap
@@ -15,14 +15,14 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpx2T0uV/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpkYt6zM/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Remote ↕ Age Commit Message
-main  ./test-repo 1310bfb910 months agoShort message
-feature-a ↓1 (no commits) ./feature-a f078644e10 months agoThis is a very long commit message that should test...
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo 1310bfb9 10 months ago Short message
+feature-a ↓1 ./feature-a f078644e 10 months ago This is a very long commit message that should test how the...
Showing 2 worktrees, 1 behind
diff --git a/tests/snapshots/integration__integration_tests__list__many_worktrees_varied.snap b/tests/snapshots/integration__integration_tests__list__many_worktrees_varied.snap
index 70f306651..853587af9 100644
--- a/tests/snapshots/integration__integration_tests__list__many_worktrees_varied.snap
+++ b/tests/snapshots/integration__integration_tests__list__many_worktrees_varied.snap
@@ -15,17 +15,17 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpoXpJFG/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp8Mr4rb/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Age Commit Message
-main  ./test-repo  b834638e10 months agoInitial commit
-medium-name  (no commits) (matches main) ./medium-name  b834638e10 months agoInitial commit
-short  (no commits) (matches main) ./short  b834638e10 months agoInitial commit
-very-long-branch-name-here (no commits) (matches main) ./very-long-branch-name-here b834638e10 months agoInitial commit
-with-changes  (no commits) (matches main) ./with-changes  b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo  b834638e 10 months ago Initial commit
+medium-name  ./medium-name  b834638e 10 months ago Initial commit
+short  ./short  b834638e 10 months ago Initial commit
+very-long-branch-name-here ./very-long-branch-name-here b834638e 10 months ago Initial commit
+with-changes  ./with-changes  b834638e 10 months ago Initial commit
Showing 5 worktrees
diff --git a/tests/snapshots/integration__integration_tests__list__multiple_worktrees.snap b/tests/snapshots/integration__integration_tests__list__multiple_worktrees.snap
index 5b5ac9acc..02b520bb1 100644
--- a/tests/snapshots/integration__integration_tests__list__multiple_worktrees.snap
+++ b/tests/snapshots/integration__integration_tests__list__multiple_worktrees.snap
@@ -15,15 +15,15 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpu76ikq/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp691xwN/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Age Commit Message
-main  ./test-repo b834638e10 months agoInitial commit
-feature-a (no commits) (matches main) ./feature-a b834638e10 months agoInitial commit
-feature-b (no commits) (matches main) ./feature-b b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo b834638e 10 months ago Initial commit
+feature-a ./feature-a b834638e 10 months ago Initial commit
+feature-b ./feature-b b834638e 10 months ago Initial commit
Showing 3 worktrees
diff --git a/tests/snapshots/integration__integration_tests__list__single_worktree.snap b/tests/snapshots/integration__integration_tests__list__single_worktree.snap
index cbd09f068..62200913e 100644
--- a/tests/snapshots/integration__integration_tests__list__single_worktree.snap
+++ b/tests/snapshots/integration__integration_tests__list__single_worktree.snap
@@ -15,13 +15,13 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpo8xVIX/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpfAKKJa/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Remote ↕ Age Commit Message
-main  .  b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  .  b834638e 10 months ago Initial commit
Showing 1 worktree
diff --git a/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap b/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap
index f70ece8aa..0d8ff7646 100644
--- a/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap
+++ b/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap
@@ -15,14 +15,14 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpdtZBUv/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpVJujXU/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Remote ↕ Age Commit Message
-main  ./test-repo  e4614cb710 months agoFix bug with café ☕ handling
-feature-test ↓1 (no commits) ./feature-test 0c53695b10 months agoAdd support for 日本語 and...
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo  e4614cb7 10 months ago Fix bug with café ☕ handling
+feature-test ↓1 ./feature-test 0c53695b 10 months ago Add support for 日本語 and émoji 🎉
Showing 2 worktrees, 1 behind
diff --git a/tests/snapshots/integration__integration_tests__list__with_branches_flag.snap b/tests/snapshots/integration__integration_tests__list__with_branches_flag.snap
index 1cd056ff4..de0167cb8 100644
--- a/tests/snapshots/integration__integration_tests__list__with_branches_flag.snap
+++ b/tests/snapshots/integration__integration_tests__list__with_branches_flag.snap
@@ -16,17 +16,17 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpZOMfa4/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpOPYVub/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Remote ↕ Age Commit Message
-main  ./test-repo  b834638e10 months agoInitial commit
-feature-with-worktree  (no commits) (matches main) ./feature-with-worktree b834638e10 months agoInitial commit
-another-branch  b834638e10 months agoInitial commit
-feature-without-worktree b834638e10 months agoInitial commit
-fix-bug  b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo  b834638e 10 months ago Initial commit
+feature-with-worktree  ./feature-with-worktree b834638e 10 months ago Initial commit
+another-branch  b834638e 10 months ago Initial commit
+feature-without-worktree b834638e 10 months ago Initial commit
+fix-bug  b834638e 10 months ago Initial commit
Showing 2 worktrees, 3 branches
diff --git a/tests/snapshots/integration__integration_tests__list__with_branches_flag_none_available.snap b/tests/snapshots/integration__integration_tests__list__with_branches_flag_none_available.snap
index 08053f887..8c60f7b97 100644
--- a/tests/snapshots/integration__integration_tests__list__with_branches_flag_none_available.snap
+++ b/tests/snapshots/integration__integration_tests__list__with_branches_flag_none_available.snap
@@ -16,15 +16,15 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpgmNBuY/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpeOSNsp/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Age Commit Message
-main  ./test-repo b834638e10 months agoInitial commit
-feature-a (no commits) (matches main) ./feature-a b834638e10 months agoInitial commit
-feature-b (no commits) (matches main) ./feature-b b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo b834638e 10 months ago Initial commit
+feature-a ./feature-a b834638e 10 months ago Initial commit
+feature-b ./feature-b b834638e 10 months ago Initial commit
Showing 3 worktrees
diff --git a/tests/snapshots/integration__integration_tests__list__with_branches_flag_only_branches.snap b/tests/snapshots/integration__integration_tests__list__with_branches_flag_only_branches.snap
index 5e7ad7c47..72077d06c 100644
--- a/tests/snapshots/integration__integration_tests__list__with_branches_flag_only_branches.snap
+++ b/tests/snapshots/integration__integration_tests__list__with_branches_flag_only_branches.snap
@@ -16,16 +16,16 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpmeyqFu/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpaApej7/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Remote ↕ Age Commit Message
-main  .  b834638e10 months agoInitial commit
-branch-alpha b834638e10 months agoInitial commit
-branch-beta  b834638e10 months agoInitial commit
-branch-gamma b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  .  b834638e 10 months ago Initial commit
+branch-alpha b834638e 10 months ago Initial commit
+branch-beta  b834638e 10 months ago Initial commit
+branch-gamma b834638e 10 months ago Initial commit
Showing 1 worktrees, 3 branches
diff --git a/tests/snapshots/integration__integration_tests__security__commit_message_with_directive_not_executed.snap b/tests/snapshots/integration__integration_tests__security__commit_message_with_directive_not_executed.snap
index d2bda0160..4fd8e8f6a 100644
--- a/tests/snapshots/integration__integration_tests__security__commit_message_with_directive_not_executed.snap
+++ b/tests/snapshots/integration__integration_tests__security__commit_message_with_directive_not_executed.snap
@@ -15,14 +15,14 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpnFkFXJ/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpiVNhgL/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Age Commit Message
-main  ./test-repo [SHA]10 months agoFix bug __WORKTRUNK_EXEC__echo PWNED > /tmp/hacked4
-feature (no commits) (matches main) ./feature  [SHA]10 months agoFix bug __WORKTRUNK_EXEC__echo PWNED > /tmp/hacked4
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo [SHA] 10 months ago Fix bug __WORKTRUNK_EXEC__echo PWNED > /tmp/hacked4
+feature ./feature  [SHA] 10 months ago Fix bug __WORKTRUNK_EXEC__echo PWNED > /tmp/hacked4
Showing 2 worktrees
diff --git a/tests/snapshots/integration__integration_tests__security__path_with_directive_not_executed.snap b/tests/snapshots/integration__integration_tests__security__path_with_directive_not_executed.snap
index 84298cdbc..a8557041c 100644
--- a/tests/snapshots/integration__integration_tests__security__path_with_directive_not_executed.snap
+++ b/tests/snapshots/integration__integration_tests__security__path_with_directive_not_executed.snap
@@ -15,13 +15,13 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpw0aAXk/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpBwKFlH/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Remote ↕ Age Commit Message
-main  .  b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  .  b834638e 10 months ago Initial commit
Showing 1 worktree
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_empty_diffs.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_empty_diffs.snap
index 621c3baf8..eb750656d 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_empty_diffs.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_empty_diffs.snap
@@ -15,16 +15,16 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpsfUMYX/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpyUX3G8/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Remote ↕ Age Commit Message
-main  ./test-repo  b834638e10 months agoInitial commit
-also-no-changes (no commits) (matches main) ./also-no-changes b834638e10 months agoInitial commit
-no-changes  (no commits) (matches main) ./no-changes  b834638e10 months agoInitial commit
-with-changes +1 -1 ./with-changes b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo  b834638e 10 months ago Initial commit
+also-no-changes ./also-no-changes b834638e 10 months ago Initial commit
+no-changes  ./no-changes  b834638e 10 months ago Initial commit
+with-changes +1 -1 ./with-changes b834638e 10 months ago Initial commit
Showing 4 worktrees, 1 with changes
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_extreme_diffs.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_extreme_diffs.snap
index 8b809a56f..2b9fb6881 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_extreme_diffs.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_extreme_diffs.snap
@@ -15,15 +15,15 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmphuoJvj/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpGggAqs/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Remote ↕ Age Commit Message
-main  ./test-repo b834638e10 months agoInitial commit
-huge  (no commits) (matches main) ./huge  b834638e10 months agoInitial commit
-tiny +1 -1 ./tiny b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo b834638e 10 months ago Initial commit
+huge  ./huge  b834638e 10 months ago Initial commit
+tiny +1 -1 ./tiny b834638e 10 months ago Initial commit
Showing 3 worktrees, 1 with changes
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_varying_diffs.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_varying_diffs.snap
index a0994f2ea..67551958c 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_varying_diffs.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_varying_diffs.snap
@@ -15,16 +15,16 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp6dujLj/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpH2NTRJ/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Remote ↕ Age Commit Message
-main  ./test-repo  b834638e10 months agoInitial commit
-feature-large  (no commits) (matches main) ./feature-large  b834638e10 months agoInitial commit
-feature-medium (no commits) (matches main) ./feature-medium b834638e10 months agoInitial commit
-feature-small  (no commits) (matches main) ./feature-small  b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo  b834638e 10 months ago Initial commit
+feature-large  ./feature-large  b834638e 10 months ago Initial commit
+feature-medium ./feature-medium b834638e 10 months ago Initial commit
+feature-small  ./feature-small  b834638e 10 months ago Initial commit
Showing 4 worktrees
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__long_branch_names.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__long_branch_names.snap
index f3b5cc0d9..dba2a687a 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__long_branch_names.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__long_branch_names.snap
@@ -15,16 +15,16 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmppuUEjJ/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpjxlend/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± State Path Age Commit Message
-main  ./test-repo  b834638e10 months agoInitial commit
-another-extremely-long-name-here (no commits) (matches main) ./another-extremely-long-name-here b834638e10 months agoInitial commit
-short  (no commits) (matches main) ./short  b834638e10 months agoInitial commit
-very-long-feature-branch-name  (no commits) (matches main) ./very-long-feature-branch-name  b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo  b834638e 10 months ago Initial commit
+another-extremely-long-name-here ./another-extremely-long-name-here b834638e 10 months ago Initial commit
+short  ./short  b834638e 10 months ago Initial commit
+very-long-feature-branch-name  ./very-long-feature-branch-name  b834638e 10 months ago Initial commit
Showing 4 worktrees
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__mixed_length_branch_names.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__mixed_length_branch_names.snap
index 9117a8dfe..8af48286c 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__mixed_length_branch_names.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__mixed_length_branch_names.snap
@@ -15,16 +15,16 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpR6yG9m/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpZYqcod/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± State Path Age Commit Message
-main  ./test-repo  b834638e10 months agoInitial commit
-long  (no commits) (matches main) ./extremely-long-branch-name-that-might-cause-layout-issues b834638e10 months agoInitial commit
-medium (no commits) (matches main) ./medium-length-name  b834638e10 months agoInitial commit
-x  (no commits) (matches main) ./x  b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo  b834638e 10 months ago Initial commit
+long  ./extremely-long-branch-name-that-might-cause-layout-issues b834638e 10 months ago Initial commit
+medium ./medium-length-name  b834638e 10 months ago Initial commit
+x  ./x  b834638e 10 months ago Initial commit
Showing 4 worktrees
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__short_branch_names.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__short_branch_names.snap
index 582274d9b..dbd42d29e 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__short_branch_names.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__short_branch_names.snap
@@ -15,16 +15,16 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpDzk2IN/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpSEYNgZ/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Age Commit Message
-main  ./test-repo b834638e10 months agoInitial commit
-a  (no commits) (matches main) ./a  b834638e10 months agoInitial commit
-bb  (no commits) (matches main) ./bb  b834638e10 months agoInitial commit
-ccc  (no commits) (matches main) ./ccc  b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo b834638e 10 months ago Initial commit
+a  ./a  b834638e 10 months ago Initial commit
+bb  ./bb  b834638e 10 months ago Initial commit
+ccc  ./ccc  b834638e 10 months ago Initial commit
Showing 4 worktrees
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_120.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_120.snap
index 9f35526cc..314e11212 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_120.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_120.snap
@@ -15,15 +15,15 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpWMYpj3/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpYDU9Lq/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch State Path Age Commit Message
-main  ./test-repo a7bc47ca10 months agoInitial commit with a reasonably long...
-feature-a (no commits) (matches main) ./feature-a a7bc47ca10 months agoInitial commit with a reasonably long...
-feature-b (no commits) (matches main) ./feature-b a7bc47ca10 months agoInitial commit with a reasonably long...
+Branch Working ± Main ↕ State Path Commit Age Message
+main  ./test-repo a7bc47ca 10 months ago Initial commit with a reasonably long message
+feature-a ./feature-a a7bc47ca 10 months ago Initial commit with a reasonably long message
+feature-b ./feature-b a7bc47ca 10 months ago Initial commit with a reasonably long message
Showing 3 worktrees
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_150.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_150.snap
index 7edf85164..817d6a34f 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_150.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_150.snap
@@ -15,15 +15,15 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmprWISpU/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpTJojTf/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Age Commit Message
-main  ./test-repo a7bc47ca10 months agoInitial commit with a reasonably long message
-feature-a (no commits) (matches main) ./feature-a a7bc47ca10 months agoInitial commit with a reasonably long message
-feature-b (no commits) (matches main) ./feature-b a7bc47ca10 months agoInitial commit with a reasonably long message
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo a7bc47ca 10 months ago Initial commit with a reasonably long message
+feature-a ./feature-a a7bc47ca 10 months ago Initial commit with a reasonably long message
+feature-b ./feature-b a7bc47ca 10 months ago Initial commit with a reasonably long message
Showing 3 worktrees
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_80.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_80.snap
index 3de88a89e..596fbe8c3 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_80.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_80.snap
@@ -15,15 +15,15 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp1Q4LV3/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpRX8cEf/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch State Path Age Commit
-main  ./test-repo a7bc47ca10 months ago
-feature-a (no commits) (matches main) ./feature-a a7bc47ca10 months ago
-feature-b (no commits) (matches main) ./feature-b a7bc47ca10 months ago
+Branch Path Commit Age Message
+main  ./test-repo a7bc47ca 10 months ago Initial commit with a...
+feature-a ./feature-a a7bc47ca 10 months ago Initial commit with a...
+feature-b ./feature-b a7bc47ca 10 months ago Initial commit with a...
Showing 3 worktrees
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__unicode_branch_names.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__unicode_branch_names.snap
index 4878177b2..0869f6bdb 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__unicode_branch_names.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__unicode_branch_names.snap
@@ -15,16 +15,16 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpqxNeC2/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpbKhZjn/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Working ± Main ↕ State Path Age Commit Message
-main  ./test-repo b834638e10 months agoInitial commit
-cafe  (no commits) (matches main) ./café  b834638e10 months agoInitial commit
-naive  (no commits) (matches main) ./naïve  b834638e10 months agoInitial commit
-resume (no commits) (matches main) ./résumé  b834638e10 months agoInitial commit
+Branch Working ± Main ↕ State Path Remote ↕ Commit Age Message
+main  ./test-repo b834638e 10 months ago Initial commit
+cafe  ./café  b834638e 10 months ago Initial commit
+naive  ./naïve  b834638e 10 months ago Initial commit
+resume ./résumé  b834638e 10 months ago Initial commit
Showing 4 worktrees