diff --git a/src/config.rs b/src/config.rs index 83e6258..55cd57a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,7 +4,6 @@ use clap::ArgMatches; use config_file::FromConfigFile; use regex::Regex; use serde::Deserialize; -use std::io::IsTerminal; use std::path::Path; use std::path::PathBuf; @@ -54,9 +53,7 @@ impl Config { Some(true) == self.force_colors || options.get_flag("force_colors") } pub fn get_disable_progress(&self, options: &ArgMatches) -> bool { - Some(true) == self.disable_progress - || options.get_flag("disable_progress") - || !std::io::stdout().is_terminal() + Some(true) == self.disable_progress || options.get_flag("disable_progress") } pub fn get_apparent_size(&self, options: &ArgMatches) -> bool { Some(true) == self.display_apparent_size || options.get_flag("display_apparent_size") diff --git a/src/progress.rs b/src/progress.rs index fd37b92..cfb47b0 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -118,7 +118,7 @@ impl PIndicator { let time_info_thread = std::thread::spawn(move || { let mut progress_char_i: usize = 0; - let mut stdout = std::io::stdout(); + let mut stderr = std::io::stderr(); let mut msg = "".to_string(); // While the timeout triggers we go round the loop @@ -127,7 +127,8 @@ impl PIndicator { receiver.recv_timeout(Duration::from_millis(SPINNER_SLEEP_TIME)) { // Clear the text written by 'write!'& Return at the start of line - print!("\r{:width$}", " ", width = msg.len()); + let clear = format!("\r{:width$}", " ", width = msg.len()); + write!(stderr, "{clear}").unwrap(); let prog_char = PROGRESS_CHARS[progress_char_i]; msg = match data.state.load(ORDERING) { @@ -136,15 +137,17 @@ impl PIndicator { _ => panic!("Unknown State"), }; - write!(stdout, "\r{msg}").unwrap(); - stdout.flush().unwrap(); + write!(stderr, "\r{msg}").unwrap(); + stderr.flush().unwrap(); progress_char_i += 1; progress_char_i %= PROGRESS_CHARS_LEN; } - print!("\r{:width$}", " ", width = msg.len()); - print!("\r"); - stdout.flush().unwrap(); + + let clear = format!("\r{:width$}", " ", width = msg.len()); + write!(stderr, "{clear}").unwrap(); + write!(stderr, "\r").unwrap(); + stderr.flush().unwrap(); }); self.thread = Some((stop_handler, time_info_thread)) } diff --git a/tests/test_flags.rs b/tests/test_flags.rs index d6e9cb9..64a7486 100644 --- a/tests/test_flags.rs +++ b/tests/test_flags.rs @@ -10,6 +10,9 @@ use std::str; fn build_command>(command_args: Vec) -> String { let mut cmd = &mut Command::cargo_bin("dust").unwrap(); + // Hide progress bar + cmd = cmd.arg("-P"); + for p in command_args { cmd = cmd.arg(p); }