changed to optional dependancy

master
Avril 4 years ago
parent cda1de618a
commit 10742e1cac
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -2,11 +2,16 @@
name = "termprogress"
description = "A terminal progress bar renderer with status and spinners"
license = "GPL-3.0-or-later"
version = "0.1.1"
version = "0.1.2"
authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["size"]
size = ["terminal_size"]
[dependencies]
terminal_size = "0.1"
terminal_size = {version = "0.1", optional = true}

@ -4,7 +4,7 @@ Simple and customiseable terminal progress bars for Rust.
## Features
- Customiseable, has a traits system to allow for passing any type of progress bar around
- Prevents long titles from overflowing the terminal by using the [terminal_size][terminal-size] crate
- Optionally prevents long titles from overflowing the terminal by using the [terminal_size][terminal-size] crate
- Interfaces for easily manipulating bar
[terminal-size]: https://crates.io/crates/terminal_size
@ -66,6 +66,11 @@ spinner.bump();
progress.complete_with("Done!");
```
## Default features
By default, the `size` feature is enabled, which requires the dependency [`terminal_size`][terminal-size].
Without this, `Bar` will not attempt to get the terminal's size to prevent overflows. You can disable it with `default-features=false`.
## Traits
The library comes with traits for progress bars: [`ProgressBar`][progress-bar], and [`Spinner`][spinner].

@ -50,14 +50,25 @@ impl Bar
this
}
/// 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)`
#[cfg_attr(not(feature="size"), inline)]
pub fn new(width: usize) -> Self
{
if let Some((terminal_size::Width(tw), _)) = terminal_size::terminal_size() {
let tw = usize::from(tw);
Self::with_max(if width < tw {width} else {tw}, tw)
} else {
#[cfg(feature="size")]
return {
if let Some((terminal_size::Width(tw), _)) = terminal_size::terminal_size() {
let tw = usize::from(tw);
Self::with_max(if width < tw {width} else {tw}, tw)
} else {
Self::with_max(width, width +20)
}
};
#[cfg(not(feature="size"))]
return {
Self::with_max(width, width +20)
}
};
}
/// Create a bar with a max display width
///
@ -77,9 +88,12 @@ impl Bar
}
/// Fit to terminal's width if possible.
///
/// # Notes
/// Available with feature `size` only.
pub fn fit(&mut self) -> bool
{
#[cfg(feature="size")]
if let Some((terminal_size::Width(tw), _)) = terminal_size::terminal_size() {
let tw = usize::from(tw);
self.width = if self.width < tw {self.width} else {tw};

Loading…
Cancel
Save