A simple, fast library for styling text with ANSI escape codes.
Features
- Simple, intuitive API
- Fast, no allocations
- No dependencies
#![no_std]out of the box- Hyperlink support
Basic Usage
Import the Styleable trait for an easy way to create
styled values. Then use the methods from Styled to style the value.
use Styleable;
println!;
You can also create a style and apply it later. Style has the same
styling options as Styled. Styling methods (on both types) are const,
so you can create constant styles.
use ;
const EMPHASIS: Style = new.bold.italic;
println!;
Styling
Both Style and Styled have 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 for setting the foreground color, background color and underline color to basic ANSI colors:
use Styleable;
println!;
There are also fg, bg
and underline_colored methods that take a 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!;
You can also create attributes separately and apply them later:
use ;
let my_attrs = ITALIC | STRIKETHROUGH;
println!;
Attributes have methods for performing bitwise operations in a const environment:
use ;
const MY_ATTRS: Attributes = ITALIC.or;
println!;
Hyperlinks
You can add a hyperlink to a styled value using the Styled::link method:
use Styleable;
println!;