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
#[cfg(not(target_os = "solana"))]
pub use console::style;

#[cfg(target_os = "solana")]
mod console_style {
    use std::fmt::*;

    pub struct ConsoleStyle<'t>(pub &'t str);

    impl<'t> ConsoleStyle<'t> {
        pub fn black(&'t self) -> &'t Self {
            self
        }
        pub fn white(&'t self) -> &'t Self {
            self
        }
        pub fn red(&'t self) -> &'t Self {
            self
        }
        pub fn green(&'t self) -> &'t Self {
            self
        }
        pub fn blue(&'t self) -> &'t Self {
            self
        }
        pub fn yellow(&'t self) -> &'t Self {
            self
        }
        pub fn cyan(&'t self) -> &'t Self {
            self
        }
        pub fn magenta(&'t self) -> &'t Self {
            self
        }
        pub fn color256(&'t self) -> &'t Self {
            self
        }

        pub fn on_black(&'t self) -> &'t Self {
            self
        }
        pub fn on_white(&'t self) -> &'t Self {
            self
        }
        pub fn on_red(&'t self) -> &'t Self {
            self
        }
        pub fn on_green(&'t self) -> &'t Self {
            self
        }
        pub fn on_blue(&'t self) -> &'t Self {
            self
        }
        pub fn on_yellow(&'t self) -> &'t Self {
            self
        }
        pub fn on_cyan(&'t self) -> &'t Self {
            self
        }
        pub fn on_magenta(&'t self) -> &'t Self {
            self
        }
    }

    impl<'t> Display for ConsoleStyle<'t> {
        fn fmt(&self, f: &mut Formatter) -> Result {
            write!(f, "{}", self.0)
        }
    }

    // #[cfg(target_os = "solana")]
    // impl<'t> Into<&'t str> for ConsoleStyle<'t> {
    //     fn into(self) -> &'t str { self.text }
    // }
}

#[cfg(target_os = "solana")]
pub fn style<'t>(text: &'t str) -> console_style::ConsoleStyle<'t> {
    console_style::ConsoleStyle(text)
}

cfg_if::cfg_if! {
    if #[cfg(target_os = "solana")] {
        pub fn set_colors_enabled(_:bool) { }
    } else {
        pub fn set_colors_enabled(enable: bool) {
            console::set_colors_enabled(enable)
        }
    }
}