yazi/yazi-parser/src/mgr/linemode.rs
2026-02-18 17:08:48 +08:00

32 lines
806 B
Rust

use anyhow::bail;
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
use yazi_shared::{SStr, event::ActionCow};
#[derive(Debug)]
pub struct LinemodeOpt {
pub new: SStr,
}
impl TryFrom<ActionCow> for LinemodeOpt {
type Error = anyhow::Error;
fn try_from(mut a: ActionCow) -> Result<Self, Self::Error> {
let Ok(new) = a.take_first::<SStr>() else {
bail!("a string argument is required for LinemodeOpt");
};
if new.is_empty() || new.len() > 20 {
bail!("Linemode must be between 1 and 20 characters long");
}
Ok(Self { new })
}
}
impl FromLua for LinemodeOpt {
fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) }
}
impl IntoLua for LinemodeOpt {
fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) }
}