Crates.io | cartographer-rs |
lib.rs | cartographer-rs |
version | 0.1.3 |
source | src |
created_at | 2023-03-07 05:20:00.664076 |
updated_at | 2023-03-07 06:07:41.235953 |
description | A small TUI crate for easily making simple, searchable, menus |
homepage | |
repository | https://github.com/Nickiel12/cartographer |
max_upload_size | |
id | 803308 |
size | 1,160,749 |
Cartographer is a small library using Console and macros to bring “just add water” TUI menus to your programs.
Utilizing the power of macros, you can create an interactive menu in less than 10 lines of code.
The main reason I created this crate, is that other, less menu-specific crates, like Dialoguer, don’t support menu-options that only show up in search results.
See examples for some… Examples of Cartographer’s offerings
(You can find more examples in the examples directory)
A basic example of a multi select menu:
// ./examples/example_menu.rs
use cartographer::{menu, menu_item, MenuOptions};
fn main() {
let options = MenuOptions::new().cursor('➤').selected_indicator('✓');
let menu = menu!(
"So you should try it!: ",
options,
[
menu_item!("Using Cartographer", true, 1),
menu_item!("Making TUI menus", true, 2),
menu_item!("Is easy", true, 3),
menu_item!("Read on for more!", false, 0, ["Ok"])
]
);
let usr_selection = menu.serve().unwrap().unwrap();
println!("\nYou Selected:\n{:?}", usr_selection);
}
Simply run
cargo add cartographer
in your project directory, or add
"cartographer" = "the latest version"
to your Cargo.toml
.
There are two ways you can create a menu.
The macro way, and the manual way.
The macro way is demonstrated in the example above.
An example of the manual way can be found in the examples directory. The manual way uses builder notation and the cartographer::Menu
and cartographer::MenuItem
structs to manually build menus and menu items.
All types handled by this crate are of type String
. The values from prompts, and the return types are all strings, so I would suggest using a solution much like what can be found in the examples to easily match
the return value.
But returned strings will match the supplied prompts including special formatting! So just be careful if you decide to match by strings!
All menu logic is handled behind the scenes once .serve()
is called on a valid Menu
, and the thread will wait for the user to make their selections.
While threading with this library is probably possible (though untested), make sure that there is no terminal output sent by other threads, or visual problems will start to crop up.
To configure how your menu looks, you can use the cartographer::MenuOptions
struct and builder notation to create a configuration.
let options = MenuOptions::new().cursor(’➤’).selectedindicator(’✓’);
The defaults and additional options can found under the docs for MenuOptions.