#prompt #toolkit #cli

console-prompt

console_prompt is a very simple library for creating clean, thread-safe cli prompts for interactive cli programs in rust heavily relying on crossterm. I created this for a C2 client, but it could likely be used in anywhere you want an interactive prompt. The simplicity of it is what I think sets it apart from other projects

6 releases

0.1.5 Jun 11, 2023
0.1.4 Jun 6, 2023
0.1.0 Mar 29, 2023

#909 in Command-line interface

Custom license

490KB
151 lines

console_prompt

A very simple way to make a clean, thread-safe, interactive CLI interface in rust.

Running example:

Example GIF

Creating a prompt is as simple as creating a vector of Command structs with pointers to your functions and handing them off to command_loop:

fn main(){
    let commands = vec![
        Command{
            command: "converse",
            func: converse, // <---- pointer to the converse function
            help_output: "converse <name> - interact with a person"
        },
    ];

    // start the command loop with the provided commands
    if let Err(e) = command_loop(&commands, &mut DynamicContext::new()){
        eprintln!("error running command loop: {}", e.to_string());
    }
}

You can also create nested command_loops that maintain state via the context argument, see the conversation example for more info.

Currently this does not support windows due to limitations with windows terminal. If someone asks for windows support i'll try and figure something out.

Dependencies

~6–19MB
~218K SLoC