diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-05-29 13:13:49 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-05-29 13:13:49 +0800 |
commit | a0d628898226e272e9f29137da148991e07f3641 (patch) | |
tree | 997cb3a5bab819799bdced29bf108c4843ded42a /src/main.rs | |
parent | e68481f3524d214b76d2895a10febc3a524c3256 (diff) |
Only display progress on if stderr is a tty
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index f8cdabc..aa9d82e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,18 +2,21 @@ use anyhow::Result; use clap::Clap; use dua::{ByteFormat, TraversalSorting}; -use std::{ - fs, io, - io::{stderr, Write}, - path::PathBuf, - process, -}; +use std::{fs, io, io::Write, path::PathBuf, process}; mod crossdev; #[cfg(any(feature = "tui-unix", feature = "tui-crossplatform"))] mod interactive; mod options; +fn stderr_if_tty() -> Option<io::Stderr> { + if atty::is(atty::Stream::Stderr) { + Some(io::stderr()) + } else { + None + } +} + fn main() -> Result<()> { use options::Command::*; @@ -72,7 +75,7 @@ fn main() -> Result<()> { let stdout_locked = stdout.lock(); let (res, stats) = dua::aggregate( stdout_locked, - stderr(), + stderr_if_tty(), walk_options, !no_total, !no_sort, @@ -88,7 +91,7 @@ fn main() -> Result<()> { let stdout_locked = stdout.lock(); dua::aggregate( stdout_locked, - stderr(), + stderr_if_tty(), walk_options, true, true, |