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 Into for MessageKind { fn into(self) -> Color { match self { Self::Error => PINK, Self::Info => WHITE, Self::Hint => CYAN, Self::LispResult => GREY, } } }