Expand description
§Terminal CLI
Need to build an interactive command prompt, with commands, properties and with full autocomplete? This is for you.
§Example, output only (Rust’s stdout
)
// 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;
}
}
Modules§
- i18n
- Internationalization support for various command line strings.
Structs§
- Autocomplete
Line - One autocomplete suggestion
- CliCommand
- A command that can be matched by the command line prompt
- CliExecutor
- Helper for matching commands and properties against an input line.
- CliLine
Matcher - Match commands against the given input line
- Command
Context - Context for the execution of the command
- Prefixed
Executor - Prompt
Buffer - Holds the current line buffer for a terminal and its possible autocomplete state.
- Prompt
Buffer Options - Options for the prompt buffer
- Property
Context Common - Property
Context Get - Property
Context Set - Stdout
Terminal - Terminal
KeyDecoder - Terminal key decoder, from raw bytes to decoded key sequences
- Value
Bool - A convenience parser for boolean properties. Parses 0/1, false/true, off/on and no/yes.
- Value
Combine Validators - Value
Input From Str - Value
Input With Validation - Value
Max - Value
Min - Value
Output ToString
Enums§
- Autocomplete
Result - Result of the autocomplete request on a given set of commands
- CliError
- Direction
Key - Direction key
- Key
- Decoded key press
- KeyDecoder
Error - Key decoder error
- Line
Buffer Result - Line
Matcher Mode - Should we stop processing commands when we find a match or should we just collect autocomplete suggestions?
- Line
Matcher Progress - State of the line matcher
- Newline
Sequence - Prompt
Event - Property
Command Style - Property
Context - Property
Validation Error - Terminal
Error
Traits§
- Character
Terminal Reader - Terminal key reader
- Character
Terminal Writer - Character based terminal trait
- CliContext
- KeyDecoder
- Key decoder trait
- Value
Input - Value
Input Validate - Value
Output
Functions§
- format_
in_ columns - Formats the strings in autocomplete-style column notation. Fills the width of the entire line with a string plus the desired spacing characters. Preserves the ordering in columns.
- longest_
common_ prefix - A naive implementation. Can be implemented with a trie, but it’s overkill here. http://en.wikipedia.org/wiki/LCP_array
- validate_
property_ min_ max