Skip to content

Commit 7ee064c

Browse files
fix(download_tracker): remove unnecessary attributes from the DownloadTracker struct
The attributes `display_progress` and `stdout_is_a_tty` are only needed when defining the draw target for the progress bars. After that, they don't need to be used anymore.
1 parent 506536c commit 7ee064c

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/cli/download_tracker.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ use crate::utils::Notification as Un;
1111
/// *not* safe for tracking concurrent downloads yet - it is basically undefined
1212
/// what will happen.
1313
pub(crate) struct DownloadTracker {
14-
/// Whether we display progress or not.
15-
display_progress: bool,
16-
stdout_is_a_tty: bool,
1714
/// Whether we display colors or not.
1815
use_colors: bool,
1916
/// MultiProgress bar for the downloads.
@@ -34,12 +31,10 @@ impl DownloadTracker {
3431
ProgressDrawTarget::term_like(Box::new(t))
3532
}
3633
Ok(s) if s.eq_ignore_ascii_case("never") => ProgressDrawTarget::hidden(),
37-
_ if is_a_tty => ProgressDrawTarget::term_like(Box::new(t)),
34+
_ if is_a_tty && display_progress => ProgressDrawTarget::term_like(Box::new(t)),
3835
_ => ProgressDrawTarget::hidden(),
3936
});
4037
Self {
41-
display_progress,
42-
stdout_is_a_tty: process.stdout().is_a_tty(process),
4338
use_colors,
4439
multi_progress_bars,
4540
progress_bar: ProgressBar::hidden(),
@@ -53,9 +48,7 @@ impl DownloadTracker {
5348
true
5449
}
5550
Notification::Install(In::Utils(Un::DownloadDataReceived(data))) => {
56-
if self.stdout_is_a_tty {
57-
self.data_received(data.len());
58-
}
51+
self.data_received(data.len());
5952
true
6053
}
6154
Notification::Install(In::Utils(Un::DownloadFinished)) => {
@@ -85,11 +78,7 @@ impl DownloadTracker {
8578

8679
/// Notifies self that data of size `len` has been received.
8780
pub(crate) fn data_received(&mut self, len: usize) {
88-
if self.progress_bar.is_hidden()
89-
&& self.display_progress
90-
&& self.stdout_is_a_tty
91-
&& self.progress_bar.elapsed() >= Duration::from_secs(1)
92-
{
81+
if self.progress_bar.is_hidden() && self.progress_bar.elapsed() >= Duration::from_secs(1) {
9382
self.multi_progress_bars.add(self.progress_bar.clone());
9483
}
9584
self.progress_bar.inc(len as u64);

0 commit comments

Comments
 (0)