Enum Animation

Source
pub enum Animation {
    Arrow,
    Classic,
    Custom(Vec<String>, Option<String>),
    FillUp,
    FiraCode,
    Tqdm,
    TqdmAscii,
}
Expand description

Animation styles for Bar.

Variants§

§

Arrow

§

Classic

§

Custom(Vec<String>, Option<String>)

§

FillUp

§

FiraCode

§

Tqdm

§

TqdmAscii

Implementations§

Source§

impl Animation

Source

pub fn custom(charset: &[&str], fill: Option<&str>) -> Self

Create a new Animation::Custom enum variant.

§Example
use kdam::Animation;

let custom = Animation::custom(&["\\", "|", "/", "-"], None);
let custom_with_fill = Animation::custom(&["\\", "|", "/", "-"], Some("."));
Examples found in repository?
examples/showcase/animations.rs (line 47)
4fn main() -> Result<()> {
5    term::init(false);
6    term::hide_cursor()?;
7
8    let render_length = 300;
9
10    let mut pb1 = tqdm!(
11        total = render_length,
12        desc = "tqdm    ",
13        position = 0,
14        force_refresh = true
15    );
16    let mut pb2 = tqdm!(
17        total = render_length,
18        desc = "ascii   ",
19        animation = "ascii",
20        position = 2,
21        force_refresh = true
22    );
23    let mut pb3 = tqdm!(
24        total = render_length,
25        desc = "fillup  ",
26        animation = "fillup",
27        position = 4,
28        force_refresh = true
29    );
30    let mut pb4 = tqdm!(
31        total = render_length,
32        desc = "classic ",
33        animation = "classic",
34        position = 6,
35        force_refresh = true
36    );
37    let mut pb5 = tqdm!(
38        total = render_length,
39        desc = "arrow   ",
40        animation = "arrow",
41        position = 8,
42        force_refresh = true
43    );
44    let mut pb6 = tqdm!(
45        total = render_length,
46        desc = "custom1 ",
47        animation = Animation::custom(&["\\", "|", "/", "-"], None),
48        position = 10,
49        force_refresh = true
50    );
51    let mut pb7 = tqdm!(
52        total = render_length,
53        desc = "custom2 ",
54        animation = Animation::custom(&["\\", "|", "/", "-"], Some(".")),
55        position = 12,
56        force_refresh = true
57    );
58
59    println!("animations:\n");
60
61    for _ in 0..render_length {
62        pb1.update(1)?;
63        pb2.update(1)?;
64        pb3.update(1)?;
65        pb4.update(1)?;
66        pb5.update(1)?;
67        pb6.update(1)?;
68        pb7.update(1)?;
69        std::thread::sleep(std::time::Duration::from_secs_f32(0.02));
70    }
71
72    eprint!("{}", "\n".repeat(13));
73    Ok(())
74}
Source

pub fn render(&self, ncols: NonZeroU16, progress: f32) -> String

Render progress bar animation.

§Arguments
  • ncols: Number of columns to render.
  • progress: Percentage done, it should be in range (0.0 - 1.0) inclusive.
Source

pub fn fmt_render( &self, ncols: NonZeroU16, progress: f32, colour: &Option<Colour>, ) -> String

Render progress bar animation with opening and closing brackets.

Examples found in repository?
examples/miscellaneous/custom.rs (lines 23-27)
12    fn render(&mut self) -> String {
13        let fmt_percentage = self.pb.fmt_percentage(0);
14        let padding = 1 + fmt_percentage.chars().count() as u16 + self.pb.animation.spaces() as u16;
15
16        let ncols = self.pb.ncols_for_animation(padding);
17
18        if ncols == 0 {
19            self.pb.bar_length = padding - 1;
20            fmt_percentage
21        } else {
22            self.pb.bar_length = padding + ncols;
23            self.pb.animation.fmt_render(
24                NonZeroU16::new(ncols).unwrap(),
25                self.pb.percentage(),
26                &None,
27            ) + " "
28                + &fmt_percentage
29        }
30    }
Source

pub fn spaces(&self) -> u8

Returns extra spaces consumed by fmt_render.

Examples found in repository?
examples/miscellaneous/custom.rs (line 14)
12    fn render(&mut self) -> String {
13        let fmt_percentage = self.pb.fmt_percentage(0);
14        let padding = 1 + fmt_percentage.chars().count() as u16 + self.pb.animation.spaces() as u16;
15
16        let ncols = self.pb.ncols_for_animation(padding);
17
18        if ncols == 0 {
19            self.pb.bar_length = padding - 1;
20            fmt_percentage
21        } else {
22            self.pb.bar_length = padding + ncols;
23            self.pb.animation.fmt_render(
24                NonZeroU16::new(ncols).unwrap(),
25                self.pb.percentage(),
26                &None,
27            ) + " "
28                + &fmt_percentage
29        }
30    }

Trait Implementations§

Source§

impl Clone for Animation

Source§

fn clone(&self) -> Animation

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Animation

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<&str> for Animation

Source§

fn from(animation: &str) -> Self

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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,