Repository: block/goose
File: crates/goose-cli/src/session/completion.rs (Rust)

Code before:
}

// Implement the Helper trait which is required by rustyline
impl Helper for GooseCompleter {}

// Implement required traits with default implementations
impl Hinter for GooseCompleter {
    type Hint = String;

    fn hint(&self, line: &str, _pos: usize, _ctx: &Context<'_>) -> Option<Self::Hint> {
        let cache = self.completion_cache.read().unwrap();

        if !line.is_empty() && cache.hint_status != HintStatus::Default {
            drop(cache);
            let mut cache_write = self.completion_cache.write().unwrap();
            cache_write.hint_status = HintStatus::Default;
            return None;
        }

        if !line.is_empty() {
            return None;
        }

        match cache.hint_status {
            HintStatus::Interrupted => {
                Some("type new instructions, or Ctrl+C again to exit".to_string())
            }
            HintStatus::MaybeExit => Some("Ctrl+C again to exit, or type to continue".to_string()),
            HintStatus::Default => {
                let newline_key = super::input::get_newline_key().to_ascii_uppercase();
                Some(format!(
                    "Enter to send · Ctrl+{} newline · Ctrl+C to add instructions or interrupt",
                    newline_key
                ))
            }
        }
    }
}

impl Highlighter for GooseCompleter {
    fn highlight_prompt<'b, 's: 'b, 'p: 'b>(
        &'s self,
        prompt: &'p str,
        _default: bool,
    ) -> Cow<'b, str> {
        Cow::Borrowed(prompt)
    }

    fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> {
        // Style the hint text with a dim color
        let styled = console::Style::new().dim().apply_to(hint).to_string();

Review comment (suggestion):
yeah, that would be nice, but that's not how it currently works. if you hit ctrl-c to interrupt you get to the normal state and so you need to hit ctrl-c twice more. so we should fix that or revert the comment

Code after:
}

// Implement the Helper trait which is required by rustyline
impl Helper for GooseCompleter {}

// Implement required traits with default implementations
impl Hinter for GooseCompleter {
    type Hint = String;

    fn hint(&self, line: &str, _pos: usize, _ctx: &Context<'_>) -> Option<Self::Hint> {
        let cache = self.completion_cache.read().unwrap();

        if !line.is_empty() && cache.hint_status != HintStatus::Default {
            drop(cache);
            let mut cache_write = self.completion_cache.write().unwrap();
            cache_write.hint_status = HintStatus::Default;
            return None;
        }

        if !line.is_empty() {
            return None;
        }

        match cache.hint_status {
            HintStatus::Interrupted => {
                Some("Interrupted, what should goose work on instead?".to_string())
            }
            HintStatus::MaybeExit => {
                Some("Press Ctrl+C again to exit, or type new instructions to continue".to_string())
            }
            HintStatus::Default => {
                let newline_key = super::input::get_newline_key().to_ascii_uppercase();
                Some(format!("Enter to send · Ctrl+{} newline", newline_key))
            }
        }
    }
}

impl Highlighter for GooseCompleter {
    fn highlight_prompt<'b, 's: 'b, 'p: 'b>(
        &'s self,
        prompt: &'p str,
        _default: bool,
    ) -> Cow<'b, str> {
        Cow::Borrowed(prompt)
    }

    fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> {
        // Style the hint text with a dim color
        let styled = console::Style::new().dim().apply_to(hint).to_string();
        Cow::Owned(styled)