Crates.io | claui |
lib.rs | claui |
version | 0.4.0 |
source | src |
created_at | 2022-05-20 15:21:27.874441 |
updated_at | 2024-09-20 09:16:07.568316 |
description | A GUI generator for clap using egui. |
homepage | https://github.com/grantshandy/claui |
repository | https://github.com/grantshandy/claui |
max_upload_size | |
id | 590338 |
size | 237,832 |
Command Line Arguments (to graphical) User Interface
A GUI generator for clap
that uses egui
.
use clap::{arg, Command};
fn main() {
let app = Command::new("Builder Greeter")
.author("Grant Handy <grantshandy@gmail.com>")
.version("1.2.3")
.about("A builder example for claui")
.arg(arg!(--name "Your name").default_value("Joe"))
.arg(arg!(--goodbye "Say goodbye"));
claui::run(app, |matches| {
println!("Hello, {}!", matches.get_one::<String>("name").unwrap());
if matches.get_flag("goodbye") {
println!("Goodbye!");
}
});
}
use clap::{CommandFactory, Parser};
#[derive(Parser, Debug)]
#[clap(
name = "Derive Greeter",
author = "Grant Handy <grantshandy@gmail.com>",
version = "1.2.3",
about = "A derive example for claui"
)]
struct Args {
#[clap(long, default_value = "Joe", help = "Your name")]
name: String,
#[clap(long, help = "Say goodbye")]
goodbye: bool,
}
fn main() {
let app = Args::command();
claui::run(app, |matches| {
println!("Hello, {}!", matches.get_one::<String>("name").unwrap());
if matches.get_flag("goodbye") {
println!("Goodbye!");
}
});
}
klask
Klask is another GUI generator for clap
that uses egui
, but claui and klask work in different ways. Klask runs your code by running itself as a child with an environment variable to ignore its GUI, then capturing the child's stdout. Claui only runs one process; it spawns your code in another thread and then reroutes all of your stdout into a buffer on each frame through shh
.