From b3aead3466a36448b0ad37667e998d3728f1b748 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 10 Jan 2024 02:17:49 +0800 Subject: [PATCH] Simplify the code --- yazi-core/src/manager/commands/quit.rs | 8 +++----- yazi-fm/src/app/commands/quit.rs | 11 +++-------- yazi-shared/src/event/event.rs | 5 ++--- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/yazi-core/src/manager/commands/quit.rs b/yazi-core/src/manager/commands/quit.rs index bd112c22..00e284bd 100644 --- a/yazi-core/src/manager/commands/quit.rs +++ b/yazi-core/src/manager/commands/quit.rs @@ -17,13 +17,11 @@ impl From<&Exec> for Opt { impl Manager { pub fn quit(&self, opt: impl Into, 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)); } } }); diff --git a/yazi-fm/src/app/commands/quit.rs b/yazi-fm/src/app/commands/quit.rs index dfb1e533..f4889ee5 100644 --- a/yazi-fm/src/app/commands/quit.rs +++ b/yazi-fm/src/app/commands/quit.rs @@ -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) -> 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) -> Result<()> { + for action in actions { + match action { QuitAction::CwdToFile => self.cwd_to_file(), QuitAction::SelectToFile(selected) => self.select_to_file(selected), } diff --git a/yazi-shared/src/event/event.rs b/yazi-shared/src/event/event.rs index f8c73af5..4f6bfd3c 100644 --- a/yazi-shared/src/event/event.rs +++ b/yazi-shared/src/event/event.rs @@ -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();