Expand description
§VelvetIO - Simple CLI Input for Rust
Getting user input in Rust CLI apps is annoying. VelvetIO makes it simple.
use velvetio::prelude::*;
let name = ask!("What's your name?");
let age = ask!("How old are you?" => u32);
if confirm!("Do you like Rust?") {
println!("Great choice, {}!", name);
}For complex input, use forms:
use velvetio::prelude::*;
let user_data = form()
.text("name", "Full name")
.number("age", "Age")
.choice("role", "Role", &["User", "Admin"])
.collect();Modules§
Macros§
- ask
- Main macro for getting input
- choose
- confirm
- multi_
select - quick_
form - Quick form macro for simple cases
- quick_
parse - Add Parse impl for types that have FromStr
- try_ask
Structs§
- VelvetIO
Error - Error type for VelvetIO operations
Traits§
- Parse
- Parse strings into Rust types
Functions§
- and
- Both validators must pass
- ask
- Keep asking until we get valid input
- ask_
with_ default - Ask with default - hit enter to use default
- ask_
with_ validation - Ask with validation function
- choose
- Pick one option from a list
- confirm
- Yes/no question
- form
- in_
range - Number is within range (inclusive)
- is_
positive - Number is positive (> 0)
- max_
length - String has at most max characters
- min_
length - String has at least min characters
- multi_
select - Pick multiple options from a list
- not_
empty - String is not empty after trimming
- or
- Either validator can pass
- try_ask
- Try once, return Result instead of retrying