@@ -9,6 +9,7 @@ use crate::{
9
9
} ;
10
10
use crossterm:: event:: { KeyCode , KeyEvent , KeyEventKind , KeyModifiers } ;
11
11
use ego_tree:: NodeId ;
12
+ use linutil_core:: Config ;
12
13
use linutil_core:: { ListNode , Tab } ;
13
14
#[ cfg( feature = "tips" ) ]
14
15
use rand:: Rng ;
@@ -19,6 +20,7 @@ use ratatui::{
19
20
widgets:: { Block , Borders , List , ListState , Paragraph } ,
20
21
Frame ,
21
22
} ;
23
+ use std:: path:: PathBuf ;
22
24
use std:: rc:: Rc ;
23
25
use temp_dir:: TempDir ;
24
26
@@ -60,6 +62,7 @@ pub struct AppState {
60
62
multi_select : bool ,
61
63
selected_commands : Vec < Rc < ListNode > > ,
62
64
drawable : bool ,
65
+ auto_execute : Option < Vec < String > > ,
63
66
#[ cfg( feature = "tips" ) ]
64
67
tip : & ' static str ,
65
68
}
@@ -79,10 +82,12 @@ pub struct ListEntry {
79
82
}
80
83
81
84
impl AppState {
82
- pub fn new ( theme : Theme , override_validation : bool ) -> Self {
85
+ pub fn new ( theme : Theme , override_validation : bool , config_path : Option < PathBuf > ) -> Self {
83
86
let ( temp_dir, tabs) = linutil_core:: get_tabs ( !override_validation) ;
84
87
let root_id = tabs[ 0 ] . tree . root ( ) . id ( ) ;
85
88
89
+ let auto_execute = config_path. map ( |path| Config :: from_file ( & path) . auto_execute ) ;
90
+
86
91
let mut state = Self {
87
92
_temp_dir : temp_dir,
88
93
theme,
@@ -95,14 +100,38 @@ impl AppState {
95
100
multi_select : false ,
96
101
selected_commands : Vec :: new ( ) ,
97
102
drawable : false ,
103
+ auto_execute,
98
104
#[ cfg( feature = "tips" ) ]
99
105
tip : get_random_tip ( ) ,
100
106
} ;
101
107
102
108
state. update_items ( ) ;
109
+
110
+ if let Some ( auto_execute) = state. auto_execute . clone ( ) {
111
+ state. handle_initial_auto_execute ( & auto_execute) ;
112
+ }
113
+
103
114
state
104
115
}
105
116
117
+ fn handle_initial_auto_execute ( & mut self , auto_execute : & [ String ] ) {
118
+ self . selected_commands = auto_execute
119
+ . iter ( )
120
+ . filter_map ( |name| self . tabs . iter ( ) . find_map ( |tab| tab. find_command ( name) ) )
121
+ . collect ( ) ;
122
+
123
+ if !self . selected_commands . is_empty ( ) {
124
+ let cmd_names: Vec < _ > = self
125
+ . selected_commands
126
+ . iter ( )
127
+ . map ( |node| node. name . as_str ( ) )
128
+ . collect ( ) ;
129
+
130
+ let prompt = ConfirmPrompt :: new ( & cmd_names) ;
131
+ self . focus = Focus :: ConfirmationPrompt ( Float :: new ( Box :: new ( prompt) , 40 , 40 ) ) ;
132
+ }
133
+ }
134
+
106
135
fn get_list_item_shortcut ( & self ) -> Box < [ Shortcut ] > {
107
136
if self . selected_item_is_dir ( ) {
108
137
Box :: new ( [ Shortcut :: new ( "Go to selected dir" , [ "l" , "Right" , "Enter" ] ) ] )
0 commit comments