#prompt #image #user-input #terminal #cli #ueberzug

selthi

A Rust library for building interactive prompts

12 releases

0.2.7 Aug 2, 2024
0.2.6 Aug 2, 2024
0.2.4 Jul 26, 2024
0.2.0 Jun 27, 2024
0.1.3 Jun 24, 2024

#44 in #prompt

Download history 196/week @ 2024-05-31 43/week @ 2024-06-07 1/week @ 2024-06-14 363/week @ 2024-06-21 205/week @ 2024-06-28 202/week @ 2024-07-05 93/week @ 2024-07-12 2/week @ 2024-07-19 180/week @ 2024-07-26 242/week @ 2024-08-02 7/week @ 2024-08-09 1/week @ 2024-08-16

319 downloads per month
Used in vizer-cli

MIT license

705KB
402 lines

Selthi

Latest Version Docs License

selthi is a library for building interactive prompts, inspired by inquire.

It provides two prompts, one for asking the user to select one option from a given list, with the ability to display images for each option, and other prompt for asking the user for a string.

Demo

Animated GIF making a demonstration of this library

Source

Examples

Examples can be found in the examples directory. Run them to see basic behavior:

cargo run --example images --features with_images

Usage

Add Selthi to your dependencies.

cargo add selthi

* If you want to support images, add the feature with_images

selthi = { version = "0.2.7", features = ["with_images"] }

Prompts

Currently, there are 2 different prompt types supported.

Input

Input displays a message to the user, prompting them to type something back. The user's input is then stored in a String and returned to the prompt caller.

let ans = Input::new("What's your name?").prompt();

match ans {
  Some(name) => println!("Hello {}!", name),
  None => println!("There was an error, please try again"),
}

Animated GIF making a demonstration of a simple prompt with Input created with this library.

Select

Select prompts are suitable for when you need the user to select one option among many.

    let options: Vec<&str> = vec![
        "Rust",
        "C",
        "C++",
        "Javascript",
        "Java",
        "C#",
        "Python",
        "Haskell",
        "Lisp",
        "Erlang",
    ];
    let ans = Select::new("What's your favorite programming language?", options).prompt();

    match ans {
        Some(language) => println!("{} rocks!", language),
        None => println!("There was an error, please try again"),
    }

Animated GIF making a demonstration of a simple prompt with Input created with this library.

You can also display images when users are choosing the options.

    let options: Vec<&str> = vec!["Linux", "Windows", "macOS"];
    let images: Vec<&str> = vec![
        "./examples/images/linux.png",
        "./examples/images/windows.png",
        "./examples/images/macos.png",
    ];

    let ans = Select::new("What's your favorite operating system?", options)
        .with_images(images)
        .without_help_message()
        .prompt();

    match ans {
        Some(os) => println!("{} is a good choice!", os),
        None => println!("There was an error, please try again"),
    }

Dependencies

~0.8–6MB
~20K SLoC