ansi_term 0.3.0

Library for ANSI terminal colours and styles (bold, underline)
docs.rs failed to build ansi_term-0.3.0
Please check the build logs and, if you believe this is docs.rs' fault, open an issue.

rust-ansi-term Build Status

This is a library for controlling colours and formatting, such as red bold text or blue underlined text, on ANSI terminals.

View the Rustdoc

Installation

It uses Cargo, Rust's package manager. You can depend on this library by adding this Git repository to your Cargo dependencies:

[dependencies.ansi_term]

git = "https://github.com/ogham/rust-ansi-term.git"

Usage

You can format strings by calling the paint method on a Colour or a Style object, passing in the string you want to format. Here are some examples:

extern crate ansi_term;
use ansi_term::Colour::{Black, Red, Green, Yellow, Blue, Purple, Cyan, Fixed};
use ansi_term::Style::Plain;
use ansi_term::Paint;
fn main() {
    println!("Red text: {}", Red.paint("Red!"));

    println!("Blue bold text: {}", Blue.bold().paint("Blue bold!"));
    println!("Yellow underline text: {}", Yellow.underline().paint("Yellow underline!"));
    println!("Blue on yellow text: {}", Blue.on(Yellow).paint("Blue on yellow!"));

    println!("Colour #134: {}", Fixed(134).paint("A sort of light purple."));
    println!("Colour #221 on #124: {}", Fixed(221).on(Fixed(124)).paint("Mustard in the ketchup."));

    println!("No formatting: {}", Plain.paint("No colours here."));
}

Available colours are Black, Red, Yellow, Green, Blue, Purple, Cyan, White, and Fixed(n) up to 256. Available formattings are .bold(), .underline(), and .on(colour).