Expand description
Lightweight CLI prompting library.
This crate provides utility traits and types to prompt values from the user in a CLI, in a more convenient way. It also allows you to customize the style of the prompts.
For example, you can ask the user for a written value:
let age = ineed::written::<u8>("How old are you?").prompt().unwrap();When running this instruction, it will print something similar to this:
- How old are you?
>If the user enters an invalid input, the prompt is repeated.
You can customize the prompt’s format:
let age = ineed::written::<u8>("How old are you?")
.fmt(ineed::fmt().input_prefix(">> ").msg_prefix("-> "))
.prompt()
.unwrap();Which will print:
-> How old are you?
>>There are a lot of other promptable types: selected prompt, password, boolean values,
etc. All the promptable types implement the Promptable trait, and support their own set of
custom format rules.
There are also promptable wrappers, with the same design as Rust’s iterator combination pattern. For example, you can filter the output of a prompt, map the result into another value, and chain it with another prompt:
enum Age {
Minor,
LegalAge,
}
let (age, name) = ineed::written::<u8>("Your age")
.until(|age| *age > 3 && *age < 120)
.map(|age| match age {
..18 => Age::Minor,
_ => Age::LegalAge,
})
.then(ineed::written::<String>("Your name"))
.prompt()
.unwrap();Re-exports§
pub use format::fmt;
Modules§
- format
- Module exposing types to customize prompt styling.
- prelude
- Exposes some traits to access their methods more conveniently.
Structs§
- Bool
- Promptable type for boolean inputs, like yes or no.
- Formatted
- Wrapper for promptable types to customize the prompt format.
- Many
Written - Promptable type for many written inputs with different types.
- Map
- Wrapper for promptable types to map the output into another value.
- MaxTries
- Wrapper for promptable types to limit the amount of tries before having a correct input.
- MaxTries
Exceeded - Raised when the user exceeded the maximum amount of tries.
- Password
rpassword - Promptable type for passwords.
- Selected
- Promptable type for selectable inputs.
- Separated
- Promptable type for separated inputs of the same type.
- Then
- Wrapper for chaining prompts.
- Until
- Wrapper for promptable types to add a validator on the output.
- Written
- Promptable type for written inputs.
Traits§
- Flattenable
- Represents promptable types that have an output type that is flattenable.
- From
Output - Used to convert a raw output into a proper output.
- Promptable
- Represents types that can be prompted to the console.
Functions§
- bool
- Returns a type that prompts the user for a boolean value, in a natural way.
- many_
written - Returns a type that prompts the user for a determined amount of written values.
- password
rpassword - Returns a type that prompts a password to the user.
- selected
- Returns a type that prompts the user a selectable value.
- separated
- Returns a type that prompts the user for an indeterminate amount of written values.
- written
- Returns a type that prompts the user for a written input.