1
1
use crate :: {
2
- helpers:: { get_config_dir, Exit } ,
2
+ helpers:: { apply_if_some , get_config_dir, Exit } ,
3
3
widgets:: table:: Table ,
4
4
} ;
5
5
use serde:: { Deserialize , Serialize } ;
@@ -32,15 +32,17 @@ pub fn parse_template_config() -> Vec<Template> {
32
32
let templates_content =
33
33
fs:: read_dir ( get_config_dir ( ) . join ( "templates/" ) ) . exit ( 1 , "Can't read template config" ) ;
34
34
35
- let templates_raw: Vec < _ > = templates_content
36
- . filter_map ( |x| x. ok ( ) )
37
- . filter ( |x| x. path ( ) . is_file ( ) )
38
- . filter_map ( |x| fs:: read_to_string ( x. path ( ) ) . ok ( ) )
39
- . collect ( ) ;
35
+ templates_content
36
+ . filter_map ( |entry| {
37
+ let entry = entry. ok ( ) ?;
38
+ let path = entry. path ( ) ;
39
+ if !path. is_file ( ) {
40
+ return None ;
41
+ }
40
42
41
- templates_raw
42
- . iter ( )
43
- . filter_map ( |x| serde_yaml :: from_str :: < Template > ( x ) . ok ( ) )
43
+ let content = fs :: read_to_string ( path ) . ok ( ) ? ;
44
+ serde_yaml :: from_str :: < Template > ( & content ) . ok ( )
45
+ } )
44
46
. collect ( )
45
47
}
46
48
@@ -53,10 +55,15 @@ pub fn apply_windows<'a>(
53
55
enumerated. fold ( tmux, |tmux, ( window_idx, window) | {
54
56
let cmd = build_tmux_command ( window_idx, window, dir) ;
55
57
56
- let layout_cmd: TmuxCommand = window. layout . as_ref ( ) . map_or_else ( || TmuxCommand :: select_layout ( ) . into ( ) , |layout| TmuxCommand :: select_layout ( ) . layout_name ( layout) . into ( ) ) ;
58
+ let layout = window. layout . as_ref ( ) ;
59
+ let layout_cmd = layout. map ( |layout| TmuxCommand :: select_layout ( ) . layout_name ( layout) ) ;
57
60
58
61
let tmux = tmux. add_command ( cmd) ;
59
- add_panes_to_tmux ( tmux, & window. panes , dir) . add_command ( layout_cmd)
62
+ apply_if_some (
63
+ add_panes_to_tmux ( tmux, & window. panes , dir) ,
64
+ layout_cmd,
65
+ |tmux, cmd| tmux. add_command ( cmd) ,
66
+ )
60
67
} )
61
68
}
62
69
@@ -87,12 +94,10 @@ fn build_tmux_command<'a>(
87
94
TmuxCommand :: rename_window ( ) . new_name ( name) . into ( )
88
95
} )
89
96
} else {
90
- let new_win = window
91
- . name
92
- . as_ref ( )
93
- . map_or_else ( TmuxCommand :: new_window, |name| {
94
- TmuxCommand :: new_window ( ) . window_name ( name)
95
- } ) ;
97
+ let name = window. name . as_ref ( ) ;
98
+ let new_win = name. map_or_else ( TmuxCommand :: new_window, |name| {
99
+ TmuxCommand :: new_window ( ) . window_name ( name)
100
+ } ) ;
96
101
match dir {
97
102
Some ( d) => new_win. start_directory ( d. to_string_lossy ( ) ) . into ( ) ,
98
103
None => new_win. into ( ) ,
0 commit comments