Skip to content

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

Fix: Ensure nested styles are correctly applied to CLI output

Maximilian Roosa00cf1eed74b
diff --git a/CLAUDE.md b/CLAUDE.md
index cbb944cba..22ac01960 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -278,26 +278,18 @@ println!("{HINT_EMOJI} {HINT}Use 'wt list' to see all worktrees{HINT:#}");
Compose styles using anstyle methods (`.bold()`, `.fg_color()`, etc.). Branch names in messages (not tables) should be bolded. Tables (`wt list`) use conditional styling for branch names to indicate worktree state (current/main/other).
-Nested style resets leak color. Compose all attributes into a single style object:
+Nested style resets leak color. Compose attributes into a single style, then re-apply the surrounding style after the reset:
```rust
-// ❌ BAD - nested reset leaks color
+// ❌ BAD - nested bold loses surrounding color, text after reset is unstyled
"{WARNING}Text with {bold}nested{bold:#} styles{WARNING:#}"
-// ✅ GOOD - compose styles together
-let warning_bold = WARNING.bold();
-"{WARNING}Text with {warning_bold}composed{warning_bold:#} styles{WARNING:#}"
+// ✅ GOOD - use composed style and re-apply surrounding style after reset
+"{WARNING}Text with {WARNING_BOLD}composed{WARNING_BOLD:#}{WARNING} styles{WARNING:#}"
+// ✅ ALSO GOOD - styled element at end (no text after reset needs styling)
+"{WARNING}Message: {WARNING_BOLD}{value}{WARNING_BOLD:#}{WARNING:#}"
```
-Styled elements must maintain their surrounding color. Compose the color with the style to avoid leaking:
-
-```rust
-// ❌ WRONG - styled element loses surrounding color
-let bold = AnstyleStyle::new().bold();
-println!("✅ {GREEN}Message {bold}{path}{bold:#}{GREEN:#}"); // Path will be black/white!
-// ✅ RIGHT - compose color with style
-let green_bold = GREEN.bold();
-println!("✅ {GREEN}Created worktree at {green_bold}{path}{green_bold:#}{GREEN:#}");
-```
+**Key insight**: `{STYLE:#}` always resets to default, not to the surrounding style. Re-apply the surrounding style after any composed style reset if there's more text to style.
### Color Detection
diff --git a/src/commands/config.rs b/src/commands/config.rs
index c6484539a..a4be86eee 100644
--- a/src/commands/config.rs
+++ b/src/commands/config.rs
@@ -6,8 +6,8 @@ use worktrunk::git::Repository;
use worktrunk::path::format_path_for_display;
use worktrunk::shell::Shell;
use worktrunk::styling::{
- AnstyleStyle, CYAN, GREEN, GREEN_BOLD, HINT, HINT_EMOJI, INFO_EMOJI, WARNING, WARNING_EMOJI,
- format_toml, format_with_gutter,
+ AnstyleStyle, CYAN, GREEN, GREEN_BOLD, HINT, HINT_BOLD, HINT_EMOJI, INFO_EMOJI, WARNING,
+ WARNING_EMOJI, format_toml, format_with_gutter,
};
use super::configure_shell::{ConfigAction, scan_shell_configs};
@@ -259,7 +259,7 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {
any_not_configured = true;
writeln!(
out,
- "{HINT_EMOJI} {HINT}Not configured completions for {bold}{shell}{bold:#} @ {completion_display}{HINT:#}"
+ "{HINT_EMOJI} {HINT}Not configured completions for {HINT_BOLD}{shell}{HINT_BOLD:#}{HINT} @ {completion_display}{HINT:#}"
)?;
}
}
@@ -268,7 +268,7 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {
any_not_configured = true;
writeln!(
out,
- "{HINT_EMOJI} {HINT}Not configured {what} for {bold}{shell}{bold:#} @ {path}{HINT:#}"
+ "{HINT_EMOJI} {HINT}Not configured {what} for {HINT_BOLD}{shell}{HINT_BOLD:#}{HINT} @ {path}{HINT:#}"
)?;
}
_ => {} // Added/Created won't appear in dry_run mode
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index 4c6d20f45..03b74571c 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -108,9 +108,8 @@ pub fn handle_switch_output(
super::success(format_switch_success(branch, path, false, None))?;
} else {
// Shell integration not configured - show warning and setup hint
- let bold = worktrunk::styling::AnstyleStyle::new().bold();
super::warning(format!(
- "{WARNING}Worktree for {bold}{branch}{bold:#}{WARNING} at {bold}{}{bold:#}{WARNING}; cannot cd (no shell integration){WARNING:#}",
+ "{WARNING}Worktree for {WARNING_BOLD}{branch}{WARNING_BOLD:#}{WARNING} at {WARNING_BOLD}{}{WARNING_BOLD:#}{WARNING}; cannot cd (no shell integration){WARNING:#}",
format_path_for_display(path)
))?;
super::shell_integration_hint(shell_integration_hint())?;
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_partial_shell_config_shows_hint.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_partial_shell_config_shows_hint.snap
index 9e091fc39..fc00a5a80 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_partial_shell_config_shows_hint.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_partial_shell_config_shows_hint.snap
@@ -33,7 +33,7 @@ exit_code: 0
⚪ Project Config: [REPO]/.config/wt.toml
💡 Not found
-💡 Not configured shell extension & completions for bash @ ~/.bashrc
+💡 Not configured shell extension & completions for bash @ ~/.bashrc
⚪ Already configured shell extension & completions for zsh @ ~/.zshrc
⚪ Skipped fish; ~/.config/fish/conf.d not found
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_skip_existing.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_skip_existing.snap
index 1cb8f4efb..c8818b225 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_skip_existing.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_skip_existing.snap
@@ -13,15 +13,17 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_BIN: ""
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
success: true
exit_code: 0
----- stdout -----
-🟡 Worktree for feature at [REPO].feature; cannot cd (no shell integration)
+🟡 Worktree for feature at [REPO].feature; cannot cd (no shell integration)
💡 Run `wt config shell install` to enable automatic cd
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_existing_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_existing_branch.snap
index 68bf9f0f4..a6d361bc7 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_existing_branch.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_existing_branch.snap
@@ -13,15 +13,17 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_BIN: ""
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
success: true
exit_code: 0
----- stdout -----
-🟡 Worktree for feature-z at [WORKTREE_FEATURE_Z]; cannot cd (no shell integration)
+🟡 Worktree for feature-z at [WORKTREE_FEATURE_Z]; cannot cd (no shell integration)
💡 Run `wt config shell install` to enable automatic cd
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_previous_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_previous_branch.snap
index 1ca4d904c..9a8ae155a 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_previous_branch.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_previous_branch.snap
@@ -13,15 +13,17 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_BIN: ""
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
success: true
exit_code: 0
----- stdout -----
-🟡 Worktree for feature-a at [REPO].feature-a; cannot cd (no shell integration)
+🟡 Worktree for feature-a at [REPO].feature-a; cannot cd (no shell integration)
💡 Run `wt config shell install` to enable automatic cd
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_previous_branch_with_worktrunk_history_back.snap b/tests/snapshots/integration__integration_tests__switch__switch_previous_branch_with_worktrunk_history_back.snap
index bbcea892e..66695a30c 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_previous_branch_with_worktrunk_history_back.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_previous_branch_with_worktrunk_history_back.snap
@@ -13,15 +13,17 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_BIN: ""
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
success: true
exit_code: 0
----- stdout -----
-🟡 Worktree for feature-x at [REPO].feature-x; cannot cd (no shell integration)
+🟡 Worktree for feature-x at [REPO].feature-x; cannot cd (no shell integration)
💡 Run `wt config shell install` to enable automatic cd
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_to_existing_primary_on_different_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_to_existing_primary_on_different_branch.snap
index 1db6c3782..5420d8fe2 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_to_existing_primary_on_different_branch.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_to_existing_primary_on_different_branch.snap
@@ -13,15 +13,17 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_BIN: ""
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
success: true
exit_code: 0
----- stdout -----
-🟡 Worktree for existing-branch at [WORKTREE_EXISTING_BRANCH]; cannot cd (no shell integration)
+🟡 Worktree for existing-branch at [WORKTREE_EXISTING_BRANCH]; cannot cd (no shell integration)
💡 Run `wt config shell install` to enable automatic cd
----- stderr -----