3 releases (breaking)

0.5.0 Jan 9, 2023
0.4.0 Dec 20, 2022
0.3.0 Feb 27, 2022

#144 in #clap

Download history 62/week @ 2024-07-22 117/week @ 2024-07-29 88/week @ 2024-08-05 73/week @ 2024-08-12 70/week @ 2024-08-19 69/week @ 2024-08-26 138/week @ 2024-09-02 63/week @ 2024-09-09 33/week @ 2024-09-16 76/week @ 2024-09-23 64/week @ 2024-09-30 14/week @ 2024-10-07 47/week @ 2024-10-14 34/week @ 2024-10-21 87/week @ 2024-10-28 67/week @ 2024-11-04

236 downloads per month
Used in 3 crates (via bevy_console)

MIT license

6KB

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)
        .add_plugin(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)
        .add_plugin(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

~1.5MB
~39K SLoC