terminal_cli/
lib.rs

1//! # Terminal CLI
2//! 
3//! Need to build an interactive command prompt, with commands, properties and with full autocomplete? This is for you.
4//!
5//! [![Build Status](https://travis-ci.org/hashmismatch/terminal_cli.rs.svg?branch=master)](https://travis-ci.org/hashmismatch/terminal_cli.rs)
6//! 
7//! [![Documentation](https://docs.rs/terminal_cli/badge.svg)](https://docs.rs/terminal_cli)
8//! 
9//!
10//! # Example, output only (Rust's ```stdout```)
11//!
12//! ```
13//! # use terminal_cli::*;
14//! # use std::io;
15//! # use std::io::Write;
16//!
17//! // Simple ranged integer property
18//! let mut num1 = 1;
19//! 
20//! // Rust stdout terminal
21//! let mut terminal = StdoutTerminal;
22//!	
23//! let options = PromptBufferOptions { echo: true, ..Default::default() };
24//! let mut prompt = PromptBuffer::new(options);
25//!
26//! let input_keys = [Key::Character('h' as u8), Key::Character('e' as u8), Key::Character('l' as u8),
27//!                   Key::Character('p' as u8), Key::Newline];
28//! 
29//! for key in &input_keys {
30//!     let p = prompt.handle_key(*key, &mut terminal, |mut m| {
31//!         if let Some(mut ctx) = m.command("help") {
32//!             ctx.get_terminal().print_line("Help!");
33//!         }
34//!
35//!         // Provides "num1/get" and "num1/set", with input validation
36//!         if let Some(mut ctx) = m.property("num1", validate_property_min_max(1, 100)) {
37//!             ctx.apply(&mut num1);
38//!         }
39//!     });
40//! 
41//!     if let PromptEvent::Break = p {
42//!         break;
43//!     }
44//! }
45//! ```
46
47#![cfg_attr(not(feature = "std"), no_std)]
48
49#![cfg_attr(not(feature="std"), feature(alloc))]
50
51#[cfg(not(feature="std"))]
52#[macro_use]
53extern crate alloc;
54
55mod autocomplete;
56mod property;
57mod utils;
58mod prelude;
59mod cli;
60mod cli_command;
61mod cli_property;
62mod keys;
63mod keys_terminal;
64mod terminal;
65mod prompt_buffer;
66
67
68pub mod i18n;
69
70pub use autocomplete::*;
71pub use utils::*;
72pub use cli::*;
73pub use cli_command::*;
74pub use cli_property::*;
75pub use keys::*;
76pub use keys_terminal::*;
77pub use property::*;
78pub use terminal::*;
79pub use prompt_buffer::*;
80
81#[cfg(test)]
82mod tests;