Commit 0b83b9bb authored by Moritz Sokoll's avatar Moritz Sokoll 🦀
Browse files

added progress bar

parent 3c9bad2f
Pipeline #290 failed with stages
[package]
name = "btui"
version = "0.4.5"
version = "0.5.5"
edition = "2018"
authors = ["Moritz Sokoll <moritz@sokoll.com>"]
license = "MIT"
......@@ -18,6 +18,7 @@ required-features = []
doc = true
[features]
default = ["core"]
default = ["core", "linux", "pbar"]
core = []
linux = ["core"]
pbar = ["linux"]
......@@ -5,9 +5,10 @@
## Usage
Add this to your `Cargo.toml` dependency list:
```toml
btui = "0.4.5"
btui = "0.5.5"
```
## Features
This crate supports some different features:
- `core`: coloring and graphical special effects (like underline)
- `linux`: extensive support for different linux features (like clear a line/the screen)
- `pbar`: create a simple progress bar
......@@ -10,6 +10,7 @@ pub mod effects {
Magenta,
Cyan,
White,
/// set color to an rgb color
RGB(u8, u8, u8),
}
......@@ -19,6 +20,7 @@ pub mod effects {
Underline,
Stroke,
Italic,
/// reset all graphical effects
Reset,
}
}
......
//! # btui
//! ## beautiful text user intefaces
//! ## beautiful text user interfaces
//!
//! with btui you can create beautiful text user interfaces for the terminal.
//! To get started add `btui` as a dependency to your project:
//! ```toml
//! btui = "0.4.5"
//! btui = "0.5.5"
//! ```
//!
//! # Examples
//! This is a basic coloring example which will output hello world in red:
//! ```ignore
//! use btui::effects::{Color, Special};
//! use btui::print::{fg, sp};
//!
//! println!("{}Hello World!{}", fg(Color::Red), sp(Special::Reset));
//! ```
#[cfg(feature = "core")]
mod ft;
#[cfg(feature = "linux")]
/// module containing stuff for basic linux based print operations
pub mod linux;
#[cfg(feature = "pbar")]
/// module containing a progressbar
pub mod pbar;
pub use ft::{effects, print};
#[cfg(test)]
......
......@@ -2,8 +2,11 @@
pub mod console {
/// enum for display control
pub enum DisplayControl {
/// clear the display (doesnt move cursor)
Clear,
/// clear the current line the cursor is on (doesn't move the cursor)
ClearLine,
/// reset the display
Reset,
}
......
/// structure representing a progressbar
pub struct ProgressBar {
progress: u8,
text: String,
empty: char,
full: char,
}
impl ProgressBar {
/// create a new progress bar
/// # Arguments
/// *`text`: the text to use for the progress bar
/// *`empty`: the character to use for empty progress bar fields
/// *`full`: the character to use for full progress bar fields
/// # Returns
/// Returns a new progress bar
pub fn new(text: &str, empty: char, full: char) -> ProgressBar {
ProgressBar {
progress: 0u8,
text: text.to_string(),
empty,
full,
}
}
/// increase the current progress
pub fn incr(&mut self) {
if self.progress < 100u8 {
self.progress += 1u8;
}
}
/// set the current progress
pub fn set_progress(&mut self, amount: u8) {
if amount > 100u8 {
self.progress = 100u8;
} else {
self.progress = amount;
}
}
/// render the current progress bar
pub fn render(&self) -> String {
let mut bar: String = String::new();
let mut idx: u8 = 0;
while idx != self.progress {
bar.push_str(format!("{}", self.full).as_str());
idx += 1;
}
let leftover: u8 = 100u8 - self.progress;
idx = 0;
while idx != leftover {
bar.push_str(format!("{}", self.empty).as_str());
idx += 1;
}
format!("{}: [{}] {}%", self.text.clone(), bar, self.progress)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment