Skip to content

rust-osdev/ansi_rgb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ansi_rgb

Colorful console text using ANSI escape sequences.

crates.io badge
docs.rs badge
Downloads badge

Cargo.toml:

ansi_rgb = "0.2.0"

Foreground colors

use ansi_rgb::{ Foreground, red };

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

Output:

Red on natural

Background colors

use ansi_rgb::{ Background, red };

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

Output:

Natural on red

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:

Green foo

Windows users

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

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

About

Colorful terminal text using ANSI escape sequences

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages