good enough

This commit is contained in:
husky 2025-09-11 16:37:15 -07:00
parent b3af2a7967
commit 776b7d131d

View file

@ -4,18 +4,18 @@ use crate::trafficcontrol::TrafficControl;
pub struct FramebufferConsole {
pub buffer: [[char; 20]; 15], // our font is 16x16, 320x240 is the standard res, so 20x15
pub cursor: (usize, usize), // (x, y)
pub cursor: (usize, usize), // (x, y)
pub need_screen_clear: bool,
}
pub static FBCONSOLE: Spinlock<FramebufferConsole> = Spinlock::new(
FramebufferConsole::empty()
);
pub static FBCONSOLE: Spinlock<FramebufferConsole> = Spinlock::new(FramebufferConsole::empty());
impl FramebufferConsole {
pub const fn empty() -> Self {
Self {
buffer: [[' '; 20]; 15],
cursor: (0, 0),
need_screen_clear: true,
}
}
@ -26,10 +26,12 @@ impl FramebufferConsole {
self.buffer[line_num] = copy_from;
}
self.buffer[self.buffer.len() - 1] = [' '; 20];
self.need_screen_clear = true;
}
// DOES send a framebuffer update!
pub fn clear_terminal(&mut self, tc: &mut TrafficControl) {
self.need_screen_clear = false;
self.buffer = [[' '; 20]; 15];
self.cursor = (0, 0);
self.render(tc);
@ -52,6 +54,7 @@ impl FramebufferConsole {
if c == '\x08' {
was_special_char = true;
// we don't clear the character, that's up to the terminal
self.need_screen_clear = true;
if self.cursor.0 > 0 {
self.cursor.0 -= 1;
} else {
@ -79,8 +82,11 @@ impl FramebufferConsole {
self.render(tc);
}
pub fn render(&self, tc: &mut TrafficControl) {
fb_clearscreen(tc);
pub fn render(&mut self, tc: &mut TrafficControl) {
if self.need_screen_clear {
fb_clearscreen(tc);
self.need_screen_clear = false;
}
for (y, line) in self.buffer.iter().enumerate() {
fb_write_char_array(tc, 0, y * 16, line);