Skip to content

Commit

Permalink
Enable hex colors in cursup
Browse files Browse the repository at this point in the history
  • Loading branch information
gyscos committed Jun 20, 2024
1 parent cb42dc1 commit 3f511e1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions cursive-core/src/utils/markup/cursup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn parse_spans(input: &str) -> Vec<StyledIndexedSpan> {
}
(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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 3f511e1

Please sign in to comment.