Skip to content

Commit 51fc6c7

Browse files
authored
[nextest-runner] explicitly disable progress bar if stderr is not a TTY (#2739)
This is also checked by indicatif, but it's nice to be more explicit about it. Plus, it allows us to use indicatif's `println` function, which appears to flicker quite a bit less than `suspend`.
1 parent 5707158 commit 51fc6c7

File tree

1 file changed

+11
-3
lines changed
  • nextest-runner/src/reporter/displayer

1 file changed

+11
-3
lines changed

nextest-runner/src/reporter/displayer/imp.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use owo_colors::OwoColorize;
4242
use std::{
4343
borrow::Cow,
4444
cmp::Reverse,
45-
io::{self, BufWriter, Write},
45+
io::{self, BufWriter, IsTerminal, Write},
4646
time::Duration,
4747
};
4848

@@ -179,9 +179,17 @@ impl DisplayReporterBuilder {
179179
return None;
180180
}
181181

182+
// If this is not a terminal, don't enable the progress bar. indicatif
183+
// also has this logic internally, but we do this check outside so we
184+
// know whether we're writing to an external buffer or to indicatif.
185+
if !std::io::stderr().is_terminal() {
186+
return None;
187+
}
188+
182189
let show_running = match self.show_progress {
183190
ShowProgress::None | ShowProgress::Counter => return None,
184-
// For auto we enable progress bar if not in ci, and it's checked above.
191+
// For auto we enable progress bar if not in CI and not a terminal.
192+
// Both of these conditions are checked above.
185193
ShowProgress::Auto | ShowProgress::Bar => false,
186194
ShowProgress::Running => true,
187195
};
@@ -260,7 +268,7 @@ impl<'a> DisplayReporter<'a> {
260268
enum ReporterStderrImpl<'a> {
261269
Terminal {
262270
// Reporter-specific progress bar state. None if the progress bar is not
263-
// enabled.
271+
// enabled (which can include the terminal not being a TTY).
264272
progress_bar: Option<Box<ProgressBarState>>,
265273
// OSC 9 code progress reporting.
266274
term_progress: Option<TerminalProgress>,

0 commit comments

Comments
 (0)