Skip to content

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.rs
index 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 directory
let (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.rs
index 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 same
diff --git a/src/output/mod.rs b/src/output/mod.rs
index 83fea126b..9a3f3d860 100644
--- a/src/output/mod.rs
+++ b/src/output/mod.rs
@@ -54,8 +54,8 @@ pub mod handlers;
// Re-export the public API
pub 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 handlers
pub use handlers::{
diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rs
index 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 ^");
+ assert_snapshot!(output, @" main ^");
}
#[rstest]
fn test_statusline_with_changes(repo: TestRepo) {
add_uncommitted_changes(&repo);
let output = run_statusline(&repo, &[], None);
- assert_snapshot!(output, @"main ?^");
+ assert_snapshot!(output, @" main ?^");
}
#[rstest]
@@ -115,7 +115,7 @@ fn test_statusline_commits_ahead(mut repo: TestRepo) {
// Run from the feature worktree to see commits ahead
let feature_path = repo.worktree_path("feature");
let output = run_statusline_from_dir(&repo, &[], None, feature_path);
- assert_snapshot!(output, @"feature ↑ ↑2 ^+2");
+ assert_snapshot!(output, @" feature ↑ ↑2 ^+2");
}
// --- Claude Code Mode Tests ---