use rmpv::Value;
use super::ParseError;
#[derive(Debug)]
pub enum CursorMode {
Normal,
Insert,
Visual,
Replace,
CmdLine,
Other(String),
}
#[derive(Debug)]
pub struct ModeChange {
mode: CursorMode,
index: i64,
}
impl TryFrom<&Vec<Value>> for ModeChange {
type Error = ParseError;
fn try_from(value: &Vec<Value>) -> Result<Self, Self::Error> {
let mode = match value.get(0).unwrap().as_str().unwrap() {
"normal" => CursorMode::Normal,
"insert" => CursorMode::Insert,
"visual" => CursorMode::Visual,
"replace" => CursorMode::Replace,
"cmdline_normal" => CursorMode::CmdLine,
mode => CursorMode::Other(mode.to_owned()),
};
let index = value.get(1).unwrap().as_i64().unwrap();
Ok(ModeChange { mode, index })
}
}