Implement backspace

This commit is contained in:
Yash Karandikar 2021-09-16 13:31:32 -05:00
parent 3f946b95b2
commit fd306dae01
2 changed files with 19 additions and 4 deletions

View file

@ -59,9 +59,14 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
if let Ok(Some(key_event)) = keyboard.add_byte(scancode) {
if let Some(key) = keyboard.process_keyevent(key_event) {
match key {
DecodedKey::Unicode(character) => print!("{}", character),
DecodedKey::RawKey(key) => print!("{:?}", key),
}
DecodedKey::Unicode(character) => {
if character == '\u{8}' {
crate::vga_buffer::backspace();
} else {
print!("{}", character)
}
},
DecodedKey::RawKey(key) => print!("{:#?}", key), }
}
}

View file

@ -150,4 +150,14 @@ pub fn _print(args: fmt::Arguments) {
}
pub fn backspace() {
let mut writer = WRITER.lock();
let row = BUFFER_HEIGHT - 1;
let col = writer.column_position;
let color_code = writer.color_code;
writer.buffer.chars[row][col - 1].write(ScreenChar {
ascii_character: b' ',
color_code
});
writer.column_position -= 1;
}