9 releases (4 breaking)

0.5.0 Sep 1, 2022
0.4.1 Jul 7, 2022
0.4.0 Jun 4, 2022
0.3.0 Jan 18, 2022
0.1.1 Jul 17, 2021

#82 in Command-line interface

Download history 1395/week @ 2023-12-07 1439/week @ 2023-12-14 3439/week @ 2023-12-21 3349/week @ 2023-12-28 4533/week @ 2024-01-04 3960/week @ 2024-01-11 3933/week @ 2024-01-18 4087/week @ 2024-01-25 3979/week @ 2024-02-01 3895/week @ 2024-02-08 3368/week @ 2024-02-15 3591/week @ 2024-02-22 3432/week @ 2024-02-29 4216/week @ 2024-03-07 4016/week @ 2024-03-14 2421/week @ 2024-03-21

14,587 downloads per month
Used in 44 crates (39 directly)

MIT license

475KB
10K SLoC

Requestty

RustCI RustCI RustCI Crates.io License Documentation

requestty (request-tty) is an easy-to-use collection of interactive cli prompts inspired by Inquirer.js.

  • Easy-to-use - The builder API and macros allow you to easily configure and use the in-built prompts.

  • Extensible - Easily create and use custom prompts with a companion ui rendering library.

  • Flexible - All prompts can be used standalone or chained together.

  • Dynamic - You can dynamically decide what questions should be asked based on previous questions.

  • Validation - You can validate user input with any prompt.

  • Examples - Every prompt is accompanied with an example as well as other examples for more complex workflows

Usage

Add this to your Cargo.toml

[dependencies]
requestty = "0.4.1"

To ask a question:

let question = requestty::Question::expand("overwrite")
    .message("Conflict on `file.rs`")
    .choices(vec![
        ('y', "Overwrite"),
        ('a', "Overwrite this one and all next"),
        ('d', "Show diff"),
    ])
    .default_separator()
    .choice('x', "Abort")
    .build();

println!("{:#?}", requestty::prompt_one(question));

More examples are available in the documentation and the examples directory.

In-built prompts

There are 11 in-built prompts:

  • Input

    Prompt that takes user input and returns a String.

  • Password

    Prompt that takes user input and hides it.

  • Editor

    Prompt that takes launches the users preferred editor on a temporary file

  • Confirm

    Prompt that returns true or false.

  • Int

    Prompt that takes a i64 as input.

  • Float

    Prompt that takes a f64 as input.

  • Expand

    Prompt that allows the user to select from a list of options by key

  • Select

    Prompt that allows the user to select from a list of options

  • RawSelect

    Prompt that allows the user to select from a list of options with indices

  • MultiSelect

    Prompt that allows the user to select multiple items from a list of options

  • OrderSelect

    Prompt that allows the user to organize a list of options.

Optional features

  • macros: Enabling this feature will allow you to use the questions and prompt_module macros.

  • smallvec (default): Enabling this feature will use SmallVec instead of Vec for auto completions. This allows inlining single completions.

  • crossterm (default): Enabling this feature will use the crossterm library for terminal interactions such as drawing and receiving events.

  • termion: Enabling this feature will use the termion library for terminal interactions such as drawing and receiving events.

Minimum Supported Rust Version (MSRV)

Minimum supported rust version (as per cargo-msrv) is 1.56.1

Dependencies

~3–13MB
~138K SLoC