mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
29 lines
616 B
Rust
29 lines
616 B
Rust
use anyhow::anyhow;
|
|
use yazi_shared::{event::Exec, render};
|
|
|
|
use crate::select::Select;
|
|
|
|
pub struct Opt {
|
|
submit: bool,
|
|
}
|
|
|
|
impl From<Exec> for Opt {
|
|
fn from(e: Exec) -> Self { Self { submit: e.named.contains_key("submit") } }
|
|
}
|
|
impl From<bool> for Opt {
|
|
fn from(submit: bool) -> Self { Self { submit } }
|
|
}
|
|
|
|
impl Select {
|
|
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(self.cursor) } else { Err(anyhow!("canceled")) });
|
|
}
|
|
|
|
self.cursor = 0;
|
|
self.offset = 0;
|
|
self.visible = false;
|
|
render!();
|
|
}
|
|
}
|