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 yazi_shared::{event::Cmd, render};
|
||||||
|
|
||||||
use crate::confirm::Confirm;
|
use crate::confirm::Confirm;
|
||||||
|
|
@ -18,7 +17,7 @@ impl Confirm {
|
||||||
pub fn close(&mut self, opt: impl Into<Opt>) {
|
pub fn close(&mut self, opt: impl Into<Opt>) {
|
||||||
let opt = opt.into() as Opt;
|
let opt = opt.into() as Opt;
|
||||||
if let Some(cb) = self.callback.take() {
|
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;
|
self.visible = false;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use crate::confirm::Confirm;
|
||||||
|
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
cfg: ConfirmCfg,
|
cfg: ConfirmCfg,
|
||||||
tx: oneshot::Sender<anyhow::Result<bool>>,
|
tx: oneshot::Sender<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Cmd> for Opt {
|
impl TryFrom<Cmd> for Opt {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
use anyhow::Result;
|
|
||||||
use tokio::sync::oneshot::Sender;
|
use tokio::sync::oneshot::Sender;
|
||||||
use yazi_config::popup::Position;
|
use yazi_config::popup::Position;
|
||||||
|
|
||||||
|
|
@ -11,6 +10,6 @@ pub struct Confirm {
|
||||||
pub offset: usize,
|
pub offset: usize,
|
||||||
pub position: Position,
|
pub position: Position,
|
||||||
|
|
||||||
pub(super) callback: Option<Sender<Result<bool>>>,
|
pub(super) callback: Option<Sender<bool>>,
|
||||||
pub visible: bool,
|
pub visible: bool,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ pub struct ConfirmProxy;
|
||||||
|
|
||||||
impl ConfirmProxy {
|
impl ConfirmProxy {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub async fn show(cfg: ConfirmCfg) -> anyhow::Result<bool> {
|
pub async fn show(cfg: ConfirmCfg) -> bool {
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
emit!(Call(Cmd::new("show").with_any("tx", tx).with_any("cfg", cfg), Layer::Confirm));
|
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