Crate ansi_rgb

Source
Expand description

Colorful console text using ANSI escape sequences.

§Foreground colors

use ansi_rgb::{ Foreground, red };

println!("{}", "Hello, world!".fg(red()));

Output:

Hello, world!

§Background colors

use ansi_rgb::{ Background, red };

println!("{}", "Hello, world!".bg(red()));

Output:

Hello, world!

§Mix and match

# Cargo.toml
[dependencies]
rbg = "0.8"
use ansi_rgb::{ Foreground, Background };
use rgb::RGB8;

let fg = RGB8::new(123, 231, 111);
let bg = RGB8::new(10, 100, 20);
println!("{}", "Yuck".fg(fg).bg(bg));

Output:

Yuck

§Anything formattable

#[derive(Debug)]
struct Foo(i32, i32);

let foo = Foo(1, 2);
println!("{:?}", foo.fg(green()));

Output:

Foo(1, 2)

§Windows users

You need to set your console mode. Otherwise you’ll get garbage like this:

�[48;2;159;114;0m �[0m

Structs§

WithBackground
Something with a background color
WithForeground
Something with a foreground color

Traits§

Background
Adds a background color
Foreground
Adds a foreground color

Functions§

black
Makes black
blue
Makes blue
blue_magenta
Makes blue magenta
cyan
Makes cyan
cyan_blue
Makes cyan blue
green
Makes green
green_cyan
Makes green cyan
magenta
Makes magenta
magenta_pink
Makes magenta pink
orange
Makes orange
red
Makes red
white
Makes white
yellow
Makes yellow
yellow_green
Makes yellow green