From 32c22fe34a80ced040c6497065e110e04db79db6 Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Thu, 16 Sep 2021 18:20:20 -0500 Subject: [PATCH] Don't move the cursor out of bounds --- src/interrupts.rs | 10 +++++++--- src/vga_buffer.rs | 12 +++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/interrupts.rs b/src/interrupts.rs index 2df9c36..a3fd5bb 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -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(); diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 68d4092..38435bc 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -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; + } }