Simplify the code

This commit is contained in:
sxyazi 2024-01-10 02:17:49 +08:00
parent 22b55e7038
commit b3aead3466
No known key found for this signature in database
3 changed files with 8 additions and 16 deletions

View file

@ -17,13 +17,11 @@ impl From<&Exec> for Opt {
impl Manager {
pub fn quit(&self, opt: impl Into<Opt>, tasks: &Tasks) {
let opt = opt.into() as Opt;
let quit_actions =
if opt.no_cwd_file { vec![QuitAction::None] } else { vec![QuitAction::CwdToFile] };
let actions = if opt.no_cwd_file { vec![] } else { vec![QuitAction::CwdToFile] };
let tasks = tasks.len();
if tasks == 0 {
emit!(Quit(quit_actions));
emit!(Quit(actions));
return;
}
@ -31,7 +29,7 @@ impl Manager {
let mut result = Input::_show(InputCfg::quit(tasks));
if let Some(Ok(choice)) = result.recv().await {
if choice == "y" || choice == "Y" {
emit!(Quit(quit_actions));
emit!(Quit(actions));
}
}
});

View file

@ -7,14 +7,9 @@ use yazi_shared::{event::QuitAction, term::Term};
use crate::app::App;
impl App {
pub(crate) fn quit(&mut self, quit_actions: Vec<QuitAction>) -> Result<()> {
if quit_actions.contains(&QuitAction::None) {
Term::goodbye(|| false)
}
for quit_action in quit_actions {
match quit_action {
QuitAction::None => unreachable!(),
pub(crate) fn quit(&mut self, actions: Vec<QuitAction>) -> Result<()> {
for action in actions {
match action {
QuitAction::CwdToFile => self.cwd_to_file(),
QuitAction::SelectToFile(selected) => self.select_to_file(selected),
}

View file

@ -20,7 +20,6 @@ pub enum Event {
#[derive(Debug, PartialEq)]
pub enum QuitAction {
None,
CwdToFile,
SelectToFile(OsString),
}
@ -40,8 +39,8 @@ impl Event {
#[macro_export]
macro_rules! emit {
(Quit($quit_actions:expr)) => {
$crate::event::Event::Quit($quit_actions).emit();
(Quit($actions:expr)) => {
$crate::event::Event::Quit($actions).emit();
};
(Call($exec:expr, $layer:expr)) => {
$crate::event::Event::Call($exec, $layer).emit();