Crates.io | rusty_prompt |
lib.rs | rusty_prompt |
version | 0.3.0 |
source | src |
created_at | 2023-10-02 02:46:05.372554 |
updated_at | 2023-10-02 02:46:05.372554 |
description | Rusty library for creating interactive runtime command line prompts. |
homepage | |
repository | https://gitlab.com/kohlten/rusty_prompt |
max_upload_size | |
id | 989568 |
size | 115,421 |
Basic example:
use rusty_prompt::{App, Color, CommandState, Completer, Document, Executor, Prompt, PromptBuilder, Suggestion, Writer};
use rusty_prompt::colored_string::{ColoredChar, ColoredString};
pub struct Cli {}
impl Completer for Cli {
fn get_suggestions(&self, doc: Document) -> Vec<Suggestion> {
vec![
Suggestion::new("find", "Find something"),
Suggestion::new("go", "Go somewhere"),
Suggestion::new("die", "kills something"),
Suggestion::new("flame", "flames something"),
Suggestion::new("Blank_Desc", ""),
]
}
}
impl Executor for Cli {
fn execute(&mut self, command: &str, writer: &mut Writer) -> CommandState {
writer.write_str(&format!("Command: {}", command));
writer.write_str("\n");
CommandState::Ok
}
}
impl App for Cli {}
fn main() {
let chr = ColoredChar::builder().ch('>' as u8).foreground_color(Color::Yellow).build();
let prefix = ColoredString::new_from_inner(&[
chr, chr, chr,
ColoredChar::builder().ch(' ' as u8).build()
]);
let mut prompt: Prompt = PromptBuilder::builder().prefix(prefix).app(Box::new(Cli {})).build().into();
prompt.run();
}
Which will output a prompt:
With Completions:
Current keybinds:
Key | Action |
---|---|
End | Moves cursor to end |
Home | Moves cursor to start |
Delete | Deletes the next char |
Backspace | Deletes the prev char |
Right | Moves cursor to the right |
Left | Moves cursor to the left |
Control+E | Moves cursor to end |
Control+A | Moves cursor to start |
Control+X | Deletes the char after the cursor |
Control+U | Deletes all chars before cursor |
Control+H | Deletes the char before the cursor |
Control+F | Moves cursor to the right |
Control+B | Moves cursor to the left |
Control+W | Removes the chars before the cursor |
Control+L | Clears the current line |
Control+D | Quit |
Control+C | Quit |
Up | Gets the previous history and puts it in the line |
Down | Gets the next history and puts it in the line |
Tab | Completes the line |