Crates.io | termenu |
lib.rs | termenu |
version | 2.3.0 |
source | src |
created_at | 2024-09-30 13:23:38.925164 |
updated_at | 2024-11-20 07:06:57.834833 |
description | A fzf-like library for terminal applications |
homepage | |
repository | https://github.com/sshelll/termenu |
max_upload_size | |
id | 1391707 |
size | 66,073 |
fzf-like terminal ui api for rust
Add this to your Cargo.toml
:
[dependencies]
termenu = "2.3.0" # use latest version
Or with no-pipe
feature, check Crate Features for more information.:
[dependencies]
termenu = { version = "2.3.0", features = ["no-pipe"], default-features = false }
This crate also provides a binary(like fzf
), you can install it with:
cargo install termenu
check examples folder
# basic example
cargo run --example basic
# complex example
cargo run --example complex
fn main() {
let mut menu = termenu::Menu::new().unwrap();
let mut item_list = Vec::new();
for i in 1..=10 {
item_list.push(termenu::Item::new(format!("{}th item", i).as_str(), i));
}
let selection = menu
.set_title("test selection:")
.add_list(item_list)
.select()
.unwrap();
if let Some(selection) = selection {
println!("You selected: {}", selection);
}
}
termenu binary is similar to fzf
, but it's quite simple and has fewer features.
It only reads from stdin and prints the selected item to stdout.
Use it like this:
# basic
echo '1st item\n2nd item\n3rd item' | termenu
# more complicated
echo $(echo '1st item\n2nd item\n3rd item' | termenu | grep item)
crossterm
, by default I enabled use-dev-tty
feature on crossterm
to support pipe input.termenu
will only depend on crossterm
without any features.