Move cursor with arrow keys

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

View file

@ -44,7 +44,7 @@ extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFr
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
use x86_64::instructions::port::Port;
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
use pc_keyboard::{layouts, DecodedKey, KeyCode, HandleControl, Keyboard, ScancodeSet1};
lazy_static! {
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> = {
@ -65,8 +65,36 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
} else {
print!("{}", character)
}
let 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, row as u16);
},
DecodedKey::RawKey(key) => print!("{:#?}", key), }
DecodedKey::RawKey(key) => {
match key {
// TODO
KeyCode::ArrowLeft => {
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;
},
KeyCode::ArrowRight => {
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;
},
_ => {}
}
},
}
}
}

View file

@ -43,7 +43,7 @@ struct ScreenChar {
color_code: ColorCode
}
const BUFFER_HEIGHT: usize = 25;
pub(crate) const BUFFER_HEIGHT: usize = 25;
const BUFFER_WIDTH: usize = 80;
#[repr(transparent)]
@ -52,7 +52,7 @@ struct Buffer {
}
pub struct Writer {
column_position: usize,
pub column_position: usize,
color_code: ColorCode,
buffer: &'static mut Buffer
}
@ -168,7 +168,6 @@ pub fn backspace() {
pub struct Cursor {
port_low: Port<u8>,
port_high: Port<u8>,
cursor_pos: u16
}
impl Cursor {
@ -176,7 +175,6 @@ impl Cursor {
Cursor {
port_low: Port::new(0x3D4),
port_high: Port::new(0x3D5),
cursor_pos: 0
}
}