Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/config/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use worktrunk::config::{
};
use worktrunk::git::Repository;
use worktrunk::styling::{
eprintln, format_bash_with_gutter, hint_message, info_message, print, println, success_message,
suggest_command_in_dir,
eprint, eprintln, format_bash_with_gutter, hint_message, info_message, print, println,
success_message, suggest_command_in_dir,
};

use crate::output::prompt::{PromptResponse, prompt_yes_no_preview};
Expand Down
2 changes: 1 addition & 1 deletion src/config/deprecation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use shell_escape::unix::escape;
use crate::config::WorktrunkConfig;
use crate::shell_exec::Cmd;
use crate::styling::{
eprintln, format_with_gutter, hint_message, info_message, suggest_command_in_dir,
eprint, eprintln, format_with_gutter, hint_message, info_message, suggest_command_in_dir,
warning_message,
};

Expand Down
4 changes: 2 additions & 2 deletions src/output/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::io::{self, Write};

use color_print::cformat;
use worktrunk::styling::PROMPT_SYMBOL;
use worktrunk::styling::{PROMPT_SYMBOL, eprint, eprintln};

/// Response from a `[y/N/?]` prompt.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -42,7 +42,7 @@ pub fn prompt_yes_no_preview(
show_preview: impl Fn(),
) -> io::Result<PromptResponse> {
// Blank line before first prompt for visual separation
worktrunk::styling::eprintln!();
eprintln!();

loop {
eprint!(
Expand Down
38 changes: 38 additions & 0 deletions tests/integration_tests/output_system_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,41 @@ fn test_stdout_surfaces_survive_a_closed_consumer(repo: TestRepo) {
);
}
}

/// Narration on stderr strips its color when stderr isn't a terminal.
///
/// The stdout rule above has a stderr counterpart, and it is the same mistake:
/// `worktrunk::styling`'s `eprint!` is anstream's and strips ANSI off a
/// non-tty, std's prelude macro of the same name keeps it. A file that
/// imported `eprintln` from `styling` but not `eprint` got one of each, so a
/// deprecation warning and the hint printed directly beneath it disagreed
/// about whether `wt list 2>log` should carry escapes.
///
/// The suite's own `CLICOLOR_FORCE=1` is what hides this — it forces color on
/// both printers, so every snapshot agrees no matter which macro is in scope.
/// This test clears it and sets `NO_COLOR`, which only anstream honors.
///
/// The trigger is a deprecated `[ci]` block, whose warning is emitted by the
/// pre-deserialization deprecation pass on every command that loads config.
#[rstest]
fn test_stderr_narration_strips_ansi_when_piped(repo: TestRepo) {
repo.write_project_config("[ci]\nplatform = \"github\"\n");

let output = repo
.wt_command()
.arg("list")
.env_remove("CLICOLOR_FORCE")
.env("NO_COLOR", "1")
.output()
.expect("failed to run wt list");

let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("deprecated"),
"expected the [ci] deprecation warning on stderr; got: {stderr:?}"
);
assert!(
!stderr.contains('\x1b'),
"wt narration redirected to a file must not contain ANSI escapes; got: {stderr:?}"
);
}
Loading