diff options
author | sharkdp <davidpeter@web.de> | 2019-09-21 13:26:44 +0200 |
---|---|---|
committer | sharkdp <davidpeter@web.de> | 2019-09-21 13:26:46 +0200 |
commit | 1adffaae5df95dec0339c7969115a7176f55369b (patch) | |
tree | 968a78f97349fa3a25cc39b0e394e7a6db67202c | |
parent | b67547fae02d42cbd9c230180cf07554549bba1e (diff) |
Add plain output format for non-interactive use
closes #35
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 15 |
3 files changed, 12 insertions, 5 deletions
@@ -101,6 +101,7 @@ dependencies = [ name = "diskus" version = "0.5.0" dependencies = [ + "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -16,6 +16,7 @@ humansize = "1.1" num-format = "0.4" rayon = "1.0" crossbeam-channel = "0.3" +atty = "0.2" [dependencies.clap] version = "2" diff --git a/src/main.rs b/src/main.rs index ed3b314..54ac6ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,11 +32,16 @@ fn print_result(size: u64, errors: &[walk::Err], size_format: &FileSizeOpts, ver "[diskus warning] the results may be tainted. Re-run with -v/--verbose to print all errors." ); } - println!( - "{} ({:} bytes)", - size.file_size(size_format).unwrap(), - size.to_formatted_string(&Locale::en) - ); + + if atty::is(atty::Stream::Stdout) { + println!( + "{} ({:} bytes)", + size.file_size(size_format).unwrap(), + size.to_formatted_string(&Locale::en) + ); + } else { + println!("{}", size); + } } fn main() { |