Skip to main content

ProgressBar

Struct ProgressBar 

Source
pub struct ProgressBar { /* private fields */ }
Expand description

A progress bar for displaying operation progress.

§Example

use click::termui::ProgressBar;

let mut bar = ProgressBar::new(100, Some("Processing"), true, true, true, 40);

for i in 0..100 {
    // Do work...
    bar.update(1);
}

bar.finish();

// Custom fill/empty characters
let mut bar = ProgressBar::new(100, None, true, true, false, 30)
    .fill_char('█')
    .empty_char('░');

Implementations§

Source§

impl ProgressBar

Source

pub fn new( length: usize, label: Option<&str>, show_eta: bool, show_percent: bool, show_pos: bool, width: usize, ) -> Self

Create a new progress bar.

§Arguments
  • length - Total number of items to process
  • label - Optional label to display before the bar
  • show_eta - Whether to show estimated time remaining
  • show_percent - Whether to show percentage complete
  • show_pos - Whether to show position/length
  • width - Width of the bar portion in characters
Source

pub fn fill_char(self, c: char) -> Self

Set the character used for the filled portion of the bar.

Default is ‘#’.

§Example
use click::termui::ProgressBar;
let bar = ProgressBar::new(100, None, true, true, false, 30)
    .fill_char('█');
Source

pub fn empty_char(self, c: char) -> Self

Set the character used for the empty portion of the bar.

Default is ‘-’.

§Example
use click::termui::ProgressBar;
let bar = ProgressBar::new(100, None, true, true, false, 30)
    .empty_char('░');
Source

pub fn update(&mut self, n: usize)

Update the progress bar by advancing by n items.

§Arguments
  • n - Number of items completed since last update
Source

pub fn set_position(&mut self, pos: usize)

Set the progress bar to a specific position.

§Arguments
  • pos - New position
Source

pub fn finish(&mut self)

Mark the progress bar as finished and render final state.

Source

pub fn render(&self) -> String

Render the current progress bar state to a string.

Trait Implementations§

Source§

impl Drop for ProgressBar

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.