aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/message.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/app/message.rs b/src/app/message.rs
new file mode 100644
index 0000000..34d3293
--- /dev/null
+++ b/src/app/message.rs
@@ -0,0 +1,50 @@
1use cursive::theme::{BaseColor, Color};
2
3#[derive(Debug, Clone, Copy)]
4pub enum MessageKind {
5 Error,
6 Info,
7 Hint,
8}
9
10impl From<MessageKind> for Color {
11 fn from(item: MessageKind) -> Self {
12 match item {
13 MessageKind::Error => Color::Dark(BaseColor::Red),
14 MessageKind::Info => Color::Dark(BaseColor::Yellow),
15 MessageKind::Hint => Color::Dark(BaseColor::White),
16 }
17 }
18}
19
20pub struct Message {
21 msg: String,
22 kind: MessageKind,
23}
24
25impl Message {
26 pub fn contents(&self) -> &str {
27 &self.msg
28 }
29 pub fn kind(&self) -> MessageKind {
30 self.kind
31 }
32 pub fn set_kind(&mut self, k: MessageKind) {
33 self.kind = k;
34 }
35 pub fn set_message<S: AsRef<str>>(&mut self, m: S) {
36 self.msg = m.as_ref().into();
37 }
38 pub fn clear(&mut self) {
39 self.msg.clear()
40 }
41}
42
43impl std::default::Default for Message {
44 fn default() -> Self {
45 Message {
46 msg: String::new(),
47 kind: MessageKind::Info,
48 }
49 }
50}