Struct kbar::KBar

source ·
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

source

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

source

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

source

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

source

pub fn update(&mut self, percent: u8)

Update the bar’s progress

Parameters

percent: the new percentage (0 to 100)

source

pub fn draw(&mut self)

Draw the bar at its set location

source

pub fn is_complete(&self) -> bool

Trait Implementations§

source§

impl Clone for KBar

source§

fn clone(&self) -> KBar

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 KBar

source§

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

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

impl Default for KBar

source§

fn default() -> Self

Creates a bar using default values

Auto Trait Implementations§

§

impl RefUnwindSafe for KBar

§

impl Send for KBar

§

impl Sync for KBar

§

impl Unpin for KBar

§

impl UnwindSafe for KBar

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · 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> 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.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.