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.mdindex 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 Detectiondiff --git a/src/commands/config.rs b/src/commands/config.rsindex 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 modediff --git a/src/output/handlers.rs b/src/output/handlers.rsindex 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.snapindex 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: [1m[REPO]/.config/wt.toml[0m💡 [2mNot found[0m-💡 [2mNot configured shell extension & completions for [1mbash[0m @ ~/.bashrc[0m+💡 [2mNot configured shell extension & completions for [1m[2mbash[0m[2m @ ~/.bashrc[0m⚪ Already configured shell extension & completions for [1mzsh[0m @ ~/.zshrc[2m⚪ Skipped fish; ~/.config/fish/conf.d not found[0mdiff --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.snapindex 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/nullGIT_EDITOR: ""+ HOME: "[TEST_HOME]"LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_BIN: ""WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"---success: trueexit_code: 0----- stdout ------🟡 [33mWorktree for [1mfeature[0m[33m at [1m[REPO].feature[0m[33m; cannot cd (no shell integration)[0m+🟡 [33mWorktree for [1m[33mfeature[0m[33m at [1m[33m[REPO].feature[0m[33m; cannot cd (no shell integration)[0m💡 [2m[2mRun `wt config shell install` to enable automatic cd[0m[0m----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__switch__switch_existing_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_existing_branch.snapindex 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/nullGIT_EDITOR: ""+ HOME: "[TEST_HOME]"LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_BIN: ""WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"---success: trueexit_code: 0----- stdout ------🟡 [33mWorktree for [1mfeature-z[0m[33m at [1m[WORKTREE_FEATURE_Z][0m[33m; cannot cd (no shell integration)[0m+🟡 [33mWorktree for [1m[33mfeature-z[0m[33m at [1m[33m[WORKTREE_FEATURE_Z][0m[33m; cannot cd (no shell integration)[0m💡 [2m[2mRun `wt config shell install` to enable automatic cd[0m[0m----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__switch__switch_previous_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_previous_branch.snapindex 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/nullGIT_EDITOR: ""+ HOME: "[TEST_HOME]"LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_BIN: ""WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"---success: trueexit_code: 0----- stdout ------🟡 [33mWorktree for [1mfeature-a[0m[33m at [1m[REPO].feature-a[0m[33m; cannot cd (no shell integration)[0m+🟡 [33mWorktree for [1m[33mfeature-a[0m[33m at [1m[33m[REPO].feature-a[0m[33m; cannot cd (no shell integration)[0m💡 [2m[2mRun `wt config shell install` to enable automatic cd[0m[0m----- 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.snapindex 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/nullGIT_EDITOR: ""+ HOME: "[TEST_HOME]"LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_BIN: ""WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"---success: trueexit_code: 0----- stdout ------🟡 [33mWorktree for [1mfeature-x[0m[33m at [1m[REPO].feature-x[0m[33m; cannot cd (no shell integration)[0m+🟡 [33mWorktree for [1m[33mfeature-x[0m[33m at [1m[33m[REPO].feature-x[0m[33m; cannot cd (no shell integration)[0m💡 [2m[2mRun `wt config shell install` to enable automatic cd[0m[0m----- 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.snapindex 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/nullGIT_EDITOR: ""+ HOME: "[TEST_HOME]"LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_BIN: ""WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"---success: trueexit_code: 0----- stdout ------🟡 [33mWorktree for [1mexisting-branch[0m[33m at [1m[WORKTREE_EXISTING_BRANCH][0m[33m; cannot cd (no shell integration)[0m+🟡 [33mWorktree for [1m[33mexisting-branch[0m[33m at [1m[33m[WORKTREE_EXISTING_BRANCH][0m[33m; cannot cd (no shell integration)[0m💡 [2m[2mRun `wt config shell install` to enable automatic cd[0m[0m----- stderr -----