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 { let mut suggestions = 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", ""), ]; let filter = doc.get_word_before_cursor_until_sep(' '); if filter == "" { suggestions } else { suggestions.retain(|v| v.get_name().contains(filter)); suggestions } } } 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(); }