Skip to content

Commit

Permalink
New progress bar rendering without indicatif
Browse files Browse the repository at this point in the history
Replaced indicatif with status-line.
The code got actually shorter and now there are even
progress bar tests.

This also opens ability to display more information
next to progress bar in the future.

Fixes #217
  • Loading branch information
pkolaczk committed Oct 22, 2023
1 parent 55a174f commit 72d5381
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 210 deletions.
66 changes: 35 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions fclones/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ exclude = [
rust-version = "1.70"

[dependencies]
atomic-counter = "1.0"
bincode = "1.3"
blake3 = { version = "1.3", optional = true }
byteorder = "1.4"
Expand All @@ -36,7 +35,6 @@ fallible-iterator = "0.3"
filetime = "0.2"
hex = "0.4"
ignore = "0.4.18"
indicatif = "0.17"
indexmap = "2"
itertools = "0.11"
lazy-init = "0.5"
Expand All @@ -56,6 +54,7 @@ sha2 = { version = "0.10", optional = true }
sha3 = { version = "0.10", optional = true }
sled = "0.34"
smallvec = "1.8"
status-line = "0.2.0"
stfu8 = "0.2"
sysinfo = "0.29"
thread_local = "1.1"
Expand Down
26 changes: 13 additions & 13 deletions fclones/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex, Weak};
use console::style;
use nom::lib::std::fmt::Display;

use crate::progress::{FastProgressBar, ProgressTracker};
use crate::progress::{ProgressBar, ProgressTracker};
use chrono::Local;

/// Determines the size of the task tracked by ProgressTracker.
Expand Down Expand Up @@ -63,7 +63,7 @@ impl<L: Log + ?Sized> LogExt for L {
/// A logger that uses standard error stream to communicate with the user.
pub struct StdLog {
program_name: String,
progress_bar: Mutex<Weak<FastProgressBar>>,
progress_bar: Mutex<Weak<ProgressBar>>,
pub log_stderr_to_stdout: bool,
pub no_progress: bool,
}
Expand All @@ -84,48 +84,48 @@ impl StdLog {
}

/// Clears any previous progress bar or spinner and installs a new spinner.
pub fn spinner(&self, msg: &str) -> Arc<FastProgressBar> {
pub fn spinner(&self, msg: &str) -> Arc<ProgressBar> {
if self.no_progress {
return Arc::new(FastProgressBar::new_hidden());
return Arc::new(ProgressBar::new_hidden());
}
self.progress_bar
.lock()
.unwrap()
.upgrade()
.iter()
.for_each(|pb| pb.finish_and_clear());
let result = Arc::new(FastProgressBar::new_spinner(msg));
let result = Arc::new(ProgressBar::new_spinner(msg));
*self.progress_bar.lock().unwrap() = Arc::downgrade(&result);
result
}

/// Clears any previous progress bar or spinner and installs a new progress bar.
pub fn progress_bar(&self, msg: &str, len: u64) -> Arc<FastProgressBar> {
pub fn progress_bar(&self, msg: &str, len: u64) -> Arc<ProgressBar> {
if self.no_progress {
return Arc::new(FastProgressBar::new_hidden());
return Arc::new(ProgressBar::new_hidden());
}
let result = Arc::new(FastProgressBar::new_progress_bar(msg, len));
let result = Arc::new(ProgressBar::new_progress_bar(msg, len));
*self.progress_bar.lock().unwrap() = Arc::downgrade(&result);
result
}

/// Creates a no-op progressbar that doesn't display itself.
pub fn hidden(&self) -> Arc<FastProgressBar> {
Arc::new(FastProgressBar::new_hidden())
pub fn hidden(&self) -> Arc<ProgressBar> {
Arc::new(ProgressBar::new_hidden())
}

/// Clears any previous progress bar or spinner and installs a new progress bar.
pub fn bytes_progress_bar(&self, msg: &str, len: u64) -> Arc<FastProgressBar> {
pub fn bytes_progress_bar(&self, msg: &str, len: u64) -> Arc<ProgressBar> {
if self.no_progress {
return Arc::new(FastProgressBar::new_hidden());
return Arc::new(ProgressBar::new_hidden());
}
self.progress_bar
.lock()
.unwrap()
.upgrade()
.iter()
.for_each(|pb| pb.finish_and_clear());
let result = Arc::new(FastProgressBar::new_bytes_progress_bar(msg, len));
let result = Arc::new(ProgressBar::new_bytes_progress_bar(msg, len));
*self.progress_bar.lock().unwrap() = Arc::downgrade(&result);
result
}
Expand Down
Loading

0 comments on commit 72d5381

Please sign in to comment.