1
2
3
4
5use colored::*;
6
7
8
9pub enum LogColor {
10 Blue,
11 Green,
12 Red,
13 Black,
14 White,
15 Purple,
16 Yellow,
17 Custom {r:u8,g:u8,b:u8}
18
19}
20
21impl LogColor {
22
23 fn get_message_of_color(&self, input_message:String) -> ColoredString {
24
25
26 match self {
27
28
29 Self::Blue => input_message.blue(),
30 Self::Green => input_message.green(),
31 Self::Red => input_message.red(),
32 Self::Black => input_message.black(),
33 Self::White => input_message.white(),
34 Self::Purple => input_message.purple(),
35 Self::Yellow => input_message.yellow(),
36 Self::Custom {r,g,b} => input_message.truecolor(r.clone(), g.clone(), b.clone())
37
38
39 }
40
41 }
42
43
44}
45
46
47pub trait DegenLogStyle {
48
49 fn get_log_color( &self ) -> LogColor ;
50
51 fn bold( &self ) -> bool;
52
53 fn show( &self ) -> bool;
54
55
56}
57
58pub fn log<T:DegenLogStyle>( message:String , style: T ) {
59
60
61 let log_color = style.get_log_color();
62
63 if style.show() {
64 match style.bold() {
65 true => println!( "{}" , log_color.get_message_of_color(message).bold()) ,
66 false => println!( "{}" , log_color.get_message_of_color(message) )
67
68 }
69 }
70
71
72}
73
74
75
76pub fn log_str<T:DegenLogStyle>( message:&str , style: T ) {
77
78
79 let log_color = style.get_log_color();
80
81 if style.show() {
82 match style.bold() {
83 true => println!( "{}" , log_color.get_message_of_color(message.into()).bold()) ,
84 false => println!( "{}" , log_color.get_message_of_color(message.into()) )
85
86 }
87 }
88
89
90}