forked from AbleOS/ableos
Working Rhai REPL
This commit is contained in:
parent
38a8ae6e20
commit
bdd866eafe
|
@ -90,6 +90,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
|
||||||
// Backspace
|
// Backspace
|
||||||
8 => {
|
8 => {
|
||||||
WRITER.lock().backspace();
|
WRITER.lock().backspace();
|
||||||
|
KEYBUFF.lock().push(8_u8 as _);
|
||||||
// print!(" ");
|
// print!(" ");
|
||||||
// WRITER.lock().backspace();
|
// WRITER.lock().backspace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub fn scratchpad() {
|
||||||
*/
|
*/
|
||||||
// interp();
|
// interp();
|
||||||
|
|
||||||
// rhai_shell();
|
rhai_shell();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PciIO {}
|
pub struct PciIO {}
|
||||||
|
@ -94,16 +94,28 @@ impl ProcessMessage {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub fn rhai_shell() {
|
pub fn rhai_shell() {
|
||||||
let mut engine = rhai::Engine::new();
|
let engine = rhai::Engine::new();
|
||||||
|
let mut buf = String::new();
|
||||||
|
print!("> ");
|
||||||
|
|
||||||
let ret = engine.eval::<i64>("1 + 2");
|
loop {
|
||||||
|
match x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()) {
|
||||||
|
Some('\n') => {
|
||||||
|
match engine.eval::<rhai::Dynamic>(&buf) {
|
||||||
|
Ok(o) => println!("{o}"),
|
||||||
|
Err(e) => println!("Eval error: {e}"),
|
||||||
|
};
|
||||||
|
|
||||||
match ret {
|
buf.clear();
|
||||||
Ok(x) => println!("{}", x),
|
print!("> ");
|
||||||
Err(e) => println!("{}", e),
|
}
|
||||||
|
Some('\u{0008}') => {
|
||||||
|
buf.pop();
|
||||||
|
}
|
||||||
|
Some(chr) => buf.push(chr),
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {}
|
|
||||||
}
|
}
|
||||||
lazy_static::lazy_static!(
|
lazy_static::lazy_static!(
|
||||||
pub static ref KEYBUFF: spin::Mutex<Vec<char>> = spin::Mutex::new(
|
pub static ref KEYBUFF: spin::Mutex<Vec<char>> = spin::Mutex::new(
|
||||||
|
|
Loading…
Reference in a new issue