Moved commands to separate file and some other cleaning

TODO: move all unrelated to kernel code in separate files/directories
This commit is contained in:
g1n 2021-07-27 14:06:38 +03:00
parent cfd4fc1151
commit 8c9a80fde2
4 changed files with 44 additions and 57 deletions

View File

@ -18,6 +18,7 @@ pub mod gdt;
pub mod memory;
pub mod task;
pub mod allocator;
pub mod software; // where all builtin commands for now
#[cfg(test)]
use bootloader::{entry_point, BootInfo};

View File

@ -45,8 +45,7 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
.expect("heap initialization failed");
let mut executor = Executor::new();
//executor.spawn(Task::new(keyboard::print_keypresses()));
executor.spawn(Task::new(keyboard::return_keychar()));
executor.spawn(Task::new(keyboard::process_keyboard_input()));
executor.run();

40
src/software.rs Normal file
View File

@ -0,0 +1,40 @@
use crate::{println, print};
use alloc::string::String;
use alloc::vec::Vec;
use crate::alloc::string::ToString;
pub fn command_func(input_command: String) {
let mut command = String::new();
let mut args = String::new();
let mut command_vec: Vec<&str> = input_command.split(" ").collect();
command = command_vec[0].to_string();
command_vec.remove(0);
for i in command_vec {
for j in i.chars() {
args.push(j);
}
args.push(' ');
}
match command.as_str() {
"hi" => {
println!("hello command!!!");
}
"wow" => {
println!("wow!!");
}
"echo" => {
println!("{} ", args);
}
"asciiart" => {
println!(" _____ _____ ____ _____ ");
println!(" / ____| __ \\ / __ \\ / ____|");
println!(" | | __| |__) | | | | (___ ");
println!(" | | |_ | _ /| | | |\\___ \\ ");
println!(" | |__| | | \\ \\| |__| |____) |");
println!(" \\_____|_| \\_\\\\____/|_____/ ");
}
command => {
println!("{}: command not found", command);
}
}
}

View File

@ -4,7 +4,7 @@ use crate::println;
use crate::{serial_print, serial_println};
use alloc::string::String;
use crate::alloc::string::ToString;
use alloc::vec::Vec;
use crate::software::command_func;
use pc_keyboard::KeyCode;
@ -69,24 +69,7 @@ use futures_util::stream::StreamExt;
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
use crate::print;
pub async fn print_keypresses() {
let mut scancodes = ScancodeStream::new();
let mut keyboard = Keyboard::new(layouts::Us104Key, ScancodeSet1,
HandleControl::Ignore);
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) => print!("{}", character),
DecodedKey::RawKey(key) => print!("{:?}", key),
}
}
}
}
}
pub async fn return_keychar() {
pub async fn process_keyboard_input() {
let mut scancodes = ScancodeStream::new();
let mut keyboard = Keyboard::new(layouts::Us104Key, ScancodeSet1,
HandleControl::Ignore);
@ -117,40 +100,4 @@ pub async fn return_keychar() {
};
}
}
}
fn command_func(input_command: String) {
let mut command = String::new();
let mut args = String::new();
let mut command_vec: Vec<&str> = input_command.split(" ").collect();
command = command_vec[0].to_string();
command_vec.remove(0);
for i in command_vec {
for j in i.chars() {
args.push(j);
}
args.push(' ');
}
match command.as_str() {
"hi" => {
println!("hello command!!!");
}
"wow" => {
println!("wow!!");
}
"echo" => {
println!("{} ", args);
}
"asciiart" => {
println!(" _____ _____ ____ _____ ");
println!(" / ____| __ \\ / __ \\ / ____|");
println!(" | | __| |__) | | | | (___ ");
println!(" | | |_ | _ /| | | |\\___ \\ ");
println!(" | |__| | | \\ \\| |__| |____) |");
println!(" \\_____|_| \\_\\\\____/|_____/ ");
}
command => {
println!("{}: command not found", command);
}
}
}