1use rusty_prompt::{App, Color, CommandState, Completer, Document, Executor, Prompt, PromptBuilder, Suggestion, Writer};
2use rusty_prompt::colored_string::{ColoredChar, ColoredString};
3
4pub struct Cli {}
5
6impl Completer for Cli {
7 fn get_suggestions(&self, doc: Document) -> Vec<Suggestion> {
8 let mut suggestions = vec![
9 Suggestion::new("find", "Find something"),
10 Suggestion::new("go", "Go somewhere"),
11 Suggestion::new("die", "kills something"),
12 Suggestion::new("flame", "flames something"),
13 Suggestion::new("Blank_Desc", ""),
14 ];
15 let filter = doc.get_word_before_cursor_until_sep(' ');
16 if filter == "" {
17 suggestions
18 } else {
19 suggestions.retain(|v| v.get_name().contains(filter));
20 suggestions
21 }
22 }
23}
24
25impl Executor for Cli {
26 fn execute(&mut self, command: &str, writer: &mut Writer) -> CommandState {
27 writer.write_str(&format!("Command: {}", command));
28 writer.write_str("\n");
29 CommandState::Ok
30 }
31}
32
33impl App for Cli {}
34
35fn main() {
36 let chr = ColoredChar::builder().ch('>' as u8).foreground_color(Color::Yellow).build();
37 let prefix = ColoredString::new_from_inner(&[
38 chr, chr, chr,
39 ColoredChar::builder().ch(' ' as u8).build()
40 ]);
41 let mut prompt: Prompt = PromptBuilder::builder().prefix(prefix).app(Box::new(Cli {})).build().into();
42 prompt.run();
43}