1- use std:: time:: Duration ;
1+ use std:: { ffi :: OsString , time:: Duration } ;
22
33use tokio:: { select, time} ;
4+ use yazi_boot:: ARGS ;
45use yazi_config:: popup:: ConfirmCfg ;
56use yazi_macro:: emit;
67use yazi_proxy:: ConfirmProxy ;
7- use yazi_shared:: event:: { CmdCow , EventQuit } ;
8+ use yazi_shared:: { event:: { CmdCow , Data , EventQuit } , url :: Url } ;
89
910use crate :: { mgr:: Mgr , tasks:: Tasks } ;
1011
1112#[ derive( Default ) ]
1213pub ( super ) struct Opt {
14+ pub ( super ) code : i32 ,
1315 pub ( super ) no_cwd_file : bool ,
1416}
17+
1518impl From < CmdCow > for Opt {
16- fn from ( c : CmdCow ) -> Self { Self { no_cwd_file : c. bool ( "no-cwd-file" ) } }
19+ fn from ( c : CmdCow ) -> Self {
20+ Self {
21+ code : c. get ( "code" ) . and_then ( Data :: as_i32) . unwrap_or_default ( ) ,
22+ no_cwd_file : c. bool ( "no-cwd-file" ) ,
23+ }
24+ }
25+ }
26+
27+ impl From < Opt > for EventQuit {
28+ fn from ( value : Opt ) -> Self {
29+ EventQuit { code : value. code , no_cwd_file : value. no_cwd_file , ..Default :: default ( ) }
30+ }
1731}
1832
1933impl Mgr {
2034 #[ yazi_codegen:: command]
2135 pub fn quit ( & self , opt : Opt , tasks : & Tasks ) {
22- let opt = EventQuit { no_cwd_file : opt. no_cwd_file , .. Default :: default ( ) } ;
36+ let event = opt. into ( ) ;
2337
2438 let ongoing = tasks. ongoing ( ) . clone ( ) ;
2539 let ( left, left_names) = {
@@ -28,7 +42,7 @@ impl Mgr {
2842 } ;
2943
3044 if left == 0 {
31- emit ! ( Quit ( opt ) ) ;
45+ emit ! ( Quit ( event ) ) ;
3246 return ;
3347 }
3448
@@ -41,22 +55,37 @@ impl Mgr {
4155 i += 1 ;
4256 if i > 40 { break }
4357 else if ongoing. lock( ) . is_empty( ) {
44- emit!( Quit ( opt ) ) ;
58+ emit!( Quit ( event ) ) ;
4559 return ;
4660 }
4761 }
4862 b = & mut rx => {
4963 if b. unwrap_or( false ) {
50- emit!( Quit ( opt ) ) ;
64+ emit!( Quit ( event ) ) ;
5165 }
5266 return ;
5367 }
5468 }
5569 }
5670
5771 if rx. await . unwrap_or ( false ) {
58- emit ! ( Quit ( opt ) ) ;
72+ emit ! ( Quit ( event ) ) ;
5973 }
6074 } ) ;
6175 }
76+
77+ pub ( super ) fn quit_with_selected ( opt : super :: open:: Opt , selected : & [ & Url ] ) -> bool {
78+ if opt. interactive || ARGS . chooser_file . is_none ( ) {
79+ return false ;
80+ }
81+
82+ let paths = selected. iter ( ) . fold ( OsString :: new ( ) , |mut s, & u| {
83+ s. push ( u. as_os_str ( ) ) ;
84+ s. push ( "\n " ) ;
85+ s
86+ } ) ;
87+
88+ emit ! ( Quit ( EventQuit { selected: Some ( paths) , ..Default :: default ( ) } ) ) ;
89+ true
90+ }
6291}
0 commit comments