@@ -25,6 +25,8 @@ pub struct Settings {
25
25
pub default_editor : String ,
26
26
pub max_history : usize ,
27
27
pub ls_display_block : usize ,
28
+ pub print_color_primary : Option < [ u8 ; 3 ] > ,
29
+ pub print_color_secondary : Option < [ u8 ; 3 ] > ,
28
30
}
29
31
30
32
#[ derive( Debug ) ]
@@ -44,33 +46,33 @@ impl Env {
44
46
home_dir
45
47
}
46
48
} ;
47
- let mut hop_config_file = PathBuf :: from ( & config_dir) ;
48
- match var ( "HOP_CONFIG_FILE_NAME " ) {
49
- Ok ( name) => hop_config_file . push ( name) ,
50
- Err ( _) => hop_config_file . push ( "bunnyhop.toml" ) ,
49
+ let mut config_file = PathBuf :: from ( & config_dir) ;
50
+ match var ( "config_file_NAME " ) {
51
+ Ok ( name) => config_file . push ( name) ,
52
+ Err ( _) => config_file . push ( "bunnyhop.toml" ) ,
51
53
} ;
52
- let mut database_dir = match var ( "HOP_DATABASE_DIRECTORY" ) {
54
+ let mut database_file = match var ( "HOP_DATABASE_DIRECTORY" ) {
53
55
Ok ( loc) => PathBuf :: from ( & loc) ,
54
56
Err ( _) => {
55
57
let mut db_dir_temp = PathBuf :: from ( format ! ( "{}" , & config_dir. as_path( ) . display( ) ) ) ;
56
58
db_dir_temp. push ( "db" ) ;
57
59
db_dir_temp
58
60
}
59
61
} ;
60
- if !Path :: new ( & database_dir ) . exists ( ) {
61
- match fs:: create_dir_all ( & database_dir ) {
62
+ if !Path :: new ( & database_file ) . exists ( ) {
63
+ match fs:: create_dir_all ( & database_file ) {
62
64
Ok ( _) => { }
63
65
Err ( e) => println ! ( "[error] Error creating database directory: {}" , e) ,
64
66
} ;
65
67
} ;
66
68
match var ( "HOP_DATABASE_FILE_NAME" ) {
67
- Ok ( name) => database_dir . push ( name) ,
68
- Err ( _) => database_dir . push ( "bunnyhop.db" ) ,
69
+ Ok ( name) => database_file . push ( name) ,
70
+ Err ( _) => database_file . push ( "bunnyhop.db" ) ,
69
71
} ;
70
72
71
73
Env {
72
- config_file : hop_config_file ,
73
- database_file : database_dir ,
74
+ config_file,
75
+ database_file,
74
76
}
75
77
}
76
78
}
@@ -356,12 +358,8 @@ impl Hopper {
356
358
Ok ( ( ) )
357
359
}
358
360
359
- fn format_lists ( & self , hops : Vec < ( String , String ) > , filter_string : Option < String > ) {
360
- let filter_condition = if filter_string. is_some ( ) {
361
- filter_string. unwrap ( )
362
- } else {
363
- "" . to_string ( )
364
- } ;
361
+ fn print_formatted_maps ( & self , hops : Vec < ( String , String ) > , filter_string : Option < String > ) {
362
+ let filter_condition = filter_string. unwrap_or ( "" . to_string ( ) ) ;
365
363
let filtered_hops: Vec < ( String , String ) > = hops
366
364
. into_iter ( )
367
365
. filter ( |( n, l) | n. contains ( & filter_condition) || l. contains ( & filter_condition) )
@@ -371,6 +369,8 @@ impl Hopper {
371
369
. map ( |( name, _) | name. len ( ) )
372
370
. max ( )
373
371
. unwrap_or ( 0 ) ;
372
+ let first_col = self . config . settings . print_color_primary . unwrap_or ( [ 51 , 255 , 255 ] ) ;
373
+ let sec_col = self . config . settings . print_color_secondary . unwrap_or ( [ 51 , 255 , 153 ] ) ;
374
374
let mut formatted_hops: Vec < String > = filtered_hops
375
375
. into_iter ( )
376
376
. map ( |( name, location) | {
@@ -384,10 +384,13 @@ impl Hopper {
384
384
. map ( |( ws, name, location) | {
385
385
format ! (
386
386
"{}{}{} {}" ,
387
- name. bold( ) . cyan( ) ,
387
+ name. truecolor( first_col[ 0 ] , first_col[ 1 ] , first_col[ 2 ] )
388
+ . bold( ) ,
388
389
ws,
389
390
"->" . bright_white( ) . bold( ) ,
390
- location. green( ) . bold( )
391
+ location
392
+ . truecolor( sec_col[ 0 ] , sec_col[ 1 ] , sec_col[ 2 ] )
393
+ . bold( )
391
394
)
392
395
} )
393
396
. collect ( ) ;
@@ -414,7 +417,7 @@ impl Hopper {
414
417
let location = query_result. read :: < String , _ > ( "location" ) ?;
415
418
hops. push ( ( name, location) ) ;
416
419
}
417
- self . format_lists ( hops, filter_string) ;
420
+ self . print_formatted_maps ( hops, filter_string) ;
418
421
Ok ( ( ) )
419
422
}
420
423
@@ -508,7 +511,7 @@ impl Hopper {
508
511
509
512
fn show_history ( & self , filter_condition : Option < String > ) -> anyhow:: Result < ( ) > {
510
513
let hops = self . retrieve_history ( ) ?;
511
- self . format_lists ( hops, filter_condition) ;
514
+ self . print_formatted_maps ( hops, filter_condition) ;
512
515
Ok ( ( ) )
513
516
}
514
517
@@ -594,7 +597,7 @@ impl Hopper {
594
597
. to_string( ) ,
595
598
) ,
596
599
] ;
597
- self . format_lists ( loc_vec, None ) ;
600
+ self . print_formatted_maps ( loc_vec, None ) ;
598
601
Ok ( ( ) )
599
602
}
600
603
}
0 commit comments