1
1
use strum_macros;
2
2
use std:: path:: PathBuf ;
3
- use std:: error:: Error ;
3
+ use std:: error;
4
+ use std:: io:: { Error , ErrorKind } ;
4
5
use config:: {
5
6
Config , File as ConfigFile , FileFormat ,
6
7
} ;
@@ -176,18 +177,27 @@ pub struct ThemeManager {
176
177
177
178
// Theme-loading logic
178
179
impl ThemeManager {
179
- pub fn new ( debug : Option < bool > ) -> Self {
180
+ pub fn new ( debug : Option < bool > , theme_dir : Option < String > ) -> Self {
180
181
Self {
181
182
loaded_themes : HashMap :: new ( ) ,
182
183
debug : debug. unwrap_or ( false ) ,
183
- override_theme_dir : std:: env:: var ( "ATUIN_THEME_DIR" ) . ok ( ) ,
184
+ override_theme_dir : match theme_dir {
185
+ Some ( theme_dir) => Some ( theme_dir) ,
186
+ None => std:: env:: var ( "ATUIN_THEME_DIR" ) . ok ( )
187
+ } ,
184
188
}
185
189
}
186
190
187
191
// Try to load a theme from a `{name}.toml` file in the theme directory. If an override is set
188
192
// for the theme dir (via ATUIN_THEME_DIR env) we should load the theme from there
189
- pub fn load_theme_from_file ( & mut self , name : & str ) -> Result < & Theme , Box < dyn Error > > {
193
+ pub fn load_theme_from_file ( & mut self , name : & str ) -> Result < & Theme , Box < dyn error :: Error > > {
190
194
let mut theme_file = if let Some ( p) = & self . override_theme_dir {
195
+ if p. is_empty ( ) {
196
+ return Err ( Box :: new ( Error :: new (
197
+ ErrorKind :: NotFound ,
198
+ "Empty theme directory override and could not find theme elsewhere"
199
+ ) ) ) ;
200
+ }
191
201
PathBuf :: from ( p)
192
202
} else {
193
203
let config_dir = atuin_common:: utils:: config_dir ( ) ;
@@ -230,7 +240,7 @@ impl ThemeManager {
230
240
None => match self . load_theme_from_file ( name) {
231
241
Ok ( theme) => theme,
232
242
Err ( err) => {
233
- print ! [ "Could not load theme {}: {}" , name, err] ;
243
+ println ! [ "Could not load theme {}: {}" , name, err] ;
234
244
built_ins. get ( "" ) . unwrap ( )
235
245
}
236
246
}
@@ -244,8 +254,8 @@ mod theme_tests {
244
254
245
255
#[ test]
246
256
fn load_theme ( ) {
247
- let mut manager = ThemeManager :: new ( Some ( false ) ) ;
257
+ let mut manager = ThemeManager :: new ( Some ( false ) , Some ( "" . to_string ( ) ) ) ;
248
258
let theme = manager. load_theme ( "autumn" ) ;
249
- assert_eq ! ( theme. as_style( Meaning :: Annotation ) . foreground_color, Some ( Color :: DarkGrey ) ) ;
259
+ assert_eq ! ( theme. as_style( Meaning :: Guidance ) . foreground_color, from_named ( "brown" ) . ok ( ) ) ;
250
260
}
251
261
}
0 commit comments