Progress

Struct Progress 

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

Multi-task progress display with optional Live-like lifecycle.

Supports start/stop methods with cursor hiding for flicker-free updates. When auto_refresh is enabled, a background thread refreshes the display at the specified refresh_per_second rate.

Implementations§

Source§

impl Progress

Source

pub fn new() -> Self

Create a new progress display with default columns.

Source

pub fn with_console(self, console: Console) -> Self

Create a progress display with a Console (enables start/stop lifecycle).

Source

pub fn transient(self, transient: bool) -> Self

Set whether output is cleared on stop (transient mode).

Source

pub fn refresh_per_second(self, rate: f64) -> Self

Set the refresh rate in Hz (refreshes per second).

Default is 10.0. Set lower if updates are infrequent to reduce CPU usage.

Source

pub fn auto_refresh(self, enabled: bool) -> Self

Enable or disable auto-refresh.

When enabled (default), a background thread automatically refreshes the display. When disabled, you must call refresh() manually after updating tasks.

Source

pub fn with_columns(self, columns: Vec<Box<dyn ProgressColumn>>) -> Self

Set custom columns.

Source

pub fn add_task(&self, description: &str, total: Option<u64>) -> usize

Add a new task.

Source

pub fn advance(&self, task_id: usize, amount: u64)

Advance a task by the given amount.

Source

pub fn update(&self, task_id: usize, completed: u64)

Update a task’s completed count.

Source

pub fn finish(&self, task_id: usize)

Mark a task as finished.

Source

pub fn remove(&self, task_id: usize)

Remove a task.

Source

pub fn is_finished(&self) -> bool

Check if all tasks are finished.

Source

pub fn render_to_string(&self) -> String

Render the progress display.

Source

pub fn print(&self)

Print the progress to stdout (with cursor control for updates).

Source

pub fn start(&mut self)

Start the live progress display.

Hides the cursor and prepares for flicker-free updates via refresh(). When auto_refresh is enabled, spawns a background thread for automatic updates. Must have a Console set via with_console() to use this method.

Source

pub fn stop(&mut self)

Stop the live progress display.

Shows the cursor and optionally clears the output (if transient mode is enabled). If a background refresh thread is running, it will be stopped.

Source

pub fn refresh(&mut self)

Refresh the progress display.

When used with start/stop lifecycle, provides flicker-free updates. Can also be used standalone as an improved version of print().

Source

pub fn run<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Execute a closure with automatic progress lifecycle management.

Provides RAII-style progress management similar to Python’s with Progress() as progress: pattern. Automatically calls start() before the closure and stop() after, even if the closure panics.

§Example
progress.run(|p| {
    let task = p.add_task("Working", Some(100));
    for i in 0..100 {
        p.advance(task, 1);
        p.refresh();
        thread::sleep(Duration::from_millis(50));
    }
});
Source

pub fn is_started(&self) -> bool

Check if the progress display is currently started.

Trait Implementations§

Source§

impl Default for Progress

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Progress

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Renderable for Progress

Source§

fn render(&self, _context: &RenderContext) -> Vec<Segment>

Render this object to a sequence of segments. Read more
Source§

fn min_width(&self) -> usize

Get the minimum width required to render this object.
Source§

fn max_width(&self) -> usize

Get the maximum/natural width of this object.

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> Measurable for T
where T: Renderable,

Source§

fn measure(&self, width: usize) -> Measurement

Measure this renderable at the given width.
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.