@@ -76,6 +76,15 @@ pub struct LaunchOptionsState {
7676 pub selections : Vec < LaunchOptionSelection > ,
7777}
7878
79+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
80+ pub struct LaunchArgumentState {
81+ pub tool_id : String ,
82+ pub tool_name : String ,
83+ pub label : String ,
84+ pub placeholder : String ,
85+ pub input : String ,
86+ }
87+
7988#[ derive( Debug , Clone , PartialEq , Eq ) ]
8089pub enum AppInput {
8190 Text ( String ) ,
@@ -162,6 +171,7 @@ pub struct AppState {
162171 pub workspace_missing_tools : Vec < String > ,
163172 pub app_view : Option < AppViewState > ,
164173 pub link_picker : Option < LinkPickerState > ,
174+ pub launch_argument : Option < LaunchArgumentState > ,
165175 pub launch_options : Option < LaunchOptionsState > ,
166176 pending_tool_launch : Option < ToolLaunchRequest > ,
167177 return_after_app_close : bool ,
@@ -246,6 +256,7 @@ impl AppState {
246256 workspace_missing_tools : Vec :: new ( ) ,
247257 app_view : None ,
248258 link_picker : None ,
259+ launch_argument : None ,
249260 launch_options : None ,
250261 pending_tool_launch : None ,
251262 return_after_app_close : false ,
@@ -288,6 +299,11 @@ impl AppState {
288299 return ;
289300 }
290301
302+ if self . launch_argument . is_some ( ) {
303+ self . handle_launch_argument_key ( key. code ) ;
304+ return ;
305+ }
306+
291307 if self . launch_options . is_some ( ) {
292308 self . handle_launch_options_key ( key. code ) ;
293309 return ;
@@ -343,6 +359,7 @@ impl AppState {
343359 if !self . mouse_enabled
344360 || self . confirmation . is_some ( )
345361 || self . ai_confirmation . is_some ( )
362+ || self . launch_argument . is_some ( )
346363 || self . launch_options . is_some ( )
347364 || self . uninstall_confirmation . is_some ( )
348365 || self . search_mode
@@ -1352,6 +1369,7 @@ impl AppState {
13521369 let tool_id = tool. id . clone ( ) ;
13531370 let tool_name = tool. name . clone ( ) ;
13541371 let command = tool. run_command_for_current_platform ( ) . to_string ( ) ;
1372+ let launch_argument = tool. launch_argument . clone ( ) ;
13551373 let options = tool. run_options . clone ( ) ;
13561374 if let Some ( index) = self
13571375 . app_view
@@ -1367,6 +1385,17 @@ impl AppState {
13671385 self . status = format ! ( "Returned to {tool_name}" ) ;
13681386 return ;
13691387 }
1388+ if let Some ( argument) = launch_argument {
1389+ self . launch_argument = Some ( LaunchArgumentState {
1390+ tool_id,
1391+ tool_name,
1392+ label : argument. label ,
1393+ placeholder : argument. placeholder ,
1394+ input : String :: new ( ) ,
1395+ } ) ;
1396+ self . status = "Enter the required launch value" . to_string ( ) ;
1397+ return ;
1398+ }
13701399 if options. is_empty ( ) {
13711400 self . effects
13721401 . push_back ( AppEffect :: LaunchTool ( ToolLaunchRequest {
@@ -1396,6 +1425,56 @@ impl AppState {
13961425 self . status = "Configure launch options" . to_string ( ) ;
13971426 }
13981427
1428+ fn handle_launch_argument_key ( & mut self , code : KeyCode ) {
1429+ match code {
1430+ KeyCode :: Esc => {
1431+ self . launch_argument = None ;
1432+ self . status = "Launch cancelled" . to_string ( ) ;
1433+ }
1434+ KeyCode :: Backspace => {
1435+ if let Some ( argument) = & mut self . launch_argument {
1436+ argument. input . pop ( ) ;
1437+ }
1438+ }
1439+ KeyCode :: Char ( ch) => {
1440+ if let Some ( argument) = & mut self . launch_argument {
1441+ argument. input . push ( ch) ;
1442+ }
1443+ }
1444+ KeyCode :: Enter => {
1445+ let Some ( argument) = self . launch_argument . take ( ) else {
1446+ return ;
1447+ } ;
1448+ let value = argument. input . trim ( ) ;
1449+ if value. is_empty ( ) {
1450+ self . launch_argument = Some ( argument) ;
1451+ self . status = "A launch value is required" . to_string ( ) ;
1452+ return ;
1453+ }
1454+ let Some ( tool) = self
1455+ . catalog
1456+ . tools
1457+ . iter ( )
1458+ . find ( |tool| tool. id == argument. tool_id )
1459+ else {
1460+ self . status = "Launch tool is no longer available" . to_string ( ) ;
1461+ return ;
1462+ } ;
1463+ self . effects
1464+ . push_back ( AppEffect :: LaunchTool ( ToolLaunchRequest {
1465+ tool_id : tool. id . clone ( ) ,
1466+ command : format ! (
1467+ "{} {}" ,
1468+ tool. run_command_for_current_platform( ) ,
1469+ shell_quote( value)
1470+ ) ,
1471+ } ) ) ;
1472+ self . status = format ! ( "Opening {}" , tool. name) ;
1473+ }
1474+ _ => { }
1475+ }
1476+ }
1477+
13991478 fn handle_launch_options_key ( & mut self , code : KeyCode ) {
14001479 let option_count = self
14011480 . launch_options
@@ -1979,6 +2058,7 @@ fn uninstall_command(method: &InstallMethod, package: &str) -> Option<String> {
19792058 InstallMethod :: Pipx => format ! ( "pipx uninstall {package}" ) ,
19802059 InstallMethod :: NpmGlobal => format ! ( "npm uninstall --global {package}" ) ,
19812060 InstallMethod :: Cargo => format ! ( "cargo uninstall {package}" ) ,
2061+ InstallMethod :: LazyVim => "rm -f \" $HOME/.local/bin/t4e-lazyvim\" && rm -rf \" ${XDG_CONFIG_HOME:-$HOME/.config}/t4e-lazyvim\" \" ${XDG_DATA_HOME:-$HOME/.local/share}/t4e-lazyvim\" \" ${XDG_STATE_HOME:-$HOME/.local/state}/t4e-lazyvim\" \" ${XDG_CACHE_HOME:-$HOME/.cache}/t4e-lazyvim\" " . to_string ( ) ,
19822062 InstallMethod :: Go | InstallMethod :: Script | InstallMethod :: Other => return None ,
19832063 } ;
19842064 Some ( command)
@@ -2033,6 +2113,10 @@ fn app_input_from_key(key: KeyEvent) -> Option<AppInput> {
20332113 ) )
20342114}
20352115
2116+ fn shell_quote ( value : & str ) -> String {
2117+ format ! ( "'{}'" , value. replace( '\'' , "'\" '\" '" ) )
2118+ }
2119+
20362120fn extract_urls ( content : & str ) -> Vec < String > {
20372121 let mut urls = Vec :: new ( ) ;
20382122 let mut offset = 0 ;
0 commit comments