1
1
pub trait Stylify {
2
- fn make_styles ( & self , paint_type : Option < PaintType > ) -> String ;
2
+ fn make_styles ( & self , paint_type : Option < & PaintType > ) -> String ;
3
3
}
4
4
#[ derive( Debug , Clone ) ]
5
5
pub enum PaintType {
@@ -16,7 +16,7 @@ pub enum Styles {
16
16
}
17
17
18
18
impl Styles {
19
- fn make_styles ( & self , paint_type : Option < PaintType > ) -> String {
19
+ pub fn make_styles ( & self , paint_type : Option < & PaintType > ) -> String {
20
20
match self {
21
21
Styles :: StyleBasicColor ( c) => c. make_styles ( paint_type) ,
22
22
Styles :: StylePaintType ( c) => c. make_styles ( paint_type) ,
@@ -27,7 +27,7 @@ impl Styles {
27
27
}
28
28
29
29
impl Stylify for PaintType {
30
- fn make_styles ( & self , _paint_type : Option < PaintType > ) -> String {
30
+ fn make_styles ( & self , _paint_type : Option < & PaintType > ) -> String {
31
31
String :: new ( )
32
32
}
33
33
}
@@ -39,8 +39,8 @@ pub struct BasicColor {
39
39
40
40
impl Stylify for BasicColor {
41
41
/// If the `is_foreground` was None it's assume as foreground
42
- fn make_styles ( & self , paint_type : Option < PaintType > ) -> String {
43
- let paint_type = paint_type. unwrap_or ( PaintType :: FG ) ;
42
+ fn make_styles ( & self , paint_type : Option < & PaintType > ) -> String {
43
+ let paint_type = paint_type. unwrap_or ( & PaintType :: FG ) ;
44
44
format ! ( "{}" , match paint_type {
45
45
PaintType :: FG => self . fg,
46
46
PaintType :: BG => self . bg,
@@ -72,8 +72,8 @@ pub struct PaletteColor {
72
72
}
73
73
74
74
impl Stylify for PaletteColor {
75
- fn make_styles ( & self , paint_type : Option < PaintType > ) -> String {
76
- let paint_type = paint_type. unwrap_or ( PaintType :: FG ) ;
75
+ fn make_styles ( & self , paint_type : Option < & PaintType > ) -> String {
76
+ let paint_type = paint_type. unwrap_or ( & PaintType :: FG ) ;
77
77
format ! (
78
78
"{};5;{}" ,
79
79
match paint_type {
@@ -92,8 +92,8 @@ pub struct Rgb {
92
92
}
93
93
94
94
impl Stylify for Rgb {
95
- fn make_styles ( & self , paint_type : Option < PaintType > ) -> String {
96
- let paint_type = paint_type. unwrap_or ( PaintType :: FG ) ;
95
+ fn make_styles ( & self , paint_type : Option < & PaintType > ) -> String {
96
+ let paint_type = paint_type. unwrap_or ( & PaintType :: FG ) ;
97
97
format ! (
98
98
"{};2;{};{};{}" ,
99
99
match paint_type {
@@ -136,7 +136,7 @@ mod test {
136
136
137
137
#[ test]
138
138
fn paint_magenta_background ( ) {
139
- let painted_bg = MAGENTA . make_styles ( Some ( PaintType :: BG ) ) ;
139
+ let painted_bg = MAGENTA . make_styles ( Some ( & PaintType :: BG ) ) ;
140
140
141
141
assert_eq ! ( "45" , painted_bg)
142
142
}
@@ -163,7 +163,7 @@ mod test {
163
163
#[ test]
164
164
fn palette_paint_blue_bg ( ) {
165
165
let blue = PaletteColor { index : 33 } ;
166
- let painted_bg = blue. make_styles ( Some ( PaintType :: BG ) ) ;
166
+ let painted_bg = blue. make_styles ( Some ( & PaintType :: BG ) ) ;
167
167
assert_eq ! ( "48;5;33" , painted_bg)
168
168
}
169
169
@@ -193,7 +193,7 @@ mod test {
193
193
#[ test]
194
194
fn rgb_paint_orange_bg ( ) {
195
195
let orange = Rgb { r : 219 , g : 132 , b : 50 } ;
196
- let painted_bg = orange. make_styles ( Some ( PaintType :: BG ) ) ;
196
+ let painted_bg = orange. make_styles ( Some ( & PaintType :: BG ) ) ;
197
197
assert_eq ! ( "48;2;219;132;50" , painted_bg)
198
198
}
199
199
}
0 commit comments