Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_console"
version = "0.16.0"
edition = "2021"
version = "0.17.0"
edition = "2024"
authors = ["RichoDemus <git@richodemus.com>"]
homepage = "https://github.com/RichoDemus/bevy-console"
repository = "https://github.com/RichoDemus/bevy-console"
Expand All @@ -10,13 +10,15 @@ license = "MIT"
readme = "README.md"

[dependencies]
bevy = { version = "0.17", default-features = false, features = [
bevy = { version = "0.18", default-features = false, features = [
"std",
"bevy_log",
"keyboard",
"mouse",
] }
clap = { version = "4.5", features = ["derive"] }
bevy_console_derive = { path = "./bevy_console_derive", version = "0.5.0" }
bevy_egui = { version = "0.37", default-features = false, features = [
bevy_egui = { version = "0.39", default-features = false, features = [
"render",
"default_fonts",
] }
Expand All @@ -26,7 +28,7 @@ strip-ansi-escapes = "0.2"
trie-rs = "0.4"

[dev-dependencies]
bevy = { version = "0.17", features = ["std", "bevy_log"] }
bevy = { version = "0.18", features = ["std", "bevy_log", "keyboard", "mouse"] }
color-print = { version = "0.3" }

[workspace]
Expand Down
2 changes: 1 addition & 1 deletion examples/capture_bevy_logs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::log::LogPlugin;
use bevy::{log, prelude::*};
use bevy_console::{make_layer, ConsolePlugin};
use bevy_console::{ConsolePlugin, make_layer};

fn main() {
App::new()
Expand Down
2 changes: 1 addition & 1 deletion examples/completions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::prelude::*;
use bevy_console::{reply, AddConsoleCommand, ConsoleCommand, ConsoleConfiguration, ConsolePlugin};
use bevy_console::{AddConsoleCommand, ConsoleCommand, ConsoleConfiguration, ConsolePlugin, reply};
use clap::{Parser, ValueEnum};

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/log_command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::prelude::*;
use bevy_console::{reply, AddConsoleCommand, ConsoleCommand, ConsolePlugin};
use bevy_console::{AddConsoleCommand, ConsoleCommand, ConsolePlugin, reply};
use clap::Parser;

fn main() {
Expand Down
9 changes: 7 additions & 2 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,14 @@ mod test {
(" ", HashSet::from([])),
(
"ERROR",
HashSet::from([TextFormattingOverride::Foreground(Color32::from_rgb(222, 56, 43))])
HashSet::from([TextFormattingOverride::Foreground(Color32::from_rgb(
222, 56, 43
))])
),
(
" error: Could not find function: Displaying ScriptValue without world access: String(",
HashSet::from([])
),
(" error: Could not find function: Displaying ScriptValue without world access: String(", HashSet::from([])),
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/clear.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bevy::prelude::*;

use crate as bevy_console;
use crate::console::ConsoleState;
use crate::ConsoleCommand;
use crate::console::ConsoleState;
use clap::Parser;

/// Clears the console
Expand Down
2 changes: 1 addition & 1 deletion src/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::prelude::*;
use clap::Parser;

use crate as bevy_console;
use crate::{reply, ConsoleCommand, ConsoleConfiguration};
use crate::{ConsoleCommand, ConsoleConfiguration, reply};

/// Prints available arguments and usage
#[derive(Parser, ConsoleCommand)]
Expand Down
84 changes: 43 additions & 41 deletions src/console.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use bevy::ecs::query::FilteredAccessSet;
use bevy::ecs::resource::Resource;
use bevy::ecs::{
component::Tick,
change_detection::Tick,
system::{ScheduleSystem, SystemMeta, SystemParam},
world::unsafe_world_cell::UnsafeWorldCell,
};
use bevy::platform::hash::FixedState;
use bevy::{input::keyboard::KeyboardInput, prelude::*};
use bevy_egui::egui::{self, Align, ScrollArea, TextEdit};
use bevy_egui::egui::{text::LayoutJob, text_selection::CCursorRange};
use bevy_egui::egui::{Context, Id};
use bevy_egui::egui::{text::LayoutJob, text_selection::CCursorRange};
use bevy_egui::{
egui::{epaint::text::cursor::CCursor, Color32, FontId, TextFormat},
EguiContexts,
egui::{Color32, FontId, TextFormat, epaint::text::cursor::CCursor},
};
use clap::{CommandFactory, FromArgMatches};
use core::str;
Expand All @@ -24,8 +24,8 @@ use std::mem;
use trie_rs::Trie;

use crate::{
color::{parse_ansi_styled_str, TextFormattingOverride},
ConsoleSet,
color::{TextFormattingOverride, parse_ansi_styled_str},
};

type ConsoleCommandEnteredReaderSystemParam =
Expand Down Expand Up @@ -156,46 +156,48 @@ unsafe impl<T: Command> SystemParam for ConsoleCommand<'_, T> {
world: UnsafeWorldCell<'w>,
change_tick: Tick,
) -> Self::Item<'w, 's> {
let mut message_reader = ConsoleCommandEnteredReaderSystemParam::get_param(
&mut state.message_reader,
system_meta,
world,
change_tick,
);
let mut console_line = PrintConsoleLineWriterSystemParam::get_param(
&mut state.console_line,
system_meta,
world,
change_tick,
);

let command = message_reader.read().find_map(|command| {
if T::name() == command.command_name {
let clap_command = T::command().no_binary_name(true);
// .color(clap::ColorChoice::Always);
let arg_matches = clap_command.try_get_matches_from(command.args.iter());

debug!(
"Trying to parse as `{}`. Result: {arg_matches:?}",
command.command_name
);
unsafe {
let mut message_reader = ConsoleCommandEnteredReaderSystemParam::get_param(
&mut state.message_reader,
system_meta,
world,
change_tick,
);
let mut console_line = PrintConsoleLineWriterSystemParam::get_param(
&mut state.console_line,
system_meta,
world,
change_tick,
);

let command = message_reader.read().find_map(|command| {
if T::name() == command.command_name {
let clap_command = T::command().no_binary_name(true);
// .color(clap::ColorChoice::Always);
let arg_matches = clap_command.try_get_matches_from(command.args.iter());

match arg_matches {
Ok(matches) => {
return Some(T::from_arg_matches(&matches));
}
Err(err) => {
console_line.write(PrintConsoleLine::new(err.to_string()));
return Some(Err(err));
debug!(
"Trying to parse as `{}`. Result: {arg_matches:?}",
command.command_name
);

match arg_matches {
Ok(matches) => {
return Some(T::from_arg_matches(&matches));
}
Err(err) => {
console_line.write(PrintConsoleLine::new(err.to_string()));
return Some(Err(err));
}
}
}
}
None
});
None
});

ConsoleCommand {
command,
console_line,
ConsoleCommand {
command,
console_line,
}
}
}
}
Expand Down Expand Up @@ -809,8 +811,8 @@ pub fn block_keyboard_input(

#[cfg(test)]
mod tests {
use bevy::input::keyboard::{Key, NativeKey, NativeKeyCode};
use bevy::input::ButtonState;
use bevy::input::keyboard::{Key, NativeKey, NativeKeyCode};

use super::*;

Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
use bevy::prelude::*;
pub use bevy_console_derive::ConsoleCommand;
use bevy_egui::{EguiPlugin, EguiPreUpdateSet, EguiPrimaryContextPass};
use console::{block_keyboard_input, block_mouse_input, ConsoleCache};
use console::{ConsoleCache, block_keyboard_input, block_mouse_input};
use trie_rs::TrieBuilder;

use crate::commands::clear::{clear_command, ClearCommand};
use crate::commands::exit::{exit_command, ExitCommand};
use crate::commands::help::{help_command, HelpCommand};
use crate::commands::clear::{ClearCommand, clear_command};
use crate::commands::exit::{ExitCommand, exit_command};
use crate::commands::help::{HelpCommand, help_command};
pub use crate::console::{
AddConsoleCommand, Command, ConsoleCommand, ConsoleCommandEntered, ConsoleConfiguration,
ConsoleOpen, NamedCommand, PrintConsoleLine,
};
pub use crate::log::*;

use crate::console::{console_ui, receive_console_line, ConsoleState};
use crate::console::{ConsoleState, console_ui, receive_console_line};
pub use clap;

mod color;
Expand Down