Don't move the cursor out of bounds
This commit is contained in:
parent
d8e3c7d8e9
commit
32c22fe34a
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue