Struct Manager

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

The manager for progress bars. It’s expected for users to create a Manager, create progress bars from it, and drop it when all work has been done.

When manager is dropped, it would force a draw. After that bars would not be able to be interacted with.

Implementations§

Source§

impl Manager

Source

pub fn new(interval: Duration) -> Self

Create a new Manager to stdout.

The interval parameter specifies the minimum interval between two unforced draws.

Source

pub fn with_stdout(self) -> Self

Set the Manager to write to stdout.

Source

pub fn with_stderr(self) -> Self

Set the Manager to write to stderr.

Source

pub fn with_file(self, file: File) -> Self

Set the Manager to write to a file.

Source

pub fn auto_ansi(self) -> Self

Let Manager automatically detect whether it’s writing to a terminal and use ANSI or not.

Source

pub fn force_ansi(self, force: bool) -> Self

Force Manager to use ANSI escape codes or not.

Source

pub fn set_ticker(&self, set_ticker: bool)

Ticker enables a background thread to draw progress bars at a fixed interval.

When ticker is enabled, unforced draw would be ignored.

Source

pub fn force_draw_when_finished(&self, force: bool)

If manager shall forcely draw when pos == len without explicitly calling finish().

Default is true.

Source

pub fn create_bar( &self, len: u64, message: &str, template: &str, visible: bool, ) -> Bar

Create a new progress bar.

  • len: The total length of the progress bar.
  • message: The message of the bar. Use {msg} in the template to refer to this.
  • template: The template of the bar.
  • visible: Whether the bar is visible.

This makes a forced draw when visible is true.

Source

pub fn draw(&self, force: bool)

Draw all progress bars. In most cases it’s not necessary to call this manually.

If nothing changed, it would not draw no matter what.

If ticker is enabled, unforced draw would be ignored. Otherwise, it would only draw when the interval has passed.

Progress bars would be drawn by the order of Bar creation. In ANSI mode, it would clear the previous output.

Finally, when output is not a terminal, bars would be drawn only when it needs to be redrawn.

Source

pub fn suspend<F: FnOnce(&mut Box<dyn Out>) -> R, R>(&self, f: F) -> R

Hide all progress bars, run the closure, and show them again like indicatif::MultiProgress::suspend.

This method is used for implementing integrations with other libraries that may print to the terminal.

When output is not a terminal, the closure would still be run but nothing would be done to the progress bars.

Source

pub fn create_writer(&self) -> KyuriWriter

Create a writer for integration with other libraries.

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.