cargo_swift/console/
theme.rs1use core::fmt;
2
3use console::Style;
4use dialoguer::theme::{ColorfulTheme, Theme};
5
6pub fn prompt_theme() -> impl Theme {
7 PromptTheme {
8 theme: ColorfulTheme::default(),
9 done: ColorfulTheme {
10 prompt_style: Style::new().for_stderr(),
11 ..ColorfulTheme::default()
12 },
13 }
14}
15
16pub struct PromptTheme<T: Theme> {
17 theme: T,
19 done: T,
21}
22
23impl<T: Theme> Theme for PromptTheme<T> {
24 #[inline]
26 fn format_prompt(&self, f: &mut dyn fmt::Write, prompt: &str) -> fmt::Result {
27 self.theme.format_prompt(f, prompt)
28 }
29
30 #[inline]
32 fn format_error(&self, f: &mut dyn fmt::Write, err: &str) -> fmt::Result {
33 self.theme.format_error(f, err)
34 }
35
36 fn format_confirm_prompt(
38 &self,
39 f: &mut dyn fmt::Write,
40 prompt: &str,
41 default: Option<bool>,
42 ) -> fmt::Result {
43 self.theme.format_confirm_prompt(f, prompt, default)
44 }
45
46 fn format_confirm_prompt_selection(
48 &self,
49 f: &mut dyn fmt::Write,
50 prompt: &str,
51 selection: Option<bool>,
52 ) -> fmt::Result {
53 self.done
54 .format_confirm_prompt_selection(f, prompt, selection)
55 }
56
57 fn format_input_prompt(
59 &self,
60 f: &mut dyn fmt::Write,
61 prompt: &str,
62 default: Option<&str>,
63 ) -> fmt::Result {
64 self.theme.format_input_prompt(f, prompt, default)
65 }
66
67 #[inline]
69 fn format_input_prompt_selection(
70 &self,
71 f: &mut dyn fmt::Write,
72 prompt: &str,
73 sel: &str,
74 ) -> fmt::Result {
75 self.done.format_input_prompt_selection(f, prompt, sel)
76 }
77
78 #[inline]
80 fn format_select_prompt(&self, f: &mut dyn fmt::Write, prompt: &str) -> fmt::Result {
81 self.theme.format_select_prompt(f, prompt)
82 }
83
84 #[inline]
86 fn format_select_prompt_selection(
87 &self,
88 f: &mut dyn fmt::Write,
89 prompt: &str,
90 sel: &str,
91 ) -> fmt::Result {
92 self.done.format_select_prompt_selection(f, prompt, sel)
93 }
94
95 #[inline]
97 fn format_multi_select_prompt(&self, f: &mut dyn fmt::Write, prompt: &str) -> fmt::Result {
98 self.format_prompt(f, prompt)
99 }
100
101 #[inline]
103 fn format_sort_prompt(&self, f: &mut dyn fmt::Write, prompt: &str) -> fmt::Result {
104 self.format_prompt(f, prompt)
105 }
106
107 fn format_multi_select_prompt_selection(
109 &self,
110 f: &mut dyn fmt::Write,
111 prompt: &str,
112 selections: &[&str],
113 ) -> fmt::Result {
114 self.done
115 .format_multi_select_prompt_selection(f, prompt, selections)
116 }
117
118 #[inline]
120 fn format_sort_prompt_selection(
121 &self,
122 f: &mut dyn fmt::Write,
123 prompt: &str,
124 selections: &[&str],
125 ) -> fmt::Result {
126 self.done
127 .format_sort_prompt_selection(f, prompt, selections)
128 }
129
130 fn format_select_prompt_item(
132 &self,
133 f: &mut dyn fmt::Write,
134 text: &str,
135 active: bool,
136 ) -> fmt::Result {
137 self.theme.format_select_prompt_item(f, text, active)
138 }
139
140 fn format_multi_select_prompt_item(
142 &self,
143 f: &mut dyn fmt::Write,
144 text: &str,
145 checked: bool,
146 active: bool,
147 ) -> fmt::Result {
148 self.theme
149 .format_multi_select_prompt_item(f, text, checked, active)
150 }
151
152 fn format_sort_prompt_item(
154 &self,
155 f: &mut dyn fmt::Write,
156 text: &str,
157 picked: bool,
158 active: bool,
159 ) -> fmt::Result {
160 self.theme.format_sort_prompt_item(f, text, picked, active)
161 }
162}