From 3f511e11c1aa7924efa5113d7589dddd8cc306b7 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 20 Jun 2024 18:04:53 -0400 Subject: [PATCH] Enable hex colors in cursup --- cursive-core/src/utils/markup/cursup.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cursive-core/src/utils/markup/cursup.rs b/cursive-core/src/utils/markup/cursup.rs index e77ccd33..ae526ab2 100644 --- a/cursive-core/src/utils/markup/cursup.rs +++ b/cursive-core/src/utils/markup/cursup.rs @@ -66,7 +66,7 @@ pub fn parse_spans(input: &str) -> Vec { } (State::Plain, _) => (), - (State::Slash(_), b'a'..=b'z' | b'+' | b'.') => (), + (State::Slash(_), b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9' | b'#' | b'+' | b'.') => (), (State::Slash(slash), b'{') => { // Add a candidate. candidates.push(Candidate { @@ -158,7 +158,7 @@ where #[cfg(test)] mod tests { - use crate::theme::{BaseColor, Effect, Style}; + use crate::theme::{BaseColor, Color, Effect, Style}; use crate::utils::markup::cursup::parse; use crate::utils::markup::StyledString; use crate::utils::span::Span; @@ -238,6 +238,20 @@ mod tests { ); } + #[test] + fn hex_color() { + let parsed = parse("/#ff0000{red}"); + let spans: Vec<_> = parsed.spans().collect(); + assert_eq!( + &spans[..], + &[Span { + content: "red", + width: 3, + attr: &Style::from_color_style(Color::Rgb(255, 0, 0).into()), + }] + ); + } + #[test] fn invalid_span_as_plain_text() { let parsed = parse("/red{red");