use mlua::{FromLua, IntoLua, Value}; use ratatui::crossterm::cursor::SetCursorStyle; #[derive(Default, Debug, Clone, Copy)] pub enum CursorShape { #[default] Block, Bar, Underscore, } impl<'lua> FromLua<'lua> for CursorShape { fn from_lua( value: mlua::prelude::LuaValue<'lua>, _lua: &'lua mlua::prelude::Lua, ) -> mlua::prelude::LuaResult { if let Value::String(s) = value { match s.to_str().unwrap().to_lowercase().as_ref() { "block" => return Ok(CursorShape::Block), "bar" => return Ok(CursorShape::Bar), "underscore" => return Ok(CursorShape::Underscore), _ => {} } } Err(mlua::Error::runtime("failed to parse cursorshape")) } } impl<'lua> IntoLua<'lua> for CursorShape { fn into_lua(self, lua: &'lua mlua::prelude::Lua) -> mlua::prelude::LuaResult> { match self { CursorShape::Block => "block", CursorShape::Bar => "bar", CursorShape::Underscore => "underscore", }.into_lua(lua) } } impl From for SetCursorStyle { fn from(shape: CursorShape) -> SetCursorStyle { match shape { CursorShape::Block => SetCursorStyle::SteadyBlock, CursorShape::Bar => SetCursorStyle::SteadyBar, CursorShape::Underscore => SetCursorStyle::SteadyUnderScore, } } }