This repository has been archived by the owner on Jun 14, 2021. It is now read-only.
generated from josephjkahn/quantum_god2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.rs
109 lines (90 loc) · 2.36 KB
/
message.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use super::emoji;
use billboard::{Billboard, BorderColor, BorderStyle};
use serde::Serialize;
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Output {
Json,
PlainText,
}
pub trait Message {
fn message(msg: &str);
fn info(msg: &str) {
let msg = format!("{} {}", emoji::INFO, msg);
Self::message(&msg);
}
fn warn(msg: &str) {
let msg = format!("{} {}", emoji::WARN, msg);
Self::message(&msg);
}
fn success(msg: &str) {
let msg = format!("{} {}", emoji::SPARKLES, msg);
Self::message(&msg);
}
fn user_error(msg: &str) {
let msg = format!("{} {}", emoji::EYES, msg);
Self::message(&msg);
}
fn working(msg: &str) {
let msg = format!("{} {}", emoji::SWIRL, msg);
Self::message(&msg);
}
fn preview(msg: &str) {
let msg = format!("{} {}", emoji::WORKER, msg);
Self::message(&msg);
}
fn help(msg: &str) {
let msg = format!("{} {}", emoji::SLEUTH, msg);
Self::message(&msg);
}
fn billboard(msg: &str);
fn deprecation_warning(msg: &str);
fn as_json<T>(value: &T)
where
T: ?Sized + Serialize;
}
pub struct StdOut;
impl Message for StdOut {
fn message(msg: &str) {
println!("{}", msg);
}
fn billboard(msg: &str) {
let billboard = Billboard::builder()
.border_style(BorderStyle::Round)
.border_color(BorderColor::Cyan)
.margin(1)
.build();
billboard.display(msg);
}
fn deprecation_warning(msg: &str) {
let bb = Billboard::builder()
.border_style(BorderStyle::Round)
.border_color(BorderColor::Red)
.margin(1)
.build();
bb.display(msg);
}
fn as_json<T>(value: &T)
where
T: ?Sized + Serialize,
{
println!("{}", &serde_json::to_string(value).unwrap());
}
}
pub struct StdErr;
impl Message for StdErr {
fn message(msg: &str) {
eprintln!("{}", msg);
}
fn billboard(_msg: &str) {
panic!("Can't display billboard to stderr.")
}
fn deprecation_warning(_msg: &str) {
panic!("Can't display billboard warning to stderr.")
}
fn as_json<T>(_value: &T)
where
T: ?Sized + Serialize,
{
panic!("Json output intended for stdout, not stderr.")
}
}