| Crates.io | ter_menu |
| lib.rs | ter_menu |
| version | 0.1.4 |
| created_at | 2025-11-01 12:03:33.546492+00 |
| updated_at | 2025-11-01 16:19:04.574888+00 |
| description | A terminal-based interactive dropdown selection component |
| homepage | https://github.com/ordinaryday-my/ter_menu |
| repository | https://github.com/ordinaryday-my/ter_menu.git |
| max_upload_size | |
| id | 1911941 |
| size | 22,421 |
A terminal-based interactive dropdown selection component for Rust, enabling users to navigate options with keyboard arrows, confirm selections with Enter, and cancel with Escape.
TerminalDropDown provides an interactive terminal interface for selecting options from a list. It leverages raw terminal mode (via crossterm) for low-level input handling and offers visual feedback with highlighted selected items, making it ideal for CLI applications requiring user input selection.
Arc and Mutex for shared state managementAdd this to your Cargo.toml:
[dependencies]
terminal_dropdown = "0.1.0" # Replace with actual version
crossterm = "0.27.0"
use std::collections::HashMap;
use terminal_dropdown::TerminalDropDown;
fn main() {
// Create a HashMap of options and their callback functions
let mut options: HashMap<&str, Box<dyn FnMut(&&str) + Send>> = HashMap::new();
options.insert("File 1.txt", Box::new(|selected| {
println!("Processing selected file: {}", selected);
// Add custom logic for handling "File 1.txt"
}));
options.insert("File 2.txt", Box::new(|selected| {
println!("Opening: {}", selected);
// Add custom logic for handling "File 2.txt"
}));
options.insert("File 3.txt", Box::new(|selected| {
println!("Deleting: {}", selected);
// Add custom logic for handling "File 3.txt"
}));
// Create and start the dropdown with a maximum of 5 visible items
let dropdown = TerminalDropDown::use_drop_down(options, 5);
// Wait for user interaction to complete
if let Err(e) = dropdown.wait() {
eprintln!("Error during dropdown interaction: {}", e);
}
}