feat(userspace): terminal server + shell desktop; US keymap w/ shift; libkos allocator multi-page fix; panics print
This commit is contained in:
48
crates/apps/shell/src/main.rs
Normal file
48
crates/apps/shell/src/main.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
//! The shell, for now built-ins only; running programs comes next.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate libkos;
|
||||
|
||||
use libkos::{print, println};
|
||||
use types::bounded::CapSlot;
|
||||
|
||||
/// Init's manifest gives it the terminal first.
|
||||
const TERMINAL: CapSlot = CapSlot::const_new(0);
|
||||
|
||||
fn run(line: &str) {
|
||||
let mut words = line.split_ascii_whitespace();
|
||||
match words.next() {
|
||||
None => {}
|
||||
Some("help") => {
|
||||
println!("built-ins: help, echo <text>, clear");
|
||||
}
|
||||
Some("echo") => {
|
||||
let mut first = true;
|
||||
for w in words {
|
||||
print!("{}{}", if first { "" } else { " " }, w);
|
||||
first = false;
|
||||
}
|
||||
println!();
|
||||
}
|
||||
Some("clear") => libkos::terminal::clear(TERMINAL),
|
||||
Some(other) => println!("shell: {}: not found", other),
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn main() {
|
||||
// Everything this shell prints goes to the terminal.
|
||||
libkos::start::set_log(Some(TERMINAL));
|
||||
println!("k-os shell. Type 'help'.");
|
||||
let mut buf = [0u8; 256];
|
||||
loop {
|
||||
print!("$ ");
|
||||
let n = libkos::terminal::read_line(TERMINAL, &mut buf);
|
||||
match core::str::from_utf8(&buf[..n]) {
|
||||
Ok(line) => run(line.trim_end_matches('\n')),
|
||||
Err(_) => println!("shell: not text"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user