Crate terminal_cli

Source
Expand description

§Terminal CLI

Need to build an interactive command prompt, with commands, properties and with full autocomplete? This is for you.

Build Status

Documentation

§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§

AutocompleteLine
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.
CliLineMatcher
Match commands against the given input line
CommandContext
Context for the execution of the command
PrefixedExecutor
PromptBuffer
Holds the current line buffer for a terminal and its possible autocomplete state.
PromptBufferOptions
Options for the prompt buffer
PropertyContextCommon
PropertyContextGet
PropertyContextSet
StdoutTerminal
TerminalKeyDecoder
Terminal key decoder, from raw bytes to decoded key sequences
ValueBool
A convenience parser for boolean properties. Parses 0/1, false/true, off/on and no/yes.
ValueCombineValidators
ValueInputFromStr
ValueInputWithValidation
ValueMax
ValueMin
ValueOutputToString

Enums§

AutocompleteResult
Result of the autocomplete request on a given set of commands
CliError
DirectionKey
Direction key
Key
Decoded key press
KeyDecoderError
Key decoder error
LineBufferResult
LineMatcherMode
Should we stop processing commands when we find a match or should we just collect autocomplete suggestions?
LineMatcherProgress
State of the line matcher
NewlineSequence
PromptEvent
PropertyCommandStyle
PropertyContext
PropertyValidationError
TerminalError

Traits§

CharacterTerminalReader
Terminal key reader
CharacterTerminalWriter
Character based terminal trait
CliContext
KeyDecoder
Key decoder trait
ValueInput
ValueInputValidate
ValueOutput

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