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);
+2 -3
View File
@@ -11,9 +11,7 @@ use pc_keyboard::{
};
use spin::{Lazy, Mutex, Once};
use crate::println;
use super::print;
use crate::prelude::*;
static KBD_QUEUE: Once<ArrayQueue<u8>> = Once::new();
static WAKER: AtomicWaker = AtomicWaker::new();
@@ -21,6 +19,7 @@ static WAKER: AtomicWaker = AtomicWaker::new();
pub static KEYBOARD: Lazy<Mutex<Keyboard<Uk105Key, ScancodeSet1>>> = Lazy::new(|| {
Mutex::new(Keyboard::new(
ScancodeSet1::new(),
// TODO: Expose an API to change the default KB layout.
layouts::Uk105Key,
HandleControl::Ignore,
))
+1
View File
@@ -26,6 +26,7 @@ pub mod resources;
pub mod std;
/// Re-exports most of the IO macros as well as standard allocation stuff
#[allow(unused)]
pub mod prelude {
pub use crate::std::io::*;
pub use alloc::{