Skip to main content

Controller

Struct Controller 

Source
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

Source

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
Source

pub fn with_options(opts: &DetectOptions) -> Self

Create a controller with custom detection options.

Source

pub fn with_backend( backend: Box<dyn Backend>, capability: TerminalCapability, ) -> Self

Create a controller with a specific backend (for testing or custom output).

Source

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.

Source

pub fn indeterminate(&mut self, label: &str)

Start indeterminate progress (spinner-like, no percentage).

Source

pub fn done(&mut self, label: &str)

Signal successful completion.

Emits 100% progress, then clears the indicator.

Source

pub fn fail(&mut self, label: &str)

Signal failure/error.

Emits error state, then clears the indicator.

Source

pub fn pause(&mut self, label: &str)

Signal paused state.

Source

pub fn clear(&mut self)

Clear/remove the progress indicator without signaling completion.

Source

pub fn capability(&self) -> TerminalCapability

Get the detected terminal capability.

Source

pub fn backend_name(&self) -> &'static str

Get the backend name (e.g., “osc”, “ascii”, “silent”).

Source

pub fn eta_display(&self) -> String

Get estimated time remaining.

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.