feat: basic GUI terminal when pressing F12

This commit is contained in:
Chance 2025-04-10 14:26:52 -04:00
parent bb9bca8ca5
commit 0acbbcf9f6
Signed by: caznix
GPG key ID: 489D213143D753FD
15 changed files with 808 additions and 826 deletions

View file

@ -16,13 +16,8 @@ use tracing::{debug, error, info, warn};
use super::handler::COMMAND_MANAGER;
use crate::error::{Result, ZenyxError, ZenyxErrorKind};
#[derive(Default)]
struct CommandCompleter;
impl CommandCompleter {
fn new() -> Self {
CommandCompleter {}
}
}
impl Completer for CommandCompleter {
type Candidate = String;
@ -138,15 +133,19 @@ pub fn parse_command(input: &str) -> Result<Vec<String>> {
Ok(commands)
}
pub fn evaluate_command(input: &str) -> Result<()> {
pub fn evaluate_command(input: &str) -> std::result::Result<String, ZenyxError> {
if input.trim().is_empty() {
return Ok(());
let err = ZenyxError::builder(ZenyxErrorKind::CommandParsing)
.with_message("Input was empty")
.build();
return Err(err);
}
let commands = input
.split(|c| c == ';' || c == '\n')
.map(|slice| slice.to_string())
.collect::<Vec<String>>();
let mut output = String::new();
for command in commands {
let command = command.trim();
@ -166,20 +165,16 @@ pub fn evaluate_command(input: &str) -> Result<()> {
} else {
None
};
COMMAND_MANAGER
.read()
.execute(cmd_name, args)
.map_err(|e| {
ZenyxError::builder(ZenyxErrorKind::CommandExecution)
.with_message(format!("Failed to execute command: {cmd_name}"))
.with_context(format!("{e}"))
.build()
})?;
match COMMAND_MANAGER.read().execute(cmd_name, args) {
Ok(command_output) => output.push_str(&command_output),
Err(e) => {
return Err(e);
}
}
}
Ok(())
Ok(output)
}
fn format_time() -> String {
pub fn format_time() -> String {
let now = SystemTime::now();
let duration = now.duration_since(UNIX_EPOCH).unwrap();
let total_seconds = duration.as_secs();
@ -201,7 +196,7 @@ pub async fn handle_repl() -> Result<()> {
let mut rl = Editor::<MyHelper, DefaultHistory>::new()?;
rl.set_helper(Some(MyHelper {
hinter: HistoryHinter::new(),
completer: CommandCompleter::new(),
completer: CommandCompleter::default(),
}));
rl.bind_sequence(
@ -218,6 +213,7 @@ pub async fn handle_repl() -> Result<()> {
loop {
let time = format_time();
let prompt = format!("[{}/{}] {}", time, "SHELL", ">>\t");
let sig = rl.readline(&prompt.bright_white());
match sig {