1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
use cursive::theme::{BaseColor, Color};
#[derive(Debug, Clone, Copy)]
pub enum MessageKind {
Error,
Info,
Hint,
}
impl From<MessageKind> for Color {
fn from(item: MessageKind) -> Self {
match item {
MessageKind::Error => Color::Dark(BaseColor::Red),
MessageKind::Info => Color::Dark(BaseColor::Yellow),
MessageKind::Hint => Color::Dark(BaseColor::White),
}
}
}
impl<T> From<T> for Message
where
T: AsRef<str>,
{
fn from(item: T) -> Self {
return Message {
msg: item.as_ref().to_string(),
kind: MessageKind::Info,
};
}
}
pub struct Message {
msg: String,
kind: MessageKind,
}
impl Message {
pub fn startup() -> Self {
"Type :add <habit-name> <goal> to get started, Ctrl-L to dismiss".into()
}
pub fn contents(&self) -> &str {
&self.msg
}
pub fn kind(&self) -> MessageKind {
self.kind
}
pub fn set_kind(&mut self, k: MessageKind) {
self.kind = k;
}
pub fn set_message<S: AsRef<str>>(&mut self, m: S) {
self.msg = m.as_ref().into();
}
pub fn clear(&mut self) {
self.msg.clear()
}
}
impl std::default::Default for Message {
fn default() -> Self {
Message {
msg: String::new(),
kind: MessageKind::Info,
}
}
}
|