Use opt to limit passed values

This commit is contained in:
Guangxiong Lin 2025-01-10 19:03:54 +08:00
parent db5823681f
commit f3b5dcf125
No known key found for this signature in database
GPG key ID: F38740D6916EF58F
2 changed files with 19 additions and 5 deletions

View file

@ -1,12 +1,26 @@
use yazi_shared::event::CmdCow;
use crate::{manager::Manager, tasks::Tasks};
use crate::{manager::Manager, tasks::Tasks, manager::commands::quit};
#[derive(Default)]
struct Opt {
no_cwd_file: bool,
}
impl From<()> for Opt {
fn from(_: ()) -> Self { Self::default() }
}
impl From<CmdCow> for Opt {
fn from(c: CmdCow) -> Self { Self { no_cwd_file: c.bool("no-cwd-file") } }
}
impl Manager {
pub fn close(&mut self, c: CmdCow, tasks: &Tasks) {
#[yazi_codegen::command]
pub fn close(&mut self, opt: Opt, tasks: &Tasks) {
if self.tabs.len() > 1 {
return self.tabs.close(self.tabs.cursor);
}
self.quit(c, tasks);
self.quit(quit::Opt{ no_cwd_file: opt.no_cwd_file }, tasks);
}
}

View file

@ -9,8 +9,8 @@ use yazi_shared::event::{CmdCow, EventQuit};
use crate::{manager::Manager, tasks::Tasks};
#[derive(Default)]
struct Opt {
no_cwd_file: bool,
pub struct Opt {
pub no_cwd_file: bool,
}
impl From<()> for Opt {
fn from(_: ()) -> Self { Self::default() }