Skip to main content

progress_bar/
style.rs

1//! A module containing style and color enums.
2
3use std::fmt;
4
5#[derive(Debug, Copy, Clone)]
6pub enum Color {
7    White,
8    Black,
9    Red,
10    Green,
11    Yellow,
12    Blue,
13    Magenta,
14    Cyan,
15    LightGray,
16    DarkGray,
17    LightRed,
18    LightGreen,
19    LightYellow,
20    LightBlue,
21    LightMagenta,
22    LightCyan
23}
24
25impl fmt::Display for Color {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        match self {
28            Color::White => write!(f, "\x1B[97m"),
29            Color::Black => write!(f, "\x1B[30m"),
30            Color::Red => write!(f, "\x1B[31m"),
31            Color::Green => write!(f, "\x1B[32m"),
32            Color::Yellow => write!(f, "\x1B[33m"),
33            Color::Blue => write!(f, "\x1B[34m"),
34            Color::Magenta => write!(f, "\x1B[35m"),
35            Color::Cyan => write!(f, "\x1B[36m"),
36            Color::LightGray => write!(f, "\x1B[37m"),
37            Color::DarkGray => write!(f, "\x1B[90m"),
38            Color::LightRed => write!(f, "\x1B[91m"),
39            Color::LightGreen => write!(f, "\x1B[92m"),
40            Color::LightYellow => write!(f, "\x1B[93m"),
41            Color::LightBlue => write!(f, "\x1B[94m"),
42            Color::LightMagenta => write!(f, "\x1B[95m"),
43            Color::LightCyan => write!(f, "\x1B[96m")
44        }
45    }
46}
47
48pub enum Style {
49    Normal, 
50    Bold,
51    Dim,
52    Italic,
53    Underlined,
54    Blink,
55    Reverse,
56    Hidden,
57    StrikeThrough,
58}
59
60impl fmt::Display for Style {
61    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62        match self {
63            Style::Normal => write!(f, "\x1B[0m"),
64            Style::Bold => write!(f, "\x1B[1m"),
65            Style::Dim => write!(f, "\x1B[2m"),
66            Style::Italic => write!(f, "\x1B[3m"),
67            Style::Underlined => write!(f, "\x1B[4m"),
68            Style::Blink => write!(f, "\x1B[5m"),
69            Style::Reverse => write!(f, "\x1B[7m"),
70            Style::Hidden => write!(f, "\x1B[8m"),
71            Style::StrikeThrough => write!(f, "\x1B[9m"),
72        }
73    }
74}
75
76pub enum ProgressStyle {
77    /// A number that shows how many actions have been finished and how many actions there are. Example: 23/57
78    Number,
79    /// A percentage of the completed work is shown. Example: 32%
80    Percentage,
81    /// No indication of progression is shown next to the progress bar.
82    Empty
83}