pub struct KBar { /* private fields */ }Expand description
The struct for handling progress bars
Example:
use kbar::{KBar, BarType};
use std::thread::sleep;
use std::time::Duration;
fn main() {
// using crossterm, this will create a kbar at 0,0
// without crossterm, this is the only way to create a bar
let mut kbar = KBar::new(BarType::Bar, true, true, 20);
for x in 0..1000 {
// get the percentage complete as a decimal
let percentage_decimal = x as f32 / 1000.0;
// scale the percentage from 0..1 to 0..100 and convert to a u8
let percent = (percentage_decimal * 100.0) as u8;
// update the kbar
kbar.update(percent);
// draw the kbar
kbar.draw();
// delay for 10ms, making this run in 10 seconds
sleep(Duration::from_millis(10));
}
}crossterm specific creation
Creating at a location
use kbar::{KBar, BarType};
KBar::new_at(0, 0, BarType::Bar, true, true, 20);Creating at the cursor’s current location
use kbar::{KBar, BarType};
KBar::new_at_cursor(BarType::Bar, true, true, 20);Implementations§
source§impl KBar
impl KBar
sourcepub fn new(
bar_type: BarType,
color: bool,
show_percent: bool,
bar_length: u16
) -> Self
pub fn new(
bar_type: BarType,
color: bool,
show_percent: bool,
bar_length: u16
) -> Self
create a new progress bar when using crossterm
parameters
bar_type: the type of bar to display color: if it should output in color show_percent: if it should show the percentage next to the bar bar_length: How long the bar should be
sourcepub fn new_at(
x: u16,
y: u16,
bar_type: BarType,
color: bool,
show_percent: bool,
bar_length: u16
) -> Self
pub fn new_at(
x: u16,
y: u16,
bar_type: BarType,
color: bool,
show_percent: bool,
bar_length: u16
) -> Self
Create a new bar using crossterm at a location
parameters
x: the x location to put the bar (0 is the left) y: the y location to put the bar (0 is the top) bar_type: the type of bar to display color: if it should output in color show_percent: if it should show the percentage next to the bar bar_length: How long the bar should be
sourcepub fn new_at_cursor(
bar_type: BarType,
color: bool,
show_percent: bool,
bar_length: u16
) -> Result<Self, String>
pub fn new_at_cursor(
bar_type: BarType,
color: bool,
show_percent: bool,
bar_length: u16
) -> Result<Self, String>
Creates a new bar using crossterm at the cursor’s current position
parameters
bar_type: the type of bar to display color: if it should output in color show_percent: if it should show the percentage next to the bar bar_length: How long the bar should be