diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..db8f0db --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,12 @@ +{ + "name": "Rust Development Environment", + "image": "rust:latest", + "customizations": { + "vscode": { + "extensions": [ + "rust-lang.rust-analyzer" + ] + } + }, + "postCreateCommand": "apt-get update && apt-get install g++ pkg-config libx11-dev libasound2-dev libudev-dev libxkbcommon-x11-0" +} \ No newline at end of file diff --git a/src/console.rs b/src/console.rs index 4c6c78a..242d3ed 100644 --- a/src/console.rs +++ b/src/console.rs @@ -191,17 +191,30 @@ pub struct ConsoleCommandEntered { pub args: Vec, } +/// Resource representing the Last Console Line +#[derive(Resource, Debug, Clone, Eq, PartialEq, Default)] +pub struct LastConsoleLine{ + pub line: String +} + /// Events to print to the console. #[derive(Clone, Debug, Eq, Event, PartialEq)] pub struct PrintConsoleLine { /// Console line pub line: String, + /// Whether the line should print + pub should_print: bool } impl PrintConsoleLine { /// Creates a new console line to print. pub const fn new(line: String) -> Self { - Self { line } + Self { line, should_print: true } + } + + /// Creates a new console line which doesn't print. + pub const fn quiet(line: String) -> Self{ + Self { line, should_print: false} } } @@ -516,27 +529,41 @@ pub(crate) fn console_ui( state.history.pop_back(); } - let mut args = Shlex::new(&state.buf).collect::>(); - - if !args.is_empty() { - let command_name = args.remove(0); - debug!("Command entered: `{command_name}`, with args: `{args:?}`"); - - let command = config.commands.get(command_name.as_str()); + //Use Shlex to Get Commands to Run + let mut commands_to_run: Vec> = vec![Vec::new()]; + for arg in Shlex::new(&state.buf){ + if arg == "|"{ + commands_to_run.push(Vec::new()); + }else{ + commands_to_run.last_mut().unwrap().push(arg); + } + } - if command.is_some() { - command_entered - .send(ConsoleCommandEntered { command_name, args }); + //Get the first bad command that is not registered + if let Some(bad_command) = commands_to_run.iter().find_map(|command_to_run| { + if !command_to_run.is_empty() && config.commands.get(command_to_run.first().unwrap().as_str()).is_none() { + Some(command_to_run.first().unwrap()) } else { - debug!( - "Command not recognized, recognized commands: `{:?}`", - config.commands.keys().collect::>() - ); + None + } + }) { + debug!( + "Command not recognized: {}, recognized commands: `{:?}`", + bad_command, + config.commands.keys().collect::>() + ); - state.scrollback.push("error: Invalid command".into()); + state.scrollback.push("error: Invalid command".into()); + } else { + for mut command_args in commands_to_run{ + if !command_args.is_empty(){ + let command_name = command_args.remove(0); + debug!("Command entered: `{command_name}`, with args: `{command_args:?}`"); + command_entered + .send(ConsoleCommandEntered { command_name, args: command_args }); + } } } - state.buf.clear(); } } @@ -586,10 +613,14 @@ pub(crate) fn console_ui( pub(crate) fn receive_console_line( mut console_state: ResMut, mut events: EventReader, + mut last_line: ResMut ) { for event in events.read() { let event: &PrintConsoleLine = event; - console_state.scrollback.push(event.line.clone()); + if event.should_print{ + console_state.scrollback.push(event.line.clone()); + } + last_line.line = event.line.clone(); } } diff --git a/src/lib.rs b/src/lib.rs index 816b160..d86f46c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ use bevy::prelude::*; pub use bevy_console_derive::ConsoleCommand; use bevy_egui::EguiPlugin; +use console::LastConsoleLine; use crate::commands::clear::{clear_command, ClearCommand}; use crate::commands::exit::{exit_command, ExitCommand}; @@ -52,6 +53,7 @@ impl Plugin for ConsolePlugin { app.init_resource::() .init_resource::() .init_resource::() + .init_resource::() .add_event::() .add_event::() .add_console_command::(clear_command) diff --git a/src/log.rs b/src/log.rs index 745c7f6..9d77586 100644 --- a/src/log.rs +++ b/src/log.rs @@ -51,7 +51,7 @@ pub fn send_log_buffer_to_console( // read and clean buffer let buffer = buffer.get_mut(); for line in buffer.lines().map_while(Result::ok) { - console_lines.send(PrintConsoleLine { line }); + console_lines.send(PrintConsoleLine::new(line)); } buffer.clear(); }