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::split;
//! use shli::completion::Command;
//! use shli::Prompt;
//! 
//! fn main() {
//!     let mut p = Prompt::new("> ".to_string(), vec!(
//! 		Command::new("print").arg("--help"),
//! 		Command::new("echo"),
//! 		Command::new("exit")
//! 	));
//!     loop {
//!         match p.read_commandline() {
//!             Ok(line) => {
//!                 println!("");
//!                 if ! line.is_empty() {
//!                     match line[0].as_str() {
//!                         "exit" => break,
//!                         "print" | "echo" => if line.len() > 1 {
//!                             let mut output = line[1].clone();
//!                             for w in &line[2..] {
//!                                 output.push_str(&format!(" {}", w));
//!                             }
//!                             println!("{}", output);
//!                         }
//!                         cmd => println!("Did not find '{}' command!", cmd),
//!                     }
//!                 }
//!             }
//!             Err(e) => {
//!                 match e.kind() {
//!                     std::io::ErrorKind::UnexpectedEof => {
//!                         println!("exit");
//!                         break;
//!                     }
//!                     std::io::ErrorKind::Other => {
//!                         println!("\nCtrl+C pressed.");
//!                     }
//!                     _ => {
//!                         println!("Reading error: {:?}", e);
//!                     }
//!                 };
//!             }
//!         }
//!     }
//! }
//! ```

extern crate termion;

pub mod prompt;
pub mod parse;
pub mod completion;

pub use prompt::Prompt;
pub use parse::split;
pub use completion::Command;

#[cfg(test)]
mod tests;