Expand description
§bevy_console
A simple Half-Life inspired console with support for argument parsing powered by clap
.
§Features
-
Command parsing with
clap
- Command history
- Command completion
- Support for ansi colors
- Customizable key bindings
- Customizable theme
- Supports capturing Bevy logs to console
§Usage
Add ConsolePlugin
and optionally the resource ConsoleConfiguration
.
ⓘ
use bevy::prelude::*;
use bevy_console::{ConsoleConfiguration, ConsolePlugin};
fn main() {
App::new()
.add_plugins((DefaultPlugins, ConsolePlugin))
.insert_resource(ConsoleConfiguration {
// override config here
..Default::default()
});
}
Create a console command struct and system and add it to your app with .add_console_command
.
Commands are created like clap
commands with an additional CommandName
trait derived via the ConsoleCommand
derive.
Add doc comments to your command to provide help information in the console.
ⓘ
use bevy::prelude::*;
use bevy_console::{reply, AddConsoleCommand, ConsoleCommand, ConsolePlugin};
use clap::Parser;
fn main() {
App::new()
.add_plugins((DefaultPlugins, ConsolePlugin))
.add_console_command::<ExampleCommand, _>(example_command);
}
/// Example command
#[derive(Parser, ConsoleCommand)]
#[command(name = "example")]
struct ExampleCommand {
/// Some message
msg: String,
}
fn example_command(mut log: ConsoleCommand<ExampleCommand>) {
if let Some(Ok(ExampleCommand { msg })) = log.take() {
// handle command
}
}
Examples can be found in the /examples directory.
cargo run --example log_command
§wasm
Should work in wasm, but you need to disable default features.
§Keyboard Shortcuts
Some shortcuts:
- Ctrl + L: Clear history
- Ctrl + C: Clear line
- Tab: Line completion
Re-exports§
pub use clap;
Macros§
- reply
- Reply with the
format!
syntax. - reply_
failed - Reply with the
format!
syntax followed by[failed]
. - reply_
ok - Reply with the
format!
syntax followed by[ok]
.
Structs§
- Bevy
LogBuffer - Buffers logs written by bevy at runtime
- Bevy
LogBuffer Writer - Writer implementation which writes into a buffer resource inside the bevy world
- Console
Command - Executed parsed console command.
- Console
Command Entered - Parsed raw console command into
command
andargs
. - Console
Configuration - Console configuration
- Console
Open - Console open state
- Console
Plugin - Console plugin.
- Print
Console Line - Events to print to the console.
Enums§
- Console
Set - The SystemSet for console/command related systems
Traits§
- AddConsole
Command - Add a console commands to Bevy app.
- Command
- A super-trait for command like structures
- Named
Command - Trait used to allow uniquely identifying commands at compile time
Functions§
- make_
filtered_ layer - Creates a tracing layer which writes logs into a buffer resource inside the bevy world Uses a custom EnvFilter string, allowing for a different subset of log entries to be captured by the console. This is used by the console plugin to capture logs written by bevy
- make_
layer - Creates a tracing layer which writes logs into a buffer resource inside the bevy world This is used by the console plugin to capture logs written by bevy Use make_filtered_layer for more customization options.
- send_
log_ buffer_ to_ console - Flushes the log buffer and sends its content to the console