Struct termprogress::progress::Bar
source · pub struct Bar<T: ?Sized = Stdout> { /* private fields */ }
Expand description
A progress bar with a size and optionally title. It implements the ProgressBar
trait, and is the default progress bar.
The bar has a max size, that is usually derived from the size of your terminal (if it can be detected) or can be set yourself, to stop the title line going over the side. It also has a configurable width, which is defaulted to 50.
Usage
To create a new progress::Bar
with a max size tuned to your terminal (or Width+20
, if it cannot be detected), and of the default size, Bar
implements the Default
trait:
let mut bar = Bar::default(); //Creates a bar of width 50 by default.
You can configure sizes and initial title with new()
, with_title()
, and with_max()
functions.
How it looks
It renders in the terminal like:
[========================= ]: 50% this is a title that may get cut if it reaches max le...
Thread Sync
safety
This type is safely Sync
(where T
is), the behaviour is defined to prevent overlapping writes to T
.
Though it is advised to not render a Bar
from more than a single thread, you still safely can.
Rendering functions should not be called on multiple threads at the same time, though it is safe to do so. A thread-sync’d rendering operation will safetly (and silently) give up before writing if another thread is already engaging in one.
A display operation on one thread will cause any other threads attempting on to silently and safely abort their display attempt before anything is written to output.
Implementations§
source§impl Bar
impl Bar
sourcepub fn with_title_default(width: usize, title: impl AsRef<str>) -> Self
pub fn with_title_default(width: usize, title: impl AsRef<str>) -> Self
Create a new bar width
long with a title using the default output descriptor stdout
.
sourcepub fn try_new_with_title_default(
width: usize,
title: impl AsRef<str>
) -> Option<Self>
pub fn try_new_with_title_default( width: usize, title: impl AsRef<str> ) -> Option<Self>
Attempt to create a new bar with max display width of our terminal and a title.
If stdout
is not a terminal, then None
is returned.
sourcepub fn new_default(width: usize) -> Self
pub fn new_default(width: usize) -> Self
Create a new bar with max display width of our terminal
Notes
Without feature size
, will be the same as Self::with_max(width, width +20)
To try to create one that always adheres to size
, use the try_new()
family of functions.
sourcepub fn try_new_default(width: usize) -> Option<Self>
pub fn try_new_default(width: usize) -> Option<Self>
Attempt to create a new bar with max display width of our terminal.
If stdout
is not a terminal, then None
is returned.
sourcepub fn try_new_default_size_default() -> Option<Self>
pub fn try_new_default_size_default() -> Option<Self>
Attempt to create a new bar with max display width of our terminal.
If stdout
is not a terminal, then None
is returned.
sourcepub fn with_max_default(width: usize, max_width: usize) -> Self
pub fn with_max_default(width: usize, max_width: usize) -> Self
source§impl<T: Write + AsRawFd> Bar<T>
impl<T: Write + AsRawFd> Bar<T>
sourcepub fn with_title(
output: impl Into<T> + AsRawFd,
width: usize,
title: impl AsRef<str>
) -> Self
pub fn with_title( output: impl Into<T> + AsRawFd, width: usize, title: impl AsRef<str> ) -> Self
Create a new bar width
long with a title.
sourcepub fn try_new_with_title(
output: impl Into<T> + AsRawFd,
width: usize,
title: impl AsRef<str>
) -> Option<Self>
pub fn try_new_with_title( output: impl Into<T> + AsRawFd, width: usize, title: impl AsRef<str> ) -> Option<Self>
Attempt to create a new bar with max display width of our terminal and a title.
If output
is not a terminal, then None
is returned.
sourcepub fn new(output: impl Into<T> + AsRawFd, width: usize) -> Self
pub fn new(output: impl Into<T> + AsRawFd, width: usize) -> Self
Create a new bar with max display width of our terminal
Notes
Without feature size
, will be the same as Self::with_max(width, width +20)
To try to create one that always adheres to size
, use the try_new()
family of functions.
sourcepub fn try_new(output: impl Into<T> + AsRawFd, width: usize) -> Option<Self>
pub fn try_new(output: impl Into<T> + AsRawFd, width: usize) -> Option<Self>
Attempt to create a new bar with max display width of our terminal.
If output
is not a terminal, then None
is returned.
sourcepub fn try_new_default_size(to: impl Into<T> + AsRawFd) -> Option<Self>
pub fn try_new_default_size(to: impl Into<T> + AsRawFd) -> Option<Self>
Attempt to create a new bar with max display width of our terminal.
If output
is not a terminal, then None
is returned.