Skip to content

Commit

Permalink
saving input
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperkowski committed Jul 19, 2024
1 parent 8068612 commit 85afd88
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 33 deletions.
40 changes: 28 additions & 12 deletions shell/src/interrupts.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions shell/src/keyboard_buffer.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
42 changes: 21 additions & 21 deletions shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 85afd88

Please sign in to comment.