Crate bevy_console

Source
Expand description

§bevy_console

Check

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§

BevyLogBuffer
Buffers logs written by bevy at runtime
BevyLogBufferWriter
Writer implementation which writes into a buffer resource inside the bevy world
ConsoleCommand
Executed parsed console command.
ConsoleCommandEntered
Parsed raw console command into command and args.
ConsoleConfiguration
Console configuration
ConsoleOpen
Console open state
ConsolePlugin
Console plugin.
PrintConsoleLine
Events to print to the console.

Enums§

ConsoleSet
The SystemSet for console/command related systems

Traits§

AddConsoleCommand
Add a console commands to Bevy app.
Command
A super-trait for command like structures
NamedCommand
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

Derive Macros§

ConsoleCommand