@@ -13,11 +13,14 @@ use toml::Value;
13
13
pub use crate :: graphics:: { Color , Modifier , Style } ;
14
14
15
15
pub static DEFAULT_THEME : Lazy < Theme > = Lazy :: new ( || {
16
- toml:: from_slice ( include_bytes ! ( "../../theme.toml" ) ) . expect ( "Failed to parse default theme" )
16
+ let raw_theme: RawTheme = toml:: from_slice ( include_bytes ! ( "../../theme.toml" ) )
17
+ . expect ( "Failed to parse default theme" ) ;
18
+ Theme :: from ( raw_theme)
17
19
} ) ;
18
20
pub static BASE16_DEFAULT_THEME : Lazy < Theme > = Lazy :: new ( || {
19
- toml:: from_slice ( include_bytes ! ( "../../base16_theme.toml" ) )
20
- . expect ( "Failed to parse base 16 default theme" )
21
+ let raw_theme: RawTheme = toml:: from_slice ( include_bytes ! ( "../../base16_theme.toml" ) )
22
+ . expect ( "Failed to parse base 16 default theme" ) ;
23
+ Theme :: from ( raw_theme)
21
24
} ) ;
22
25
23
26
#[ derive( Clone , Debug ) ]
@@ -53,11 +56,6 @@ impl Loader {
53
56
}
54
57
55
58
Ok ( Theme :: from ( raw_theme) )
56
-
57
- // let path = self.path(name);
58
- // let data = std::fs::read(&path)?;
59
-
60
- // toml::from_slice(data.as_slice()).context("Faled to deserialize theme")
61
59
}
62
60
63
61
pub fn read_names ( path : & Path ) -> Vec < String > {
@@ -88,13 +86,11 @@ impl Loader {
88
86
let filename = format ! ( "{}.toml" , name) ;
89
87
90
88
let user_path = self . user_dir . join ( & filename) ;
91
- let path = if user_path. exists ( ) {
89
+ if user_path. exists ( ) {
92
90
user_path
93
91
} else {
94
92
self . default_dir . join ( filename)
95
- } ;
96
-
97
- path
93
+ }
98
94
}
99
95
100
96
/// Lists all theme names available in default and user directory
@@ -171,7 +167,7 @@ impl<'de> Deserialize<'de> for RawTheme {
171
167
172
168
let inherits_from = values
173
169
. remove ( "inherits_from" )
174
- . map ( |value| value. to_string ( ) . replace ( " \" " , "" ) ) ;
170
+ . map ( |value| value. to_string ( ) . replace ( '\"' , "" ) ) ;
175
171
176
172
Ok ( Self {
177
173
values,
@@ -216,52 +212,6 @@ impl From<RawTheme> for Theme {
216
212
}
217
213
}
218
214
219
- impl < ' de > Deserialize < ' de > for Theme {
220
- fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
221
- where
222
- D : Deserializer < ' de > ,
223
- {
224
- let mut styles = HashMap :: new ( ) ;
225
- let mut scopes = Vec :: new ( ) ;
226
- let mut highlights = Vec :: new ( ) ;
227
-
228
- if let Ok ( mut colors) = HashMap :: < String , Value > :: deserialize ( deserializer) {
229
- // TODO: alert user of parsing failures in editor
230
- let palette = colors
231
- . remove ( "palette" )
232
- . map ( |value| {
233
- ThemePalette :: try_from ( value) . unwrap_or_else ( |err| {
234
- warn ! ( "{}" , err) ;
235
- ThemePalette :: default ( )
236
- } )
237
- } )
238
- . unwrap_or_default ( ) ;
239
-
240
- styles. reserve ( colors. len ( ) ) ;
241
- scopes. reserve ( colors. len ( ) ) ;
242
- highlights. reserve ( colors. len ( ) ) ;
243
-
244
- for ( name, style_value) in colors {
245
- let mut style = Style :: default ( ) ;
246
- if let Err ( err) = palette. parse_style ( & mut style, style_value) {
247
- warn ! ( "{}" , err) ;
248
- }
249
-
250
- // these are used both as UI and as highlights
251
- styles. insert ( name. clone ( ) , style) ;
252
- scopes. push ( name) ;
253
- highlights. push ( style) ;
254
- }
255
- }
256
-
257
- Ok ( Self {
258
- scopes,
259
- styles,
260
- highlights,
261
- } )
262
- }
263
- }
264
-
265
215
impl Theme {
266
216
#[ inline]
267
217
pub fn highlight ( & self , index : usize ) -> Style {
0 commit comments