Struct stati::BarManager
source · [−]pub struct BarManager<'bar> { /* private fields */ }
Expand description
Manager for all current progress bars and text output.
the bars produced by this can be used in other threads from the manager, if they are created with register_threadsafe
This can be used, with the register
and register_threadsafe
methods and
the println!
and print!
(crate) macros
to display progress bars and even print while doing so
to display the bar, simply call .print()
.
in adition, the bar will be automaticaly printed when using
the print!
and println!
macros.
Examples
simple bar
use std::thread;
use stati::BarManager;
use stati::prelude::*;
let mut manager = BarManager::new();
let mut bar = manager.register(stati::bars::SimpleBar::new(&"Working...", 100));
for i in 0..=100 {
bar.bar().set_progress(i);
manager.print();
thread::sleep_ms(40);
}
printing while using progress bar
use std::thread;
use stati::BarManager;
use stati::prelude::*;
let mut manager = BarManager::new();
let mut bar = manager.register(stati::bars::SimpleBar::new(&"Working...", 100));
for i in 0..=100 {
bar.bar().set_progress(i);
stati::println!(manager, "Progressed to {} in the first section", i);
manager.print();
thread::sleep_ms(40);
}
A note on ANSI controll charecters
The way that this uses these charecters to re-print bars is rather finicky, and if you use ANSI text while using this, it probably will work, but could also break and cause hard to debug errors.
a note on bar ordering
bars created with register_threadsafe
will always be displayed after bars
created with register
Implementations
sourceimpl<'bar> BarManager<'bar>
impl<'bar> BarManager<'bar>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new BarManager
sourcepub fn register<B: 'bar + IsBar + Debug>(&mut self, bar: B) -> BarWrapper<B>
pub fn register<B: 'bar + IsBar + Debug>(&mut self, bar: B) -> BarWrapper<B>
Registers a progress bar with the bar manager, to be drawn with the manager.
Returns what is effectively a reference to it, and when that refference is dropped or .done()
is called,
the bar is finished, and is completed according to bar.close_method()
to register a bar so it can be used across threads, see register_threadsafe
sourcepub fn register_threadsafe<B: 'bar + IsBar + Debug>(
&mut self,
bar: B
) -> ThreadedBarWrapper<B>
pub fn register_threadsafe<B: 'bar + IsBar + Debug>(
&mut self,
bar: B
) -> ThreadedBarWrapper<B>
Like register
, however the wrapper returned by this can be used across threads
sourcepub fn try_flush(&mut self) -> Result<()>
pub fn try_flush(&mut self) -> Result<()>
Attempts to flush the output, returning if it was sucsessfull or not
sourcepub fn flush(&mut self)
pub fn flush(&mut self)
Flushes updates to stdout.
Currently this only flushes stdout, but will hopefully do more in the future
Panics
if stdout cannot be flushed
for a non-panicing alternative, see BarManager::try_flush
sourcepub fn queue_text(&mut self, text: &str)
pub fn queue_text(&mut self, text: &str)
Queues text to be printed before the bars. this should NOT be use directly, but should be used with the println! and print! macros
this does NOT immediataly print the text
sourcepub fn print(&mut self)
pub fn print(&mut self)
Prints the bar status and any queued text to stdout, and flushes it.
Panics
if stdout cannot be flushed
for a non-panicing alternative, see BarManager::try_print
sourcepub fn print_no_flush(&mut self)
pub fn print_no_flush(&mut self)
Prints the bar status and any queued text to stdout, without flushing it
Trait Implementations
sourceimpl<'bar> Debug for BarManager<'bar>
impl<'bar> Debug for BarManager<'bar>
Auto Trait Implementations
impl<'bar> !RefUnwindSafe for BarManager<'bar>
impl<'bar> !Send for BarManager<'bar>
impl<'bar> !Sync for BarManager<'bar>
impl<'bar> Unpin for BarManager<'bar>
impl<'bar> !UnwindSafe for BarManager<'bar>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more