use reedline::{Prompt, PromptEditMode, PromptHistorySearch};
use std::borrow::Cow;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
pub struct ChatPrompt {
left: String,
indicator: String,
multiline: String,
reverse_search_active: Arc<AtomicBool>,
}
impl ChatPrompt {
pub fn new(left: String, indicator: String, reverse_search_active: Arc<AtomicBool>) -> Self {
Self {
left,
indicator,
multiline: " ".to_string(),
reverse_search_active,
}
}
}
impl Prompt for ChatPrompt {
fn render_prompt_left(&self) -> Cow<'_, str> {
Cow::Owned(self.left.clone())
}
fn render_prompt_right(&self) -> Cow<'_, str> {
Cow::Borrowed("")
}
fn render_prompt_indicator(&self, _prompt_mode: PromptEditMode) -> Cow<'_, str> {
self.reverse_search_active.store(false, Ordering::SeqCst);
Cow::Owned(self.indicator.clone())
}
fn render_prompt_multiline_indicator(&self) -> Cow<'_, str> {
Cow::Owned(self.multiline.clone())
}
fn render_prompt_history_search_indicator(
&self,
history_search: PromptHistorySearch,
) -> Cow<'_, str> {
self.reverse_search_active.store(true, Ordering::SeqCst);
Cow::Owned(format!("(search: {}) ", history_search.term))
}
}