summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsharkdp <davidpeter@web.de>2019-09-21 13:26:44 +0200
committersharkdp <davidpeter@web.de>2019-09-21 13:26:46 +0200
commit1adffaae5df95dec0339c7969115a7176f55369b (patch)
tree968a78f97349fa3a25cc39b0e394e7a6db67202c
parentb67547fae02d42cbd9c230180cf07554549bba1e (diff)
Add plain output format for non-interactive use
closes #35
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs15
3 files changed, 12 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ac40bcd..239ff27 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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)",
diff --git a/Cargo.toml b/Cargo.toml
index 1da357b..bf20b92 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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() {