.
.
This commit is contained in:
+4
-3
@@ -1,6 +1,7 @@
|
|||||||
pub mod calc;
|
pub mod calc;
|
||||||
pub mod rickroll;
|
|
||||||
pub mod crystalfetch;
|
|
||||||
pub mod tasks;
|
|
||||||
pub mod crystal_rpg;
|
pub mod crystal_rpg;
|
||||||
|
pub mod crystalfetch;
|
||||||
|
pub mod rickroll;
|
||||||
pub mod shell;
|
pub mod shell;
|
||||||
|
pub mod shellrewrite;
|
||||||
|
pub mod tasks;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
// importing libraries
|
// importing libraries
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
@@ -12,14 +11,13 @@ use alloc::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
kernel::tasks::{Task, Executor},
|
kernel::tasks::{executor::Executor, Task},
|
||||||
applications::*,
|
|
||||||
std::application::{Application, Error},
|
std::application::{Application, Error},
|
||||||
std::io::{stdin, print, println},
|
std::io::{print, println, stdin},
|
||||||
user::bin::*,
|
user::bin::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
// [ 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
|
||||||
@@ -32,15 +30,11 @@ use crate::{
|
|||||||
// - 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// initialises a global tasks struct, this can be accessed from anywhere in the program;
|
/// initialises a global tasks struct, this can be accessed from anywhere in the program;
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref TASKS: Mutex<Vec<Task>> = Mutex::new(Vec::new());
|
pub static ref TASKS: Mutex<Vec<Task>> = Mutex::new(Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// starts the shell
|
/// starts the shell
|
||||||
/// this function should be directly called by main.rs or by an init system
|
/// this function should be directly called by main.rs or by an init system
|
||||||
pub fn init_sh(args: Option<Vec<String>>) -> Result<(), String> {
|
pub fn init_sh(args: Option<Vec<String>>) -> Result<(), String> {
|
||||||
@@ -57,14 +51,13 @@ pub fn init_sh(args: Option<Vec<String>>) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
drop(tasks);
|
drop(tasks);
|
||||||
|
|
||||||
executor.run();
|
executor.try_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_args(command: String) -> Result<(String, Vec<String>), String> {
|
fn parse_args(command: String) -> Result<(String, Vec<String>), String> {
|
||||||
|
|
||||||
let mut args: Vec<String> = Vec::new();
|
let mut args: Vec<String> = Vec::new();
|
||||||
|
|
||||||
for arg in command.split(" ").collect::<Vec<&str>>() {
|
for arg in command.split(" ").collect::<Vec<&str>>() {
|
||||||
@@ -78,7 +71,6 @@ fn parse_args(command: String) -> Result<(String, Vec<String>), String> {
|
|||||||
if args.len() > 0 {
|
if args.len() > 0 {
|
||||||
cmd = args[0].clone();
|
cmd = args[0].clone();
|
||||||
args.remove(0);
|
args.remove(0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return Err("command was empty.".to_string());
|
return Err("command was empty.".to_string());
|
||||||
};
|
};
|
||||||
@@ -86,41 +78,24 @@ fn parse_args(command: String) -> Result<(String, Vec<String>), String> {
|
|||||||
Ok((cmd, args))
|
Ok((cmd, args))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fn run_binary(binary: dyn Application) -> Result<Vec<String>, String> {
|
||||||
fn run_binary(binary: Application) -> Result<Vec<String>, String> {
|
// binary.run();
|
||||||
binary.run()
|
// Ok(Vec::<String::new()>)
|
||||||
Ok(Vec::<String::new()>)
|
//}
|
||||||
}
|
|
||||||
|
|
||||||
async fn next() {
|
async fn next() {
|
||||||
let command: String = stdin();
|
let command: String = stdin();
|
||||||
let parsed = match parse_args(command) {
|
let parsed = match parse_args(command) {
|
||||||
Ok(x) -> x
|
Ok(x) => x,
|
||||||
Err(e) -> {
|
Err(e) => {
|
||||||
println!("Error Parsing Command: Invalid Syntax")
|
println!("Error Parsing Command: Invalid Syntax")
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
// tokens will eventually be parsed here
|
// tokens will eventually be parsed here
|
||||||
|
|
||||||
/*
|
/*
|
||||||
- PARSER
|
- PARSER
|
||||||
- this will allow the use of more complex commands later down the line
|
- this will allow the use of more complex commands later down the line
|
||||||
*/
|
*/
|
||||||
TASKS.lock().push(Task::new(cmd));
|
TASKS.lock().push(Task::new(parsed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user