Ben Chuanlong Du's Blog

It is never too late to learn.

Print Colored Text in Terminal in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Comments

There are a few crates yansi, termcolor, colored, and ansi_term in Rust which can help print colorful text in terminal. Yansi is recommended as it is dead simple and the project is active.

Hands on yansi

In [2]:
:dep yansi = "0.5.1"
In [3]:
use yansi::Paint;
In [4]:
println!("{} light, {} light!", Paint::green("Green"), Paint::red("red").underline());
Green light, red light!
In [ ]:

Comments