Skip to content

Commit

Permalink
Add backspace and command interrupting functionality
Browse files Browse the repository at this point in the history
- backspace removes a charcter from buffer and moves the cursor back
- F1 interrupts current buffer but only when it's > 0
  • Loading branch information
adamperkowski committed Jul 27, 2024
1 parent aaf4068 commit f125d57
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
37 changes: 28 additions & 9 deletions shell/src/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
7 changes: 7 additions & 0 deletions shell/src/vga_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f125d57

Please sign in to comment.