Crates.io | zen-console-input |
lib.rs | zen-console-input |
version | 1.0.0 |
source | src |
created_at | 2024-09-05 23:34:02.468578 |
updated_at | 2024-10-15 09:32:59.143317 |
description | Simple but full fledged CLI |
homepage | |
repository | https://github.com/yuuhikaze/zen-console-input |
max_upload_size | |
id | 1365271 |
size | 23,548 |
ZenConsoleInput is a simple, cross-platform console input library for Rust. It provides an easy-to-use interface for getting various types of user input from the console, including single-line input, multiline input, password input, and selection from a list of options.
Add this to your Cargo.toml
:
[dependencies]
zen_console_input = "0.1.0"
If you want to use the external editor feature, add this instead:
[dependencies]
zen_console_input = { version = "0.1.0", features = ["editor"] }
Here's a quick example of how to use ZenConsoleInput:
use zen_console_input::ZenConsoleInput;
fn main() {
let zci = ZenConsoleInput::new();
// Simple input
let name = zci.input().message("Enter your name: ").get_input();
println!("Hello, {}!", name);
// Input with default value
let age: u32 = zci
.input()
.message("Enter your age [19]: ")
.default("19")
.get_parsed_input();
println!("You are {} years old.", age);
// Multiline input (with optional editor support)
let bio = zci
.input()
.message("Enter your bio")
.multiline()
.get_input();
println!("Your bio:\n{}", bio);
// Selection
let favorite_color = zci
.selection()
.message("Choose your favorite color")
.options(vec![
"Red".to_string(),
"Green".to_string(),
"Blue".to_string(),
])
.get_selection();
println!("Your favorite color is {}", favorite_color);
// Password
let password = zci
.password()
.message("Enter your password: ")
.get_password();
println!("Your password is {} characters long", password.len());
}
The code provided above is already included as an example, and can be executed with cargo run --example demo
or cargo run --example demo --features="editor"
.
If you've enabled the editor
feature, you can use an external editor for multiline input. When in multiline input mode, type @e
on a blank line and press Enter to open your default text editor (set by the EDITOR
environment variable, or vi
if not set).
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.