pub enum Animation {
Arrow,
Classic,
Custom(Vec<String>, Option<String>),
FillUp,
FiraCode,
Tqdm,
TqdmAscii,
}
Expand description
Animation styles for Bar.
Variants§
Implementations§
Source§impl Animation
impl Animation
Sourcepub fn custom(charset: &[&str], fill: Option<&str>) -> Self
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}
Sourcepub fn render(&self, ncols: NonZeroU16, progress: f32) -> String
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.
Sourcepub fn fmt_render(
&self,
ncols: NonZeroU16,
progress: f32,
colour: &Option<Colour>,
) -> String
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 }
Sourcepub fn spaces(&self) -> u8
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§
Auto Trait Implementations§
impl Freeze for Animation
impl RefUnwindSafe for Animation
impl Send for Animation
impl Sync for Animation
impl Unpin for Animation
impl UnwindSafe for Animation
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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