From a488a6aa99d3535b0a385ca6eb91ef42dbf005fd Mon Sep 17 00:00:00 2001 From: "Dhanji R. Prasanna" Date: Thu, 22 Jan 2026 10:48:17 +0530 Subject: [PATCH] feat(cli): colorize project name in prompt via rustyline Highlighter Implement highlight_prompt() in G3Helper to colorize the project portion of the prompt in blue. This uses rustyline's proper mechanism for ANSI codes in prompts, which correctly handles cursor positioning. Prompt 'butler | finances> ' now shows '| finances>' in blue. --- crates/g3-cli/src/completion.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/g3-cli/src/completion.rs b/crates/g3-cli/src/completion.rs index e4fc1a2..6174bc8 100644 --- a/crates/g3-cli/src/completion.rs +++ b/crates/g3-cli/src/completion.rs @@ -1,6 +1,7 @@ //! Tab completion support for g3 interactive mode. //! //! Provides: +//! - Prompt highlighting (colorizes project name in blue) //! - Command completion for `/` commands at line start //! - File path completion for `./`, `../`, `~/`, `/` prefixes //! - Session ID completion for `/resume` command @@ -274,7 +275,27 @@ impl Hinter for G3Helper { } } -impl Highlighter for G3Helper {} +impl Highlighter for G3Helper { + fn highlight_prompt<'b, 's: 'b, 'p: 'b>( + &'s self, + prompt: &'p str, + _default: bool, + ) -> std::borrow::Cow<'b, str> { + // If prompt contains " | ", colorize from "|" to ">" in blue + if let Some(pipe_pos) = prompt.find(" | ") { + if let Some(gt_pos) = prompt.rfind('>') { + let before = &prompt[..pipe_pos + 1]; // "butler " + let colored_part = &prompt[pipe_pos + 1..gt_pos + 1]; // "| project>" + let after = &prompt[gt_pos + 1..]; // " " + return std::borrow::Cow::Owned(format!( + "{}\x1b[34m{}\x1b[0m{}", + before, colored_part, after + )); + } + } + std::borrow::Cow::Borrowed(prompt) + } +} impl Validator for G3Helper {}