use crate::consts::colors::*; use sdl2::pixels::Color; #[derive(Debug)] pub struct Message { pub text: String, pub kind: MessageKind, } impl Message { pub fn new() -> Self { Self { text: String::new(), kind: MessageKind::Info, } } pub fn kind(mut self, kind: MessageKind) -> Self { self.kind = kind; self } pub fn text>(mut self, text: S) -> Self { self.text = text.as_ref().into(); self } pub fn set_info>(&mut self, text: S) { self.text = text.as_ref().into(); self.kind = MessageKind::Info; } pub fn set_error>(&mut self, text: S) { self.text = text.as_ref().into(); self.kind = MessageKind::Error; } pub fn set_hint>(&mut self, text: S) { self.text = text.as_ref().into(); self.kind = MessageKind::Hint; } pub fn clear(&mut self) { self.text.clear(); self.kind = MessageKind::Info; } } #[derive(Debug, Copy, Clone)] pub enum MessageKind { Error, Info, Hint, LispResult, } impl From for Message where T: AsRef, { fn from(item: T) -> Self { return Message { text: item.as_ref().into(), kind: MessageKind::Info, }; } } impl std::default::Default for Message { fn default() -> Self { Message::new() } } impl From for Color { fn from(msg: MessageKind) -> Color { match msg { MessageKind::Error => PINK, MessageKind::Info => WHITE, MessageKind::Hint => CYAN, MessageKind::LispResult => GREY, } } }