1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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_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 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)]
pub enum PromptViMode {
Normal,
Insert,
}
impl Default for PromptViMode {
fn default() -> Self {
PromptViMode::Normal
}
}
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_indicator_color(&self) -> Color {
DEFAULT_INDICATOR_COLOR
}
fn get_prompt_right_color(&self) -> Color {
DEFAULT_PROMPT_RIGHT_COLOR
}
}