pub struct OperationProgress { /* private fields */ }Expand description
A progress bar for operations with known total count.
Tracks completion percentage, calculates throughput rate, and estimates time remaining based on current progress speed.
§Rendering Modes
- Rich mode: Colored progress bar with percentage, counter, throughput, ETA
- Plain mode: Text format suitable for agents:
Name: 42% (420/1000) 50.2/s ETA: 12s - JSON mode: Structured data for programmatic consumption
§Example
use sqlmodel_console::renderables::OperationProgress;
let mut progress = OperationProgress::new("Processing", 100);
progress.set_completed(50);
assert_eq!(progress.percentage(), 50.0);Implementations§
Source§impl OperationProgress
impl OperationProgress
Sourcepub fn new(operation_name: impl Into<String>, total: u64) -> Self
pub fn new(operation_name: impl Into<String>, total: u64) -> Self
Create a new progress tracker.
§Arguments
operation_name: Human-readable name for the operationtotal: Total number of items to process
Sourcepub fn set_completed(&mut self, completed: u64)
pub fn set_completed(&mut self, completed: u64)
Set the number of completed items (mutable version).
Sourcepub fn show_throughput(self, show: bool) -> Self
pub fn show_throughput(self, show: bool) -> Self
Set whether to show throughput.
Sourcepub fn state(self, state: ProgressState) -> Self
pub fn state(self, state: ProgressState) -> Self
Set the state manually (e.g., for error indication).
Sourcepub fn reset_timer(&mut self)
pub fn reset_timer(&mut self)
Reset the start time (useful when reusing a progress tracker).
Sourcepub fn operation_name(&self) -> &str
pub fn operation_name(&self) -> &str
Get the operation name.
Sourcepub fn completed_count(&self) -> u64
pub fn completed_count(&self) -> u64
Get the completed count.
Sourcepub fn total_count(&self) -> u64
pub fn total_count(&self) -> u64
Get the total count.
Sourcepub fn current_state(&self) -> ProgressState
pub fn current_state(&self) -> ProgressState
Get the current state.
Sourcepub fn percentage(&self) -> f64
pub fn percentage(&self) -> f64
Calculate the completion percentage.
Sourcepub fn elapsed_secs(&self) -> f64
pub fn elapsed_secs(&self) -> f64
Calculate the elapsed time in seconds.
Sourcepub fn throughput(&self) -> f64
pub fn throughput(&self) -> f64
Calculate the throughput (items per second).
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check if the operation is complete.
Sourcepub fn render_plain(&self) -> String
pub fn render_plain(&self) -> String
Render as plain text for agents.
Format: Name: 42% (420/1000) 50.2/s ETA: 12s
Sourcepub fn render_styled(&self) -> String
pub fn render_styled(&self) -> String
Render with ANSI styling.
Shows a visual progress bar with colors based on state.
Trait Implementations§
Source§impl Clone for OperationProgress
impl Clone for OperationProgress
Source§fn clone(&self) -> OperationProgress
fn clone(&self) -> OperationProgress
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more