mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
fix: status mesages go to stderr not stdout
Progress spinner and status line are written to stderr instead of stdout. No longer any need to detect if stdout is being redirected.
This commit is contained in:
+1
-4
@@ -4,7 +4,6 @@ use clap::ArgMatches;
|
|||||||
use config_file::FromConfigFile;
|
use config_file::FromConfigFile;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::io::IsTerminal;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
@@ -54,9 +53,7 @@ impl Config {
|
|||||||
Some(true) == self.force_colors || options.get_flag("force_colors")
|
Some(true) == self.force_colors || options.get_flag("force_colors")
|
||||||
}
|
}
|
||||||
pub fn get_disable_progress(&self, options: &ArgMatches) -> bool {
|
pub fn get_disable_progress(&self, options: &ArgMatches) -> bool {
|
||||||
Some(true) == self.disable_progress
|
Some(true) == self.disable_progress || options.get_flag("disable_progress")
|
||||||
|| options.get_flag("disable_progress")
|
|
||||||
|| !std::io::stdout().is_terminal()
|
|
||||||
}
|
}
|
||||||
pub fn get_apparent_size(&self, options: &ArgMatches) -> bool {
|
pub fn get_apparent_size(&self, options: &ArgMatches) -> bool {
|
||||||
Some(true) == self.display_apparent_size || options.get_flag("display_apparent_size")
|
Some(true) == self.display_apparent_size || options.get_flag("display_apparent_size")
|
||||||
|
|||||||
+10
-7
@@ -118,7 +118,7 @@ impl PIndicator {
|
|||||||
|
|
||||||
let time_info_thread = std::thread::spawn(move || {
|
let time_info_thread = std::thread::spawn(move || {
|
||||||
let mut progress_char_i: usize = 0;
|
let mut progress_char_i: usize = 0;
|
||||||
let mut stdout = std::io::stdout();
|
let mut stderr = std::io::stderr();
|
||||||
let mut msg = "".to_string();
|
let mut msg = "".to_string();
|
||||||
|
|
||||||
// While the timeout triggers we go round the loop
|
// While the timeout triggers we go round the loop
|
||||||
@@ -127,7 +127,8 @@ impl PIndicator {
|
|||||||
receiver.recv_timeout(Duration::from_millis(SPINNER_SLEEP_TIME))
|
receiver.recv_timeout(Duration::from_millis(SPINNER_SLEEP_TIME))
|
||||||
{
|
{
|
||||||
// Clear the text written by 'write!'& Return at the start of line
|
// 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];
|
let prog_char = PROGRESS_CHARS[progress_char_i];
|
||||||
|
|
||||||
msg = match data.state.load(ORDERING) {
|
msg = match data.state.load(ORDERING) {
|
||||||
@@ -136,15 +137,17 @@ impl PIndicator {
|
|||||||
_ => panic!("Unknown State"),
|
_ => panic!("Unknown State"),
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(stdout, "\r{msg}").unwrap();
|
write!(stderr, "\r{msg}").unwrap();
|
||||||
stdout.flush().unwrap();
|
stderr.flush().unwrap();
|
||||||
|
|
||||||
progress_char_i += 1;
|
progress_char_i += 1;
|
||||||
progress_char_i %= PROGRESS_CHARS_LEN;
|
progress_char_i %= PROGRESS_CHARS_LEN;
|
||||||
}
|
}
|
||||||
print!("\r{:width$}", " ", width = msg.len());
|
|
||||||
print!("\r");
|
let clear = format!("\r{:width$}", " ", width = msg.len());
|
||||||
stdout.flush().unwrap();
|
write!(stderr, "{clear}").unwrap();
|
||||||
|
write!(stderr, "\r").unwrap();
|
||||||
|
stderr.flush().unwrap();
|
||||||
});
|
});
|
||||||
self.thread = Some((stop_handler, time_info_thread))
|
self.thread = Some((stop_handler, time_info_thread))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ use std::str;
|
|||||||
|
|
||||||
fn build_command<T: AsRef<OsStr>>(command_args: Vec<T>) -> String {
|
fn build_command<T: AsRef<OsStr>>(command_args: Vec<T>) -> String {
|
||||||
let mut cmd = &mut Command::cargo_bin("dust").unwrap();
|
let mut cmd = &mut Command::cargo_bin("dust").unwrap();
|
||||||
|
// Hide progress bar
|
||||||
|
cmd = cmd.arg("-P");
|
||||||
|
|
||||||
for p in command_args {
|
for p in command_args {
|
||||||
cmd = cmd.arg(p);
|
cmd = cmd.arg(p);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user