[][src]Enum yansi_term::Colour

pub enum Colour {
    Black,
    Red,
    Green,
    Yellow,
    Blue,
    Purple,
    Cyan,
    White,
    Fixed(u8),
    RGB(u8u8u8),
}

A colour is one specific type of ANSI escape code, and can refer to either the foreground or background colour.

These use the standard numeric sequences. See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html

Variants

Black

Colour #0 (foreground code 30, background code 40).

This is not necessarily the background colour, and using it as one may render the text hard to read on terminals with dark backgrounds.

Red

Colour #1 (foreground code 31, background code 41).

Green

Colour #2 (foreground code 32, background code 42).

Yellow

Colour #3 (foreground code 33, background code 43).

Blue

Colour #4 (foreground code 34, background code 44).

Purple

Colour #5 (foreground code 35, background code 45).

Cyan

Colour #6 (foreground code 36, background code 46).

White

Colour #7 (foreground code 37, background code 47).

As above, this is not necessarily the foreground colour, and may be hard to read on terminals with light backgrounds.

Fixed(u8)

A colour number from 0 to 255, for use in 256-colour terminal environments.

  • Colours 0 to 7 are the Black to White variants respectively. These colours can usually be changed in the terminal emulator.
  • Colours 8 to 15 are brighter versions of the eight colours above. These can also usually be changed in the terminal emulator, or it could be configured to use the original colours and show the text in bold instead. It varies depending on the program.
  • Colours 16 to 231 contain several palettes of bright colours, arranged in six squares measuring six by six each.
  • Colours 232 to 255 are shades of grey from black to white.

It might make more sense to look at a colour chart.

RGB(u8u8u8)

A 24-bit RGB color, as specified by ISO-8613-3.

Implementations

impl Colour[src]

pub fn write_prefix(self, f: &mut Formatter) -> Result<bool, Error>[src]

Write any bytes that go before a piece of text to the given writer.

impl Colour[src]

pub fn normal(self) -> Style[src]

Returns a Style with the foreground colour set to this colour.

Examples

use yansi_term::Colour;

let style = Colour::Red.normal();
println!("{}", style.paint("hi"));

pub fn bold(self) -> Style[src]

Returns a Style with the foreground colour set to this colour and the bold property set.

Examples

use yansi_term::Colour;

let style = Colour::Green.bold();
println!("{}", style.paint("hey"));

pub fn dimmed(self) -> Style[src]

Returns a Style with the foreground colour set to this colour and the dimmed property set.

Examples

use yansi_term::Colour;

let style = Colour::Yellow.dimmed();
println!("{}", style.paint("sup"));

pub fn italic(self) -> Style[src]

Returns a Style with the foreground colour set to this colour and the italic property set.

Examples

use yansi_term::Colour;

let style = Colour::Blue.italic();
println!("{}", style.paint("greetings"));

pub fn underline(self) -> Style[src]

Returns a Style with the foreground colour set to this colour and the underline property set.

Examples

use yansi_term::Colour;

let style = Colour::Purple.underline();
println!("{}", style.paint("salutations"));

Returns a Style with the foreground colour set to this colour and the blink property set.

Examples

use yansi_term::Colour;

let style = Colour::Cyan.blink();
println!("{}", style.paint("wazzup"));

pub fn reverse(self) -> Style[src]

Returns a Style with the foreground colour set to this colour and the reverse property set.

Examples

use yansi_term::Colour;

let style = Colour::Black.reverse();
println!("{}", style.paint("aloha"));

pub fn hidden(self) -> Style[src]

Returns a Style with the foreground colour set to this colour and the hidden property set.

Examples

use yansi_term::Colour;

let style = Colour::White.hidden();
println!("{}", style.paint("ahoy"));

pub fn strikethrough(self) -> Style[src]

Returns a Style with the foreground colour set to this colour and the strikethrough property set.

Examples

use yansi_term::Colour;

let style = Colour::Fixed(244).strikethrough();
println!("{}", style.paint("yo"));

pub fn on(self, background: Colour) -> Style[src]

Returns a Style with the foreground colour set to this colour and the background colour property set to the given colour.

Examples

use yansi_term::Colour;

let style = Colour::RGB(31, 31, 31).on(Colour::White);
println!("{}", style.paint("eyyyy"));

impl Colour[src]

pub fn paint<'a>(self, input: &'a str) -> impl Display + 'a[src]

Paints the given text with this colour This is a short-cut so you don’t have to use Blue.normal() just to get blue text.

use yansi_term::Colour::Blue;
println!("{}", Blue.paint("da ba dee"));

pub fn paint_fn<F: FnOnce(&mut Formatter) -> Result>(self, f: F) -> impl Display[src]

Paints the given format function with this colour

Trait Implementations

impl Clone for Colour[src]

impl Copy for Colour[src]

impl Debug for Colour[src]

impl From<Colour> for Style[src]

fn from(colour: Colour) -> Style[src]

You can turn a Colour into a Style with the foreground colour set with the From trait.

use yansi_term::{Style, Colour};
let green_foreground = Style::default().fg(Colour::Green);
assert_eq!(green_foreground, Colour::Green.normal());
assert_eq!(green_foreground, Colour::Green.into());
assert_eq!(green_foreground, Style::from(Colour::Green));

impl PartialEq<Colour> for Colour[src]

impl StructuralPartialEq for Colour[src]

Auto Trait Implementations

impl RefUnwindSafe for Colour

impl Send for Colour

impl Sync for Colour

impl Unpin for Colour

impl UnwindSafe for Colour

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.