Expand description
§Rusty Prompt
§Rusty Prompt is a command line interface builder based off of the go-prompt library.
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();
}
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 |
Modules§
Structs§
- Buffer
- Document
- Allows you to do functions on the current line.
- Prompt
- Manages the whole prompt.
- Prompt
Builder - Build a new prompt. history_max_items is how many items to store in the history. This defaults at 100. This is optional. app is the callbacks prefix is the prefix to show before the command
- Signal
Manager - Used if you need signals in your own program using run_one. Signal manager for posix. Used to get SIGINT (Exit), SIGTERM (Exit), SIGWINCH (Resize)
- Suggestion
- Suggestion for completion.
- Writer
Enums§
- Color
- Command
State - Return value for a command. If CommandState::Err is returned, the prompt will exit.
- Display
Attribute - Key
- Available keys for KeyBinds
- KeyAction
- What to do on completion of KeyBind
- Signal
Action - Used if you need signals in your own program using run_one. Action from a signal