pub struct Controller { /* private fields */ }Expand description
High-level progress controller.
Automatically detects the best backend and manages throttling, deduplication, and ETA estimation.
§Example
use termpulse::Controller;
let mut ctrl = Controller::auto();
ctrl.set(25, "Downloading");
ctrl.set(50, "Downloading");
ctrl.set(100, "Downloading");
ctrl.done("Complete");Implementations§
Source§impl Controller
impl Controller
Sourcepub fn auto() -> Self
pub fn auto() -> Self
Create a controller with automatic backend detection.
Detects the terminal capability and selects the best backend:
- OSC 9;4 for supported terminals
- ASCII progress bar for TTY without OSC support
- Silent for non-TTY environments
Sourcepub fn with_options(opts: &DetectOptions) -> Self
pub fn with_options(opts: &DetectOptions) -> Self
Create a controller with custom detection options.
Sourcepub fn with_backend(
backend: Box<dyn Backend>,
capability: TerminalCapability,
) -> Self
pub fn with_backend( backend: Box<dyn Backend>, capability: TerminalCapability, ) -> Self
Create a controller with a specific backend (for testing or custom output).
Sourcepub fn set(&mut self, percent: u8, label: &str)
pub fn set(&mut self, percent: u8, label: &str)
Set progress to a specific percentage with a label.
Percentage is clamped to 0-100. Updates are throttled and deduplicated automatically.
Sourcepub fn indeterminate(&mut self, label: &str)
pub fn indeterminate(&mut self, label: &str)
Start indeterminate progress (spinner-like, no percentage).
Sourcepub fn done(&mut self, label: &str)
pub fn done(&mut self, label: &str)
Signal successful completion.
Emits 100% progress, then clears the indicator.
Sourcepub fn fail(&mut self, label: &str)
pub fn fail(&mut self, label: &str)
Signal failure/error.
Emits error state, then clears the indicator.
Sourcepub fn capability(&self) -> TerminalCapability
pub fn capability(&self) -> TerminalCapability
Get the detected terminal capability.
Sourcepub fn backend_name(&self) -> &'static str
pub fn backend_name(&self) -> &'static str
Get the backend name (e.g., “osc”, “ascii”, “silent”).
Sourcepub fn eta_display(&self) -> String
pub fn eta_display(&self) -> String
Get estimated time remaining.