Crate rusty_prompt

Source
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:

KeyAction
EndMoves cursor to end
HomeMoves cursor to start
DeleteDeletes the next char
BackspaceDeletes the prev char
RightMoves cursor to the right
LeftMoves cursor to the left
Control+EMoves cursor to end
Control+AMoves cursor to start
Control+XDeletes the char after the cursor
Control+UDeletes all chars before cursor
Control+HDeletes the char before the cursor
Control+FMoves cursor to the right
Control+BMoves cursor to the left
Control+WRemoves the chars before the cursor
Control+LClears the current line
Control+DQuit
Control+CQuit
UpGets the previous history and puts it in the line
DownGets the next history and puts it in the line
TabCompletes the line

Modules§

colored_string

Structs§

Buffer
Document
Allows you to do functions on the current line.
Prompt
Manages the whole prompt.
PromptBuilder
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
SignalManager
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
CommandState
Return value for a command. If CommandState::Err is returned, the prompt will exit.
DisplayAttribute
Key
Available keys for KeyBinds
KeyAction
What to do on completion of KeyBind
SignalAction
Used if you need signals in your own program using run_one. Action from a signal

Traits§

App
The trait to make an app. Implement Completer and Executor for this. See the examples for code.
Completer
Executor