A simple, fast library for styling text with ANSI escape codes.
Features
- Simple, intuitive API
- Fast, no allocations
#![no_std]support- No dependencies
- Supports hyperlinks
- Supports globally enabling and disabling styling
Usage
Use the style function to create a Styled value which can be styled using methods from the Stylize trait and can be displayed.
use ;
println!;
The Stylize trait provides methods for setting the foreground color, background color, underline color, and attributes of the text (such as bold, italic, etc).
Available attributes are:
bolddimitalicunderlinedblinkinvertedhiddenstrikethrough
Available colors include basic ANSI colors, the extended 256-color palette, and RGB colors.
The ANSI colors are:
blackredgreenyellowbluemagentacyanwhite
Plus bright variants.
There are methods on the Style struct for setting the foreground color, background color and underline color to basic ansi colors:
use ;
println!;
There are also fg, bg and underline_colored methods that take a Color or any other value implementing Into<Color>, allowing the use of colors from the extended 256-color palette and RGB colors:
use ;
// Setting the foreground color to red.
println!;
println!;
// Setting the background color to a color from the 256-color palette.
println!;
println!;
// Setting the underline color to a RGB color.
println!;
println!;
Styles can also be created and stored for later use:
use ;
let my_style = new.bold.bright_blue;
println!;
Enabling and disabling styling
Use the set_style_enabled function from the enable module to globally enable or disable styling. See the module documentation for more information.