diff --git a/yazi-core/src/mgr/commands/close.rs b/yazi-core/src/mgr/commands/close.rs index a71f9d9f..3e40f233 100644 --- a/yazi-core/src/mgr/commands/close.rs +++ b/yazi-core/src/mgr/commands/close.rs @@ -1,16 +1,24 @@ -use yazi_shared::event::CmdCow; +use yazi_shared::event::{CmdCow, Data}; use crate::{mgr::{Mgr, commands::quit}, tasks::Tasks}; #[derive(Default)] struct Opt { no_cwd_file: bool, + exit_code: i32, } impl From for Opt { - fn from(c: CmdCow) -> Self { Self { no_cwd_file: c.bool("no-cwd-file") } } + fn from(c: CmdCow) -> Self { + Self { + no_cwd_file: c.bool("no-cwd-file"), + exit_code: c.get("exit_code").and_then(Data::as_i32).unwrap_or_default(), + } + } } impl From for quit::Opt { - fn from(value: Opt) -> Self { Self { no_cwd_file: value.no_cwd_file } } + fn from(value: Opt) -> Self { + Self { no_cwd_file: value.no_cwd_file, exit_code: value.exit_code } + } } impl Mgr { diff --git a/yazi-core/src/mgr/commands/quit.rs b/yazi-core/src/mgr/commands/quit.rs index 343ed732..36949f09 100644 --- a/yazi-core/src/mgr/commands/quit.rs +++ b/yazi-core/src/mgr/commands/quit.rs @@ -4,22 +4,29 @@ use tokio::{select, time}; use yazi_config::popup::ConfirmCfg; use yazi_macro::emit; use yazi_proxy::ConfirmProxy; -use yazi_shared::event::{CmdCow, EventQuit}; +use yazi_shared::event::{CmdCow, Data, EventQuit}; use crate::{mgr::Mgr, tasks::Tasks}; #[derive(Default)] pub(super) struct Opt { pub(super) no_cwd_file: bool, + pub(super) exit_code: i32, } impl From for Opt { - fn from(c: CmdCow) -> Self { Self { no_cwd_file: c.bool("no-cwd-file") } } + fn from(c: CmdCow) -> Self { + Self { + no_cwd_file: c.bool("no-cwd-file"), + exit_code: c.get("exit_code").and_then(Data::as_i32).unwrap_or_default(), + } + } } impl Mgr { #[yazi_codegen::command] pub fn quit(&self, opt: Opt, tasks: &Tasks) { - let opt = EventQuit { no_cwd_file: opt.no_cwd_file, ..Default::default() }; + let opt = + EventQuit { no_cwd_file: opt.no_cwd_file, exit_code: opt.exit_code, ..Default::default() }; let ongoing = tasks.ongoing().clone(); let (left, left_names) = { diff --git a/yazi-fm/src/app/commands/quit.rs b/yazi-fm/src/app/commands/quit.rs index 9b725a50..eabdfbc7 100644 --- a/yazi-fm/src/app/commands/quit.rs +++ b/yazi-fm/src/app/commands/quit.rs @@ -19,7 +19,7 @@ impl App { self.selected_to_file(selected); } - Term::goodbye(|| false); + Term::goodbye(|| opt.exit_code); } fn cwd_to_file(&self) { diff --git a/yazi-fm/src/panic.rs b/yazi-fm/src/panic.rs index ca8cedfe..bd2c46e4 100644 --- a/yazi-fm/src/panic.rs +++ b/yazi-fm/src/panic.rs @@ -10,7 +10,7 @@ impl Panic { std::panic::set_hook(Box::new(move |info| { Term::goodbye(|| { hook(info); - true + true as i32 }); })); } diff --git a/yazi-fm/src/term.rs b/yazi-fm/src/term.rs index f26a03fc..59bdeea0 100644 --- a/yazi-fm/src/term.rs +++ b/yazi-fm/src/term.rs @@ -89,7 +89,7 @@ impl Term { Ok(disable_raw_mode()?) } - pub(super) fn goodbye(f: impl FnOnce() -> bool) -> ! { + pub(super) fn goodbye(f: impl FnOnce() -> i32) -> ! { if CSI_U.swap(false, Ordering::Relaxed) { PopKeyboardEnhancementFlags.write_ansi(&mut TTY.writer()).ok(); } @@ -111,7 +111,7 @@ impl Term { disable_raw_mode().ok(); - std::process::exit(f() as i32); + std::process::exit(f()); } pub(super) fn draw(&mut self, f: impl FnOnce(&mut Frame)) -> io::Result { diff --git a/yazi-shared/src/event/data.rs b/yazi-shared/src/event/data.rs index fac8cc4a..1eab3f7b 100644 --- a/yazi-shared/src/event/data.rs +++ b/yazi-shared/src/event/data.rs @@ -182,6 +182,7 @@ macro_rules! impl_number_as { impl_integer_as!(usize, as_usize); impl_integer_as!(isize, as_isize); impl_integer_as!(i16, as_i16); +impl_integer_as!(i32, as_i32); impl_number_as!(f64, as_f64); diff --git a/yazi-shared/src/event/event.rs b/yazi-shared/src/event/event.rs index 9bb24f48..8e2defb6 100644 --- a/yazi-shared/src/event/event.rs +++ b/yazi-shared/src/event/event.rs @@ -24,6 +24,7 @@ pub enum Event { #[derive(Debug, Default)] pub struct EventQuit { pub no_cwd_file: bool, + pub exit_code: i32, pub selected: Option, }