diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index df67a363..ea11a450 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -119,6 +119,11 @@ overwrite_title = "Overwrite an existing file? (y/N)" overwrite_origin = "top-center" overwrite_offset = [ 0, 2, 50, 3 ] +# quit +quit_title = "{n} task{s} running, sure to quit? (y/N)" +quit_origin = "top-center" +quit_offset = [ 0, 2, 50, 3 ] + [select] open_title = "Open with:" open_origin = "hovered" diff --git a/yazi-config/src/popup/input.rs b/yazi-config/src/popup/input.rs index 9c704044..d1f87da1 100644 --- a/yazi-config/src/popup/input.rs +++ b/yazi-config/src/popup/input.rs @@ -49,6 +49,11 @@ pub struct Input { pub overwrite_title: String, pub overwrite_origin: Origin, pub overwrite_offset: Offset, + + // quit + pub quit_title: String, + pub quit_origin: Origin, + pub quit_offset: Offset, } impl Default for Input { diff --git a/yazi-config/src/popup/options.rs b/yazi-config/src/popup/options.rs index 03039953..45c2c15b 100644 --- a/yazi-config/src/popup/options.rs +++ b/yazi-config/src/popup/options.rs @@ -1,5 +1,5 @@ use super::Position; -use crate::INPUT; +use crate::{INPUT, SELECT}; #[derive(Default)] pub struct InputOpt { @@ -105,6 +105,16 @@ impl InputOpt { } } + #[inline] + pub fn quit(n: usize) -> Self { + let title = INPUT.quit_title.replace("{n}", &n.to_string()); + Self { + title: title.replace("{s}", if n > 1 { "s" } else { "" }), + position: Position::new(INPUT.quit_origin, INPUT.quit_offset), + ..Default::default() + } + } + #[inline] pub fn with_value(mut self, value: impl Into) -> Self { self.value = value.into(); @@ -114,7 +124,13 @@ impl InputOpt { impl SelectOpt { #[inline] - pub fn open() -> Self { todo!() } + pub fn open() -> Self { + Self { + title: SELECT.open_title.to_owned(), + position: Position::new(SELECT.open_origin, SELECT.open_offset), + ..Default::default() + } + } #[inline] pub fn with_items(mut self, items: Vec) -> Self { diff --git a/yazi-core/src/manager/commands/quit.rs b/yazi-core/src/manager/commands/quit.rs index 65f02070..e4f70fc0 100644 --- a/yazi-core/src/manager/commands/quit.rs +++ b/yazi-core/src/manager/commands/quit.rs @@ -1,4 +1,4 @@ -use yazi_config::keymap::Exec; +use yazi_config::{keymap::Exec, popup::InputOpt}; use crate::{emit, manager::Manager, tasks::Tasks}; @@ -24,17 +24,12 @@ impl Manager { } tokio::spawn(async move { - // TODO - // let mut result = emit!(Input(InputOpt::top_center( - // format!("{tasks} tasks running, sure to quit? (y/N)",), - // Default::default() - // ))); - - // if let Some(Ok(choice)) = result.recv().await { - // if choice == "y" || choice == "Y" { - // emit!(Quit(opt.no_cwd_file)); - // } - // } + let mut result = emit!(Input(InputOpt::quit(tasks))); + if let Some(Ok(choice)) = result.recv().await { + if choice == "y" || choice == "Y" { + emit!(Quit(opt.no_cwd_file)); + } + } }); false }