A simple cross platform library for writing colored text to a terminal. This library writes colored text either using standard ANSI escape sequences or by interacting with the Windows console. Several convenient abstractions are provided for use in single-threaded or multi-threaded command line applications.
Dual-licensed under MIT or the UNLICENSE.
Add this to your
 = "1.1"
WriteColor trait extends the
io::Write trait with methods for setting
colors or resetting them.
StandardStreamLock both satisfy
WriteColor and are
Buffer is an in memory buffer that supports colored text. In a parallel
program, each thread might write to its own buffer. A buffer can be printed to
stdout or stderr using a
BufferWriter. The advantage of this design is that
each thread can work in parallel on a buffer without having to synchronize
access to global resources such as the Windows console. Moreover, this design
also prevents interleaving of buffer output.
NoColor both satisfy
WriteColor for arbitrary implementors of
io::Write. These types are useful when you know exactly what you need. An
analogous type for the Windows console is not provided since it cannot exist.
StandardStream type in this crate works similarly to
except it is augmented with methods for coloring by the
For example, to write some green text:
use ; use ;
BufferWriter can create buffers and write buffers to stdout or stderr. It
does not implement
WriteColor itself. Instead,
This example shows how to print some green text to stderr.
use ; use ;
Automatic color selection
When building a writer with termcolor, the caller must provide a
selection. When the color choice is
Auto, termcolor will attempt to determine
whether colors should be enabled by inspecting the environment. Currently,
termcolor will inspect the
NO_COLOR environment variables:
NO_COLORis set to any value, then colors will be suppressed.
TERMis set to
dumb, then colors will be suppressed.
- In non-Windows environments, if
TERMis not set, then colors will be suppressed.
This decision procedure may change over time.
termcolor does not attempt to detect whether a tty is present or
not. To achieve that, please use the
Minimum Rust version policy
This crate's minimum supported
rustc version is
The current policy is that the minimum Rust version required to use this crate
can be increased in minor version updates. For example, if
crate 1.0 requires
Rust 1.20.0, then
crate 1.0.z for all values of
z will also require Rust
1.20.0 or newer. However,
crate 1.y for
y > 0 may require a newer minimum
version of Rust.
In general, this crate will be conservative with respect to the minimum supported version of Rust.