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 39/week @ 2024-01-01 24/week @ 2024-01-08 99/week @ 2024-01-15 59/week @ 2024-01-22 76/week @ 2024-01-29 29/week @ 2024-02-05 31/week @ 2024-02-12 256/week @ 2024-02-19 305/week @ 2024-02-26 235/week @ 2024-03-04 110/week @ 2024-03-11 80/week @ 2024-03-18 46/week @ 2024-03-25 206/week @ 2024-04-01 74/week @ 2024-04-08 99/week @ 2024-04-15

431 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

~24–62MB
~1M SLoC