Skip to content

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

Refactor statusline rendering to improve clarity

Maximilian Roos06bb86d5b6ea
diff --git a/src/commands/list/model.rs b/src/commands/list/model.rs
index 3834fd86e..757124d9c 100644
--- a/src/commands/list/model.rs
+++ b/src/commands/list/model.rs
@@ -410,6 +410,16 @@ impl MainDivergence {
_ => Self::Diverged,
}
}
+
+ /// Returns styled symbol (dimmed), or None for None variant.
+ pub fn styled(&self) -> Option<String> {
+ use worktrunk::styling::HINT;
+ if *self == Self::None {
+ None
+ } else {
+ Some(format!("{HINT}{self}{HINT:#}"))
+ }
+ }
}
/// Upstream/remote divergence state
@@ -460,6 +470,16 @@ impl UpstreamDivergence {
_ => Self::Diverged,
}
}
+
+ /// Returns styled symbol (dimmed), or None for None variant.
+ pub fn styled(&self) -> Option<String> {
+ use worktrunk::styling::HINT;
+ if *self == Self::None {
+ None
+ } else {
+ Some(format!("{HINT}{self}{HINT:#}"))
+ }
+ }
}
/// Combined branch and operation state
@@ -662,39 +682,29 @@ impl StatusSymbols {
// - Yellow (WARNING): Potential conflicts, git operations, locked/prunable (active/stuck states)
// - Cyan: Working tree changes (activity)
// - Dimmed (HINT): Branch state symbols that indicate removability + divergence arrows (low urgency)
- let (branch_op_state_str, has_branch_op_state) = match self.branch_op_state.styled() {
- Some(s) => (s, true),
- None => (String::new(), false),
- };
- let main_divergence_str = if self.main_divergence != MainDivergence::None {
- format!("{HINT}{}{HINT:#}", self.main_divergence)
- } else {
- String::new()
- };
- let upstream_divergence_str = if self.upstream_divergence != UpstreamDivergence::None {
- format!("{HINT}{}{HINT:#}", self.upstream_divergence)
- } else {
- String::new()
- };
+ let (branch_op_state_str, has_branch_op_state) = self
+ .branch_op_state
+ .styled()
+ .map_or((String::new(), false), |s| (s, true));
+ let (main_divergence_str, has_main_divergence) = self
+ .main_divergence
+ .styled()
+ .map_or((String::new(), false), |s| (s, true));
+ let (upstream_divergence_str, has_upstream_divergence) = self
+ .upstream_divergence
+ .styled()
+ .map_or((String::new(), false), |s| (s, true));
// Working tree symbols split into 3 fixed columns for vertical alignment
- let has_staged = self.working_tree.contains('+');
- let has_modified = self.working_tree.contains('!');
- let has_untracked = self.working_tree.contains('?');
- let staged_str = if has_staged {
- format!("{CYAN}+{CYAN:#}")
- } else {
- String::new()
- };
- let modified_str = if has_modified {
- format!("{CYAN}!{CYAN:#}")
- } else {
- String::new()
- };
- let untracked_str = if has_untracked {
- format!("{CYAN}?{CYAN:#}")
- } else {
- String::new()
+ let style_working = |sym: char| -> (String, bool) {
+ if self.working_tree.contains(sym) {
+ (format!("{CYAN}{sym}{CYAN:#}"), true)
+ } else {
+ (String::new(), false)
+ }
};
+ let (staged_str, has_staged) = style_working('+');
+ let (modified_str, has_modified) = style_working('!');
+ let (untracked_str, has_untracked) = style_working('?');
let worktree_state_str = if !self.worktree_state.is_empty() {
// Branch indicator (⎇) is informational (dimmed), worktree attrs (⌫⊠) are warnings (yellow)
if self.worktree_state == "⎇" {
@@ -725,12 +735,12 @@ impl StatusSymbols {
(
PositionMask::MAIN_DIVERGENCE,
main_divergence_str,
- self.main_divergence != MainDivergence::None,
+ has_main_divergence,
),
(
PositionMask::UPSTREAM_DIVERGENCE,
upstream_divergence_str,
- self.upstream_divergence != UpstreamDivergence::None,
+ has_upstream_divergence,
),
(
PositionMask::WORKTREE_STATE,
diff --git a/src/commands/statusline.rs b/src/commands/statusline.rs
index d9ab69fa1..11b4176a3 100644
--- a/src/commands/statusline.rs
+++ b/src/commands/statusline.rs
@@ -87,7 +87,6 @@ fn format_directory_fish_style(path: &str) -> String {
path.to_string()
};
- // Handle absolute paths - preserve leading /
let is_absolute = path.starts_with('/');
let parts: Vec<&str> = path.split('/').filter(|p| !p.is_empty()).collect();
@@ -95,42 +94,21 @@ fn format_directory_fish_style(path: &str) -> String {
return path;
}
- if parts.len() == 1 {
- // Single component - return as-is with leading / if absolute
- return if is_absolute {
- format!("/{}", parts[0])
- } else {
- parts[0].to_string()
- };
- }
-
let mut result = String::new();
-
- // Add leading / for absolute paths
if is_absolute {
result.push('/');
}
for (i, part) in parts.iter().enumerate() {
- let is_last = i == parts.len() - 1;
- let is_first = i == 0;
-
- if is_first && *part == "~" {
- result.push('~');
- } else if is_last {
- // Keep full name for last component
- if !is_first {
- result.push('/');
- }
+ if i > 0 {
+ result.push('/');
+ }
+
+ // Keep ~ and last component full, abbreviate others to first char
+ if (i == 0 && *part == "~") || i == parts.len() - 1 {
result.push_str(part);
- } else {
- // Abbreviate to first character
- if !is_first {
- result.push('/');
- }
- if let Some(c) = part.chars().next() {
- result.push(c);
- }
+ } else if let Some(c) = part.chars().next() {
+ result.push(c);
}
}
@@ -155,13 +133,12 @@ pub fn run(claude_code: bool) -> Result<()> {
)
};
- // Build output parts
- let mut parts: Vec<String> = Vec::new();
+ // Build output string
+ let mut output = String::new();
// Directory (claude-code mode only)
if claude_code {
- let formatted_dir = format_directory_fish_style(&cwd.display().to_string());
- parts.push(formatted_dir);
+ output = format_directory_fish_style(&cwd.display().to_string());
}
// Git status
@@ -169,25 +146,21 @@ pub fn run(claude_code: bool) -> Result<()> {
if repo.git_dir().is_ok()
&& let Some(status_line) = get_git_status(&repo, &cwd)?
{
- parts.push(status_line);
+ if !output.is_empty() {
+ output.push_str(" ");
+ }
+ output.push_str(&status_line);
}
// Model name (claude-code mode only)
if let Some(model) = model_name {
- // Use " | " as separator before model name
- if !parts.is_empty() {
- let last = parts.pop().unwrap();
- parts.push(format!("{last} | {model}"));
- } else {
- parts.push(format!("| {model}"));
- }
+ output.push_str(" | ");
+ output.push_str(&model);
}
// Output with ANSI reset prefix
- if !parts.is_empty() {
- let output = parts.join(" ");
+ if !output.is_empty() {
if claude_code {
- // Reset any prior formatting, add leading space for visual separation
let reset = anstyle::Reset;
print!("{reset} {output}");
} else {