fb: Added support for typing backspaces.

This commit is contained in:
2025-02-24 23:24:03 +00:00
parent f7723a3944
commit 00d3a1de72
3 changed files with 25 additions and 8 deletions
+22 -5
View File
@@ -64,13 +64,19 @@ impl Writer {
self.font = font;
}
/// This is sent when the user types a backspace.
const BACKSPACE: u16 = 8;
pub fn write_glyph(&mut self, c: u16) {
if c as u8 == b'\n' {
if c == b'\n' as u16 {
self.newline();
return;
} else if c == Self::BACKSPACE {
self.backspace();
return;
}
// get the character data from the font array. -- each byte is a row of pixels
// Get the character data from the font array. -- each byte is a row of pixels
let data: &[u8] = &self.font.0[c as usize];
if let Some(writer) = FRAMEBUFFER_WRITER.lock().as_mut() {
@@ -80,17 +86,17 @@ impl Writer {
let pixel_y: u32 = self.text_line * FONT_HEIGHT + row as u32;
if line & (0x80 >> col) != 0 {
// write the foreground color
// Write the foreground color
writer.write_pixel(pixel_x as usize, pixel_y as usize, self.fg_color);
} else {
// write the background color
// Write the background color
writer.write_pixel(pixel_x as usize, pixel_y as usize, self.bg_color);
}
}
}
}
// go to next position
// Go to next position
if self.text_col + 1 >= self.screen_width {
self.newline();
} else {
@@ -121,6 +127,17 @@ impl Writer {
}
}
/// Handles the backspace character. TODO: Implement VT-100 style terminal control
/// codes alongside a shell. Not simple.
pub fn backspace(&mut self) {
if self.text_col > 0 {
self.text_col -= 1;
// Blank out the previous char.
self.write_glyph(' ' as u16);
self.text_col -= 1;
}
}
pub fn write_string(&mut self, s: &str) {
for c in s.chars() {
self.write_glyph(c as u16);