1 stable release

new 2.0.2 Oct 30, 2024
2.0.1 Oct 4, 2024
1.1.2 Oct 2, 2024
0.1.4 Oct 1, 2024
0.1.3 Sep 30, 2024

#174 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

243 downloads per month

MIT license

33KB
781 lines

Termenu

fzf-like terminal ui api for rust

Demo

demo

Examples

check examples folder

# basic example
cargo run --example basic

# complex example
cargo run --example complex

Basic Usage

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

NOTE

  • Currently, termenu does not support window resizing.

lib.rs:

A fzf-like library for terminal applications

You can use it to build a menu for selecting items from a list in terminal with ui. It supports both normal mode and query mode, and you can customize the colorscheme.

Demo

demo

Key Mapping

  • j/k or down/up to move the cursor
  • enter to select the item
  • / to enter query mode just like vim
  • ctrl-n/ctrl-p to move the cursor in query mode
  • esc to exit query mode or the menu
  • ctrl-c to exit the menu

Examples

let mut menu = termenu::Menu::new().unwrap();
let mut item_list = Vec::new();
for i in 1..=10 {
   item_list.push(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);
}

Check the examples folder for more details.

Dependencies

~4–12MB
~166K SLoC