1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Console Utils - 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.
//!
//! # Getting Started
//!
//! To use Console Utils in your Rust project, you can add the following dependency to your `Cargo.toml` file:
//!
//! ```toml
//! [dependencies]
//! console-utils = "1.5.4"
//! ```
//!
//! After adding the dependency, you can import the modules you need in your Rust code. For example:
//!
//! ```rust
//! use console_utils::input::{input, select};
//! use console_utils::control::{flush, clear_line};
//! ```
//!
//! # Examples
//!
//! ## Reading User Input
//!
//! ```no_run
//! use console_utils::input::input;
//!
//! // Read user input as a string
//! let user_input: Option<String> = input("Enter something: ", false);
//!
//! match user_input {
//!     Some(value) => println!("You entered: {}", value),
//!     None => panic!("Input cannot be None when 'allow_empty' is set to false."),
//! }
//! ```
//!
//! ## Selecting Options
//!
//! ```no_run
//! use console_utils::input::select;
//!
//! let options = vec![
//!     "Option 1",
//!     "Option 2",
//!     "Option 3",
//! ];
//!
//! // Allow the user to select one option
//! let selected_indices = select("Select an option:", &options, false, false);
//!
//! match selected_indices {
//!     Some(indices) => println!("Selected indices: {:?}", indices),
//!     None => panic!("The Options cannot be None, allow_empty is false."),
//! }
//! ```
//!
//! ## Console Control
//!
//! ```rust
//! 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();
//! ```
//!
//! ## Displaying a Spinner
//!
//! ```rust
//! 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"]));
//! ```
//!
//! ## Gradual String Reveal
//!
//! ```rust
//! use console_utils::input::reveal;
//!
//! // Display "Hello World!" with a time interval of 0.1 seconds between each character
//! reveal("Hello World!", 0.1);
//! ```

pub mod control;
pub mod input;
pub mod read;