From 26c7bcfdd5a87e3f6d7018cde13c8a237936a6e3 Mon Sep 17 00:00:00 2001 From: UncleScientist <77306152+UncleScientist@users.noreply.github.com> Date: Mon, 20 Mar 2023 13:39:27 -0400 Subject: [PATCH] fix(style): bold needs a bit (#104) --- src/style.rs | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/src/style.rs b/src/style.rs index ec0684f4..d894026a 100644 --- a/src/style.rs +++ b/src/style.rs @@ -39,16 +39,16 @@ bitflags! { /// let m = Modifier::BOLD | Modifier::ITALIC; /// ``` #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] - pub struct Modifier: u8 { - const BOLD = 0b0000_0000; - const DIM = 0b0000_0001; - const ITALIC = 0b0000_0010; - const UNDERLINED = 0b0000_0100; - const SLOW_BLINK = 0b0000_1000; - const RAPID_BLINK = 0b0001_0000; - const REVERSED = 0b0010_0000; - const HIDDEN = 0b0100_0000; - const CROSSED_OUT = 0b1000_0000; + pub struct Modifier: u16 { + const BOLD = 0b0000_0000_0001; + const DIM = 0b0000_0000_0010; + const ITALIC = 0b0000_0000_0100; + const UNDERLINED = 0b0000_0000_1000; + const SLOW_BLINK = 0b0000_0001_0000; + const RAPID_BLINK = 0b0000_0010_0000; + const REVERSED = 0b0000_0100_0000; + const HIDDEN = 0b0000_1000_0000; + const CROSSED_OUT = 0b0001_0000_0000; } } @@ -278,4 +278,33 @@ mod tests { } } } + + #[test] + fn combine_individual_modifiers() { + use crate::{buffer::Buffer, layout::Rect}; + + let mods = vec![ + Modifier::BOLD, + Modifier::DIM, + Modifier::ITALIC, + Modifier::UNDERLINED, + Modifier::SLOW_BLINK, + Modifier::RAPID_BLINK, + Modifier::REVERSED, + Modifier::HIDDEN, + Modifier::CROSSED_OUT, + ]; + + let mut buffer = Buffer::empty(Rect::new(0, 0, 1, 1)); + + for m in &mods { + buffer.get_mut(0, 0).set_style(Style::reset()); + buffer + .get_mut(0, 0) + .set_style(Style::default().add_modifier(*m)); + let style = buffer.get(0, 0).style(); + assert!(style.add_modifier.contains(*m)); + assert!(!style.sub_modifier.contains(*m)); + } + } }