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>
impl<W: Write + Send + 'static> LiveProgress<W>
Sourcepub fn with<R>(&self, f: impl FnOnce(&mut Progress) -> R) -> R
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.
Sourcepub fn add_task(
&self,
description: impl Into<String>,
total: impl Into<Option<f64>>,
completed: f64,
) -> TaskId
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).
Sourcepub fn reset(&self, id: TaskId, start: bool, total: Option<f64>, completed: f64)
pub fn reset(&self, id: TaskId, start: bool, total: Option<f64>, completed: f64)
Progress::reset, then redraw (upstream’s reset refreshes).
Sourcepub fn update(&self, id: TaskId, update: TaskUpdate)
pub fn update(&self, id: TaskId, update: TaskUpdate)
Progress::update; redraws when the update asks to
(TaskUpdate::refresh).
Sourcepub fn refresh(&self)
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.
Sourcepub fn print(&self, renderable: Box<dyn Renderable + Send>)
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.
Sourcepub fn log(
&self,
objects: &[LogObject<'_>],
options: &LogOptions<'_>,
) -> Result<()>
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.
Sourcepub fn log_at(
&self,
objects: &[LogObject<'_>],
options: &LogOptions<'_>,
file: &str,
line: u32,
) -> Result<()>
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).
Sourcepub fn stdout(&self) -> FileProxy<LiveHandle<W>, Stdout> ⓘ
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.
Sourcepub fn file_proxy<F: Write>(
&self,
stream: ProxyStream,
file: F,
) -> FileProxy<LiveHandle<W>, F> ⓘ
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.
Sourcepub fn track<I: IntoIterator>(
&self,
iter: I,
total: Option<f64>,
description: impl Into<String>,
) -> Track<'_, I::IntoIter, W> ⓘ
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.
Sourcepub 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> ⓘ
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.
Sourcepub fn wrap_read<R: Read>(
&self,
reader: R,
total: Option<u64>,
task: Option<TaskId>,
description: impl Into<String>,
) -> Result<ProgressReader<'_, R, W>>
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.