diff --git a/shell/src/interrupts.rs b/shell/src/interrupts.rs index 632328f..5925c2e 100644 --- a/shell/src/interrupts.rs +++ b/shell/src/interrupts.rs @@ -1,5 +1,6 @@ use crate::gdt; use crate::hlt_loop; +use crate::keyboard_buffer::{clear_buffer, read_buffer, BUFFER, BUFFER_INDEX, BUFFER_SIZE}; use crate::print; use crate::println; use lazy_static::lazy_static; @@ -88,18 +89,33 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac )); } - let mut keyboard = KEYBOARD.lock(); - let mut port = Port::new(0x60); - - let scancode: u8 = unsafe { port.read() }; - if let Ok(Some(key_event)) = keyboard.add_byte(scancode) { - if let Some(key) = keyboard.process_keyevent(key_event) { - match key { - DecodedKey::Unicode(character) => print!("{}", character), - #[cfg(debug_assertions)] - DecodedKey::RawKey(key) => print!("{:?}", key), - #[cfg(not(debug_assertions))] - DecodedKey::RawKey(key) => (), + if unsafe { BUFFER_INDEX } < BUFFER_SIZE { + let mut keyboard = KEYBOARD.lock(); + let mut port = Port::new(0x60); + + let scancode: u8 = unsafe { port.read() }; + if let Ok(Some(key_event)) = keyboard.add_byte(scancode) { + if let Some(key) = keyboard.process_keyevent(key_event) { + match key { + DecodedKey::Unicode(character) => { + unsafe { + if character != '\n' { + BUFFER[BUFFER_INDEX] = character; + BUFFER_INDEX += 1; + } else { + clear_buffer(); + } + } + print!("{}", character); + } + + #[cfg(debug_assertions)] + DecodedKey::RawKey(key) => print!("{:?}", key), + + #[cfg(not(debug_assertions))] + DecodedKey::RawKey(_) => (), + } + // print!("{}", read_buffer()); } } } diff --git a/shell/src/keyboard_buffer.rs b/shell/src/keyboard_buffer.rs new file mode 100644 index 0000000..a0a5158 --- /dev/null +++ b/shell/src/keyboard_buffer.rs @@ -0,0 +1,26 @@ +use alloc::string::String; + +pub const BUFFER_SIZE: usize = 256; +pub static mut BUFFER: [char; BUFFER_SIZE] = ['\0'; BUFFER_SIZE]; +pub static mut BUFFER_INDEX: usize = 0; + +pub fn read_buffer() -> String { + let mut buffer_content = String::new(); + + unsafe { + for i in 0..BUFFER_INDEX { + buffer_content.push(BUFFER[i]); + } + } + + buffer_content +} + +pub fn clear_buffer() { + unsafe { + for i in 0..BUFFER_SIZE { + BUFFER[i] = '\0'; + } + BUFFER_INDEX = 0; + } +} diff --git a/shell/src/lib.rs b/shell/src/lib.rs index 3a07547..da744e6 100644 --- a/shell/src/lib.rs +++ b/shell/src/lib.rs @@ -8,6 +8,7 @@ extern crate alloc; pub mod allocator; pub mod gdt; pub mod interrupts; +pub mod keyboard_buffer; pub mod mem; pub mod vga_buffer; diff --git a/shell/src/main.rs b/shell/src/main.rs index 7aa824e..43c0bf5 100644 --- a/shell/src/main.rs +++ b/shell/src/main.rs @@ -43,33 +43,33 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { print!("\nHighlightOS Shell v{}\n\n", env!("CARGO_PKG_VERSION")); - loop { - let mut input = String::new(); - print!("hls < "); + // loop { + // let mut input = String::new(); + // print!("hls < "); - // io::stdout().flush().unwrap(); - // io::stdin().read_line(&mut inpt).unwrap(); + // // io::stdout().flush().unwrap(); + // // io::stdin().read_line(&mut inpt).unwrap(); - // input.pop(); + // // input.pop(); - let mut args: vec::Vec<&str> = input.split(' ').collect(); + // let mut args: vec::Vec<&str> = input.split(' ').collect(); - if let Some(command) = COMMAND_LIST.iter().find(|&com| com.name == args[0]) { - // args.remove(0); + // if let Some(command) = COMMAND_LIST.iter().find(|&com| com.name == args[0]) { + // // args.remove(0); - let rtr = (command.fun)(args); + // let rtr = (command.fun)(args); - if rtr != 1 { - if let Some(return_code) = RTR_LIST.iter().find(|&rtr_t| rtr_t.code == &rtr) { - println!("\n > {}\n{}\n", input, return_code.info); - } else { - println!("\n > {}\nreturned : {}\n", input, rtr); - } - } - } else { - println!("\n > {}\ncommand not found\n", input); - } - } + // if rtr != 1 { + // if let Some(return_code) = RTR_LIST.iter().find(|&rtr_t| rtr_t.code == &rtr) { + // println!("\n > {}\n{}\n", input, return_code.info); + // } else { + // println!("\n > {}\nreturned : {}\n", input, rtr); + // } + // } + // } else { + // println!("\n > {}\ncommand not found\n", input); + // } + // } hlshell::hlt_loop(); }