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
//! shli provides a few raw building blocks for building your own shell-like CLI.
//! It uses termion and should thus be compatible with all terminals termion supports.
//!
//! An example:
//! ```no_run
//! extern crate shli;
//! use shli::completion::Command;
//! use shli::{Prompt, Error};
//!
//! fn main() {
//! let mut p = Prompt::new(
//! "> ".to_string(),
//! vec![
//! Command::new("print"),
//! Command::new("echo"),
//! Command::new("cat").arg("--help"),
//! Command::new("exit"),
//! ],
//! );
//! loop {
//! // read_commandline does all the reading and tab completion
//! match p.read_commandline() {
//! Ok(line) => {
//! println!("");
//! match line.get(0).map(|s| s.as_str()) {
//! Some("exit") => break,
//! Some("print") | Some("echo") => {
//! if line.len() > 1 {
//! let output = line[1..]
//! .iter()
//! .map(|s| &**s)
//! .collect::<Vec<&str>>()
//! .join(" ");
//! println!("{}", output);
//! }
//! }
//! Some(cmd) => println!("Did not find '{}' command!", cmd),
//! None => {}
//! }
//! }
//! Err(Error::CtrlD) => {
//! println!("exit");
//! break;
//! }
//! Err(Error::CtrlC) => println!("\nCtrl+C pressed."),
//! Err(Error::IoError(e)) => println!("Reading error: {:?}", e),
//! }
//! }
//! }
//! ```
extern crate termion;
pub use Command;
pub use Error;
pub use Prompt;
pub use split;