19 releases (10 breaking)

0.11.1 Mar 1, 2024
0.9.0 Nov 4, 2023
0.8.0 Jul 14, 2023
0.7.0 Mar 18, 2023
0.2.1 Jun 4, 2021

#156 in Game dev

Download history 24/week @ 2023-12-24 34/week @ 2023-12-31 25/week @ 2024-01-07 94/week @ 2024-01-14 59/week @ 2024-01-21 69/week @ 2024-01-28 42/week @ 2024-02-04 32/week @ 2024-02-11 251/week @ 2024-02-18 288/week @ 2024-02-25 238/week @ 2024-03-03 123/week @ 2024-03-10 82/week @ 2024-03-17 48/week @ 2024-03-24 204/week @ 2024-03-31 43/week @ 2024-04-07

392 downloads per month
Used in 2 crates

MIT license

520KB
585 lines

bevy_console

Check

A simple Half-Life inspired console with support for argument parsing powered by clap.

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

~25–63MB
~1M SLoC