theming: add Attr::Reverse

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-04-10 23:55:01 +02:00
parent 429c382f60
commit 80553747c2
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -1,5 +1,7 @@
use enum_set::{CLike, EnumSet}; use enum_set::{CLike, EnumSet};
use ncurses::{attr_t, init_pair, A_BLINK, A_BOLD, A_ITALIC, A_UNDERLINE, COLORS, COLOR_PAIR}; use ncurses::{
attr_t, init_pair, A_BLINK, A_BOLD, A_ITALIC, A_REVERSE, A_UNDERLINE, COLORS, COLOR_PAIR,
};
use nom::{ use nom::{
branch::alt, branch::alt,
bytes::complete::tag, bytes::complete::tag,
@ -18,6 +20,7 @@ pub enum Attr {
Italic, Italic,
Underline, Underline,
Blink, Blink,
Reverse,
} }
impl Attr { impl Attr {
@ -27,6 +30,7 @@ impl Attr {
Attr::Italic => A_ITALIC(), Attr::Italic => A_ITALIC(),
Attr::Underline => A_UNDERLINE(), Attr::Underline => A_UNDERLINE(),
Attr::Blink => A_BLINK(), Attr::Blink => A_BLINK(),
Attr::Reverse => A_REVERSE(),
} }
} }
} }
@ -42,7 +46,7 @@ impl CLike for Attr {
} }
fn parse_attr(input: &str) -> IResult<&str, Attr> { fn parse_attr(input: &str) -> IResult<&str, Attr> {
let (input, attr) = alt((tag("b"), tag("i"), tag("u"), tag("a")))(input)?; let (input, attr) = alt((tag("b"), tag("i"), tag("u"), tag("a"), tag("r")))(input)?;
Ok(( Ok((
input, input,
@ -51,6 +55,7 @@ fn parse_attr(input: &str) -> IResult<&str, Attr> {
"i" => Attr::Italic, "i" => Attr::Italic,
"u" => Attr::Underline, "u" => Attr::Underline,
"a" => Attr::Blink, "a" => Attr::Blink,
"r" => Attr::Reverse,
_ => { _ => {
return Err(NomErr::Error(NomError::from_error_kind( return Err(NomErr::Error(NomError::from_error_kind(
input, input,
@ -166,12 +171,13 @@ mod tests {
#[test] #[test]
fn all() { fn all() {
let attrs = "baiu"; let attrs = "baiur";
let mut expected = EnumSet::new(); let mut expected = EnumSet::new();
expected.insert(Attr::Bold); expected.insert(Attr::Bold);
expected.insert(Attr::Blink); expected.insert(Attr::Blink);
expected.insert(Attr::Italic); expected.insert(Attr::Italic);
expected.insert(Attr::Underline); expected.insert(Attr::Underline);
expected.insert(Attr::Reverse);
let received = parse_attrs(attrs).unwrap(); let received = parse_attrs(attrs).unwrap();
assert_eq!(received, expected); assert_eq!(received, expected);
} }