From 78144a4f60f66905f1a5ade957b744c60c672135 Mon Sep 17 00:00:00 2001 From: FantasyPvP Date: Mon, 13 Mar 2023 00:30:52 +0000 Subject: [PATCH] . . --- src/user/bin/mod.rs | 9 +++--- src/user/bin/shellrewrite.rs | 59 +++++++++++------------------------- 2 files changed, 22 insertions(+), 46 deletions(-) diff --git a/src/user/bin/mod.rs b/src/user/bin/mod.rs index bb8f9b9..d643a6c 100644 --- a/src/user/bin/mod.rs +++ b/src/user/bin/mod.rs @@ -1,6 +1,7 @@ pub mod calc; -pub mod rickroll; -pub mod crystalfetch; -pub mod tasks; pub mod crystal_rpg; -pub mod shell; \ No newline at end of file +pub mod crystalfetch; +pub mod rickroll; +pub mod shell; +pub mod shellrewrite; +pub mod tasks; diff --git a/src/user/bin/shellrewrite.rs b/src/user/bin/shellrewrite.rs index f5e9ab3..7ac247c 100644 --- a/src/user/bin/shellrewrite.rs +++ b/src/user/bin/shellrewrite.rs @@ -1,4 +1,3 @@ - // importing libraries use async_trait::async_trait; use lazy_static::lazy_static; @@ -12,14 +11,13 @@ use alloc::{ }; use crate::{ - kernel::tasks::{Task, Executor}, - applications::*, + kernel::tasks::{executor::Executor, Task}, std::application::{Application, Error}, - std::io::{stdin, print, println}, + std::io::{print, println, stdin}, user::bin::*, }; - +use super::*; // [ CRYSTAL SHELL ] // 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 // 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; lazy_static! { pub static ref TASKS: Mutex> = 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>) -> Result<(), String> { @@ -48,7 +42,7 @@ pub fn init_sh(args: Option>) -> Result<(), String> { loop { executor.spawn(Task::new(next())); - + let tasks = TASKS.lock(); while tasks.len() > 0 { let next = tasks[0].clone(); @@ -57,70 +51,51 @@ pub fn init_sh(args: Option>) -> Result<(), String> { } drop(tasks); - executor.run(); + executor.try_run(); } - + Ok(()) } fn parse_args(command: String) -> Result<(String, Vec), String> { - let mut args: Vec = Vec::new(); - + for arg in command.split(" ").collect::>() { 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, String> { - binary.run() - Ok(Vec::) -} +//fn run_binary(binary: dyn Application) -> Result, String> { +// binary.run(); +// Ok(Vec::) +//} async fn next() { let command: String = stdin(); let parsed = match parse_args(command) { - Ok(x) -> x - Err(e) -> { + 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)); + TASKS.lock().push(Task::new(parsed)); } - - - - - - - - - - - - - - - -