Added `silent` implemetor

master
Avril 4 years ago
parent 60a070d18e
commit e81bf8403f
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -2,7 +2,7 @@
name = "termprogress"
description = "A terminal progress bar renderer with status and spinners"
license = "GPL-3.0-or-later"
version = "0.2.2"
version = "0.2.3"
authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018"

@ -31,13 +31,23 @@ pub trait Display
/// A trait for any bar with progress. You can implemnent your own styles through this trait.
pub trait ProgressBar: Display
{
{
fn set_progress(&mut self, value: f64);
fn get_progress(&self) -> f64;
}
/// A trait for any bar without progress. You can implemnent your own styles through this trait.
pub trait Spinner: Display
{
{
/// Cause the spinner to increment once.
fn bump(&mut self);
}
/// A trait for creating a progress bar or spinner with a title.
pub trait WithTitle: Sized + ProgressBar + Display
{
fn with_title(len: usize, string: impl AsRef<str>) -> Self;
fn update(&mut self);
fn complete(self);
}

@ -16,6 +16,7 @@ pub use inter::*;
pub mod progress;
pub mod wheel;
pub mod spinner;
pub mod silent;
/// The prelude exposes the traits for spinners and progress bars, and the `spinner::Spin` and `progress::Bar` types for easy access and use.
pub mod prelude {
@ -23,5 +24,6 @@ pub mod prelude {
pub use super::{
spinner::Spin,
progress::Bar,
silent::Silent,
};
}

@ -253,3 +253,19 @@ impl ProgressBar for Bar
self.refresh();
}
}
impl WithTitle for Bar
{
fn with_title(len: usize, string: impl AsRef<str>) -> Self
{
Self::with_title(len, string)
}
fn update(&mut self)
{
self.update();
}
fn complete(self)
{
self.complete();
}
}

@ -0,0 +1,42 @@
//! A silent progress bar and spinner that does nothing.
//!
//! Useful for when progress bars are optional.
use super::*;
/// An implementor for the `Display`, `ProgressBar`, `Spinner`, and `WithTitle` that does nothing.
///
/// It also implements `Display::println()` and `Display::eprintln()` to do nothing as well.
#[derive(Debug)]
pub struct Silent;
impl Display for Silent
{
#[inline] fn println(&self, _: &str){}
#[inline] fn eprintln(&self, _: &str){}
#[inline] fn refresh(&self){}
#[inline] fn blank(&self){}
#[inline] fn get_title(&self) -> &str{""}
#[inline] fn set_title(&mut self, _: &str){}
#[inline] fn update_dimensions(&mut self, _:usize){}
}
impl ProgressBar for Silent
{
#[inline] fn set_progress(&mut self, _:f64){}
#[inline] fn get_progress(&self) -> f64{0.0}
}
impl Spinner for Silent
{
#[inline] fn bump(&mut self){}
}
impl WithTitle for Silent
{
#[inline] fn with_title(_: usize, _: impl AsRef<str>) -> Self{Self}
#[inline] fn update(&mut self) {}
#[inline] fn complete(self) {}
}

@ -119,3 +119,20 @@ impl Spinner for Spin
self.refresh();
}
}
impl WithTitle for Spin
{
fn with_title(_: usize, t: impl AsRef<str>) -> Self
{
Self::with_title(t, Default::default())
}
fn update(&mut self)
{
Self::update(self)
}
fn complete(self)
{
Self::complete(self)
}
}

Loading…
Cancel
Save