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.mdindex 334ebf31e..ea8369485 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -349,6 +349,14 @@ println!("✅ {GREEN}Created worktree, changed directory to {green_bold}{}{greenlet 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 messageslet 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.rsindex 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.rsindex 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.rsindex 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.snapindex 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.rsexpression: output.normalized()----✅ [32mAlready on [1m[32mmain[0m, nothing to merge[0m+✅ [32mAlready on [1m[32mmain[0m[32m, nothing to merge[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap b/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snapindex 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: CLC_ALL: CSOURCE_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: trueexit_code: 0----- stdout ------✅ [32mAlready on [1m[32mmain[0m, nothing to merge[0m+✅ [32mAlready on [1m[32mmain[0m[32m, nothing to merge[0m----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snapindex 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: CLC_ALL: CSOURCE_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: trueexit_code: 0----- stdout ------✅ [32mAlready on [1m[32mfeature[0m, nothing to merge[0m+✅ [32mAlready on [1m[32mfeature[0m[32m, nothing to merge[0m----- 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.snapindex 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: CLC_ALL: CSOURCE_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: trueexit_code: 0----- stdout -----🔄 [36mRemoving worktree for [1m[36mfeature-current[0m...[0m-✅ [32mRemoved worktree & branch for [1m[32mfeature-current[0m, returned to primary at [1m[32m[REPO][0m[0m+✅ [32mRemoved worktree & branch for [1m[32mfeature-current[0m[32m, returned to primary at [1m[32m[REPO][0m[0m----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snapindex 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: CLC_ALL: CSOURCE_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: trueexit_code: 0----- stdout -----🔄 [36mRemoving worktree...[0m-✅ [32mRemoved worktree & branch for [1m[32mfeature-wt[0m, returned to primary at [1m[32m[REPO][0m[0m+✅ [32mRemoved worktree & branch for [1m[32mfeature-wt[0m[32m, returned to primary at [1m[32m[REPO][0m[0m----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap b/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snapindex ddefe7c8b..7b14d663e 100644Binary files a/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap and b/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap differdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap b/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snapindex 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: CLC_ALL: CSOURCE_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: trueexit_code: 0@@ -28,6 +28,6 @@ exit_code: 0🔄 [36mRemoving worktree for [1m[36mfeature-c[0m...[0m✅ [32mRemoved worktree & branch for [1m[32mfeature-c[0m[0m🔄 [36mRemoving worktree for [1m[36mfeature-a[0m...[0m-✅ [32mRemoved worktree & branch for [1m[32mfeature-a[0m, returned to primary at [1m[32m[REPO][0m[0m+✅ [32mRemoved worktree & branch for [1m[32mfeature-a[0m[32m, returned to primary at [1m[32m[REPO][0m[0m----- stderr -----