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
93
94
95
96
97
98
99
100
101
102
103
104
105
//! A helper library for implementing low-level terminal command line interfaces,
//! like those on embedded bare-bones environments with UART ports.
//!
//! The library doesn't use Rust's ```std``` library, but requires the ```alloc```
//! and ```collections``` libraries for heap memory allocation and vector manipulation.
//!
//! Custom commands can be easily added by implementing the ```CliCommand``` trait.
//!
//! # Example
//!
//! ```
//! #![feature(convert)]
//! # use terminal_cli::*;
//! # use std::io;
//! # use std::io::Write;
//! let help = CliCommandKeyword {
//! keyword: "help".to_string(),
//! action: |line, cli| {
//! cli.output_line("Help here!");
//! }
//! };
//!
//! // Adds "set time <HH:mm>" and "get time" commands. No parsing here.
//! let time = CliPropertyVar {
//! var_name: "time".to_string(),
//! var_value: "11:15".to_string(),
//! val_hint: "HH:mm".to_string(),
//!
//! var_output: |v| { v.to_string() },
//! var_input: |v| {
//! if v.len() > 0 { Some(v.to_string()) }
//! else { None }
//! }
//! };
//!
//! // For this test, a ```stdout``` terminal. Isn't included in the
//! // library as it's meant for bare-bones usage - no std library.
//! struct StdoutTerminal;
//! impl CliTerminal for StdoutTerminal {
//! fn output_line(&mut self, line: &str) {
//! println!("{}", line);
//! }
//! }
//!
//! let mut commands = vec![
//! Box::new(help) as Box<CliCommand>,
//! Box::new(time) as Box<CliCommand>
//! ];
//!
//! let mut term = StdoutTerminal;
//!
//! // Execute a line buffer
//! cli_execute("help", commands.as_mut_slice(), &mut term);
//!
//! // Try to autocomplete the active buffer. Will return a summary of all commands.
//! let autocomplete = cli_try_autocomplete("", commands.as_mut_slice());
//!
//!
//! // Serial terminal input handling
//! struct StdoutPromptOutput;
//! impl CliPromptTerminal for StdoutPromptOutput {
//! fn print_bytes(&self, bytes: &[u8]) {
//! io::stdout().write(bytes);
//! }
//! }
//!
//! let mut prompt = CliPromptAutocompleteBuffer::new("#".to_string());
//! // help + newline
//! let keyboard_input = vec!['h' as u8, 'e' as u8, 'l' as u8,
//! 0x7f /* backspace */, 'l' as u8, 'p' as u8, 0x0d /* \r */ ];
//!
//! for byte in keyboard_input {
//! prompt.handle_received_byte(byte, &StdoutPromptOutput,
//! commands.as_mut_slice(), &mut term);
//! }
//! ```
extern crate core;
extern crate alloc;
extern crate collections;
// for tests
extern crate std;
pub use *;
pub use *;
pub use *;
pub use *;