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.
This commit is contained in:
Barnaby Keene 2019-10-08 21:39:58 +01:00
parent ef3e8eb778
commit 0412c3a2f8
2 changed files with 2 additions and 2 deletions

View File

@ -376,7 +376,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
#[cfg(not(feature = "starship-prompt"))]
{
&format!(
"{}{}> ",
"{}{}\x1b[m> ",
cwd,
match current_branch() {
Some(s) => format!("({})", s),

View File

@ -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> {