cli(ux): add hint for enter/ctrl-j if input is empty (#2632)

Co-authored-by: Yingjie He <yingjiehe@squareup.com>
This commit is contained in:
Raduan Al-Shedivat
2025-05-22 17:14:36 +02:00
committed by GitHub
parent e9c93834cc
commit e465ea60cf

View File

@@ -352,8 +352,13 @@ impl Helper for GooseCompleter {}
impl Hinter for GooseCompleter {
type Hint = String;
fn hint(&self, _line: &str, _pos: usize, _ctx: &rustyline::Context<'_>) -> Option<Self::Hint> {
None
fn hint(&self, line: &str, _pos: usize, _ctx: &rustyline::Context<'_>) -> Option<Self::Hint> {
// Only show hint when line is empty
if line.is_empty() {
Some("Press Enter to send, Ctrl-J for new line".to_string())
} else {
None
}
}
}
@@ -367,7 +372,9 @@ impl Highlighter for GooseCompleter {
}
fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> {
Cow::Borrowed(hint)
// Style the hint text with a dim color
let styled = console::Style::new().dim().apply_to(hint).to_string();
Cow::Owned(styled)
}
fn highlight<'l>(&self, line: &'l str, _pos: usize) -> Cow<'l, str> {