use crossterm::style::{Attribute, ContentStyle};
use crate::style::combine_attributes;
use crate::{
style::{Color, StyledString},
styled_string,
};
#[derive(Clone, Debug)]
pub struct Frames {
pub begin: Vec<StyledString>,
pub bar_complete_char: Vec<StyledString>,
pub limiter: Vec<StyledString>,
pub bar_incomplete_char: Vec<StyledString>,
pub end: Vec<StyledString>,
pub size: usize,
pub goal: usize,
pub current: usize,
}
impl Default for Frames {
fn default() -> Self {
Self::equal()
}
}
impl PartialEq for Frames {
fn eq(&self, other: &Self) -> bool {
self.begin == other.begin
&& self.bar_complete_char == other.bar_complete_char
&& self.bar_incomplete_char == other.bar_incomplete_char
&& self.end == other.end
&& self.size == other.size
&& self.goal == other.goal
&& self.current == other.current
}
}
impl Eq for Frames {}
impl Frames {
pub fn new(
begin: Vec<StyledString>,
bar_complete_char: Vec<StyledString>,
limiter: Vec<StyledString>,
bar_incomplete_char: Vec<StyledString>,
end: Vec<StyledString>,
) -> Frames {
Frames {
begin,
bar_complete_char,
limiter,
bar_incomplete_char,
end,
size: 30,
goal: 100,
current: 0,
}
}
pub fn set_size(&mut self, size: usize) -> Self {
self.size = size;
self.clone()
}
pub fn set_goal(&self, goal: usize) -> Self {
let _ = self.current.min(goal);
self.clone()
}
pub fn inc(&mut self, num: &usize) -> Self {
self.current = (self.current + num).min(self.goal);
self.clone()
}
pub fn equal() -> Self {
Self::new(
styled_string!["["],
styled_string!["="],
styled_string![""],
styled_string!["-"],
styled_string!["]"],
)
}
pub fn hash() -> Self {
Self::new(
styled_string!["["],
styled_string!["#"],
styled_string![""],
styled_string!["."],
styled_string!["]"],
)
}
pub fn rect() -> Self {
Self::new(
styled_string![" "],
styled_string!["\u{25A0}"],
styled_string![""],
styled_string![" "],
styled_string![" "],
)
}
pub fn dotted_rich() -> Self {
Self::new(
styled_string![" "],
vec![StyledString {
string: "━".to_string(),
style: ContentStyle {
foreground_color: Some(Color::Rgb {
r: 245,
g: 48,
b: 119,
}),
background_color: None,
underline_color: None,
attributes: combine_attributes(&[&Attribute::Bold]),
},
}],
vec![StyledString::simple("╸", None, None, None)],
vec![StyledString {
string: "╸".to_string(),
style: ContentStyle {
foreground_color: Some(Color::DarkGrey),
background_color: None,
underline_color: None,
attributes: combine_attributes(&[&Attribute::NoBold]),
},
}],
styled_string![" "],
)
}
pub fn rich() -> Self {
Self::new(
styled_string![" "],
vec![StyledString {
string: "━".to_string(),
style: ContentStyle {
foreground_color: Some(Color::Rgb {
r: 245,
g: 48,
b: 119,
}),
background_color: None,
underline_color: None,
attributes: combine_attributes(&[&Attribute::Bold]),
},
}],
vec![StyledString::simple("╺", Some(Color::DarkGrey), None, None)],
vec![StyledString {
string: "━".to_string(),
style: ContentStyle {
foreground_color: Some(Color::DarkGrey),
background_color: None,
underline_color: None,
attributes: combine_attributes(&[]),
},
}],
styled_string![" "],
)
}
}