2019-12-28 17:08:11 +00:00
|
|
|
use lazy_static::lazy_static;
|
2019-12-29 13:20:34 +00:00
|
|
|
use crate::print;
|
2019-12-29 13:43:36 +00:00
|
|
|
use crate::user;
|
2019-12-28 17:08:11 +00:00
|
|
|
use spin::Mutex;
|
2019-12-29 13:43:36 +00:00
|
|
|
use heapless::{String, FnvIndexSet, Vec};
|
2019-12-29 09:34:08 +00:00
|
|
|
use heapless::consts::*;
|
|
|
|
use pc_keyboard::{KeyCode, DecodedKey};
|
2019-12-28 17:08:11 +00:00
|
|
|
|
|
|
|
lazy_static! {
|
2019-12-29 09:34:08 +00:00
|
|
|
pub static ref STDIN: Mutex<String<U256>> = Mutex::new(String::new());
|
|
|
|
pub static ref HISTORY: Mutex<FnvIndexSet<String<U256>, U256>> = Mutex::new(FnvIndexSet::new());
|
|
|
|
pub static ref HISTORY_INDEX: Mutex<usize> = Mutex::new(0);
|
2019-12-28 17:08:11 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 07:28:19 +00:00
|
|
|
pub fn print_banner() {
|
|
|
|
print!(" _M_\n");
|
|
|
|
print!(" (o o)\n");
|
|
|
|
print!("+--------------------------------ooO--(_)--Ooo---------------------------------+\n");
|
|
|
|
print!("| |\n");
|
|
|
|
print!("| MOROS |\n");
|
|
|
|
print!("| |\n");
|
|
|
|
print!("| Omniscient Rust Operating System |\n");
|
|
|
|
print!("| |\n");
|
|
|
|
print!("+------------------------------------------------------------------------------+\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn print_prompt() {
|
2019-12-29 07:35:16 +00:00
|
|
|
print!("\n> ");
|
2019-12-29 07:28:19 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 09:34:08 +00:00
|
|
|
pub fn key_handle(key: DecodedKey) {
|
2019-12-28 17:08:11 +00:00
|
|
|
let mut stdin = STDIN.lock();
|
2019-12-29 09:34:08 +00:00
|
|
|
let mut history = HISTORY.lock();
|
|
|
|
let mut history_index = HISTORY_INDEX.lock();
|
|
|
|
match key {
|
|
|
|
DecodedKey::Unicode('\n') => {
|
|
|
|
print!("\n");
|
|
|
|
if history.len() == history.capacity() {
|
|
|
|
let first = history.iter().next().unwrap().clone();
|
|
|
|
history.remove(&first);
|
2019-12-28 17:08:11 +00:00
|
|
|
}
|
2019-12-29 09:34:08 +00:00
|
|
|
if history.insert((*stdin).clone()).is_ok() {
|
|
|
|
*history_index = history.len();
|
|
|
|
}
|
2019-12-29 13:43:36 +00:00
|
|
|
|
|
|
|
if stdin.len() > 0 {
|
|
|
|
let line = stdin.clone();
|
|
|
|
let args: Vec<&str, U256> = line.split_whitespace().collect();
|
|
|
|
match args[0] {
|
2019-12-30 20:55:42 +00:00
|
|
|
"a" | "alias" => print!("TODO\n"),
|
|
|
|
"b" => print!("?\n"),
|
|
|
|
"c" | "copy" | "cp" => print!("TODO\n"),
|
|
|
|
"d" | "del" | "delete" | "rm" => print!("TODO\n"),
|
|
|
|
"e" | "edit" => print!("TODO\n"),
|
|
|
|
"f" | "find" => print!("TODO\n"),
|
|
|
|
"g" | "gd" | "go" | "go-dir" | "cd" => print!("TODO\n"),
|
|
|
|
"h" | "help" => print!("RTFM!\n"),
|
|
|
|
"i" => print!("?\n"),
|
|
|
|
"j" | "jd" | "jump" | "jump-dir" => print!("TODO\n"),
|
|
|
|
"k" | "kill" => print!("TODO\n"),
|
|
|
|
"l" | "list" | "ls" => print!("TODO\n"), // same as `rd`
|
2019-12-30 21:48:43 +00:00
|
|
|
"m" | "move" | "mv" => user::r#move::main(&args),
|
2019-12-30 20:55:42 +00:00
|
|
|
"n" => print!("?\n"),
|
|
|
|
"o" => print!("?\n"),
|
|
|
|
"p" | "print" => print!("TODO\n"),
|
|
|
|
"q" | "quit" | "exit" => print!("QUIT\n"),
|
|
|
|
"r" | "read" => user::read::main(&args),
|
|
|
|
"s" => print!("?\n"),
|
|
|
|
"t" | "tag" => print!("TODO\n"),
|
|
|
|
"u" => print!("?\n"),
|
|
|
|
"v" => print!("?\n"),
|
|
|
|
"w" | "write" => user::write::main(&args),
|
|
|
|
"x" => print!("?\n"),
|
|
|
|
"y" => print!("?\n"),
|
|
|
|
"z" => print!("?\n"),
|
|
|
|
"rd" | "read-dir" => print!("TODO\n"),
|
|
|
|
"wd" | "write-dir" | "mkdir" => print!("TODO\n"),
|
|
|
|
_ => print!("?\n"),
|
2019-12-29 09:34:08 +00:00
|
|
|
}
|
2019-12-29 13:43:36 +00:00
|
|
|
stdin.clear();
|
2019-12-29 09:34:08 +00:00
|
|
|
}
|
|
|
|
print_prompt();
|
|
|
|
},
|
|
|
|
DecodedKey::Unicode('\x08') => {
|
2019-12-28 18:00:51 +00:00
|
|
|
if stdin.len() > 0 {
|
|
|
|
stdin.pop();
|
2019-12-29 09:34:08 +00:00
|
|
|
print!("\x08");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
DecodedKey::Unicode(c) => {
|
|
|
|
if stdin.push(c).is_ok() {
|
2019-12-28 18:00:51 +00:00
|
|
|
print!("{}", c);
|
|
|
|
}
|
2019-12-29 09:34:08 +00:00
|
|
|
},
|
|
|
|
DecodedKey::RawKey(KeyCode::ArrowUp) => {
|
|
|
|
if history.len() > 0 {
|
|
|
|
if *history_index > 0 {
|
|
|
|
*history_index -= 1;
|
|
|
|
}
|
|
|
|
if let Some(cmd) = history.iter().nth(*history_index) {
|
|
|
|
let n = stdin.len();
|
|
|
|
for _ in 0..n {
|
|
|
|
print!("\x08");
|
|
|
|
}
|
|
|
|
*stdin = cmd.clone();
|
|
|
|
print!("{}", cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
DecodedKey::RawKey(KeyCode::ArrowDown) => {
|
|
|
|
if history.len() > 0 {
|
|
|
|
if *history_index < history.len() - 1 {
|
|
|
|
*history_index += 1;
|
|
|
|
}
|
|
|
|
if let Some(cmd) = history.iter().nth(*history_index) {
|
|
|
|
let n = stdin.len();
|
|
|
|
for _ in 0..n {
|
|
|
|
print!("\x08");
|
|
|
|
}
|
|
|
|
*stdin = cmd.clone();
|
|
|
|
print!("{}", cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
DecodedKey::RawKey(_) => {}
|
2019-12-28 17:08:11 +00:00
|
|
|
}
|
|
|
|
}
|