mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
5cddad4e53
commit
a4a869464a
4 changed files with 17 additions and 12 deletions
|
|
@ -46,7 +46,7 @@ pub struct Input {
|
|||
}
|
||||
|
||||
impl Input {
|
||||
pub const fn border(&self) -> u16 { 2 }
|
||||
pub const fn border(&self) -> u16 { 1 }
|
||||
}
|
||||
|
||||
impl FromStr for Input {
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ impl Input {
|
|||
self.visible = false;
|
||||
self.ticket.next();
|
||||
|
||||
if let Some(cb) = self.tx.take() {
|
||||
if let Some(tx) = self.tx.take() {
|
||||
let value = self.snap().value.clone();
|
||||
_ = cb.send(if opt.submit { Ok(value) } else { Err(InputError::Canceled(value)) });
|
||||
_ = tx.send(if opt.submit { Ok(value) } else { Err(InputError::Canceled(value)) });
|
||||
}
|
||||
|
||||
CmpProxy::close();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use tokio::sync::mpsc;
|
||||
use yazi_config::popup::InputCfg;
|
||||
use yazi_config::{INPUT, popup::InputCfg};
|
||||
use yazi_macro::render;
|
||||
use yazi_shared::{errors::InputError, event::CmdCow};
|
||||
use yazi_widgets::input::InputCallback;
|
||||
|
||||
use crate::input::Input;
|
||||
|
||||
|
|
@ -29,22 +30,24 @@ impl Input {
|
|||
|
||||
// Typing
|
||||
self.tx = Some(opt.tx.clone());
|
||||
let ticket = self.ticket.clone();
|
||||
|
||||
// Shell
|
||||
self.highlight = opt.cfg.highlight;
|
||||
|
||||
// Reset input
|
||||
let ticket = self.ticket.clone();
|
||||
let cb: Box<dyn Fn(&str, &str)> = Box::new(move |before, after| {
|
||||
let cb: InputCallback = Box::new(move |before, after| {
|
||||
if opt.cfg.realtime {
|
||||
opt.tx.send(Err(InputError::Typed(format!("{before}{after}")))).ok();
|
||||
}
|
||||
|
||||
if opt.cfg.completion {
|
||||
} else if opt.cfg.completion {
|
||||
opt.tx.send(Err(InputError::Completed(before.to_owned(), ticket.current()))).ok();
|
||||
}
|
||||
});
|
||||
self.inner = yazi_widgets::input::Input::new(opt.cfg.value, self.limit, cb);
|
||||
self.inner = yazi_widgets::input::Input::new(
|
||||
opt.cfg.value,
|
||||
opt.cfg.position.offset.width.saturating_sub(INPUT.border()) as usize,
|
||||
cb,
|
||||
);
|
||||
|
||||
// Set cursor after reset
|
||||
// TODO: remove this
|
||||
|
|
|
|||
|
|
@ -5,15 +5,17 @@ use yazi_plugin::CLIPBOARD;
|
|||
|
||||
use super::{InputSnap, InputSnaps, mode::InputMode, op::InputOp};
|
||||
|
||||
pub type InputCallback = Box<dyn Fn(&str, &str)>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Input {
|
||||
pub snaps: InputSnaps,
|
||||
pub limit: usize,
|
||||
pub callback: Option<Box<dyn Fn(&str, &str)>>,
|
||||
pub callback: Option<InputCallback>,
|
||||
}
|
||||
|
||||
impl Input {
|
||||
pub fn new(value: String, limit: usize, callback: Box<dyn Fn(&str, &str)>) -> Self {
|
||||
pub fn new(value: String, limit: usize, callback: InputCallback) -> Self {
|
||||
Self { snaps: InputSnaps::new(value, limit), limit, callback: Some(callback) }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue