mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
6e1d88c3fa
commit
189a1bc745
2 changed files with 17 additions and 12 deletions
|
|
@ -8,6 +8,15 @@ pub struct InputRx {
|
||||||
|
|
||||||
impl InputRx {
|
impl InputRx {
|
||||||
pub fn new(inner: UnboundedReceiver<Result<String, InputError>>) -> Self { Self { inner } }
|
pub fn new(inner: UnboundedReceiver<Result<String, InputError>>) -> Self { Self { inner } }
|
||||||
|
|
||||||
|
pub fn parse(res: Result<String, InputError>) -> (Option<String>, 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 {
|
impl UserData for InputRx {
|
||||||
|
|
@ -17,11 +26,7 @@ impl UserData for InputRx {
|
||||||
return Ok((None, 0));
|
return Ok((None, 0));
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(match res {
|
Ok(Self::parse(res))
|
||||||
Ok(s) => (Some(s), 1),
|
|
||||||
Err(InputError::Typed(s)) => (Some(s), 2),
|
|
||||||
_ => (None, 0),
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::str::FromStr;
|
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 tokio::sync::mpsc;
|
||||||
use yazi_config::{keymap::{Control, Key}, popup::InputCfg};
|
use yazi_config::{keymap::{Control, Key}, popup::InputCfg};
|
||||||
use yazi_proxy::InputProxy;
|
use yazi_proxy::InputProxy;
|
||||||
|
|
@ -69,13 +69,13 @@ impl Utils {
|
||||||
highlight: false,
|
highlight: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(if realtime {
|
if realtime {
|
||||||
(InputRx::new(rx).into_lua(lua)?, Value::Nil)
|
(InputRx::new(rx), Value::Nil).into_lua_multi(lua)
|
||||||
} else if let Some(Ok(res)) = rx.recv().await {
|
} else if let Some(res) = rx.recv().await {
|
||||||
(res.into_lua(lua)?, 1.into_lua(lua)?)
|
InputRx::parse(res).into_lua_multi(lua)
|
||||||
} else {
|
} else {
|
||||||
(Value::Nil, 0.into_lua(lua)?)
|
(Value::Nil, 0).into_lua_multi(lua)
|
||||||
})
|
}
|
||||||
})?,
|
})?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue