#fzf #command-line #tui #fuzzy-matcher

bin+lib termenu

A fzf-like library for terminal applications

1 stable release

new 2.3.0 Nov 20, 2024
2.2.3 Nov 19, 2024
2.0.2 Oct 30, 2024
1.1.2 Oct 2, 2024
0.1.3 Sep 30, 2024

#363 in Command-line interface

Download history 1328/week @ 2024-09-30 40/week @ 2024-10-07 33/week @ 2024-10-14 127/week @ 2024-10-28 4/week @ 2024-11-04 580/week @ 2024-11-11

712 downloads per month

MIT license

42KB
973 lines

Termenu

fzf-like terminal ui api for rust

Demo

demo

Install

Add this to your Cargo.toml:

[dependencies]
termenu = "2.2.2" # use latest version

Or with no-pipe feature, check Crate Features for more information.:

[dependencies]
termenu = { version = "2.2.2", features = ["no-pipe"], default-features = false }

This crate also provides a binary(like fzf), you can install it with:

cargo install termenu

Examples

check examples folder

# basic example
cargo run --example basic

# complex example
cargo run --example complex

Use as a library

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);
    }
}

Use as a binary

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)

Crate Features

  • no-pipe This crate depends on crossterm, by default I enabled use-dev-tty feature on crossterm to support pipe input.
    If you don't need to use pipe input, or this feature causes some problems, you can disable it.
    In that way, termenu will only depend on crossterm without any features.

NOTE

  • Currently, termenu does not support window resizing.

Dependencies

~2–15MB
~148K SLoC