Rust-Terminal cli.rs: Low-level Rust library for implementing terminal command line interface, like in embedded systems.

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;
    }
}

License: MIT/Apache-2.0

Comments

  • V02
    V02

    Jan 19, 2018

                                                                                                                                                                                                           
    Reply
  • Reworked the API to perform all command prompt operations directly within the execution context
    Reworked the API to perform all command prompt operations directly within the execution context

    May 29, 2017

    ...instead of relying on global, synced and unsynced versions of owned function lambdas or owned property values.

    Reduces the runtime memory usage and improves development ergonomics, sacrifices potential future optimizations.

    Reply
  • rework
    rework

    Aug 14, 2016

                                                                                                                                                                                                           
    Reply
  • std lib change
    std lib change

    Mar 20, 2016

                                                                                                                                                                                                           
    Reply
  • temporary fix for unstable feature
    temporary fix for unstable feature

    Dec 13, 2015

    the syntax used should be updated

    Reply