use {
crossterm::style::Color,
serde::{Deserialize, Serialize},
std::{
borrow::Cow,
fmt::{Display, Formatter},
},
strum_macros::EnumIter,
};
pub static DEFAULT_PROMPT_COLOR: Color = Color::Green;
pub static DEFAULT_PROMPT_MULTILINE_COLOR: nu_ansi_term::Color = nu_ansi_term::Color::LightBlue;
pub static DEFAULT_INDICATOR_COLOR: Color = Color::Cyan;
pub static DEFAULT_PROMPT_RIGHT_COLOR: Color = Color::AnsiValue(5);
pub enum PromptHistorySearchStatus {
Passing,
Failing,
}
pub struct PromptHistorySearch {
pub status: PromptHistorySearchStatus,
pub term: String,
}
impl PromptHistorySearch {
pub const fn new(status: PromptHistorySearchStatus, search_term: String) -> Self {
PromptHistorySearch {
status,
term: search_term,
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, EnumIter)]
pub enum PromptEditMode {
Default,
Emacs,
Vi(PromptViMode),
Custom(String),
}
#[derive(Serialize, Deserialize, Clone, Debug, EnumIter, Default)]
pub enum PromptViMode {
#[default]
Normal,
Insert,
}
impl Display for PromptEditMode {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
match self {
PromptEditMode::Default => write!(f, "Default"),
PromptEditMode::Emacs => write!(f, "Emacs"),
PromptEditMode::Vi(_) => write!(f, "Vi_Normal\nVi_Insert"),
PromptEditMode::Custom(s) => write!(f, "Custom_{s}"),
}
}
}
pub trait Prompt: Send {
fn render_prompt_left(&self) -> Cow<str>;
fn render_prompt_right(&self) -> Cow<str>;
fn render_prompt_indicator(&self, prompt_mode: PromptEditMode) -> Cow<str>;
fn render_prompt_multiline_indicator(&self) -> Cow<str>;
fn render_prompt_history_search_indicator(
&self,
history_search: PromptHistorySearch,
) -> Cow<str>;
fn get_prompt_color(&self) -> Color {
DEFAULT_PROMPT_COLOR
}
fn get_prompt_multiline_color(&self) -> nu_ansi_term::Color {
DEFAULT_PROMPT_MULTILINE_COLOR
}
fn get_indicator_color(&self) -> Color {
DEFAULT_INDICATOR_COLOR
}
fn get_prompt_right_color(&self) -> Color {
DEFAULT_PROMPT_RIGHT_COLOR
}
fn right_prompt_on_last_line(&self) -> bool {
false
}
}