colored-rs / colored

(Rust) Coloring terminal so simple you already know how to do it !

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coloring for write!

shusheaan opened this issue · comments

Hi there,

This crate is awesome!!! Thanks for the work.

I'm trying to apply color in write!() instead of println!(), since I'm writing fmt::Display for my own enum and it will be println! later with other variables. I would like to define different colors for different enum value so that it's visually good. How can I do that?

To be specific, here's the code

enum Type {
    A,
    B,
}

impl fmt::Display for Type {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
             Type::A => {write!(f, "A")}, // can I add color here? like red for A and green for B?
             Type::B => {write!(f, "B")},
        }
    }
}

Thanks

directly writing "A".red() shows a compiler error: "argument never used" pointing ".red()"