Crates.io | interactor |
lib.rs | interactor |
version | 0.1.3 |
source | src |
created_at | 2015-11-12 20:28:30.551489 |
updated_at | 2022-10-01 23:12:41.243959 |
description | A library for simple (usually command-line) user interaction. |
homepage | https://codeberg.org/valpackett/interactor |
repository | https://codeberg.org/valpackett/interactor |
max_upload_size | |
id | 3401 |
size | 12,102 |
A Rust library for simple (usually command-line) user interaction.
A program that accepts a newline-separated list of items on stdin
, presents a UI to the user (directly on /dev/tty
if it's a CLI; can also be a GUI), and outputs the selected item on stdout
.
You should let the users of your application pick their own favorite tool as a config option.
I propose the $MENU
environment variable, like $EDITOR
, as a place to look for user preference.
extern crate interactor;
use std::io::Write;
use interactor::*;
fn main() {
let read_result = read_from_tty(|buf, b, tty| {
tty.write(&format!("({:?} | {})\n", buf, b).into_bytes());
}, false, false).unwrap();
println!("Read: {}", String::from_utf8(read_result).unwrap());
let chosen_ext = pick_from_list(default_menu_cmd().as_mut(), &["first", "second"], "Selection: ").unwrap();
println!("Congratulations, you chose '{}'!!", chosen_ext);
}
This is free and unencumbered software released into the public domain.
For more information, please refer to the UNLICENSE
file or unlicense.org.