Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-view/src/graphics.rs')
| -rw-r--r-- | helix-view/src/graphics.rs | 68 |
1 files changed, 1 insertions, 67 deletions
diff --git a/helix-view/src/graphics.rs b/helix-view/src/graphics.rs index 3a4eee3d..a26823b9 100644 --- a/helix-view/src/graphics.rs +++ b/helix-view/src/graphics.rs @@ -263,59 +263,7 @@ pub enum Color { Indexed(u8), } -impl Color { - /// Creates a `Color` from a hex string - /// - /// # Examples - /// - /// ```rust - /// use helix_view::theme::Color; - /// - /// let color1 = Color::from_hex("#c0ffee").unwrap(); - /// let color2 = Color::Rgb(192, 255, 238); - /// - /// assert_eq!(color1, color2); - /// ``` - pub fn from_hex(hex: &str) -> Option<Self> { - if !(hex.starts_with('#') && hex.len() == 7) { - return None; - } - match [1..=2, 3..=4, 5..=6].map(|i| hex.get(i).and_then(|c| u8::from_str_radix(c, 16).ok())) - { - [Some(r), Some(g), Some(b)] => Some(Self::Rgb(r, g, b)), - _ => None, - } - } -} - #[cfg(feature = "term")] -impl From<Color> for termina::style::ColorSpec { - fn from(color: Color) -> Self { - match color { - Color::Reset => Self::Reset, - Color::Black => Self::BLACK, - Color::Red => Self::RED, - Color::Green => Self::GREEN, - Color::Yellow => Self::YELLOW, - Color::Blue => Self::BLUE, - Color::Magenta => Self::MAGENTA, - Color::Cyan => Self::CYAN, - Color::Gray => Self::BRIGHT_BLACK, - Color::White => Self::BRIGHT_WHITE, - Color::LightRed => Self::BRIGHT_RED, - Color::LightGreen => Self::BRIGHT_GREEN, - Color::LightBlue => Self::BRIGHT_BLUE, - Color::LightYellow => Self::BRIGHT_YELLOW, - Color::LightMagenta => Self::BRIGHT_MAGENTA, - Color::LightCyan => Self::BRIGHT_CYAN, - Color::LightGray => Self::WHITE, - Color::Indexed(i) => Self::PaletteIndex(i), - Color::Rgb(r, g, b) => termina::style::RgbColor::new(r, g, b).into(), - } - } -} - -#[cfg(all(feature = "term", windows))] impl From<Color> for crossterm::style::Color { fn from(color: Color) -> Self { use crossterm::style::Color as CColor; @@ -343,6 +291,7 @@ impl From<Color> for crossterm::style::Color { } } } + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum UnderlineStyle { Reset, @@ -368,21 +317,6 @@ impl FromStr for UnderlineStyle { } } -#[cfg(feature = "term")] -impl From<UnderlineStyle> for termina::style::Underline { - fn from(style: UnderlineStyle) -> Self { - match style { - UnderlineStyle::Reset => Self::None, - UnderlineStyle::Line => Self::Single, - UnderlineStyle::Curl => Self::Curly, - UnderlineStyle::Dotted => Self::Dotted, - UnderlineStyle::Dashed => Self::Dashed, - UnderlineStyle::DoubleLine => Self::Double, - } - } -} - -#[cfg(all(feature = "term", windows))] impl From<UnderlineStyle> for crossterm::style::Attribute { fn from(style: UnderlineStyle) -> Self { match style { |