From d27227f58f1abfbace6c21c0caa2e7a45aa56997 Mon Sep 17 00:00:00 2001 From: Patrick Kuo Date: Tue, 12 Jul 2022 10:14:08 +0100 Subject: [PATCH] use prompt highlighter to highlight prompt correctly for both mac and windows. (#3133) --- crates/sui/src/shell.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/sui/src/shell.rs b/crates/sui/src/shell.rs index 570bd2786124a..72a1836b4eafc 100644 --- a/crates/sui/src/shell.rs +++ b/crates/sui/src/shell.rs @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 use anyhow::anyhow; +use std::borrow::Cow; +use std::borrow::Cow::Owned; use std::cmp::Ordering; use std::collections::BTreeMap; use std::env; @@ -73,9 +75,6 @@ impl> Shell { })); loop { - write!(out, "{}", format!("{}", self.prompt).bold().green())?; - out.flush()?; - // Read a line let readline = rl.readline(&self.prompt.to_string()); let line = match readline { @@ -196,7 +195,15 @@ impl Hinter for ShellHelper { type Hint = String; } -impl Highlighter for ShellHelper {} +impl Highlighter for ShellHelper { + fn highlight_prompt<'b, 's: 'b, 'p: 'b>( + &'s self, + prompt: &'p str, + _default: bool, + ) -> Cow<'b, str> { + Owned(prompt.bold().green().to_string()) + } +} impl Validator for ShellHelper {}