From 0412c3a2f8e5ad660b9d957e292007df399d50f8 Mon Sep 17 00:00:00 2001 From: Barnaby Keene Date: Tue, 8 Oct 2019 21:39:58 +0100 Subject: [PATCH] fix: remove the additional characters from highlighter This resolves a small integration issue that would make custom prompts problematic (if they are implemented). The approach was to use the highlighter implementation in Helper to insert colour codes to the prompt however it heavily relies on the prompt being in a specific format, ending with a `> ` sequence. However, this should really be the job of the prompt itself not the presentation layer. For now, I've simply stripped off the additional `> ` characters and passed in just the prompt itself without slicing off the last two characters. I moved the `\x1b[m` control sequence to the prompt creation in `cli.rs` as this feels like the more logical home for controlling what the prompt looks like. I can think of better ways to do this in future but this should be a fine solution for now. In future it would probably make sense to completely separate prompts (be it, internal or external) from this code so it can be configured as an isolated piece of code. --- src/cli.rs | 2 +- src/shell/helper.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 42a9aa931..6e92b3818 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -376,7 +376,7 @@ pub async fn cli() -> Result<(), Box> { #[cfg(not(feature = "starship-prompt"))] { &format!( - "{}{}> ", + "{}{}\x1b[m> ", cwd, match current_branch() { Some(s) => format!("({})", s), diff --git a/src/shell/helper.rs b/src/shell/helper.rs index 6fb454435..fa6c0bb67 100644 --- a/src/shell/helper.rs +++ b/src/shell/helper.rs @@ -58,7 +58,7 @@ impl Hinter for Helper { impl Highlighter for Helper { fn highlight_prompt<'b, 's: 'b, 'p: 'b>(&'s self, prompt: &'p str, _: bool) -> Cow<'b, str> { - Owned("\x1b[32m".to_owned() + &prompt[0..prompt.len() - 2] + "\x1b[m> ") + Owned("\x1b[32m".to_owned() + &prompt + "\x1b[m") } fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> {