diff --git a/src/lib.rs b/src/lib.rs index 4a8c4b6..60b813d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -167,7 +167,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let max_count = matches.get_one::("max_count").copied(); let byte_offset = matches.get_flag("byte_offset"); let line_number = matches.get_flag("line_number"); - let line_buffered = matches.get_flag("line_buffered"); + let stdout_is_terminal = std::io::stdout().is_terminal(); + let line_buffered = matches.get_flag("line_buffered") || stdout_is_terminal; let with_filename = matches.get_flag("with_filename"); let no_filename = matches.get_flag("no_filename"); let label = matches @@ -391,7 +392,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { ColorMode::Never => false, // On Windows, an unset TERM allows color support, matching anstyle-query. ColorMode::Auto => { - std::io::stdout().is_terminal() + stdout_is_terminal && match std::env::var_os("TERM") { Some(term) => term != "dumb", None => cfg!(windows), diff --git a/src/output.rs b/src/output.rs index ba1f06a..dc90127 100644 --- a/src/output.rs +++ b/src/output.rs @@ -231,7 +231,7 @@ impl<'a> OutputWriter<'a> { } } - /// Flush in `--line-buffered` mode. + /// Flush for terminal output or explicit `--line-buffered` mode. fn maybe_flush(&mut self) -> io::Result<()> { if self.config.line_buffered { self.out.flush()