14 releases (6 breaking)

0.7.0 Mar 18, 2023
0.5.0 Dec 20, 2022
0.4.0 Aug 10, 2022
0.3.1 Apr 27, 2022
0.2.1 Jun 4, 2021

#275 in Game dev

Download history 131/week @ 2022-12-04 108/week @ 2022-12-11 51/week @ 2022-12-18 68/week @ 2022-12-25 31/week @ 2023-01-01 79/week @ 2023-01-08 30/week @ 2023-01-15 95/week @ 2023-01-22 54/week @ 2023-01-29 56/week @ 2023-02-05 62/week @ 2023-02-12 70/week @ 2023-02-19 12/week @ 2023-02-26 54/week @ 2023-03-05 85/week @ 2023-03-12 181/week @ 2023-03-19

332 downloads per month
Used in 2 crates

MIT license

515KB
584 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)
        .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

~25–60MB
~1M SLoC