cli_prompts/style/
label_style.rs1use crate::engine::CommandBuffer;
2
3use super::{Color, Formatting};
4
5#[derive(Clone)]
7pub struct LabelStyle {
8 prefix: String,
9 prefix_formatting: Formatting,
10 prompt_formatting: Formatting,
11}
12
13impl LabelStyle {
14
15 pub fn prefix<S: Into<String>>(mut self, p: S) -> Self {
17 self.prefix = p.into();
18 self
19 }
20
21 pub fn prefix_formatting(mut self, f: Formatting) -> Self {
23 self.prefix_formatting = f;
24 self
25 }
26
27 pub fn prompt_formatting(mut self, f: Formatting) -> Self {
29 self.prompt_formatting = f;
30 self
31 }
32
33 pub fn print(&self, text: impl Into<String>, cmd_buffer: &mut impl CommandBuffer) {
35 cmd_buffer.set_formatting(&self.prefix_formatting);
36 cmd_buffer.print(&self.prefix);
37 cmd_buffer.reset_formatting();
38 cmd_buffer.print(" ");
39 cmd_buffer.set_formatting(&self.prompt_formatting);
40 cmd_buffer.print(&text.into());
41 cmd_buffer.print(":");
42 cmd_buffer.reset_formatting();
43 cmd_buffer.print(" ");
44 }
45}
46
47impl Default for LabelStyle {
48 fn default() -> Self {
49 LabelStyle {
50 prefix: "?".into(),
51 prefix_formatting: Formatting::default().bold().foreground_color(Color::Green),
52 prompt_formatting: Formatting::default().bold(),
53 }
54 }
55}