nu_ansi_term

Enum Color

Source
pub enum Color {
Show 21 variants Black, DarkGray, Red, LightRed, Green, LightGreen, Yellow, LightYellow, Blue, LightBlue, Purple, LightPurple, Magenta, LightMagenta, Cyan, LightCyan, White, LightGray, Fixed(u8), Rgb(u8, u8, u8), Default,
}
Expand description

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

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

Variants§

§

Black

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

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

§

DarkGray

Color #0 (foreground code 90, background code 100).

§

Red

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

§

LightRed

Color #1 (foreground code 91, background code 101).

§

Green

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

§

LightGreen

Color #2 (foreground code 92, background code 102).

§

Yellow

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

§

LightYellow

Color #3 (foreground code 93, background code 103).

§

Blue

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

§

LightBlue

Color #4 (foreground code 94, background code 104).

§

Purple

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

§

LightPurple

Color #5 (foreground code 95, background code 105).

§

Magenta

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

§

LightMagenta

Color #5 (foreground code 95, background code 105).

§

Cyan

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

§

LightCyan

Color #6 (foreground code 96, background code 106).

§

White

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

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

§

LightGray

Color #7 (foreground code 97, background code 107).

§

Fixed(u8)

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

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

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

§

Rgb(u8, u8, u8)

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

§

Default

The default color (foreground code 39, background codr 49).

Implementations§

Source§

impl Color

Source

pub fn prefix(self) -> Prefix

The prefix bytes for this color as a Style. These are the bytes that tell the terminal to use a different color or font style.

See also Style::prefix.

§Examples
use nu_ansi_term::Color::Green;

assert_eq!("\x1b[0m",
           Green.suffix().to_string());
Source

pub fn infix(self, next: Color) -> Infix

The infix bytes between this color and next color. These are the bytes that tell the terminal to use the next color, or to do nothing if the two colors are equal.

See also Style::infix.

§Examples
use nu_ansi_term::Color::{Red, Yellow};

assert_eq!("\x1b[33m",
           Red.infix(Yellow).to_string());
Source

pub fn suffix(self) -> Suffix

The suffix for this color as a Style. These are the bytes that tell the terminal to reset back to its normal color and font style.

See also Style::suffix.

§Examples
use nu_ansi_term::Color::Purple;

assert_eq!("\x1b[0m",
           Purple.suffix().to_string());
Source§

impl Color

Source

pub fn normal(self) -> Style

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

§Examples
use nu_ansi_term::Color;

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

pub fn bold(self) -> Style

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

§Examples
use nu_ansi_term::Color;

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

pub fn dimmed(self) -> Style

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

§Examples
use nu_ansi_term::Color;

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

pub fn italic(self) -> Style

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

§Examples
use nu_ansi_term::Color;

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

pub fn underline(self) -> Style

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

§Examples
use nu_ansi_term::Color;

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

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

§Examples
use nu_ansi_term::Color;

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

pub fn reverse(self) -> Style

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

§Examples
use nu_ansi_term::Color;

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

pub fn hidden(self) -> Style

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

§Examples
use nu_ansi_term::Color;

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

pub fn strikethrough(self) -> Style

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

§Examples
use nu_ansi_term::Color;

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

pub fn on(self, background: Color) -> Style

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

§Examples
use nu_ansi_term::Color;

let style = Color::Rgb(31, 31, 31).on(Color::White);
println!("{}", style.paint("eyyyy"));
Source§

impl Color

Source

pub fn paint<'a, I, S: 'a + ToOwned + ?Sized>( self, input: I, ) -> AnsiGenericString<'a, S>
where I: Into<Cow<'a, S>>, <S as ToOwned>::Owned: Debug,

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

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

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Color

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Color

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Color> for Style

Source§

fn from(color: Color) -> Style

You can turn a Color into a Style with the foreground color set with the From trait.

use nu_ansi_term::{Style, Color};
let green_foreground = Style::default().fg(Color::Green);
assert_eq!(green_foreground, Color::Green.normal());
assert_eq!(green_foreground, Color::Green.into());
assert_eq!(green_foreground, Style::from(Color::Green));
Source§

impl PartialEq for Color

Source§

fn eq(&self, other: &Color) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Color

Source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnwindSafe for Color

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 4 bytes

Size for each variant:

  • Black: 0 bytes
  • DarkGray: 0 bytes
  • Red: 0 bytes
  • LightRed: 0 bytes
  • Green: 0 bytes
  • LightGreen: 0 bytes
  • Yellow: 0 bytes
  • LightYellow: 0 bytes
  • Blue: 0 bytes
  • LightBlue: 0 bytes
  • Purple: 0 bytes
  • LightPurple: 0 bytes
  • Magenta: 0 bytes
  • LightMagenta: 0 bytes
  • Cyan: 0 bytes
  • LightCyan: 0 bytes
  • White: 0 bytes
  • LightGray: 0 bytes
  • Fixed: 1 byte
  • Rgb: 3 bytes
  • Default: 0 bytes