diff --git a/Cargo.toml b/Cargo.toml index 60a702d9e..15e5112d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ serde_json = "1.0" chrono = "0.4.6" failure = "0.1.5" # TODO: make optional -rustyline = { git = "https://github.com/kkawakam/rustyline/" } +rustyline = "4.1.0" lazy_static = "1.3.0" [dev-dependencies] diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index f51ca2e88..de7666e70 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -83,12 +83,7 @@ pub unsafe fn dc_reset_tables(context: &Context, bits: i32) -> i32 { info!(context, 0, "(8) Rest but server config reset."); } - (context.cb)( - context, - Event::MSGS_CHANGED, - 0 as uintptr_t, - 0 as uintptr_t, - ); + (context.cb)(context, Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t); 1 } diff --git a/examples/repl/main.rs b/examples/repl/main.rs index b2cd2e514..3832b73d3 100644 --- a/examples/repl/main.rs +++ b/examples/repl/main.rs @@ -243,7 +243,6 @@ struct DcHelper { completer: FilenameCompleter, highlighter: MatchingBracketHighlighter, hinter: HistoryHinter, - colored_prompt: String, } impl Completer for DcHelper { @@ -358,14 +357,13 @@ impl Hinter for DcHelper { } } +static COLORED_PROMPT: &'static str = "\x1b[1;32m> \x1b[0m"; +static PROMPT: &'static str = "> "; + impl Highlighter for DcHelper { - fn highlight_prompt<'b, 's: 'b, 'p: 'b>( - &'s self, - prompt: &'p str, - default: bool, - ) -> Cow<'b, str> { - if default { - Borrowed(&self.colored_prompt) + fn highlight_prompt<'p>(&self, prompt: &'p str) -> Cow<'p, str> { + if prompt == PROMPT { + Borrowed(COLORED_PROMPT) } else { Borrowed(prompt) } @@ -423,7 +421,6 @@ fn main_0(args: Vec) -> Result<(), failure::Error> { completer: FilenameCompleter::new(), highlighter: MatchingBracketHighlighter::new(), hinter: HistoryHinter {}, - colored_prompt: "".to_owned(), }; let mut rl = Editor::with_config(config); rl.set_helper(Some(h)); @@ -435,7 +432,6 @@ fn main_0(args: Vec) -> Result<(), failure::Error> { loop { let p = "> "; - rl.helper_mut().unwrap().colored_prompt = format!("\x1b[1;32m{}\x1b[0m", p); let readline = rl.readline(&p); match readline { Ok(line) => {