egui_console

Crates.ioegui_console
lib.rsegui_console
version0.2.0
sourcesrc
created_at2024-08-07 00:14:17.501119
updated_at2024-09-28 00:40:25.603347
descriptionA Console Window for egui
homepage
repositoryhttps://github.com/pm100/egui_console
max_upload_size
id1327886
size39,857
(pm100)

documentation

README

A console window for egui

Provides a console window for egui. This is not a shell to the OS its simply a command shell window. Its very useful for providing a command line interface inside a GUI app.

features

  • host in any container
  • persisted (optional) searchable history
  • tab completion for filesystem paths and arbitrary commands

demo

Run it with cargo run -p demo. Type 'help' at the command prompt. Shows integration with https://docs.rs/clap/latest/clap/

image

To see command completeion type 'l'. To see filesystem completion try 'cd s'

use

You need a ConsoleWindow instance in your egui App

pub struct ConsoleDemo {
    // Example stuff:
    label: String,
    #[serde(skip)] // This how you opt-out of serialization of a field
    value: f32,
    console: ConsoleWindow,
}

And then use the builder to instantiate a ConsoleWindow

        ConsoleBuilder::new()
                .prompt(">> ")
                .history_size(20)
                .tab_quote_character('\"')
                .build();

On each ui update cycle call the draw method, passing in the Ui instance that should host the console window. Draw returns a ConsoleEvent enum, at the moment this is either None or the text of the command the user entered.

    let console_response = self.console.draw(ui);
    if let ConsoleEvent::Command(command) = console_response {
        self.console.write(&command);
        self.console.prompt();
    }

The prompt method repromts the user. The sample above simply echoes the command the user entered and then reprompts.

command completion

Tab completion for 'commands' works if the user types part of a command at the prompt; ie it must be the first thing on the line.

You must supply a table of commands for tab completion to work. The console window maintains a Vec<String> of commands. you can modify this table by calling the command_table_mut method. THis returns a mutable reference to the command table.

The demo app loads this from the clap subcommands

Commit count: 39

cargo fmt