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

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

medakk opened this issue · comments

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?

never mind, I figure it out:

stdout.write(s.to_string().as_bytes())

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

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