Struct kdam::RichProgress
source · pub struct RichProgress {
pub columns: Vec<Column>,
pub pb: Bar,
}
Available on crate feature
rich
only.Expand description
An implementation rich.progress using Bar.
§Example
use kdam::{tqdm, Column, BarExt, RichProgress};
let mut pb = RichProgress::new(
tqdm!(total = 100),
vec![Column::Animation, Column::Percentage(2)]
);
for _ in 0..100 {
pb.update(1).unwrap();
}
eprintln!();
Fields§
§columns: Vec<Column>
§pb: Bar
Implementations§
source§impl RichProgress
impl RichProgress
sourcepub fn new(pb: Bar, columns: Vec<Column>) -> Self
pub fn new(pb: Bar, columns: Vec<Column>) -> Self
Create a new RichProgress.
Examples found in repository?
examples/rich.rs (lines 8-31)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
fn main() -> Result<()> {
term::init(stderr().is_terminal());
term::hide_cursor()?;
let mut pb = RichProgress::new(
tqdm!(
total = 231231231,
unit_scale = true,
unit_divisor = 1024,
unit = "B"
),
vec![
Column::Spinner(Spinner::new(
&["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
80.0,
1.0,
)),
Column::Text("[bold blue]?".to_owned()),
Column::Animation,
Column::Percentage(1),
Column::Text("•".to_owned()),
Column::CountTotal,
Column::Text("•".to_owned()),
Column::Rate,
Column::Text("•".to_owned()),
Column::RemainingTime,
],
);
pb.write("download will begin in 5 seconds".colorize("bold red"))?;
while pb.pb.elapsed_time() <= 5.0 {
pb.refresh()?;
}
pb.replace(1, Column::Text("[bold blue]docker.exe".to_owned()));
pb.write("downloading docker.exe".colorize("bold cyan"))?;
let total_size = 231231231;
let mut downloaded = 0;
while downloaded < total_size {
let new = std::cmp::min(downloaded + 223211, total_size);
downloaded = new;
pb.update_to(new)?;
std::thread::sleep(std::time::Duration::from_millis(12));
}
pb.write("downloaded docker.exe".colorize("bold green"))?;
eprintln!();
Ok(())
}
sourcepub fn replace(&mut self, index: usize, col: Column)
pub fn replace(&mut self, index: usize, col: Column)
Examples found in repository?
examples/rich.rs (line 39)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
fn main() -> Result<()> {
term::init(stderr().is_terminal());
term::hide_cursor()?;
let mut pb = RichProgress::new(
tqdm!(
total = 231231231,
unit_scale = true,
unit_divisor = 1024,
unit = "B"
),
vec![
Column::Spinner(Spinner::new(
&["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
80.0,
1.0,
)),
Column::Text("[bold blue]?".to_owned()),
Column::Animation,
Column::Percentage(1),
Column::Text("•".to_owned()),
Column::CountTotal,
Column::Text("•".to_owned()),
Column::Rate,
Column::Text("•".to_owned()),
Column::RemainingTime,
],
);
pb.write("download will begin in 5 seconds".colorize("bold red"))?;
while pb.pb.elapsed_time() <= 5.0 {
pb.refresh()?;
}
pb.replace(1, Column::Text("[bold blue]docker.exe".to_owned()));
pb.write("downloading docker.exe".colorize("bold cyan"))?;
let total_size = 231231231;
let mut downloaded = 0;
while downloaded < total_size {
let new = std::cmp::min(downloaded + 223211, total_size);
downloaded = new;
pb.update_to(new)?;
std::thread::sleep(std::time::Duration::from_millis(12));
}
pb.write("downloaded docker.exe".colorize("bold green"))?;
eprintln!();
Ok(())
}
Trait Implementations§
source§impl BarExt for RichProgress
impl BarExt for RichProgress
source§fn input<T: Into<String>>(&mut self, text: T) -> Result<String>
fn input<T: Into<String>>(&mut self, text: T) -> Result<String>
Take input via progress bar (without overlaping with bar(s)). Read more
source§fn update(&mut self, n: usize) -> Result<bool>
fn update(&mut self, n: usize) -> Result<bool>
Manually update the progress bar, useful for streams such as reading files. Read more
Auto Trait Implementations§
impl Freeze for RichProgress
impl !RefUnwindSafe for RichProgress
impl Send for RichProgress
impl Sync for RichProgress
impl Unpin for RichProgress
impl !UnwindSafe for RichProgress
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more