1use std::borrow::Cow;
2use std::fmt;
3use std::sync::Arc;
4
5type Text = Cow<'static, str>;
6
7#[derive(Clone)]
8#[non_exhaustive]
9pub struct Words {
10 pub help: Text,
11 pub again: Text,
12 pub yes: Text,
13 pub no: Text,
14 pub choose: Text,
15 pub leave: Text,
16 pub too_small: Text,
17 pub waiting: Text,
18 pub busy: Arc<dyn Fn(usize) -> String + Send + Sync>,
19}
20
21impl Words {
22 pub fn new() -> Self {
23 Words {
24 help: Cow::Borrowed(""),
25 again: Cow::Borrowed(""),
26 yes: Cow::Borrowed(""),
27 no: Cow::Borrowed(""),
28 choose: Cow::Borrowed(""),
29 leave: Cow::Borrowed(""),
30 too_small: Cow::Borrowed(""),
31 waiting: Cow::Borrowed(""),
32 busy: Arc::new(|_| String::new()),
33 }
34 }
35
36 pub fn help(mut self, text: impl Into<Text>) -> Self {
37 self.help = text.into();
38 self
39 }
40
41 pub fn again(mut self, text: impl Into<Text>) -> Self {
42 self.again = text.into();
43 self
44 }
45
46 pub fn yes(mut self, text: impl Into<Text>) -> Self {
47 self.yes = text.into();
48 self
49 }
50
51 pub fn no(mut self, text: impl Into<Text>) -> Self {
52 self.no = text.into();
53 self
54 }
55
56 pub fn choose(mut self, text: impl Into<Text>) -> Self {
57 self.choose = text.into();
58 self
59 }
60
61 pub fn leave(mut self, text: impl Into<Text>) -> Self {
62 self.leave = text.into();
63 self
64 }
65
66 pub fn too_small(mut self, text: impl Into<Text>) -> Self {
67 self.too_small = text.into();
68 self
69 }
70
71 pub fn waiting(mut self, text: impl Into<Text>) -> Self {
72 self.waiting = text.into();
73 self
74 }
75
76 pub fn busy(mut self, words: impl Fn(usize) -> String + Send + Sync + 'static) -> Self {
77 self.busy = Arc::new(words);
78 self
79 }
80}
81
82impl Default for Words {
83 fn default() -> Self {
84 Words::new()
85 }
86}
87
88impl fmt::Debug for Words {
89 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
90 f.debug_struct("Words")
91 .field("help", &self.help)
92 .field("again", &self.again)
93 .field("yes", &self.yes)
94 .field("no", &self.no)
95 .field("choose", &self.choose)
96 .field("leave", &self.leave)
97 .field("too_small", &self.too_small)
98 .field("waiting", &self.waiting)
99 .finish_non_exhaustive()
100 }
101}