@@ -8,81 +8,92 @@ use std::io::{Read, Write};
8
8
use std:: path:: PathBuf ;
9
9
use tui:: style:: { Color , Modifier , Style } ;
10
10
11
- #[ derive( Serialize , Deserialize , Debug , Default , Clone , Copy ) ]
11
+ #[ derive( Serialize , Deserialize , Debug , Clone , Copy ) ]
12
12
pub struct Theme {
13
- selected_tab : ColorDef ,
14
- command_foreground : ColorDef ,
15
- command_background : ColorDef ,
16
- command_disabled : ColorDef ,
17
- diff_line_add : ColorDef ,
18
- diff_line_delete : ColorDef ,
19
- diff_file_added : ColorDef ,
20
- diff_file_removed : ColorDef ,
21
- diff_file_moved : ColorDef ,
22
- diff_file_modified : ColorDef ,
23
- table_colors : [ ColorDef ; 3 ] ,
13
+ #[ serde( with = "ColorDef" ) ]
14
+ selected_tab : Color ,
15
+ #[ serde( with = "ColorDef" ) ]
16
+ command_foreground : Color ,
17
+ #[ serde( with = "ColorDef" ) ]
18
+ command_background : Color ,
19
+ #[ serde( with = "ColorDef" ) ]
20
+ command_disabled : Color ,
21
+ #[ serde( with = "ColorDef" ) ]
22
+ diff_line_add : Color ,
23
+ #[ serde( with = "ColorDef" ) ]
24
+ diff_line_delete : Color ,
25
+ #[ serde( with = "ColorDef" ) ]
26
+ diff_file_added : Color ,
27
+ #[ serde( with = "ColorDef" ) ]
28
+ diff_file_removed : Color ,
29
+ #[ serde( with = "ColorDef" ) ]
30
+ diff_file_moved : Color ,
31
+ #[ serde( with = "ColorDef" ) ]
32
+ diff_file_modified : Color ,
33
+ #[ serde( with = "ColorDef" ) ]
34
+ commit_hash : Color ,
35
+ #[ serde( with = "ColorDef" ) ]
36
+ commit_time : Color ,
37
+ #[ serde( with = "ColorDef" ) ]
38
+ commit_author : Color ,
24
39
}
25
40
26
41
pub const DARK_THEME : Theme = Theme {
27
- selected_tab : ColorDef :: Yellow ,
28
- command_foreground : ColorDef :: White ,
29
- command_background : ColorDef :: Rgb ( 0 , 0 , 100 ) ,
30
- command_disabled : ColorDef :: DarkGray ,
31
- diff_line_add : ColorDef :: Green ,
32
- diff_line_delete : ColorDef :: Red ,
33
- diff_file_added : ColorDef :: LightGreen ,
34
- diff_file_removed : ColorDef :: LightRed ,
35
- diff_file_moved : ColorDef :: LightMagenta ,
36
- diff_file_modified : ColorDef :: Yellow ,
37
- table_colors : [
38
- ColorDef :: Magenta ,
39
- ColorDef :: Blue ,
40
- ColorDef :: Green ,
41
- ] ,
42
+ selected_tab : Color :: Yellow ,
43
+ command_foreground : Color :: White ,
44
+ command_background : Color :: Rgb ( 0 , 0 , 100 ) ,
45
+ command_disabled : Color :: DarkGray ,
46
+ diff_line_add : Color :: Green ,
47
+ diff_line_delete : Color :: Red ,
48
+ diff_file_added : Color :: LightGreen ,
49
+ diff_file_removed : Color :: LightRed ,
50
+ diff_file_moved : Color :: LightMagenta ,
51
+ diff_file_modified : Color :: Yellow ,
52
+ commit_hash : Color :: Magenta ,
53
+ commit_time : Color :: Blue ,
54
+ commit_author : Color :: Green ,
42
55
} ;
43
56
44
57
impl Theme {
45
58
pub fn block ( & self , focus : bool ) -> Style {
46
59
if focus {
47
60
Style :: default ( )
48
61
} else {
49
- Style :: default ( ) . fg ( self . command_disabled . into ( ) )
62
+ Style :: default ( ) . fg ( self . command_disabled )
50
63
}
51
64
}
52
65
53
66
pub fn tab ( & self , selected : bool ) -> Style {
54
67
if selected {
55
- Style :: default ( ) . fg ( self . selected_tab . into ( ) )
68
+ Style :: default ( ) . fg ( self . selected_tab )
56
69
} else {
57
70
Style :: default ( )
58
71
}
59
72
}
60
73
61
74
pub fn text ( & self , enabled : bool , selected : bool ) -> Style {
62
75
match ( enabled, selected) {
63
- ( false , _) => {
64
- Style :: default ( ) . fg ( self . command_disabled . into ( ) )
65
- }
76
+ ( false , _) => Style :: default ( ) . fg ( self . command_disabled ) ,
66
77
( true , false ) => Style :: default ( ) ,
67
78
( true , true ) => {
68
- Style :: default ( ) . bg ( self . command_background . into ( ) )
79
+ Style :: default ( ) . bg ( self . command_background )
69
80
}
70
81
}
71
82
}
72
83
73
84
pub fn item ( & self , typ : StatusItemType , selected : bool ) -> Style {
74
85
let style = match typ {
75
86
StatusItemType :: New => {
76
- Style :: default ( ) . fg ( self . diff_file_added . into ( ) )
87
+ Style :: default ( ) . fg ( self . diff_file_added )
77
88
}
78
89
StatusItemType :: Modified => {
79
- Style :: default ( ) . fg ( self . diff_file_modified . into ( ) )
90
+ Style :: default ( ) . fg ( self . diff_file_modified )
80
91
}
81
92
StatusItemType :: Deleted => {
82
- Style :: default ( ) . fg ( self . diff_file_removed . into ( ) )
93
+ Style :: default ( ) . fg ( self . diff_file_removed )
83
94
}
84
95
StatusItemType :: Renamed => {
85
- Style :: default ( ) . fg ( self . diff_file_moved . into ( ) )
96
+ Style :: default ( ) . fg ( self . diff_file_moved )
86
97
}
87
98
_ => Style :: default ( ) ,
88
99
} ;
@@ -92,7 +103,7 @@ impl Theme {
92
103
93
104
fn apply_select ( & self , style : Style , selected : bool ) -> Style {
94
105
if selected {
95
- style. bg ( self . command_background . into ( ) )
106
+ style. bg ( self . command_background )
96
107
} else {
97
108
style
98
109
}
@@ -105,10 +116,10 @@ impl Theme {
105
116
) -> Style {
106
117
let style = match typ {
107
118
DiffLineType :: Add => {
108
- Style :: default ( ) . fg ( self . diff_line_add . into ( ) )
119
+ Style :: default ( ) . fg ( self . diff_line_add )
109
120
}
110
121
DiffLineType :: Delete => {
111
- Style :: default ( ) . fg ( self . diff_line_delete . into ( ) )
122
+ Style :: default ( ) . fg ( self . diff_line_delete )
112
123
}
113
124
DiffLineType :: Header => {
114
125
Style :: default ( ) . modifier ( Modifier :: BOLD )
@@ -120,21 +131,33 @@ impl Theme {
120
131
}
121
132
122
133
pub fn text_danger ( & self ) -> Style {
123
- Style :: default ( ) . fg ( self . diff_file_removed . into ( ) )
134
+ Style :: default ( ) . fg ( self . diff_file_removed )
124
135
}
125
136
126
137
pub fn toolbar ( & self , enabled : bool ) -> Style {
127
138
if enabled {
128
- Style :: default ( ) . fg ( self . command_foreground . into ( ) )
139
+ Style :: default ( ) . fg ( self . command_foreground )
129
140
} else {
130
- Style :: default ( ) . fg ( self . command_disabled . into ( ) )
141
+ Style :: default ( ) . fg ( self . command_disabled )
131
142
}
132
- . bg ( self . command_background . into ( ) )
143
+ . bg ( self . command_background )
133
144
}
134
145
135
- pub fn table ( & self , column : usize , selected : bool ) -> Style {
146
+ pub fn commit_hash ( & self , selected : bool ) -> Style {
147
+ self . apply_select (
148
+ Style :: default ( ) . fg ( self . commit_hash ) ,
149
+ selected,
150
+ )
151
+ }
152
+ pub fn commit_time ( & self , selected : bool ) -> Style {
153
+ self . apply_select (
154
+ Style :: default ( ) . fg ( self . commit_time ) ,
155
+ selected,
156
+ )
157
+ }
158
+ pub fn commit_author ( & self , selected : bool ) -> Style {
136
159
self . apply_select (
137
- Style :: default ( ) . fg ( self . table_colors [ column ] . into ( ) ) ,
160
+ Style :: default ( ) . fg ( self . commit_author ) ,
138
161
selected,
139
162
)
140
163
}
@@ -182,7 +205,8 @@ impl Theme {
182
205
/// we duplicate the Color definition from `tui` crate to implement Serde serialisation
183
206
/// this enum can be removed once [tui-#292](https://github.com/fdehau/tui-rs/issues/292) is resolved
184
207
#[ derive( Serialize , Deserialize , Debug , Copy , Clone ) ]
185
- pub enum ColorDef {
208
+ #[ serde( remote = "Color" ) ]
209
+ enum ColorDef {
186
210
Reset ,
187
211
Black ,
188
212
Red ,
@@ -203,35 +227,3 @@ pub enum ColorDef {
203
227
Rgb ( u8 , u8 , u8 ) ,
204
228
Indexed ( u8 ) ,
205
229
}
206
-
207
- impl Default for ColorDef {
208
- fn default ( ) -> Self {
209
- ColorDef :: Reset
210
- }
211
- }
212
-
213
- impl From < ColorDef > for Color {
214
- fn from ( def : ColorDef ) -> Self {
215
- match def {
216
- ColorDef :: Reset => Color :: Reset ,
217
- ColorDef :: Black => Color :: Black ,
218
- ColorDef :: Red => Color :: Red ,
219
- ColorDef :: Green => Color :: Green ,
220
- ColorDef :: Yellow => Color :: Yellow ,
221
- ColorDef :: Blue => Color :: Blue ,
222
- ColorDef :: Magenta => Color :: Magenta ,
223
- ColorDef :: Cyan => Color :: Cyan ,
224
- ColorDef :: Gray => Color :: Gray ,
225
- ColorDef :: DarkGray => Color :: DarkGray ,
226
- ColorDef :: LightRed => Color :: LightRed ,
227
- ColorDef :: LightGreen => Color :: LightGreen ,
228
- ColorDef :: LightYellow => Color :: LightYellow ,
229
- ColorDef :: LightBlue => Color :: LightBlue ,
230
- ColorDef :: LightMagenta => Color :: LightMagenta ,
231
- ColorDef :: LightCyan => Color :: LightCyan ,
232
- ColorDef :: White => Color :: White ,
233
- ColorDef :: Rgb ( a, b, c) => Color :: Rgb ( a, b, c) ,
234
- ColorDef :: Indexed ( x) => Color :: Indexed ( x) ,
235
- }
236
- }
237
- }
0 commit comments