From 75b6fec5abfd3944c714b128edfc0cccf3142854 Mon Sep 17 00:00:00 2001 From: Elfein Landers Date: Fri, 4 Feb 2022 22:18:02 -0800 Subject: [PATCH 1/2] made style struct packed --- ableos/src/experiments/vterm.rs | 110 ++++++++++++++++++++++++++------ 1 file changed, 91 insertions(+), 19 deletions(-) diff --git a/ableos/src/experiments/vterm.rs b/ableos/src/experiments/vterm.rs index 9f7efd2..53b3aff 100644 --- a/ableos/src/experiments/vterm.rs +++ b/ableos/src/experiments/vterm.rs @@ -1,3 +1,5 @@ +use core::ops::Not; + use shadeable::pixel_format::Rgba64; pub const VTERM_HEIGHT: u32 = 40; @@ -6,34 +8,104 @@ pub const VTERM_WIDTH: u32 = 100; pub type ColorCharacter = (Rgba64, Rgba64); pub struct VtermCharacter { - pub character: char, - // - pub fg: Rgba64, - pub bg: Rgba64, - // - pub style: Style, + pub character: char, + // + pub fg: Rgba64, + pub bg: Rgba64, + // + pub style: Style, } pub struct Vterm { - pub characters: [[VtermCharacter; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize], - pub cursor_x: u32, - pub cursor_y: u32, - pub cursor_visible: bool, + pub characters: [[VtermCharacter; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize], + pub cursor_x: u32, + pub cursor_y: u32, + pub cursor_visible: bool, } pub struct Style { - pub bold: bool, - pub underline: bool, - pub italic: bool, - pub blink: bool, - pub reverse: bool, - pub strike: bool, + pub bold: bool, + pub underline: bool, + pub italic: bool, + pub blink: bool, + pub reverse: bool, + pub strike: bool, } +#[derive(Default)] pub struct StylePacked(u8); impl StylePacked { - pub fn new() -> Self { - StylePacked(0) - } + pub fn bold(&self) -> bool { + (self.0 & 0x01) > 0 + } + pub fn underlined(&self) -> bool { + (self.0 & 0x02) > 0 + } + pub fn italic(&self) -> bool { + (self.0 & 0x04) > 0 + } + pub fn blinking(&self) -> bool { + (self.0 & 0x08) > 0 + } + pub fn reversed(&self) -> bool { + (self.0 & 0x10) > 0 + } + pub fn struck(&self) -> bool { + (self.0 & 0x20) > 0 + } + #[must_use] + pub fn set_bold(mut self, v: bool) -> Self { + if v { + self.0 |= 0x01; + } else { + self.0 &= 0x01u8.not(); + } + self + } + #[must_use] + pub fn set_underlined(mut self, v: bool) -> Self { + if v { + self.0 |= 0x02; + } else { + self.0 &= 0x02u8.not(); + } + self + } + #[must_use] + pub fn set_italic(mut self, v: bool) -> Self { + if v { + self.0 |= 0x04; + } else { + self.0 &= 0x04u8.not(); + } + self + } + #[must_use] + pub fn set_blinking(mut self, v: bool) -> Self { + if v { + self.0 |= 0x08; + } else { + self.0 &= 0x08u8.not(); + } + self + } + #[must_use] + pub fn set_reversed(mut self, v: bool) -> Self { + if v { + self.0 |= 0x10; + } else { + self.0 &= 0x10u8.not(); + } + self + } + #[must_use] + pub fn set_struck(mut self, v: bool) -> Self { + if v { + self.0 |= 0x20; + } else { + self.0 &= 0x20u8.not(); + } + self + } } From 2780afd1e1ce56cc03076d4100d5bb2bc9ee8a23 Mon Sep 17 00:00:00 2001 From: Elfein Landers Date: Fri, 4 Feb 2022 22:25:42 -0800 Subject: [PATCH 2/2] made a default for vterm --- ableos/src/experiments/vterm.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ableos/src/experiments/vterm.rs b/ableos/src/experiments/vterm.rs index 94eb18a..9acb188 100644 --- a/ableos/src/experiments/vterm.rs +++ b/ableos/src/experiments/vterm.rs @@ -115,8 +115,8 @@ pub struct Vterm { pub cursor_visible: bool, } -impl Vterm { - pub fn new() -> Self { +impl Default for Vterm { + fn default() -> Self { Vterm { characters: [[VtermCharacter { character: ' ', @@ -142,7 +142,9 @@ impl Vterm { }, } } +} +impl Vterm { /// Set the vterm cursor to the given position pub fn set_cursor_position(&mut self, x: u32, y: u32) { if x > VTERM_WIDTH {