1pub mod input {
2 use crate::style::{Color, Formatting, LabelStyle};
3
4 pub struct InputStyle {
6 pub label_style: LabelStyle,
8
9 pub default_value_formatting: Formatting,
11
12 pub error_formatting: Formatting,
14
15 pub input_formatting: Formatting,
17
18 pub submitted_formatting: Formatting,
20
21 pub help_message_formatting: Formatting,
23 }
24
25 impl Default for InputStyle {
26 fn default() -> Self {
27 InputStyle {
28 label_style: LabelStyle::default(),
29 default_value_formatting: Formatting::default().foreground_color(Color::Grey),
30 error_formatting: Formatting::default().foreground_color(Color::Red),
31 input_formatting: Formatting::default(),
32 submitted_formatting: Formatting::default().foreground_color(Color::Green),
33 help_message_formatting: Formatting::default().foreground_color(Color::DarkGreen),
34 }
35 }
36 }
37
38 impl InputStyle {
39 pub fn label_style(mut self, l: LabelStyle) -> Self {
40 self.label_style = l;
41 self
42 }
43
44 pub fn default_value_formatting(mut self, f: Formatting) -> Self {
45 self.default_value_formatting = f;
46 self
47 }
48
49 pub fn error_formatting(mut self, f: Formatting) -> Self {
50 self.error_formatting = f;
51 self
52 }
53
54 pub fn input_formatting(mut self, f: Formatting) -> Self {
55 self.input_formatting = f;
56 self
57 }
58
59 pub fn submitted_formatting(mut self, f: Formatting) -> Self {
60 self.submitted_formatting = f;
61 self
62 }
63
64 pub fn help_message_formatting(mut self, f: Formatting) -> Self {
65 self.help_message_formatting = f;
66 self
67 }
68 }
69}
70
71pub mod confirmation {
72 use crate::style::{Color, Formatting, LabelStyle};
73
74 pub struct ConfirmationStyle {
76 pub label_style: LabelStyle,
78
79 pub input_formatting: Formatting,
81
82 pub submitted_formatting: Formatting,
84 }
85
86 impl Default for ConfirmationStyle {
87 fn default() -> Self {
88 ConfirmationStyle {
89 label_style: LabelStyle::default(),
90 input_formatting: Formatting::default(),
91 submitted_formatting: Formatting::default().foreground_color(Color::Green),
92 }
93 }
94 }
95
96 impl ConfirmationStyle {
97 pub fn label_style(mut self, l: LabelStyle) -> Self {
98 self.label_style = l;
99 self
100 }
101
102 pub fn input_formatting(mut self, f: Formatting) -> Self {
103 self.input_formatting = f;
104 self
105 }
106
107 pub fn submitted_formatting(mut self, f: Formatting) -> Self {
108 self.submitted_formatting = f;
109 self
110 }
111 }
112}
113
114pub mod selection {
115 use crate::{
116 engine::CommandBuffer,
117 style::{Color, Formatting, LabelStyle},
118 };
119
120 pub struct Marker {
122 pub marker: String,
124
125 pub formatting: Formatting,
127 }
128
129 pub struct SelectionStyle {
131 pub label_style: LabelStyle,
133
134 pub submitted_formatting: Formatting,
136
137 pub option_formatting: Formatting,
139
140 pub selected_option_formatting: Formatting,
142
143 pub filter_formatting: Formatting,
145
146 pub not_selected_marker: Marker,
148
149 pub selected_marker: Marker,
151 }
152
153 impl Default for SelectionStyle {
154 fn default() -> Self {
155 SelectionStyle {
156 label_style: LabelStyle::default(),
157 submitted_formatting: Formatting::default().foreground_color(Color::Green),
158 option_formatting: Formatting::default(),
159 selected_option_formatting: Formatting::default().bold(),
160 filter_formatting: Formatting::default(),
161 not_selected_marker: Marker {
162 marker: " ".into(),
163 formatting: Formatting::default(),
164 },
165 selected_marker: Marker {
166 marker: "> ".into(),
167 formatting: Formatting::default().bold(),
168 },
169 }
170 }
171 }
172
173 impl SelectionStyle {
174 pub fn label_style(mut self, l: LabelStyle) -> Self {
175 self.label_style = l;
176 self
177 }
178
179 pub fn submitted_formatting(mut self, f: Formatting) -> Self {
180 self.submitted_formatting = f;
181 self
182 }
183
184 pub fn option_formatting(mut self, f: Formatting) -> Self {
185 self.option_formatting = f;
186 self
187 }
188
189 pub fn not_selected_marker(mut self, m: Marker) -> Self {
190 self.not_selected_marker = m;
191 self
192 }
193
194 pub fn selected_marker(mut self, m: Marker) -> Self {
195 self.selected_marker = m;
196 self
197 }
198 }
199
200 impl Marker {
201 pub fn print(&self, cmd_buffer: &mut impl CommandBuffer) {
202 cmd_buffer.set_formatting(&self.formatting);
203 cmd_buffer.print(&self.marker);
204 cmd_buffer.reset_formatting();
205 }
206 }
207}
208
209pub mod multiselection {
210 use crate::{
211 engine::CommandBuffer,
212 style::{Color, Formatting, LabelStyle},
213 };
214
215 pub struct MultiselectionStyle {
217 pub label_style: LabelStyle,
219
220 pub submitted_formatting: Formatting,
222
223 pub filter_formatting: Formatting,
225
226
227 pub help_message_formatting: Formatting,
229
230 pub marker: Marker,
232
233 pub highlighted_option_formatting: Formatting,
235
236 pub normal_option_formatting: Formatting,
238 }
239
240 pub struct Marker {
245 pub opening_sign: String,
247
248 pub closing_sign: String,
250
251 pub selection_sign: String,
253 }
254
255 impl Default for MultiselectionStyle {
256 fn default() -> Self {
257 MultiselectionStyle {
258 label_style: LabelStyle::default(),
259 submitted_formatting: Formatting::default().foreground_color(Color::Green),
260 filter_formatting: Formatting::default(),
261 help_message_formatting: Formatting::default().foreground_color(Color::DarkGreen),
262 marker: Marker {
263 opening_sign: "[".into(),
264 selection_sign: "x".into(),
265 closing_sign: "]".into(),
266 },
267 highlighted_option_formatting: Formatting::default()
268 .foreground_color(Color::DarkGreen),
269 normal_option_formatting: Formatting::default(),
270 }
271 }
272 }
273
274 impl Marker {
275 pub fn print(&self, is_selected: bool, commands: &mut impl CommandBuffer) {
277 let sign = if is_selected {
278 &self.selection_sign
279 } else {
280 " "
281 };
282 commands.print(&format!(
283 "{}{}{}",
284 self.opening_sign, sign, self.closing_sign
285 ));
286 }
287 }
288
289 impl MultiselectionStyle {
290
291 pub fn print_option(
294 &self,
295 option_text: &str,
296 is_selected: bool,
297 is_highlighted: bool,
298 commands: &mut impl CommandBuffer,
299 ) {
300 let formatting = if is_highlighted {
301 &self.highlighted_option_formatting
302 } else {
303 &self.normal_option_formatting
304 };
305
306 commands.set_formatting(formatting);
307 self.marker.print(is_selected, commands);
308 commands.print(" ");
309
310 commands.print(option_text);
311 commands.reset_formatting();
312 }
313 }
314}