Crates.io | egui_console |
lib.rs | egui_console |
version | 0.2.0 |
source | src |
created_at | 2024-08-07 00:14:17.501119 |
updated_at | 2024-09-28 00:40:25.603347 |
description | A Console Window for egui |
homepage | |
repository | https://github.com/pm100/egui_console |
max_upload_size | |
id | 1327886 |
size | 39,857 |
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.
Run it with cargo run -p demo
. Type 'help' at the command prompt. Shows integration with https://docs.rs/clap/latest/clap/
To see command completeion type 'l
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.
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