Console Utils
A Rust library for console-based user input, option selection, control, and more.
Overview
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.
Usage
To use Console Utils in your Rust project, you can add the following dependency to your Cargo.toml file:
[]
= "1.8.2"
After adding the dependency, you can import the modules you need in your Rust code. For example:
use ;
use ;
Examples
Reading User Input
use ;
// Read user input as a plain string
let text: String = input;
println!;
// Or read user input as a u8; returns Empty(None) if left blank.
let number: = input;
println!;
Selecting Options
Single Option
use select;
let options = ;
// Allow the user to select one option
let selected_index = select;
println!;
Multiple Options
use multiselect;
let options = ;
// Allow the user to select multiple options
let selected_indices = multiselect;
println!;
Text styling
use ;
let text = new
.fg
.bg
.bold
.underline;
// Prints now a `Hello, world!` with red, bold and underlined text on a black background
println!;
Console Control
use ;
// 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!
Reading Key
use ;
// Cross-platform key reading
let key = read_key;
println!;
Displaying a Spinner
use ;
// Display a standard spinner for 3 seconds
spinner;
// Display a custom spinner for 2 seconds
spinner;
Skippable Gradual String Reveal
use ;
// Displays "Hello World!" with 0.1s between characters.
// Tip: Press/hold **Tab** to fast-forward the reveal by decreasing the time between characters to 0.001s.
reveal;
For more detailed documentation, please refer to the generated Rust Docs.