aboutsummaryrefslogtreecommitdiff
path: root/src/message.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-03-25 07:39:05 +0000
committerAkshay <[email protected]>2021-03-25 07:39:05 +0000
commit3fff29b73c0402f6cd82c47990a372fcf68b44c3 (patch)
tree557e7648a8de688a8e9eba4a5b5c4e05df3ab289 /src/message.rs
parent8171b30adbc4cddd2c51f043c3379d78428666b8 (diff)
impl message colors; reading file path on load
Diffstat (limited to 'src/message.rs')
-rw-r--r--src/message.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/message.rs b/src/message.rs
index d1032cf..958dd68 100644
--- a/src/message.rs
+++ b/src/message.rs
@@ -1,3 +1,7 @@
1use crate::consts::colors::*;
2
3use sdl2::pixels::Color;
4
1#[derive(Debug)] 5#[derive(Debug)]
2pub struct Message { 6pub struct Message {
3 pub text: String, 7 pub text: String,
@@ -11,14 +15,36 @@ impl Message {
11 kind: MessageKind::Info, 15 kind: MessageKind::Info,
12 } 16 }
13 } 17 }
18
14 pub fn kind(mut self, kind: MessageKind) -> Self { 19 pub fn kind(mut self, kind: MessageKind) -> Self {
15 self.kind = kind; 20 self.kind = kind;
16 self 21 self
17 } 22 }
23
18 pub fn text<S: AsRef<str>>(mut self, text: S) -> Self { 24 pub fn text<S: AsRef<str>>(mut self, text: S) -> Self {
19 self.text = text.as_ref().into(); 25 self.text = text.as_ref().into();
20 self 26 self
21 } 27 }
28
29 pub fn set_info<S: AsRef<str>>(&mut self, text: S) {
30 self.text = text.as_ref().into();
31 self.kind = MessageKind::Info;
32 }
33
34 pub fn set_error<S: AsRef<str>>(&mut self, text: S) {
35 self.text = text.as_ref().into();
36 self.kind = MessageKind::Error;
37 }
38
39 pub fn set_hint<S: AsRef<str>>(&mut self, text: S) {
40 self.text = text.as_ref().into();
41 self.kind = MessageKind::Hint;
42 }
43
44 pub fn clear(&mut self) {
45 self.text.clear();
46 self.kind = MessageKind::Info;
47 }
22} 48}
23 49
24#[derive(Debug, Copy, Clone)] 50#[derive(Debug, Copy, Clone)]
@@ -40,3 +66,14 @@ where
40 }; 66 };
41 } 67 }
42} 68}
69
70impl Into<Color> for MessageKind {
71 fn into(self) -> Color {
72 match self {
73 Self::Error => PINK,
74 Self::Info => WHITE,
75 Self::Hint => CYAN,
76 Self::LispResult => GREY,
77 }
78 }
79}