forked from AbleOS/ableos
move rhai shell to its own sub folder
This commit is contained in:
parent
44c252ed84
commit
b7431ba474
|
@ -33,6 +33,7 @@ pub mod arch;
|
|||
#[macro_use]
|
||||
pub mod print;
|
||||
pub mod devices;
|
||||
pub mod rhai_shell;
|
||||
pub mod wasm_jumploader;
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -48,12 +48,6 @@ macro_rules! print {
|
|||
}
|
||||
#[macro_export]
|
||||
macro_rules! println {
|
||||
// TODO: The panic here should not be here
|
||||
() =>{
|
||||
|
||||
// ::core::writeln!($crate::print::Stdout, "\n")
|
||||
panic![];
|
||||
};
|
||||
($($tt:tt)*) => {
|
||||
::core::writeln!($crate::print::Stdout, $($tt)*)
|
||||
// panic![];
|
||||
|
|
76
ableos/src/rhai_shell/mod.rs
Normal file
76
ableos/src/rhai_shell/mod.rs
Normal file
|
@ -0,0 +1,76 @@
|
|||
use alloc::vec::Vec;
|
||||
|
||||
pub fn rhai_shell() {
|
||||
let mut engine = rhai::Engine::new();
|
||||
|
||||
engine.on_print(|x| println!("{}", x));
|
||||
|
||||
engine.on_debug(|x, src, pos| {
|
||||
let src = src.unwrap_or("unknown");
|
||||
println!("DEBUG: {} at {:?}: {}", src, pos, x);
|
||||
debug!("{} at {:?}: {}", src, pos, x);
|
||||
});
|
||||
|
||||
engine.register_fn("afetch", afetch);
|
||||
engine.register_fn("set_hostname", set_hostname);
|
||||
engine.register_fn("shutdown", shutdown);
|
||||
|
||||
let mut scope = rhai::Scope::new();
|
||||
|
||||
let mut buf = String::new();
|
||||
print!("> ");
|
||||
|
||||
loop {
|
||||
match x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()) {
|
||||
Some('\n') => {
|
||||
match engine.eval_with_scope::<rhai::Dynamic>(&mut scope, &buf) {
|
||||
Ok(o) => println!("{o}"),
|
||||
Err(e) => println!("Eval error: {e}"),
|
||||
};
|
||||
|
||||
buf.clear();
|
||||
print!("> ");
|
||||
}
|
||||
Some('\u{0008}') => {
|
||||
buf.pop();
|
||||
}
|
||||
Some(chr) => buf.push(chr),
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
lazy_static::lazy_static!(
|
||||
pub static ref KEYBUFF: spin::Mutex<Vec<char>> = spin::Mutex::new(
|
||||
Vec::new())
|
||||
;
|
||||
);
|
||||
|
||||
use alloc::string::{String, ToString};
|
||||
use x86_64::instructions::interrupts::{disable, enable};
|
||||
|
||||
use crate::{
|
||||
arch::{shutdown, sloop},
|
||||
kmain::{tick, TICK},
|
||||
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
||||
KERNEL_STATE,
|
||||
};
|
||||
|
||||
pub fn afetch() {
|
||||
let kstate = KERNEL_STATE.lock();
|
||||
use core::sync::atomic::Ordering::*;
|
||||
|
||||
disable();
|
||||
let tick_time = TICK.load(Relaxed);
|
||||
enable();
|
||||
|
||||
println!("OS: AbleOS");
|
||||
println!("Host: {}", kstate.hostname);
|
||||
println!("Kernel: AKern-{}-v{}", RELEASE_TYPE, KERNEL_VERSION);
|
||||
println!("Uptime: {}", tick_time);
|
||||
|
||||
drop(kstate);
|
||||
}
|
||||
pub fn set_hostname(name: String) {
|
||||
let mut kstate = KERNEL_STATE.lock();
|
||||
kstate.hostname = name;
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
use crate::rhai_shell::rhai_shell;
|
||||
|
||||
use {
|
||||
crate::{
|
||||
devices::{pci_inner::DeviceClass, Device, DEVICE_TABLE},
|
||||
|
@ -92,78 +94,3 @@ impl ProcessMessage {
|
|||
}
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn rhai_shell() {
|
||||
let mut engine = rhai::Engine::new();
|
||||
|
||||
engine.on_print(|x| println!("{}", x));
|
||||
|
||||
engine.on_debug(|x, src, pos| {
|
||||
let src = src.unwrap_or("unknown");
|
||||
println!("DEBUG: {} at {:?}: {}", src, pos, x);
|
||||
debug!("{} at {:?}: {}", src, pos, x);
|
||||
});
|
||||
|
||||
engine.register_fn("afetch", afetch);
|
||||
engine.register_fn("set_hostname", set_hostname);
|
||||
engine.register_fn("shutdown", shutdown);
|
||||
|
||||
let mut scope = rhai::Scope::new();
|
||||
|
||||
let mut buf = String::new();
|
||||
print!("> ");
|
||||
|
||||
loop {
|
||||
match x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()) {
|
||||
Some('\n') => {
|
||||
match engine.eval_with_scope::<rhai::Dynamic>(&mut scope, &buf) {
|
||||
Ok(o) => println!("{o}"),
|
||||
Err(e) => println!("Eval error: {e}"),
|
||||
};
|
||||
|
||||
buf.clear();
|
||||
print!("> ");
|
||||
}
|
||||
Some('\u{0008}') => {
|
||||
buf.pop();
|
||||
}
|
||||
Some(chr) => buf.push(chr),
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
lazy_static::lazy_static!(
|
||||
pub static ref KEYBUFF: spin::Mutex<Vec<char>> = spin::Mutex::new(
|
||||
Vec::new())
|
||||
;
|
||||
);
|
||||
|
||||
use alloc::string::{String, ToString};
|
||||
use x86_64::instructions::interrupts::{disable, enable};
|
||||
|
||||
use crate::{
|
||||
arch::{shutdown, sloop},
|
||||
kmain::{tick, TICK},
|
||||
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
||||
KERNEL_STATE,
|
||||
};
|
||||
|
||||
pub fn afetch() {
|
||||
let kstate = KERNEL_STATE.lock();
|
||||
use core::sync::atomic::Ordering::*;
|
||||
|
||||
disable();
|
||||
let tick_time = TICK.load(Relaxed);
|
||||
enable();
|
||||
|
||||
println!("OS: AbleOS");
|
||||
println!("Host: {}", kstate.hostname);
|
||||
println!("Kernel: AKern-{}-v{}", RELEASE_TYPE, KERNEL_VERSION);
|
||||
println!("Uptime: {}", tick_time);
|
||||
|
||||
drop(kstate);
|
||||
}
|
||||
pub fn set_hostname(name: String) {
|
||||
let mut kstate = KERNEL_STATE.lock();
|
||||
kstate.hostname = name;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue