Crates.io | cnsl |
lib.rs | cnsl |
version | 0.1.3 |
source | src |
created_at | 2022-05-17 23:29:56.688149 |
updated_at | 2022-05-27 00:30:18.646943 |
description | A crate that provides methods and macros for interacting with the command line. |
homepage | |
repository | https://www.github.com/imajindevon/cnsl/ |
max_upload_size | |
id | 588649 |
size | 7,206 |
cnsl
is a crate for writing to the standard output, standard error, and reading from standard input.
This crate is lightly coded, and also requires no external dependencies.
// without a prompt
use cnsl::readln;
fn main() {
println!("What is your name?");
let name = readln!();
println!("Hello, {}!", name);
}
// with a prompt
use cnsl::readln;
fn main() {
let name = readln!("Enter your name: ");
println!("Hello, {}!", name);
}
// with a formatted prompt
// note: defaults are not actually supported, this is just a demonstration
use cnsl::readln;
const DEFAULT_AGE: u8 = 18;
fn main() {
let age_input = readln!("Enter your age (default {}): ", DEFAULT_AGE);
let age = if age_input.is_empty() {
DEFAULT_AGE
} else {
age_input.parse::<u8>().expect("invalid input for age")
};
}
This software is licensed under the WTFPL.