Color class sealed

Represents a color that can be used in ANSI escape codes, i.e. SetStyles.

This is a minimal representation of a color, and is not intended to be exhaustive. For more advanced color manipulation, consider using a library more suited to that purpose.

Most modern terminal emulators support the full range of 24-bit colors, which can be defined using Color.fromRGB or Color24 to create a color from an RGB value:

// Equivalent.
SetStyles(Style.foreground(Color.fromRGB(255, 0, 0)));
SetStyles(Style.foreground(Color24(0xFF0000)));

For compatibility with older terminals, the 256-color palette can be used with Color.from256 or Color8:

// Equivalent.
SetStyles(Style.foreground(Color.from256(196)));
SetStyles(Style.foreground(Color8.fromIndex(196)));

The base 16 colors are also available as Color4:

// Equivalent.
SetStyles(Style.foreground(Color.red));
SetStyles(Style.foreground(Color4.red));
Annotations
  • @immutable

Constructors

Color.from256(int index)
Creates a color from an 8-bit index in the 256-color palette.
const
factory
Color.fromRGB(int red, int green, int blue)
Creates a color from an 24-bit RGB value.
const
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

black → const Color
The color black.
blue → const Color
The color blue.
brightBlack → const Color
The color bright black.
brightBlue → const Color
The color bright blue.
brightCyan → const Color
The color bright cyan.
brightGreen → const Color
The color bright green.
brightMagenta → const Color
The color bright magenta.
brightRed → const Color
The color bright red.
brightWhite → const Color
The color bright white.
brightYellow → const Color
The color bright yellow.
cyan → const Color
The color cyan.
green → const Color
The color green.
magenta → const Color
The color magenta.
red → const Color
The color red.
reset → const Color
A color that resets the current color to the terminal's default.
white → const Color
The color white.
yellow → const Color
The color yellow.