Enum kdam::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)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
fn main() -> Result<()> {
    term::init(false);
    term::hide_cursor()?;

    let render_length = 300;

    let mut pb1 = tqdm!(
        total = render_length,
        desc = "tqdm    ",
        position = 0,
        force_refresh = true
    );
    let mut pb2 = tqdm!(
        total = render_length,
        desc = "ascii   ",
        animation = "ascii",
        position = 2,
        force_refresh = true
    );
    let mut pb3 = tqdm!(
        total = render_length,
        desc = "fillup  ",
        animation = "fillup",
        position = 4,
        force_refresh = true
    );
    let mut pb4 = tqdm!(
        total = render_length,
        desc = "classic ",
        animation = "classic",
        position = 6,
        force_refresh = true
    );
    let mut pb5 = tqdm!(
        total = render_length,
        desc = "arrow   ",
        animation = "arrow",
        position = 8,
        force_refresh = true
    );
    let mut pb6 = tqdm!(
        total = render_length,
        desc = "custom1 ",
        animation = Animation::custom(&["\\", "|", "/", "-"], None),
        position = 10,
        force_refresh = true
    );
    let mut pb7 = tqdm!(
        total = render_length,
        desc = "custom2 ",
        animation = Animation::custom(&["\\", "|", "/", "-"], Some(".")),
        position = 12,
        force_refresh = true
    );

    println!("animations:\n");

    for _ in 0..render_length {
        pb1.update(1)?;
        pb2.update(1)?;
        pb3.update(1)?;
        pb4.update(1)?;
        pb5.update(1)?;
        pb6.update(1)?;
        pb7.update(1)?;
        std::thread::sleep(std::time::Duration::from_secs_f32(0.02));
    }

    eprint!("{}", "\n".repeat(13));
    Ok(())
}
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
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    fn render(&mut self) -> String {
        let fmt_percentage = self.pb.fmt_percentage(0);
        let padding = 1 + fmt_percentage.chars().count() as u16 + self.pb.animation.spaces() as u16;

        let ncols = self.pb.ncols_for_animation(padding);

        if ncols == 0 {
            self.pb.bar_length = padding - 1;
            fmt_percentage
        } else {
            self.pb.bar_length = padding + ncols;
            self.pb.animation.fmt_render(
                NonZeroU16::new(ncols).unwrap(),
                self.pb.percentage(),
                &None,
            ) + " "
                + &fmt_percentage
        }
    }
source

pub fn spaces(&self) -> u8

Returns extra spaces consumed by fmt_render.

Examples found in repository?
examples/miscellaneous/custom.rs (line 14)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    fn render(&mut self) -> String {
        let fmt_percentage = self.pb.fmt_percentage(0);
        let padding = 1 + fmt_percentage.chars().count() as u16 + self.pb.animation.spaces() as u16;

        let ncols = self.pb.ncols_for_animation(padding);

        if ncols == 0 {
            self.pb.bar_length = padding - 1;
            fmt_percentage
        } else {
            self.pb.bar_length = padding + ncols;
            self.pb.animation.fmt_render(
                NonZeroU16::new(ncols).unwrap(),
                self.pb.percentage(),
                &None,
            ) + " "
                + &fmt_percentage
        }
    }

Trait Implementations§

source§

impl Clone for Animation

source§

fn clone(&self) -> Animation

Returns a copy 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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 Twhere T: Send,