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 {
|
impl Manager {
|
||||||
pub fn quit(&self, opt: impl Into<Opt>, tasks: &Tasks) {
|
pub fn quit(&self, opt: impl Into<Opt>, tasks: &Tasks) {
|
||||||
let opt = opt.into() as Opt;
|
let opt = opt.into() as Opt;
|
||||||
|
let actions = if opt.no_cwd_file { vec![] } else { vec![QuitAction::CwdToFile] };
|
||||||
let quit_actions =
|
|
||||||
if opt.no_cwd_file { vec![QuitAction::None] } else { vec![QuitAction::CwdToFile] };
|
|
||||||
|
|
||||||
let tasks = tasks.len();
|
let tasks = tasks.len();
|
||||||
if tasks == 0 {
|
if tasks == 0 {
|
||||||
emit!(Quit(quit_actions));
|
emit!(Quit(actions));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,7 +29,7 @@ impl Manager {
|
||||||
let mut result = Input::_show(InputCfg::quit(tasks));
|
let mut result = Input::_show(InputCfg::quit(tasks));
|
||||||
if let Some(Ok(choice)) = result.recv().await {
|
if let Some(Ok(choice)) = result.recv().await {
|
||||||
if choice == "y" || choice == "Y" {
|
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;
|
use crate::app::App;
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub(crate) fn quit(&mut self, quit_actions: Vec<QuitAction>) -> Result<()> {
|
pub(crate) fn quit(&mut self, actions: Vec<QuitAction>) -> Result<()> {
|
||||||
if quit_actions.contains(&QuitAction::None) {
|
for action in actions {
|
||||||
Term::goodbye(|| false)
|
match action {
|
||||||
}
|
|
||||||
|
|
||||||
for quit_action in quit_actions {
|
|
||||||
match quit_action {
|
|
||||||
QuitAction::None => unreachable!(),
|
|
||||||
QuitAction::CwdToFile => self.cwd_to_file(),
|
QuitAction::CwdToFile => self.cwd_to_file(),
|
||||||
QuitAction::SelectToFile(selected) => self.select_to_file(selected),
|
QuitAction::SelectToFile(selected) => self.select_to_file(selected),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ pub enum Event {
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum QuitAction {
|
pub enum QuitAction {
|
||||||
None,
|
|
||||||
CwdToFile,
|
CwdToFile,
|
||||||
SelectToFile(OsString),
|
SelectToFile(OsString),
|
||||||
}
|
}
|
||||||
|
|
@ -40,8 +39,8 @@ impl Event {
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! emit {
|
macro_rules! emit {
|
||||||
(Quit($quit_actions:expr)) => {
|
(Quit($actions:expr)) => {
|
||||||
$crate::event::Event::Quit($quit_actions).emit();
|
$crate::event::Event::Quit($actions).emit();
|
||||||
};
|
};
|
||||||
(Call($exec:expr, $layer:expr)) => {
|
(Call($exec:expr, $layer:expr)) => {
|
||||||
$crate::event::Event::Call($exec, $layer).emit();
|
$crate::event::Event::Call($exec, $layer).emit();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue