diff --git a/shell/src/interrupts.rs b/shell/src/interrupts.rs index f9b9a2b..e09f007 100644 --- a/shell/src/interrupts.rs +++ b/shell/src/interrupts.rs @@ -2,11 +2,13 @@ extern crate alloc; use crate::gdt; use crate::hlt_loop; +use crate::keyboard_buffer; use crate::keyboard_buffer::{BUFFER, BUFFER_INDEX, BUFFER_SIZE}; use crate::print; use crate::vga_buffer::{Color, WRITER}; use alloc::format; use lazy_static::lazy_static; +use pc_keyboard::KeyCode; use pic8259::ChainedPics; use spin; use x86_64::structures::idt::PageFaultErrorCode; @@ -105,20 +107,37 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac if let Some(key) = keyboard.process_keyevent(key_event) { match key { DecodedKey::Unicode(character) => { - unsafe { - BUFFER[BUFFER_INDEX] = character; - BUFFER_INDEX += 1; + if character == '\u{8}' { + // backspace + if unsafe { BUFFER_INDEX } > 0 { + unsafe { + BUFFER_INDEX -= 1; + WRITER.lock().decrement_column_position(); + print!(" "); + WRITER.lock().decrement_column_position(); + } + } + } else { + unsafe { + BUFFER[BUFFER_INDEX] = character; + BUFFER_INDEX += 1; + } + print!("{}", character); } - print!("{}", character); } - #[cfg(debug_assertions)] DecodedKey::RawKey(key) => { - print!("{:?}", key); + if key == KeyCode::F1 { + if unsafe { BUFFER_INDEX } > 0 { + keyboard_buffer::clear_buffer(); + print!("\n"); + unsafe { + BUFFER[BUFFER_INDEX] = '\n'; + BUFFER_INDEX += 1; + } + } + } } - - #[cfg(not(debug_assertions))] - DecodedKey::RawKey(_) => (), } // print!("{}", read_buffer()); } diff --git a/shell/src/vga_buffer.rs b/shell/src/vga_buffer.rs index 986c237..b4e6a00 100644 --- a/shell/src/vga_buffer.rs +++ b/shell/src/vga_buffer.rs @@ -200,6 +200,13 @@ impl Writer { self.write_string(&string); self.color_code = prv_colorcode; } + + pub fn decrement_column_position(&mut self) { + self.column_position -= 1; + } + pub fn increment_column_position(&mut self) { + self.column_position += 1; + } } impl fmt::Write for Writer {