RichProgress

Struct 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

Source

pub fn new(pb: Bar, columns: Vec<Column>) -> Self

Create a new RichProgress.

Examples found in repository?
examples/rich.rs (lines 8-31)
4fn main() -> Result<()> {
5    term::init(stderr().is_terminal());
6    term::hide_cursor()?;
7
8    let mut pb = RichProgress::new(
9        tqdm!(
10            total = 231231231,
11            unit_scale = true,
12            unit_divisor = 1024,
13            unit = "B"
14        ),
15        vec![
16            Column::Spinner(Spinner::new(
17                &["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
18                80.0,
19                1.0,
20            )),
21            Column::Text("[bold blue]?".to_owned()),
22            Column::Animation,
23            Column::Percentage(1),
24            Column::Text("•".to_owned()),
25            Column::CountTotal,
26            Column::Text("•".to_owned()),
27            Column::Rate,
28            Column::Text("•".to_owned()),
29            Column::RemainingTime,
30        ],
31    );
32
33    pb.write("download will begin in 5 seconds".colorize("bold red"))?;
34
35    while pb.pb.elapsed_time() <= 5.0 {
36        pb.refresh()?;
37    }
38
39    pb.replace(1, Column::Text("[bold blue]docker.exe".to_owned()));
40    pb.write("downloading docker.exe".colorize("bold cyan"))?;
41
42    let total_size = 231231231;
43    let mut downloaded = 0;
44
45    while downloaded < total_size {
46        let new = std::cmp::min(downloaded + 223211, total_size);
47        downloaded = new;
48        pb.update_to(new)?;
49        std::thread::sleep(std::time::Duration::from_millis(12));
50    }
51
52    pb.write("downloaded docker.exe".colorize("bold green"))?;
53    eprintln!();
54
55    Ok(())
56}
Source

pub fn replace(&mut self, index: usize, col: Column)

Replace a column at specific index.

§Panics

If index is out of bounds.

Examples found in repository?
examples/rich.rs (line 39)
4fn main() -> Result<()> {
5    term::init(stderr().is_terminal());
6    term::hide_cursor()?;
7
8    let mut pb = RichProgress::new(
9        tqdm!(
10            total = 231231231,
11            unit_scale = true,
12            unit_divisor = 1024,
13            unit = "B"
14        ),
15        vec![
16            Column::Spinner(Spinner::new(
17                &["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
18                80.0,
19                1.0,
20            )),
21            Column::Text("[bold blue]?".to_owned()),
22            Column::Animation,
23            Column::Percentage(1),
24            Column::Text("•".to_owned()),
25            Column::CountTotal,
26            Column::Text("•".to_owned()),
27            Column::Rate,
28            Column::Text("•".to_owned()),
29            Column::RemainingTime,
30        ],
31    );
32
33    pb.write("download will begin in 5 seconds".colorize("bold red"))?;
34
35    while pb.pb.elapsed_time() <= 5.0 {
36        pb.refresh()?;
37    }
38
39    pb.replace(1, Column::Text("[bold blue]docker.exe".to_owned()));
40    pb.write("downloading docker.exe".colorize("bold cyan"))?;
41
42    let total_size = 231231231;
43    let mut downloaded = 0;
44
45    while downloaded < total_size {
46        let new = std::cmp::min(downloaded + 223211, total_size);
47        downloaded = new;
48        pb.update_to(new)?;
49        std::thread::sleep(std::time::Duration::from_millis(12));
50    }
51
52    pb.write("downloaded docker.exe".colorize("bold green"))?;
53    eprintln!();
54
55    Ok(())
56}
Source

pub fn render(&mut self) -> String

Render progress bar text.

Trait Implementations§

Source§

impl BarExt for RichProgress

Source§

fn clear(&mut self) -> Result<()>

Clear current progress bar display. Read more
Source§

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 refresh(&mut self) -> Result<()>

Force refresh current progress bar display. Read more
Source§

fn render(&mut self) -> String

Render progress bar text.
Source§

fn reset(&mut self, total: Option<usize>)

Resets counter to 0 for repeated use. Read more
Source§

fn update(&mut self, n: usize) -> Result<bool>

Manually update the progress bar, useful for streams such as reading files. Read more
Source§

fn update_to(&mut self, n: usize) -> Result<bool>

Set counter value instead of incrementing counter through update method. Read more
Source§

fn write<T: Into<String>>(&mut self, text: T) -> Result<()>

Print a message via progress bar (without overlaping with bar(s)). Read more
Source§

fn write_to<T: Write>( &mut self, writer: &mut T, n: Option<usize>, ) -> Result<bool>

Write progress bar rendered text to a writer (useful for writing files). Read more
Source§

impl Debug for RichProgress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,