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
//! # Terminal CLI
//!
//! Need to build an interactive command prompt, with commands, properties and with full autocomplete? This is for you.
//!
//! [](https://travis-ci.org/hashmismatch/terminal_cli.rs)
//!
//! [](https://docs.rs/terminal_cli)
//!
//!
//! # Example, output only (Rust's ```stdout```)
//!
//! ```
//! # use terminal_cli::*;
//! # use std::io;
//! # use std::io::Write;
//!
//! // Simple ranged integer property
//! let mut num1 = 1;
//!
//! // Rust stdout terminal
//! let mut terminal = StdoutTerminal;
//!
//! let options = PromptBufferOptions { echo: true, ..Default::default() };
//! let mut prompt = PromptBuffer::new(options);
//!
//! let input_keys = [Key::Character('h' as u8), Key::Character('e' as u8), Key::Character('l' as u8),
//! Key::Character('p' as u8), Key::Newline];
//!
//! for key in &input_keys {
//! let p = prompt.handle_key(*key, &mut terminal, |mut m| {
//! if let Some(mut ctx) = m.command("help") {
//! ctx.get_terminal().print_line("Help!");
//! }
//!
//! // Provides "num1/get" and "num1/set", with input validation
//! if let Some(mut ctx) = m.property("num1", validate_property_min_max(1, 100)) {
//! ctx.apply(&mut num1);
//! }
//! });
//!
//! if let PromptEvent::Break = p {
//! break;
//! }
//! }
//! ```
extern crate alloc;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;