fix(style): bold needs a bit (#104)

This commit is contained in:
UncleScientist 2023-03-20 13:39:27 -04:00 committed by GitHub
parent cf1b05d16e
commit 26c7bcfdd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,16 +39,16 @@ bitflags! {
/// let m = Modifier::BOLD | Modifier::ITALIC; /// let m = Modifier::BOLD | Modifier::ITALIC;
/// ``` /// ```
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Modifier: u8 { pub struct Modifier: u16 {
const BOLD = 0b0000_0000; const BOLD = 0b0000_0000_0001;
const DIM = 0b0000_0001; const DIM = 0b0000_0000_0010;
const ITALIC = 0b0000_0010; const ITALIC = 0b0000_0000_0100;
const UNDERLINED = 0b0000_0100; const UNDERLINED = 0b0000_0000_1000;
const SLOW_BLINK = 0b0000_1000; const SLOW_BLINK = 0b0000_0001_0000;
const RAPID_BLINK = 0b0001_0000; const RAPID_BLINK = 0b0000_0010_0000;
const REVERSED = 0b0010_0000; const REVERSED = 0b0000_0100_0000;
const HIDDEN = 0b0100_0000; const HIDDEN = 0b0000_1000_0000;
const CROSSED_OUT = 0b1000_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));
}
}
} }