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
490KB
151 lines
console_prompt
A very simple way to make a clean, thread-safe, interactive CLI interface in rust.
Running example:
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