diff --git a/yazi-plugin/src/bindings/input.rs b/yazi-plugin/src/bindings/input.rs index 65eca5ef..fd6b671c 100644 --- a/yazi-plugin/src/bindings/input.rs +++ b/yazi-plugin/src/bindings/input.rs @@ -8,6 +8,15 @@ pub struct InputRx { impl InputRx { pub fn new(inner: UnboundedReceiver>) -> Self { Self { inner } } + + pub fn parse(res: Result) -> (Option, u8) { + match res { + Ok(s) => (Some(s), 1), + Err(InputError::Canceled(s)) => (Some(s), 2), + Err(InputError::Typed(s)) => (Some(s), 3), + _ => (None, 0), + } + } } impl UserData for InputRx { @@ -17,11 +26,7 @@ impl UserData for InputRx { return Ok((None, 0)); }; - Ok(match res { - Ok(s) => (Some(s), 1), - Err(InputError::Typed(s)) => (Some(s), 2), - _ => (None, 0), - }) + Ok(Self::parse(res)) }); } } diff --git a/yazi-plugin/src/utils/layer.rs b/yazi-plugin/src/utils/layer.rs index e33c1a57..50c28b53 100644 --- a/yazi-plugin/src/utils/layer.rs +++ b/yazi-plugin/src/utils/layer.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use mlua::{ExternalError, ExternalResult, IntoLua, Lua, Table, Value}; +use mlua::{ExternalError, ExternalResult, IntoLuaMulti, Lua, Table, Value}; use tokio::sync::mpsc; use yazi_config::{keymap::{Control, Key}, popup::InputCfg}; use yazi_proxy::InputProxy; @@ -69,13 +69,13 @@ impl Utils { highlight: false, }); - Ok(if realtime { - (InputRx::new(rx).into_lua(lua)?, Value::Nil) - } else if let Some(Ok(res)) = rx.recv().await { - (res.into_lua(lua)?, 1.into_lua(lua)?) + if realtime { + (InputRx::new(rx), Value::Nil).into_lua_multi(lua) + } else if let Some(res) = rx.recv().await { + InputRx::parse(res).into_lua_multi(lua) } else { - (Value::Nil, 0.into_lua(lua)?) - }) + (Value::Nil, 0).into_lua_multi(lua) + } })?, )?;