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
//! # rust-colors
//!
//! `rust-colors` is a library for parsing ANSI Strings to colors. 
//! 
//! ## Example
//! ```
//! use rust_colors::{Ansi, Color};
//! 
//! fn my_function() {
//!     let colors = Ansi;
//!    
//!     println!(
//!         "Roses are {}, the sky is {}, I like {} vegetables, but the color {} is even better!",
//!         colors.red("red"),
//!         colors.blue("blue"),
//!         colors.green("green"),
//!         colors.black("black"),
//!     );
//! }
//! 
//! ```
//! 
//! # Github
//! [Git repo RedIsGaming rust-colors](https://github.com/RedIsGaming/rust-colors)

pub use self::ansi_color::{Ansi, Color};
mod colors;

pub mod ansi_color {
    use std::fmt;
    use crate::colors::Colors;

    #[derive(Debug)]
    pub struct Ansi;

    pub trait Color<T: fmt::Debug> {
        type Transform;

        fn black(&self, txt: T) -> Self::Transform;
        fn red(&self, txt: T) -> Self::Transform;
        fn green(&self, txt: T) -> Self::Transform;
        fn yellow(&self, txt: T) -> Self::Transform;
        fn blue(&self, txt: T) -> Self::Transform;
        fn purple(&self, txt: T) -> Self::Transform;
        fn cyan(&self, txt: T) -> Self::Transform;
        fn white(&self, txt: T) -> Self::Transform;
    }

    impl<T: fmt::Debug> Color<T> for Ansi {
        type Transform = String;

        fn black(&self, txt: T) -> Self::Transform {
            format!("\x1b{}{:?}\x1b{}", Colors::assign(&Colors::Black), txt, Colors::assign(&Colors::Default))
        }

        fn red(&self, txt: T) -> Self::Transform {
            format!("\x1b{}{:?}\x1b{}", Colors::assign(&Colors::Red), txt, Colors::assign(&Colors::Default))
        }

        fn green(&self, txt: T) -> Self::Transform {
            format!("\x1b{}{:?}\x1b{}", Colors::assign(&Colors::Green), txt, Colors::assign(&Colors::Default))
        }

        fn yellow(&self, txt: T) -> Self::Transform {
            format!("\x1b{}{:?}\x1b{}", Colors::assign(&Colors::Yellow), txt, Colors::assign(&Colors::Default))
        }

        fn blue(&self, txt: T) -> Self::Transform {
            format!("\x1b{}{:?}\x1b{}", Colors::assign(&Colors::Blue), txt, Colors::assign(&Colors::Default))
        }

        fn purple(&self, txt: T) -> Self::Transform {
            format!("\x1b{}{:?}\x1b{}", Colors::assign(&Colors::Purple), txt, Colors::assign(&Colors::Default))
        }

        fn cyan(&self, txt: T) -> Self::Transform {
            format!("\x1b{}{:?}\x1b{}", Colors::assign(&Colors::Cyan), txt, Colors::assign(&Colors::Default))
        }

        fn white(&self, txt: T) -> Self::Transform {
            format!("\x1b{}{:?}\x1b{}", Colors::assign(&Colors::White), txt, Colors::assign(&Colors::Default))
        }
    }
}