Skip to main content

git_gamble/
message.rs

1use std::fmt::Display;
2
3use yansi::Paint;
4use yansi::Painted;
5
6#[derive(Clone, Debug)]
7pub enum Message {
8	Error(String),
9	Warn(String),
10	Info(String),
11}
12
13impl Message {
14	fn color(&self) -> Painted<&String> {
15		match self {
16			Self::Error(msg) => msg.bold().red(),
17			Self::Warn(msg) => msg.bold().yellow(),
18			Self::Info(msg) => msg.bold().blue(),
19		}
20	}
21
22	pub fn display(&self) {
23		println!("{self}")
24	}
25}
26
27impl Display for Message {
28	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29		write!(f, "{}", self.color())
30	}
31}