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