1use termcolor::{Color, ColorSpec};
2
3pub trait Style {
5 fn foreground_color(self, foreground_color: Option<Color>) -> Self;
7 fn background_color(self, background_color: Option<Color>) -> Self;
9 fn bold(self, bold: bool) -> Self;
11 fn underline(self, underline: bool) -> Self;
13 fn italic(self, italic: bool) -> Self;
15 fn intense(self, intense: bool) -> Self;
17 fn dimmed(self, dimmed: bool) -> Self;
19}
20
21#[derive(Debug, Clone, Copy, Default)]
22pub(crate) struct StyleStruct {
23 pub(crate) foreground_color: Option<Color>,
24 pub(crate) background_color: Option<Color>,
25 pub(crate) bold: bool,
26 pub(crate) underline: bool,
27 pub(crate) italic: bool,
28 pub(crate) intense: bool,
29 pub(crate) dimmed: bool,
30}
31
32impl StyleStruct {
33 pub(crate) fn color_spec(&self) -> ColorSpec {
34 let mut color_spec = ColorSpec::new();
35
36 color_spec.set_fg(self.foreground_color);
37 color_spec.set_bg(self.background_color);
38 color_spec.set_bold(self.bold);
39 color_spec.set_underline(self.underline);
40 color_spec.set_italic(self.italic);
41 color_spec.set_intense(self.intense);
42 color_spec.set_dimmed(self.dimmed);
43
44 color_spec
45 }
46}
47
48impl Style for StyleStruct {
49 fn foreground_color(mut self, foreground_color: Option<Color>) -> Self {
50 self.foreground_color = foreground_color;
51 self
52 }
53
54 fn background_color(mut self, background_color: Option<Color>) -> Self {
55 self.background_color = background_color;
56 self
57 }
58
59 fn bold(mut self, bold: bool) -> Self {
60 self.bold = bold;
61 self
62 }
63
64 fn underline(mut self, underline: bool) -> Self {
65 self.underline = underline;
66 self
67 }
68
69 fn italic(mut self, italic: bool) -> Self {
70 self.italic = italic;
71 self
72 }
73
74 fn intense(mut self, intense: bool) -> Self {
75 self.intense = intense;
76 self
77 }
78
79 fn dimmed(mut self, dimmed: bool) -> Self {
80 self.dimmed = dimmed;
81 self
82 }
83}