From 29d49dddaae57d59a2c99c376a632a0d9560dcfc Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 18 Jul 2020 21:05:27 +0530 Subject: add message type --- src/app/message.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/app/message.rs (limited to 'src/app') 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 @@ +use cursive::theme::{BaseColor, Color}; + +#[derive(Debug, Clone, Copy)] +pub enum MessageKind { + Error, + Info, + Hint, +} + +impl From 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), + } + } +} + +pub struct Message { + msg: String, + kind: MessageKind, +} + +impl Message { + 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>(&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, + } + } +} -- cgit v1.2.3