1
+ use crate :: config:: Config ;
1
2
use crate :: {
2
3
confirmation:: { ConfirmPrompt , ConfirmStatus } ,
3
4
filter:: { Filter , SearchAction } ,
@@ -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_select : Option < Vec < String > > ,
63
66
#[ cfg( feature = "tips" ) ]
64
67
tip : & ' static str ,
65
68
}
@@ -79,10 +82,16 @@ 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_select = config_path. and_then ( |path| {
90
+ Config :: from_file ( & path)
91
+ . map ( |config| config. auto_select )
92
+ . ok ( )
93
+ } ) ;
94
+
86
95
let mut state = Self {
87
96
_temp_dir : temp_dir,
88
97
theme,
@@ -95,14 +104,44 @@ impl AppState {
95
104
multi_select : false ,
96
105
selected_commands : Vec :: new ( ) ,
97
106
drawable : false ,
107
+ auto_select,
98
108
#[ cfg( feature = "tips" ) ]
99
109
tip : get_random_tip ( ) ,
100
110
} ;
101
111
102
112
state. update_items ( ) ;
113
+
114
+ if let Some ( auto_select) = state. auto_select . clone ( ) {
115
+ state. handle_initial_auto_select ( & auto_select) ;
116
+ }
117
+
103
118
state
104
119
}
105
120
121
+ fn handle_initial_auto_select ( & mut self , auto_select : & [ String ] ) {
122
+ let item_list = self . filter . item_list ( ) ;
123
+ self . selected_commands = auto_select
124
+ . iter ( )
125
+ . filter_map ( |name| {
126
+ item_list
127
+ . iter ( )
128
+ . find ( |item| item. node . name == * name)
129
+ . map ( |item| item. node . clone ( ) )
130
+ } )
131
+ . collect ( ) ;
132
+
133
+ if !self . selected_commands . is_empty ( ) {
134
+ let cmd_names = self
135
+ . selected_commands
136
+ . iter ( )
137
+ . map ( |node| node. name . as_str ( ) )
138
+ . collect :: < Vec < _ > > ( ) ;
139
+
140
+ let prompt = ConfirmPrompt :: new ( & cmd_names) ;
141
+ self . focus = Focus :: ConfirmationPrompt ( Float :: new ( Box :: new ( prompt) , 40 , 40 ) ) ;
142
+ }
143
+ }
144
+
106
145
fn get_list_item_shortcut ( & self ) -> Box < [ Shortcut ] > {
107
146
if self . selected_item_is_dir ( ) {
108
147
Box :: new ( [ Shortcut :: new ( "Go to selected dir" , [ "l" , "Right" , "Enter" ] ) ] )
0 commit comments