Don't move the cursor out of bounds

This commit is contained in:
Yash Karandikar 2021-09-16 18:20:20 -05:00
parent d8e3c7d8e9
commit 32c22fe34a
Signed by: karx
GPG key ID: A794DA2529474BA5
2 changed files with 14 additions and 8 deletions

View file

@ -62,6 +62,8 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
DecodedKey::Unicode(character) => {
if character == '\u{8}' {
crate::vga_buffer::backspace();
} else if character == '\u{9}' {
print!(" ");
} else {
print!("{}", character)
}
@ -79,9 +81,11 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
let mut writer = crate::vga_buffer::WRITER.lock();
let col = writer.column_position;
let row = crate::vga_buffer::BUFFER_HEIGHT - 1;
crate::vga_buffer::move_cursor((col as u16) - 1, row as u16);
writer.column_position -= 1;
if col != 0 {
crate::vga_buffer::move_cursor((col as u16) - 1, row as u16);
writer.column_position -= 1;
}
},
KeyCode::ArrowRight => {
let mut writer = crate::vga_buffer::WRITER.lock();

View file

@ -157,11 +157,13 @@ pub fn backspace() {
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;
if col != 0 {
writer.buffer.chars[row][col - 1].write(ScreenChar {
ascii_character: b' ',
color_code
});
writer.column_position -= 1;
}
}