1use {
2 crossterm::style::Color,
3 serde::{Deserialize, Serialize},
4 std::{
5 borrow::Cow,
6 fmt::{Display, Formatter},
7 },
8 strum::EnumIter,
9};
10
11pub static DEFAULT_PROMPT_COLOR: Color = Color::Green;
13pub static DEFAULT_PROMPT_MULTILINE_COLOR: nu_ansi_term::Color = nu_ansi_term::Color::LightBlue;
14pub static DEFAULT_INDICATOR_COLOR: Color = Color::Cyan;
15pub static DEFAULT_PROMPT_RIGHT_COLOR: Color = Color::AnsiValue(5);
16
17pub enum PromptHistorySearchStatus {
19 Passing,
21
22 Failing,
24}
25
26pub struct PromptHistorySearch {
28 pub status: PromptHistorySearchStatus,
30
31 pub term: String,
33}
34
35impl PromptHistorySearch {
36 pub const fn new(status: PromptHistorySearchStatus, search_term: String) -> Self {
38 PromptHistorySearch {
39 status,
40 term: search_term,
41 }
42 }
43}
44
45#[derive(Serialize, Deserialize, Clone, Debug, EnumIter, Default)]
47pub enum PromptEditMode {
48 #[default]
50 Default,
51
52 Emacs,
54
55 Vi(PromptViMode),
57
58 Custom(String),
60}
61
62#[derive(Serialize, Deserialize, Clone, Debug, EnumIter, Default)]
64pub enum PromptViMode {
65 #[default]
67 Normal,
68
69 Insert,
71}
72
73impl Display for PromptEditMode {
74 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
75 match self {
76 PromptEditMode::Default => write!(f, "Default"),
77 PromptEditMode::Emacs => write!(f, "Emacs"),
78 PromptEditMode::Vi(_) => write!(f, "Vi_Normal\nVi_Insert"),
79 PromptEditMode::Custom(s) => write!(f, "Custom_{s}"),
80 }
81 }
82}
83pub trait Prompt: Send {
88 fn render_prompt_left(&self) -> Cow<'_, str>;
90 fn render_prompt_right(&self) -> Cow<'_, str>;
92 fn render_prompt_indicator(&self, prompt_mode: PromptEditMode) -> Cow<'_, str>;
94 fn render_prompt_multiline_indicator(&self) -> Cow<'_, str>;
96 fn render_prompt_history_search_indicator(
98 &self,
99 history_search: PromptHistorySearch,
100 ) -> Cow<'_, str>;
101 fn get_prompt_color(&self) -> Color {
103 DEFAULT_PROMPT_COLOR
104 }
105 fn get_prompt_multiline_color(&self) -> nu_ansi_term::Color {
107 DEFAULT_PROMPT_MULTILINE_COLOR
108 }
109 fn get_indicator_color(&self) -> Color {
111 DEFAULT_INDICATOR_COLOR
112 }
113 fn get_prompt_right_color(&self) -> Color {
115 DEFAULT_PROMPT_RIGHT_COLOR
116 }
117
118 fn right_prompt_on_last_line(&self) -> bool {
120 false
121 }
122}