This commit is contained in:
Elfein Landers 2022-02-04 22:20:28 -08:00
commit 4dc0b92778
2 changed files with 71 additions and 12 deletions

View file

@ -7,22 +7,17 @@ pub const VTERM_WIDTH: u32 = 100;
/// Fg and bg colors for vterm /// Fg and bg colors for vterm
pub type ColorCharacter = (Rgba64, Rgba64); pub type ColorCharacter = (Rgba64, Rgba64);
/// A vterm representation of a character
#[derive(Debug, Clone, Copy)]
pub struct VtermCharacter { pub struct VtermCharacter {
pub character: char, pub character: char,
// //
pub fg: Rgba64,
pub bg: Rgba64,
//
pub style: Style, pub style: Style,
//
pub char_color: ColorCharacter,
} }
pub struct Vterm { #[derive(Debug, Clone, Copy)]
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 struct Style {
pub bold: bool, pub bold: bool,
pub underline: bool, pub underline: bool,
@ -33,7 +28,7 @@ pub struct Style {
} }
#[derive(Default)] #[derive(Default)]
pub struct StylePacked(u8); pub struct StylePacked(pub u8);
impl StylePacked { impl StylePacked {
pub fn bold(&self) -> bool { pub fn bold(&self) -> bool {
@ -109,3 +104,61 @@ impl StylePacked {
self self
} }
} }
pub struct Vterm {
pub characters: [[VtermCharacter; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize],
/// The internal representation of the vterm
style: Style,
/// The cursor position in layout x,y
cursor_position: (u32, u32),
pub cursor_visible: bool,
}
impl Vterm {
pub fn new() -> Self {
Vterm {
characters: [[VtermCharacter {
character: ' ',
char_color: (0xff_ff_ff_ff, 0x00_00_00_00),
style: Style {
bold: false,
underline: false,
italic: false,
blink: false,
reverse: false,
strike: false,
},
}; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize],
cursor_position: (0, 0),
cursor_visible: true,
style: Style {
bold: false,
underline: false,
italic: false,
blink: false,
reverse: false,
strike: false,
},
}
}
/// Set the vterm cursor to the given position
pub fn set_cursor_position(&mut self, x: u32, y: u32) {
if x > VTERM_WIDTH {
self.cursor_position.0 = VTERM_WIDTH;
} else {
self.cursor_position.0 = x;
}
if y > VTERM_HEIGHT {
self.cursor_position.1 = VTERM_HEIGHT;
} else {
self.cursor_position.1 = y;
}
}
/// Set the vterm style
pub fn set_vterm_style(&mut self, style: Style) {
self.style = style;
}
}

View file

@ -84,6 +84,9 @@ pub fn kernel_main() -> ! {
} }
*/ */
let mut vterm0 = Vterm::new();
vterm0.set_cursor_position(123, 123);
start_facepalm(); start_facepalm();
sloop() sloop()
} }
@ -138,7 +141,10 @@ use uefi::{
}; };
use uefi::{proto::console::gop::FrameBuffer, ResultExt}; use uefi::{proto::console::gop::FrameBuffer, ResultExt};
use crate::{GraphicsReturn, ScreenBuffer}; use crate::{
vterm::{self, Vterm},
GraphicsReturn, ScreenBuffer,
};
#[entry] #[entry]
fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status { fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {