summaryrefslogtreecommitdiff
path: root/helix-view/src/graphics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src/graphics.rs')
-rw-r--r--helix-view/src/graphics.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/helix-view/src/graphics.rs b/helix-view/src/graphics.rs
index 0bfca04a..c9dd21e3 100644
--- a/helix-view/src/graphics.rs
+++ b/helix-view/src/graphics.rs
@@ -1,4 +1,6 @@
+use anyhow::{anyhow, Error};
use bitflags::bitflags;
+use serde::de::{self, Deserialize, Deserializer};
use std::{
cmp::{max, min},
str::FromStr,
@@ -17,6 +19,36 @@ pub enum CursorKind {
Hidden,
}
+impl Default for CursorKind {
+ fn default() -> Self {
+ Self::Block
+ }
+}
+
+impl FromStr for CursorKind {
+ type Err = Error;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "bar" => Ok(Self::Bar),
+ "block" => Ok(Self::Block),
+ "underline" => Ok(Self::Underline),
+ _ => Err(anyhow!("Invalid cursor '{}'", s)),
+ }
+ }
+}
+
+// toml deserializer doesn't seem to recognize string as enum
+impl<'de> Deserialize<'de> for CursorKind {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ let s = String::deserialize(deserializer)?;
+ s.parse().map_err(de::Error::custom)
+ }
+}
+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Margin {
pub vertical: u16,