Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fn output_palette(params: &Params) -> Option<Palette> {
ColorWhen::Always => true,
ColorWhen::Auto => {
(params.presume_output_tty || stdout().is_terminal())
&& std::env::var_os("TERM").is_some_and(|term| term != "dumb")
&& std::env::var_os("TERM").is_none_or(|term| term != "dumb")
}
};
if !enabled {
Expand Down
12 changes: 12 additions & 0 deletions tests/by-util/test_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,18 @@ fn color() -> Result<(), Box<dyn std::error::Error>> {
.stdout("2c2\n< rain\n---\n> snow\n");
}

// Like GNU diff, an unset TERM does not disable --color=auto on a terminal.
let mut cmd = cargo_bin_cmd!("diffutils");
cmd.env_remove("TERM")
.arg("diff")
.arg("--color=auto")
.arg("---presume-output-tty")
.arg(&old)
.arg(&new);
cmd.assert()
.code(predicate::eq(1))
.stdout("\x1b[36m2c2\x1b[0m\n\x1b[31m< rain\x1b[0m\n---\n\x1b[32m> snow\x1b[0m\n");

// An invalid palette is reported and disables colors.
let mut cmd = cargo_bin_cmd!("diffutils");
cmd.arg("diff")
Expand Down
Loading