Skip to content

Commit 60e51ce

Browse files
committed
progress bars uses \r if stdout is a terminal.
1 parent 7feee4b commit 60e51ce

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

clang-installer/src/progress_bar.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::io::{IsTerminal, Result, Write, stdin, stdout};
1+
use std::io::{IsTerminal, Result, Write, stdout};
22

33
/// A simple progress bar implementation that supports both interactive and non-interactive terminals.
44
pub struct ProgressBar {
@@ -44,12 +44,14 @@ impl ProgressBar {
4444
/// // stdout lock is released when `progress_bar` goes out of scope
4545
/// ```
4646
pub fn new(total: Option<u64>, prompt: &str) -> Self {
47+
let stdout_handle = stdout().lock();
48+
let is_interactive = stdout_handle.is_terminal();
4749
Self {
4850
total,
4951
current: 0,
5052
steps: 0,
51-
stdout_handle: stdout().lock(),
52-
is_interactive: stdin().is_terminal(),
53+
stdout_handle,
54+
is_interactive,
5355
prompt: prompt.to_string(),
5456
}
5557
}

0 commit comments

Comments
 (0)