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
3fc1c86fcf
commit
dab892e77c
4 changed files with 5 additions and 7 deletions
|
|
@ -1,4 +1,3 @@
|
|||
use anyhow::anyhow;
|
||||
use yazi_shared::{event::Cmd, render};
|
||||
|
||||
use crate::confirm::Confirm;
|
||||
|
|
@ -18,7 +17,7 @@ impl Confirm {
|
|||
pub fn close(&mut self, opt: impl Into<Opt>) {
|
||||
let opt = opt.into() as Opt;
|
||||
if let Some(cb) = self.callback.take() {
|
||||
_ = cb.send(if opt.submit { Ok(true) } else { Err(anyhow!("canceled")) });
|
||||
_ = cb.send(opt.submit);
|
||||
}
|
||||
|
||||
self.visible = false;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::confirm::Confirm;
|
|||
|
||||
pub struct Opt {
|
||||
cfg: ConfirmCfg,
|
||||
tx: oneshot::Sender<anyhow::Result<bool>>,
|
||||
tx: oneshot::Sender<bool>,
|
||||
}
|
||||
|
||||
impl TryFrom<Cmd> for Opt {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use anyhow::Result;
|
||||
use tokio::sync::oneshot::Sender;
|
||||
use yazi_config::popup::Position;
|
||||
|
||||
|
|
@ -11,6 +10,6 @@ pub struct Confirm {
|
|||
pub offset: usize,
|
||||
pub position: Position,
|
||||
|
||||
pub(super) callback: Option<Sender<Result<bool>>>,
|
||||
pub(super) callback: Option<Sender<bool>>,
|
||||
pub visible: bool,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ pub struct ConfirmProxy;
|
|||
|
||||
impl ConfirmProxy {
|
||||
#[inline]
|
||||
pub async fn show(cfg: ConfirmCfg) -> anyhow::Result<bool> {
|
||||
pub async fn show(cfg: ConfirmCfg) -> bool {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
emit!(Call(Cmd::new("show").with_any("tx", tx).with_any("cfg", cfg), Layer::Confirm));
|
||||
rx.await?
|
||||
rx.await.unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue