Skip to main content

LiveProgress

Struct LiveProgress 

Source
pub struct LiveProgress<W: Write + Send + 'static> { /* private fields */ }
Expand description

A running Progress display. Task changes made through it are picked up by the next refresh, as with upstream’s refresh=False updates.

Implementations§

Source§

impl<W: Write + Send + 'static> LiveProgress<W>

Source

pub fn with<R>(&self, f: impl FnOnce(&mut Progress) -> R) -> R

Run f with the progress locked, for any change not wrapped below.

f may call refresh (the frame is drawn as soon as the lock is released), but not with or a method built on it: upstream re-enters its RLock, which a &mut Progress cannot express, so a nested call panics instead of deadlocking.

Source

pub fn add_task( &self, description: impl Into<String>, total: impl Into<Option<f64>>, completed: f64, ) -> TaskId

Progress::add_task, then redraw (upstream’s add_task refreshes).

Source

pub fn reset(&self, id: TaskId, start: bool, total: Option<f64>, completed: f64)

Progress::reset, then redraw (upstream’s reset refreshes).

Source

pub fn advance(&self, id: TaskId, amount: f64)

Source

pub fn update(&self, id: TaskId, update: TaskUpdate)

Progress::update; redraws when the update asks to (TaskUpdate::refresh).

Source

pub fn refresh(&self)

Redraw now rather than at the next tick, returning once the frame is written. Port of Progress.refresh.

Called from inside with, the redraw is queued instead: the refresh thread needs the lock this thread holds to render, so waiting for it would deadlock. The frame is drawn when with returns.

Source

pub fn print(&self, renderable: Box<dyn Renderable + Send>)

Print renderable above the display. Port of Progress.print (console.print through the live display’s render hook). The print is queued on the refresh thread, so it is safe inside with.

Source

pub fn print_str(&self, content: impl Into<String>)

print a string as console markup.

Source

pub fn log( &self, objects: &[LogObject<'_>], options: &LogOptions<'_>, ) -> Result<()>

Log objects above the display with the time and the caller. Port of Progress.log, which upstream binds to console.log: the log goes through the live display’s render hook, so it lands above the tasks. The caller is found with #[track_caller] (DIVERGENCES §47); a disabled display logs straight to its sink.

Source

pub fn log_at( &self, objects: &[LogObject<'_>], options: &LogOptions<'_>, file: &str, line: u32, ) -> Result<()>

log with the caller’s file and line given (Console::log_at).

Source

pub fn stdout(&self) -> FileProxy<LiveHandle<W>, Stdout> ⓘ

A writer standing in for stdout while the display runs: whole lines print above it (upstream’s redirect_stdout FileProxy). A disabled display writes straight to stdout.

Source

pub fn stderr(&self) -> FileProxy<LiveHandle<W>, Stderr> ⓘ

stdout for stderr.

Source

pub fn file_proxy<F: Write>( &self, stream: ProxyStream, file: F, ) -> FileProxy<LiveHandle<W>, F> ⓘ

A proxy for stream over any file, which receives the writes when the display is not redirecting.

Source

pub fn track<I: IntoIterator>( &self, iter: I, total: Option<f64>, description: impl Into<String>, ) -> Track<'_, I::IntoIter, W> ⓘ

Iterate iter, advancing a new task by one after each item is processed. Port of Progress.track: the total defaults to the iterator’s exact length, else the task is indeterminate.

Source

pub fn track_with<I: IntoIterator>( &self, iter: I, total: Option<f64>, completed: f64, task: Option<TaskId>, description: impl Into<String>, update_period: f64, ) -> Track<'_, I::IntoIter, W> ⓘ

track with every argument of upstream’s Progress.track: completed to start from, an existing task (its total and completed are set) and the update_period in seconds.

As upstream’s _TrackThread, a background thread advances the task by the items counted every update_period, and when the iterator is exhausted or dropped the task’s completed is set to the count and the display refreshed.

Source

pub fn wrap_read<R: Read>( &self, reader: R, total: Option<u64>, task: Option<TaskId>, description: impl Into<String>, ) -> Result<ProgressReader<'_, R, W>>

Track reading from reader: each read advances the task by the bytes read. Port of Progress.wrap_file: total is the byte count, or else the total of task; a new task named description is added when task is None, otherwise task’s total is set.

Source

pub fn open( &self, path: impl AsRef<Path>, total: Option<u64>, task: Option<TaskId>, description: impl Into<String>, ) -> Result<ProgressReader<'_, File, W>>

Open path for reading and track it. Port of Progress.open in binary mode: total defaults to the file’s size.

Source

pub fn stop(self) -> (Progress, W)

Commit the final frame, stop the refresh thread, and return the progress and the output sink. Port of Progress.stop.

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.