Made very-very basic shell (? is used as Enter key)
This commit is contained in:
parent
31467a940d
commit
a2109db431
|
@ -7,6 +7,7 @@
|
|||
|
||||
use core::panic::PanicInfo;
|
||||
use gros::{println, print};
|
||||
use gros::{serial_println, serial_print};
|
||||
use bootloader::{BootInfo, entry_point};
|
||||
use gros::memory::BootInfoFrameAllocator;
|
||||
use gros::task::{Task, simple_executor::SimpleExecutor};
|
||||
|
@ -45,7 +46,9 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
|||
|
||||
let mut executor = Executor::new();
|
||||
//executor.spawn(Task::new(example_task()));
|
||||
executor.spawn(Task::new(keyboard::print_keypresses()));
|
||||
//executor.spawn(Task::new(keyboard::print_keypresses()));
|
||||
executor.spawn(Task::new(keyboard::return_keychar()));
|
||||
|
||||
executor.run();
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
use conquer_once::spin::OnceCell;
|
||||
use crossbeam_queue::ArrayQueue;
|
||||
use crate::println;
|
||||
use crate::serial_print;
|
||||
use alloc::string::String;
|
||||
use crate::alloc::string::ToString;
|
||||
|
||||
use pc_keyboard::KeyCode;
|
||||
|
||||
static SCANCODE_QUEUE: OnceCell<ArrayQueue<u8>> = OnceCell::uninit();
|
||||
|
||||
|
@ -78,4 +83,41 @@ pub async fn print_keypresses() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn return_keychar() {
|
||||
let mut scancodes = ScancodeStream::new();
|
||||
let mut keyboard = Keyboard::new(layouts::Us104Key, ScancodeSet1,
|
||||
HandleControl::Ignore);
|
||||
let mut command = String::new();
|
||||
while let Some(scancode) = scancodes.next().await {
|
||||
if let Ok(Some(key_event)) = keyboard.add_byte(scancode) {
|
||||
if let Some(key) = keyboard.process_keyevent(key_event) {
|
||||
match key {
|
||||
DecodedKey::Unicode(character) => (
|
||||
match character {
|
||||
'?' => { println!(); command_func(command); command = "".to_string(); print!("> "); }
|
||||
char => { print!("{}", char); command.push(char); serial_print!("{:?}", char); }
|
||||
}
|
||||
|
||||
),
|
||||
DecodedKey::RawKey(key) => serial_print!("{:?}", key),
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn command_func(command: String) {
|
||||
match command.as_str() {
|
||||
"hi" => {
|
||||
println!("hello command!!!");
|
||||
}
|
||||
"wow" => {
|
||||
println!("wow!!");
|
||||
}
|
||||
command => {
|
||||
println!("I don't know that command");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue