22 releases (12 breaking)

new 0.13.0 Dec 2, 2024
0.12.1 Sep 7, 2024
0.11.1 Mar 1, 2024
0.9.0 Nov 4, 2023
0.2.1 Jun 4, 2021

#84 in Game dev

Download history 37/week @ 2024-08-16 28/week @ 2024-08-23 55/week @ 2024-08-30 446/week @ 2024-09-06 44/week @ 2024-09-13 85/week @ 2024-09-20 90/week @ 2024-09-27 32/week @ 2024-10-04 25/week @ 2024-10-11 13/week @ 2024-10-18 10/week @ 2024-10-25 88/week @ 2024-11-01 29/week @ 2024-11-08 16/week @ 2024-11-15 20/week @ 2024-11-22 297/week @ 2024-11-29

373 downloads per month
Used in 2 crates

MIT license

93KB
999 lines

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 ansii 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.

Dependencies

~38–75MB
~1.5M SLoC