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)
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(())
}
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 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
}
}
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 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§
Auto Trait Implementations§
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