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
impl Progress
Sourcepub fn with_console(self, console: Console) -> Self
pub fn with_console(self, console: Console) -> Self
Create a progress display with a Console (enables start/stop lifecycle).
Sourcepub fn transient(self, transient: bool) -> Self
pub fn transient(self, transient: bool) -> Self
Set whether output is cleared on stop (transient mode).
Sourcepub fn refresh_per_second(self, rate: f64) -> Self
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.
Sourcepub fn auto_refresh(self, enabled: bool) -> Self
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.
Sourcepub fn with_columns(self, columns: Vec<Box<dyn ProgressColumn>>) -> Self
pub fn with_columns(self, columns: Vec<Box<dyn ProgressColumn>>) -> Self
Set custom columns.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Check if all tasks are finished.
Sourcepub fn render_to_string(&self) -> String
pub fn render_to_string(&self) -> String
Render the progress display.
Sourcepub fn start(&mut self)
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.
Sourcepub fn stop(&mut self)
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.
Sourcepub fn refresh(&mut self)
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().
Sourcepub fn run<F, R>(&mut self, f: F) -> Rwhere
F: FnOnce(&mut Self) -> R,
pub fn run<F, R>(&mut self, f: F) -> Rwhere
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));
}
});Sourcepub fn is_started(&self) -> bool
pub fn is_started(&self) -> bool
Check if the progress display is currently started.