Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor: use single atomic prints for multi-line output (#727)
Maximilian Roos119ddbe40077
diff --git a/src/config/expansion.rs b/src/config/expansion.rsindex 14bbdaf28..2d9224d57 100644--- a/src/config/expansion.rs+++ b/src/config/expansion.rs@@ -742,79 +742,6 @@ mod tests {assert_eq!(r1, r2);}- #[test]- fn test_verbose_output_is_atomic_single_line() {- // Verify that verbose output produces a single combined string- // with header and gutter content, suitable for atomic emission.- // This prevents multi-threaded output interleaving.-- let header = info_message(cformat!("Expanding <bold>test-template</>"));- let template = "{{ branch }}";- let result = "feature-branch";- let content = cformat!("{template} <dim>→</> {result}");- let gutter = format_with_gutter(&content, Some(80));- let output = format!("{header}\n{gutter}");-- // Output should contain both header and gutter in order- assert!(output.contains("Expanding"), "Should contain header text");- assert!(- output.contains("test-template"),- "Should contain template name"- );- assert!(output.contains("{{ branch }}"), "Should contain template");- assert!(output.contains("→"), "Should contain arrow separator");- assert!(output.contains("feature-branch"), "Should contain result");-- // Output should be a single string with newline between header and gutter- let lines: Vec<&str> = output.lines().collect();- assert!(- lines.len() >= 2,- "Should have at least 2 lines (header + gutter)"- );-- // First line should be the info message (contains ○ symbol from info_message)- assert!(lines[0].contains('○'), "First line should be info message");- }-- #[test]- fn test_verbose_output_is_atomic_multiline() {- // Verify that multiline template expansion also produces atomic output.-- let header = info_message(cformat!("Expanding <bold>multiline-template</>"));- let template = "line1\nline2";- let result = "result1\nresult2";- let content = cformat!("{template}\n<dim>→</>\n{result}");- let gutter = format_with_gutter(&content, Some(80));- let output = format!("{header}\n{gutter}");-- // Output should contain multiline content- assert!(- output.contains("line1"),- "Should contain first template line"- );- assert!(- output.contains("line2"),- "Should contain second template line"- );- assert!(- output.contains("result1"),- "Should contain first result line"- );- assert!(- output.contains("result2"),- "Should contain second result line"- );-- // All lines should be present in a single string- let lines: Vec<&str> = output.lines().collect();- // Header (1) + template (2) + arrow (1) + result (2) = 6 lines minimum- assert!(- lines.len() >= 5,- "Should have multiple lines for multiline template, got {}",- lines.len()- );- }-#[test]fn test_redact_credentials_https_token() {// GitHub-style personal access tokendiff --git a/src/help.rs b/src/help.rsindex dffdfd9e7..d4ee1aa8b 100644--- a/src/help.rs+++ b/src/help.rs@@ -244,8 +244,10 @@ fn handle_help_page(args: &[String]) {});let Some(subcommand) = subcommand else {- eprintln!("Usage: wt <command> --help-page");- eprintln!("Commands with pages: merge, switch, remove, list");+ eprintln!(+ "Usage: wt <command> --help-page+Commands with pages: merge, switch, remove, list"+ );return;};diff --git a/src/main.rs b/src/main.rsindex bdff28495..e9bd17dea 100644--- a/src/main.rs+++ b/src/main.rs@@ -69,8 +69,11 @@ fn enhance_and_exit_error(err: clap::Error) -> ! {let cmd = cli::build_command();if let Some(suggestion) = cli::suggest_nested_subcommand(&cmd, unknown.to_string().as_str()){- eprint!("{}", err.render().ansi());- ceprintln!("\n <yellow>tip:</> did you mean <cyan,bold>{suggestion}</cyan,bold>?");+ ceprintln!(+ "{}+ <yellow>tip:</> did you mean <cyan,bold>{suggestion}</cyan,bold>?",+ err.render().ansi()+ );process::exit(2);}}@@ -82,12 +85,15 @@ fn enhance_and_exit_error(err: clap::Error) -> ! {let is_switch_missing_arg = err.kind() == ErrorKind::MissingRequiredArgument&& (err_str.contains("wt switch") || err_str.contains("wt.exe switch"));if is_switch_missing_arg {- eprint!("{}", err.render().ansi());- eprintln!();- ceprintln!("<green,bold>Quick switches:</>");- ceprintln!(" <cyan,bold>wt switch ^</> default branch's worktree");- ceprintln!(" <cyan,bold>wt switch -</> previous worktree");- ceprintln!(" <cyan,bold>wt select</> interactive picker");+ ceprintln!(+ "{}++<green,bold>Quick switches:</>+ <cyan,bold>wt switch ^</> # default branch's worktree+ <cyan,bold>wt switch -</> # previous worktree+ <cyan,bold>wt select</> # interactive picker",+ err.render().ansi()+ );process::exit(2);}diff --git a/tests/snapshots/integration__integration_tests__switch__switch_missing_argument_hints.snap b/tests/snapshots/integration__integration_tests__switch__switch_missing_argument_hints.snapindex 232bf6b27..f8f1e3378 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_missing_argument_hints.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_missing_argument_hints.snap@@ -12,6 +12,7 @@ info:GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""GIT_TERMINAL_PROMPT: "0"HOME: "[TEST_HOME]"LANG: C@@ -39,7 +40,8 @@ exit_code: 2For more information, try '[1m[36m--help[0m'.+[32m[1mQuick switches:[39m[22m- [36m[1mwt switch ^[39m[22m default branch's worktree- [36m[1mwt switch -[39m[22m previous worktree- [36m[1mwt select[39m[22m interactive picker+ [36m[1mwt switch ^[39m[22m # default branch's worktree+ [36m[1mwt switch -[39m[22m # previous worktree+ [36m[1mwt select[39m[22m # interactive picker