Skip to content

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

fix: Re-establish outer color after styled elements

Maximilian Roos4500fbf0f2fc
diff --git a/CLAUDE.md b/CLAUDE.md
index 334ebf31e..ea8369485 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -349,6 +349,14 @@ println!("✅ {GREEN}Created worktree, changed directory to {green_bold}{}{green
let green_dim = GREEN.dimmed();
println!("✅ {GREEN}Committed changes @ {green_dim}{hash}{green_dim:#}{GREEN:#}");
+// CRITICAL: Styled elements in the MIDDLE of messages
+// When a styled element appears mid-message with text after it, re-establish the outer color
+// because {styled:#} resets ALL attributes including the outer color
+let green_bold = GREEN.bold();
+println!("✅ {GREEN}Already on {green_bold}{branch}{green_bold:#}{GREEN}, nothing to merge{GREEN:#}");
+// ^^^^^^^ Re-establish GREEN here!
+// Without re-establishing GREEN, ", nothing to merge" would appear in default color (black/white)
+
// Parenthesized suffixes - unstyled even in colored messages
let cyan_dim = CYAN.dimmed();
println!("🔄 {CYAN}Merging to main @ {cyan_dim}{hash}{cyan_dim:#}{CYAN:#} (no squashing needed)");
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index c70b558fc..82e885e8a 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -139,7 +139,7 @@ pub fn handle_merge(
use worktrunk::styling::GREEN;
let green_bold = GREEN.bold();
crate::output::success(format!(
- "{GREEN}Already on {green_bold}{target_branch}{green_bold:#}, nothing to merge{GREEN:#}"
+ "{GREEN}Already on {green_bold}{target_branch}{green_bold:#}{GREEN}, nothing to merge{GREEN:#}"
))?;
return Ok(());
}
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index 1836cba21..6233c67df 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -45,18 +45,25 @@ fn format_remove_message(result: &RemoveResult, branch: Option<&str>) -> String
"Removed worktree & branch"
};
- let branch_suffix = branch
- .or(Some(branch_name))
- .map(|b| format!(" for {green_bold}{b}{green_bold:#}"))
- .unwrap_or_default();
+ let branch_display = branch.or(Some(branch_name));
if *changed_directory {
- format!(
- "{GREEN}{action}{branch_suffix}, returned to primary at {green_bold}{}{green_bold:#}{GREEN:#}",
- primary_path.display()
- )
+ if let Some(b) = branch_display {
+ // Re-establish GREEN after each green_bold reset to prevent color leak
+ format!(
+ "{GREEN}{action} for {green_bold}{b}{green_bold:#}{GREEN}, returned to primary at {green_bold}{}{green_bold:#}{GREEN:#}",
+ primary_path.display()
+ )
+ } else {
+ format!(
+ "{GREEN}{action}, returned to primary at {green_bold}{}{green_bold:#}{GREEN:#}",
+ primary_path.display()
+ )
+ }
+ } else if let Some(b) = branch_display {
+ format!("{GREEN}{action} for {green_bold}{b}{green_bold:#}{GREEN:#}")
} else {
- format!("{GREEN}{action}{branch_suffix}{GREEN:#}")
+ format!("{GREEN}{action}{GREEN:#}")
}
}
RemoveResult::SwitchedToDefault(branch) => {
diff --git a/src/output/mod.rs b/src/output/mod.rs
index 797d62ec7..c6229728e 100644
--- a/src/output/mod.rs
+++ b/src/output/mod.rs
@@ -94,13 +94,17 @@ pub(crate) fn format_switch_success_message(
} else {
"Switched to worktree for"
};
- let base_suffix = base_branch
- .map(|b| format!(" from {green_bold}{b}{green_bold:#}{GREEN}"))
- .unwrap_or_default();
let location = if use_past_tense { ":" } else { " at" };
- format!(
- "{GREEN}{action} {green_bold}{branch}{green_bold:#}{GREEN}{base_suffix}{location} {green_bold}{}{green_bold:#}{GREEN:#}",
- path.display()
- )
+ // Re-establish GREEN after each green_bold reset to prevent color leak
+ match base_branch {
+ Some(base) => format!(
+ "{GREEN}{action} {green_bold}{branch}{green_bold:#}{GREEN} from {green_bold}{base}{green_bold:#}{GREEN}{location} {green_bold}{}{green_bold:#}{GREEN:#}",
+ path.display()
+ ),
+ None => format!(
+ "{GREEN}{action} {green_bold}{branch}{green_bold:#}{GREEN}{location} {green_bold}{}{green_bold:#}{GREEN:#}",
+ path.display()
+ ),
+ }
}
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge.snap
index a470fe25a..27789aa57 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-✅ Already on main, nothing to merge
+✅ Already on main, nothing to merge
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap b/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap
index 62266671e..b70639dd1 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap
@@ -15,11 +15,11 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp9cXob6/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpiqh9z4/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-✅ Already on main, nothing to merge
+✅ Already on main, nothing to merge
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap
index b717104c4..4964d920e 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap
@@ -15,11 +15,11 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpQgOXQf/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpVJHt5s/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-✅ Already on feature, nothing to merge
+✅ Already on feature, nothing to merge
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_current_by_name.snap b/tests/snapshots/integration__integration_tests__remove__remove_current_by_name.snap
index 07ccf282a..e6c30b102 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_current_by_name.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_current_by_name.snap
@@ -16,12 +16,12 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpl0MgDF/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpNsr0R8/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
🔄 Removing worktree for feature-current...
-✅ Removed worktree & branch for feature-current, returned to primary at [REPO]
+✅ Removed worktree & branch for feature-current, returned to primary at [REPO]
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap
index ceef2d1c9..e172a6ae1 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap
@@ -15,12 +15,12 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpVXvlyL/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpTU3y3F/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
🔄 Removing worktree...
-✅ Removed worktree & branch for feature-wt, returned to primary at [REPO]
+✅ Removed worktree & branch for feature-wt, returned to primary at [REPO]
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap b/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap
index ddefe7c8b..7b14d663e 100644
Binary files a/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap and b/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap differ
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap b/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap
index 57c06c6df..542449385 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap
@@ -18,7 +18,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpO0TJZf/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpoHTh6V/test-config.toml
---
success: true
exit_code: 0
@@ -28,6 +28,6 @@ exit_code: 0
🔄 Removing worktree for feature-c...
✅ Removed worktree & branch for feature-c
🔄 Removing worktree for feature-a...
-✅ Removed worktree & branch for feature-a, returned to primary at [REPO]
+✅ Removed worktree & branch for feature-a, returned to primary at [REPO]
----- stderr -----