colored-rs / colored

(Rust) Coloring terminal so simple you already know how to do it !
Mozilla Public License 2.0
1.73k stars 83 forks source link

How to use with std::io::stdout? #89

Closed medakk closed 4 years ago

medakk commented 4 years ago

The library works fine when I am using print! or println!. But when writing to stdout, like:

let mut stdout = stdout();
let s = "Hello\n".truecolor(200, 50, 50);
stdout.write(s.as_bytes());
stdout.flush();

I see only regular black-and-white text. How do I get the library to work with stdout?

medakk commented 4 years ago

never mind, I figure it out:

stdout.write(s.to_string().as_bytes())
spenserblack commented 4 years ago

You might also want to check out the write! macro. This should work fine

write!(stdout, "{}", "Hello".truecolor(200, 50, 50));