diff options
| author | sigoden <sigoden@gmail.com> | 2023-12-24 16:04:18 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-24 16:04:18 +0800 |
| commit | 1c9ca1b002badb511ff21d58b3f20986741ab31f (patch) | |
| tree | 171edf24341f96ac4a93e00b315a3ce8b90455fc /src/repl | |
| parent | 89fefb4d1a3239496e90daf74be8b08decc603d2 (diff) | |
| download | aichat-1c9ca1b002badb511ff21d58b3f20986741ab31f.tar.gz | |
feat: custom REPL prompt (#283)
Diffstat (limited to 'src/repl')
| -rw-r--r-- | src/repl/prompt.rs | 36 |
1 files changed, 2 insertions, 34 deletions
diff --git a/src/repl/prompt.rs b/src/repl/prompt.rs index 30600af..7b52106 100644 --- a/src/repl/prompt.rs +++ b/src/repl/prompt.rs @@ -1,14 +1,8 @@ use crate::config::GlobalConfig; -use crossterm::style::Color; use reedline::{Prompt, PromptHistorySearch, PromptHistorySearchStatus}; use std::borrow::Cow; -const PROMPT_COLOR: Color = Color::Green; -const PROMPT_MULTILINE_COLOR: nu_ansi_term::Color = nu_ansi_term::Color::LightBlue; -const INDICATOR_COLOR: Color = Color::Cyan; -const PROMPT_RIGHT_COLOR: Color = Color::AnsiValue(5); - #[derive(Clone)] pub struct ReplPrompt { config: GlobalConfig, @@ -24,13 +18,7 @@ impl ReplPrompt { impl Prompt for ReplPrompt { fn render_prompt_left(&self) -> Cow<str> { - if let Some(session) = &self.config.read().session { - Cow::Owned(session.name().to_string()) - } else if let Some(role) = &self.config.read().role { - Cow::Owned(role.name.clone()) - } else { - Cow::Borrowed("") - } + Cow::Owned(self.config.read().render_prompt_left()) } fn render_prompt_right(&self) -> Cow<str> { @@ -38,11 +26,7 @@ impl Prompt for ReplPrompt { } fn render_prompt_indicator(&self, _prompt_mode: reedline::PromptEditMode) -> Cow<str> { - if self.config.read().session.is_some() { - Cow::Borrowed(") ") - } else { - Cow::Borrowed("> ") - } + Cow::Borrowed("") } fn render_prompt_multiline_indicator(&self) -> Cow<str> { @@ -64,20 +48,4 @@ impl Prompt for ReplPrompt { prefix, history_search.term )) } - - fn get_prompt_color(&self) -> Color { - PROMPT_COLOR - } - /// Get the default multiline prompt color - fn get_prompt_multiline_color(&self) -> nu_ansi_term::Color { - PROMPT_MULTILINE_COLOR - } - /// Get the default indicator color - fn get_indicator_color(&self) -> Color { - INDICATOR_COLOR - } - /// Get the default right prompt color - fn get_prompt_right_color(&self) -> Color { - PROMPT_RIGHT_COLOR - } } |
