//! ANSI Terminal Stream Parsing. pub use vte::ansi::*; #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)] pub struct CursorShapeShim(CursorShape); impl Default for CursorShapeShim { fn default() -> CursorShapeShim { CursorShapeShim(CursorShape::Block) } } impl From for CursorShape { fn from(value: CursorShapeShim) -> Self { value.0 } } struct CursorShapeVisitor; impl<'de> serde::de::Visitor<'de> for CursorShapeVisitor { type Value = CursorShapeShim; fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { formatter.write_str("one of `Block`, `Underline`, `Beam`") } fn visit_str(self, s: &str) -> Result where E: serde::de::Error, { match s.to_lowercase().as_str() { "block" => Ok(CursorShapeShim(CursorShape::Block)), "underline" => Ok(CursorShapeShim(CursorShape::Underline)), "beam" => Ok(CursorShapeShim(CursorShape::Beam)), _ => Err(E::custom(format!( "unknown variant `{0}`, expected {1}", s, "one of `Block`, `Underline`, `Beam`" ))), } } } impl<'de> serde::Deserialize<'de> for CursorShapeShim { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { deserializer.deserialize_str(CursorShapeVisitor) } } impl alacritty_config::SerdeReplace for CursorShapeShim { fn replace( &mut self, key: &str, value: serde_yaml::Value, ) -> Result<(), Box> { if !key.is_empty() { return Err(format!("Fields \"{0}\" do not exist", key).into()); } *self = serde::Deserialize::deserialize(value)?; Ok(()) } }