Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Route statusline output via output::data_raw() (#205)
Maximilian Roosa379177894eb
diff --git a/src/commands/statusline.rs b/src/commands/statusline.rsindex ef9068682..be4d0dd4d 100644--- a/src/commands/statusline.rs+++ b/src/commands/statusline.rs@@ -70,8 +70,8 @@ impl ClaudeCodeContext {let _ = tx.send(input);});- // Wait up to 50ms for stdin (needs to be longer on Windows where process spawning is slower)- let input = rx.recv_timeout(Duration::from_millis(50)).ok()?;+ // Wait up to 100ms for stdin (Windows CI can be slow)+ let input = rx.recv_timeout(Duration::from_millis(100)).ok()?;Self::parse(&input)}@@ -129,9 +129,9 @@ fn format_directory_fish_style(path: &str) -> String {/// Run the statusline command.///-/// Uses the output system like other commands:-/// - Interactive mode: output goes to stdout-/// - Directive mode: output goes to stderr, keeping stdout clean for shell directives+/// Output uses `output::data_raw()` which routes based on mode:+/// - Interactive: stdout (for shell prompts)+/// - Directive: stderr (stdout reserved for shell script)pub fn run(claude_code: bool) -> Result<()> {// Get context - either from stdin (claude-code mode) or current directorylet (cwd, model_name) = if claude_code {@@ -202,20 +202,12 @@ pub fn run(claude_code: bool) -> Result<()> {output.push_str(&model);}- // Output via output system (goes to stderr, like `wt list`)+ // Output via output system (routes based on mode: interactive→stdout, directive→stderr)if !output.is_empty() {- if claude_code {- use std::io::Write;- use worktrunk::styling::fix_dim_after_color_reset;- let reset = anstyle::Reset;- // Bypass anstream - write directly to stdout to preserve ANSI codes- // regardless of TTY detection (Claude Code expects raw ANSI)- let output = fix_dim_after_color_reset(&output);- writeln!(std::io::stdout(), "{reset} {output}")?;- std::io::stdout().flush()?;- } else {- output::data(output)?;- }+ use worktrunk::styling::fix_dim_after_color_reset;+ let reset = anstyle::Reset;+ let output = fix_dim_after_color_reset(&output);+ output::data_raw(format!("{reset} {output}"))?;}Ok(())diff --git a/src/output/global.rs b/src/output/global.rsindex b365bf03c..1dd48d0f1 100644--- a/src/output/global.rs+++ b/src/output/global.rs@@ -151,6 +151,28 @@ pub fn data(content: impl Into<String>) -> io::Result<()> {}}+/// Emit raw data output, bypassing anstream color detection+///+/// Like `data()` but writes directly to stdout/stderr without anstream processing.+/// Use when ANSI codes must be preserved regardless of TTY detection (e.g., statusline+/// output for Claude Code which always expects ANSI).+///+/// - **Interactive**: writes to stdout+/// - **Directive**: writes to stderr (stdout reserved for shell script)+pub fn data_raw(content: impl Into<String>) -> io::Result<()> {+ let content = content.into();+ match get_mode() {+ OutputMode::Interactive => {+ writeln!(io::stdout(), "{content}")?;+ io::stdout().flush()+ }+ OutputMode::Directive(_) => {+ writeln!(io::stderr(), "{content}")?;+ io::stderr().flush()+ }+ }+}+/// Emit table/UI output to stderr////// Used for table rows and progress indicators that should appear on the samediff --git a/src/output/mod.rs b/src/output/mod.rsindex 83fea126b..9a3f3d860 100644--- a/src/output/mod.rs+++ b/src/output/mod.rs@@ -54,8 +54,8 @@ pub mod handlers;// Re-export the public APIpub use global::{- OutputMode, blank, change_directory, data, execute, flush, flush_for_stderr_prompt, gutter,- initialize, print, shell_integration_hint, table, terminate_output,+ OutputMode, blank, change_directory, data, data_raw, execute, flush, flush_for_stderr_prompt,+ gutter, initialize, print, shell_integration_hint, table, terminate_output,};// Re-export output handlerspub use handlers::{diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rsindex 1c83a19bc..a3bef4339 100644--- a/tests/integration_tests/statusline.rs+++ b/tests/integration_tests/statusline.rs@@ -99,14 +99,14 @@ fn add_commits_ahead(repo: &mut TestRepo) {#[rstest]fn test_statusline_basic(repo: TestRepo) {let output = run_statusline(&repo, &[], None);- assert_snapshot!(output, @"main [2m^[22m");+ assert_snapshot!(output, @"[0m main [2m^[22m");}#[rstest]fn test_statusline_with_changes(repo: TestRepo) {add_uncommitted_changes(&repo);let output = run_statusline(&repo, &[], None);- assert_snapshot!(output, @"main [36m?[39m[2m^[22m");+ assert_snapshot!(output, @"[0m main [36m?[0m[2m^[22m");}#[rstest]@@ -115,7 +115,7 @@ fn test_statusline_commits_ahead(mut repo: TestRepo) {// Run from the feature worktree to see commits aheadlet feature_path = repo.worktree_path("feature");let output = run_statusline_from_dir(&repo, &[], None, feature_path);- assert_snapshot!(output, @"feature [2m↑[22m [32m↑2[0m ^[32m+2[0m");+ assert_snapshot!(output, @"[0m feature [2m↑[22m [32m↑2[0m ^[32m+2[0m");}// --- Claude Code Mode Tests ---