e
e
This commit is contained in:
+5
-2
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
use CrystalOS::{println, print, println_log, print_log};
|
use CrystalOS::{println, print, println_log, print_log};
|
||||||
use CrystalOS::kernel::tasks::{Task, executor::Executor, keyboard};
|
use CrystalOS::kernel::tasks::{Task, executor::Executor};
|
||||||
use bootloader::{BootInfo, entry_point};
|
use bootloader::{BootInfo, entry_point};
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
use alloc::{boxed::Box, vec, vec::Vec, rc::Rc, string, string::String};
|
use alloc::{boxed::Box, vec, vec::Vec, rc::Rc, string, string::String};
|
||||||
@@ -48,7 +48,10 @@ fn main(boot_info: &'static BootInfo) -> ! {
|
|||||||
|
|
||||||
executor.spawn(Task::new(shell::command_handler()));
|
executor.spawn(Task::new(shell::command_handler()));
|
||||||
|
|
||||||
executor.run();
|
|
||||||
|
loop {
|
||||||
|
executor.try_run();
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
test_main();
|
test_main();
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
use lazy_static::lazy_static;
|
|
||||||
use spin::Mutex;
|
|
||||||
use alloc::{string::String};
|
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
pub static ref OS: Mutex<SysInfo> = Mutex::new(SysInfo {
|
|
||||||
os: String::from("CrystalOS Alpha"),
|
|
||||||
version: String::from("0.2.1"),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SysInfo {
|
|
||||||
pub os: String,
|
|
||||||
pub version: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -50,11 +50,9 @@ impl Executor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&mut self) -> ! {
|
pub fn try_run(&mut self) {
|
||||||
loop {
|
self.run_ready_tasks();
|
||||||
self.run_ready_tasks();
|
self.sleep_if_idle();
|
||||||
self.sleep_if_idle();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sleep_if_idle(&self) {
|
fn sleep_if_idle(&self) {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
|
||||||
|
// importing libraries
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
@@ -10,21 +12,14 @@ use alloc::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
kernel::tasks::{Task, Executor},
|
||||||
applications::*,
|
applications::*,
|
||||||
std::application::{Application, Error},
|
std::application::{Application, Error},
|
||||||
std::io::{print, println},
|
std::io::{stdin, print, println},
|
||||||
user::bin::*,
|
user::bin::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
pub static ref CMD: Mutex<Cmd> = Mutex::new(Cmd::new());
|
|
||||||
}
|
|
||||||
struct Cmd {}
|
|
||||||
impl Cmd {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// [ CRYSTAL SHELL ]
|
// [ CRYSTAL SHELL ]
|
||||||
// the purpose of this module is to provide a basic unix shell like experience for the user
|
// the purpose of this module is to provide a basic unix shell like experience for the user
|
||||||
@@ -37,6 +32,95 @@ impl Cmd {
|
|||||||
// - chained execution ( multiple commands linked together) eg: '5 + 5 | echo' which calculates
|
// - chained execution ( multiple commands linked together) eg: '5 + 5 | echo' which calculates
|
||||||
// the result of 5 + 5 and then sends the result to an echo command which prints it to console
|
// the result of 5 + 5 and then sends the result to an echo command which prints it to console
|
||||||
|
|
||||||
pub fn init_sh() -> Result<(), String> {
|
|
||||||
|
|
||||||
|
|
||||||
|
/// initialises a global tasks struct, this can be accessed from anywhere in the program;
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref TASKS: Mutex<Vec<Task>> = Mutex::new(Vec::new());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// starts the shell
|
||||||
|
/// this function should be directly called by main.rs or by an init system
|
||||||
|
pub fn init_sh(args: Option<Vec<String>>) -> Result<(), String> {
|
||||||
|
let mut executor = Executor::new();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
executor.spawn(Task::new(next()));
|
||||||
|
|
||||||
|
let tasks = TASKS.lock();
|
||||||
|
while tasks.len() > 0 {
|
||||||
|
let next = tasks[0].clone();
|
||||||
|
tasks.remove(0);
|
||||||
|
executor.spawn(next);
|
||||||
|
}
|
||||||
|
drop(tasks);
|
||||||
|
|
||||||
|
executor.run();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_args(command: String) -> Result<(String, Vec<String>), String> {
|
||||||
|
|
||||||
|
let mut args: Vec<String> = Vec::new();
|
||||||
|
|
||||||
|
for arg in command.split(" ").collect::<Vec<&str>>() {
|
||||||
|
match arg {
|
||||||
|
"" => {}
|
||||||
|
x => args.push(x.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let cmd: String;
|
||||||
|
if args.len() > 0 {
|
||||||
|
cmd = args[0].clone();
|
||||||
|
args.remove(0);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return Err("command was empty.".to_string());
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok((cmd, args))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn run_binary(binary: Application) -> Result<Vec<String>, String> {
|
||||||
|
binary.run()
|
||||||
|
Ok(Vec::<String::new()>)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn next() {
|
||||||
|
let command: String = stdin();
|
||||||
|
let parsed = match parse_args(command) {
|
||||||
|
Ok(x) -> x
|
||||||
|
Err(e) -> {
|
||||||
|
println!("Error Parsing Command: Invalid Syntax")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// tokens will eventually be parsed here
|
||||||
|
|
||||||
|
/*
|
||||||
|
- PARSER
|
||||||
|
- this will allow the use of more complex commands later down the line
|
||||||
|
*/
|
||||||
|
TASKS.lock().push(Task::new(cmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user