VelvetIO
CLI input for Rust that doesn't suck.
Tired of wrestling with stdin().read_line() and manual parsing? VelvetIO handles the annoying stuff so you can focus on building your CLI tool.
use *;
let name = ask!;
let age = ask!;
if confirm!
Installation
[]
= "0.1"
Features
- Actually zero dependencies - No bloat, fast builds
- Type-safe parsing - Works with any type that makes sense
- Smart validation - Built-in validators + custom functions
- Form builder - Collect multiple inputs without repetition
- Helpful errors - Clear messages when things go wrong
- Flexible - Start simple, add complexity as needed
Quick Examples
Basic Input
use *;
// Strings (most common)
let name = ask!;
// Numbers
let port = ask!;
let price = ask!;
// Booleans (accepts y/n, yes/no, true/false, 1/0)
let enabled = ask!;
Input with Defaults
// Hit enter to use the default
let host = ask!;
let port = ask!;
// Try once, fall back if parsing fails
let timeout = ask!;
Validation
// Simple validation
let email = ask!;
// With custom error message
let username = ask!;
// Built-in validators
let password = ask!;
Choice Selection
// Pick one
let os = choose!;
// Pick multiple (comma-separated: 1,3,5 or "all" or "none")
let features = multi_select!;
Yes/No Questions
let proceed = confirm!;
let save_config = confirm!;
Form Builder
For collecting multiple related inputs:
let config = form
.text
.number
.boolean
.choice
.multi_choice
.optional
.validated_text
.collect;
// Access values
let app_name = config.get.unwrap;
let port: u16 = config.get.unwrap.parse.unwrap;
Quick Forms
For simple cases:
let info = quick_form! ;
Advanced Type Parsing
VelvetIO parses many types automatically:
Collections
// Vec - detects separators automatically
let numbers: = ask!;
// Input: "1,2,3" or "1 2 3" or "1;2;3" or "1|2|3"
let tags: = ask!;
// Input: "rust,cli,tool"
Tuples
// Pairs
let coords: = ask!;
// Input: "40.7,-74.0" or "40.7 -74.0"
// Triples
let rgb: = ask!;
// Input: "255,128,0"
Optional Values
let backup_email: = ask!;
// Empty input, "none", "null", "-", or "skip" becomes None
// Anything else gets parsed as Some(value)
Custom Types
Make your own types work with VelvetIO:
;
// Add parsing support
quick_parse!;
// Now you can use it
let user_id = ask!;
Validation
Built-in Validators
// String validators
not_empty // String is not empty
min_length // At least n characters
max_length // At most n characters
// Number validators
is_positive // Greater than zero
in_range // Between min and max (inclusive)
// Combining validators
and // Both must pass
or // Either can pass
Custom Validators
// Email validation
let email = ask!;
// Port range
let port = ask!;
// Complex validation
let username = ask!;
Error Handling
Most functions retry automatically on invalid input. Use try_ask! if you want to handle errors yourself:
match try_ask!
Boolean Parsing
Accepts many formats:
| Input | Result |
|---|---|
y, yes, true, t, 1, on |
true |
n, no, false, f, 0, off |
false |
Case insensitive.
Important Notes
Passwords
VelvetIO doesn't include password input to keep zero dependencies. For secure password input, use the rpassword crate:
[]
= "0.1"
= "7.0"
use *;
let username = ask!;
let password = prompt_password.unwrap;
Performance
- Input is read synchronously (blocks until user responds)
- Form building is cheap - only prompts when you call
.collect() - Vec parsing pre-allocates based on detected items
- No heap allocations for simple types
Thread Safety
VelvetIO uses stdin()/stdout() which are globally shared. Don't use from multiple threads simultaneously.
Examples
Check out examples/setup_wizard.rs for a comprehensive demo:
Comparison with Other Crates
| Feature | VelvetIO | dialoguer | inquire |
|---|---|---|---|
| Dependencies | 0 | 3+ | 5+ |
| Forms | ✅ Elegant | ❌ None | ❌ None |
| API | ask!("Name") |
Verbose builders | Complex setup |
| Type parsing | ✅ Automatic | ❌ Manual | ❌ Manual |
| Maintenance | ✅ Active | ⚠️ Stagnant | ⚠️ Slow |
Common Patterns
Configuration Wizard
let config = form
.text
.choice
.multi_choice
.boolean
.collect;
User Registration
let username = ask!;
let email = ask!;
let age: = ask!;
Server Configuration
let host = ask!;
let port = ask!;
let workers = ask!;
let ssl = confirm!;
if ssl
Contributing
Found a bug or want to add a feature? PRs welcome!
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.