mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Simplify the code
This commit is contained in:
parent
22b55e7038
commit
b3aead3466
3 changed files with 8 additions and 16 deletions
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue