Crates.io | console-utils |
lib.rs | console-utils |
version | 1.6.0 |
source | src |
created_at | 2023-11-28 14:11:09.554322 |
updated_at | 2024-03-27 17:50:15.542101 |
description | Simple CLI Input and Control Utilities |
homepage | |
repository | https://github.com/nwrenger/console-utils-rs |
max_upload_size | |
id | 1052021 |
size | 27,315 |
A Rust library for console-based user input, option selection, control, and more.
This crate offers utility functions for various console-related operations in Rust programs. From obtaining user input to achieving precise terminal control, its main focus is to remain simple while providing extensive functionality.
To use Console Utils in your Rust project, you can add the following dependency to your Cargo.toml
file:
[dependencies]
console-utils = "1.6.0"
After adding the dependency, you can import the modules you need in your Rust code. For example:
use console_utils::input::{input, select};
use console_utils::control::{flush, clear_line};
use console_utils::input::input;
// Read user input as a string
let user_input: String = input("Enter something: ");
println!("You entered: {}", user_input);
use console_utils::input::select;
let options = [
"Option 1",
"Option 2",
"Option 3",
];
// Allow the user to select one option
let selected_index = select("Select an option:", &options);
println!("Selected option: {}", options[selected_index]);
use console_utils::input::multiselect;
let options = [
"Option 1",
"Option 2",
"Option 3",
];
// Allow the user to select multiple options
let selected_indices = multiselect("Select options:", &options);
println!("Selected indices: {:?}", selected_indices);
use console_utils::control::{flush, clear_line};
// Flush the output buffer to ensure content is displayed immediately
flush();
// Clear the current line in the console
clear_line();
// and more...
// Consult the docs for more details!
use console_utils::read::{read_key};
// Cross-platform key reading
let key = read_key();
println!("Pressed key: {:?}", key);
use console_utils::input::{spinner, SpinnerType};
// Display a standard spinner for 3 seconds
spinner(3.0, SpinnerType::Standard);
// Display a custom spinner for 2 seconds
spinner(2.0, SpinnerType::Custom(vec!["1", "2", "3", "4", "3", "2"]));
use console_utils::input::reveal;
// Display "Hello World!" with a time interval of 0.1 seconds between each character
reveal("Hello World!", 0.1);
For more detailed documentation, please refer to the generated Rust Docs.