Colors class Color Component Styling
Standard ANSI colors implementation with support for normal and bright variants.
Provides common ANSI colors with their respective codes for foreground and background.
Properties
- code: ANSI code for the foreground color.
- bgCode: ANSI code for the background color.
- name: Human-readable name of the color.
_dim
: Whether this color is dimmed (faint).
Responsibilities
- Map ANSI color codes to predefined colors.
- Provide ANSI escape sequences for foreground and background.
- Generate dimmed variants.
Example
final red = Colors.red;
print(red.fg); // Outputs: 31
print(red.printableFg); // Outputs: "red"
final dimRed = red.dimmed();
print(dimRed.fg); // Outputs: "2;31"
See Also
- AnsiColorType - For parent class
- ColorRGB - For true color (24-bit RGB) ANSI colors
- Implemented types
Constructors
- Colors.fromCode(int code)
-
Returns the predefined color corresponding to the given ANSI code.
factory
Properties
- bg → String
-
Returns the ANSI escape sequence for the background color.
no setteroverride
- bgCode → int
-
The ANSI escape code for the background color.
final
- code → int
-
The ANSI escape code for the foreground color.
final
- fg → String
-
Returns the ANSI escape sequence for the foreground color.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
Human-readable name of the color.
final
- printableBg → String
-
Returns a human-readable string representation of the background color.
no setteroverride
- printableFg → String
-
Returns a human-readable string representation of the foreground color.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dimmed(
) → Colors -
Creates a dimmed version of this color.
override
-
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 Colors
- Standard black ANSI color.
- blue → const Colors
- Standard blue ANSI color.
- cyan → const Colors
- Standard cyan ANSI color.
- green → const Colors
- Standard green ANSI color.
- highBlack → const Colors
- Bright black ANSI color.
- highBlue → const Colors
- Bright blue ANSI color.
- highCyan → const Colors
- Bright cyan ANSI color.
- highGreen → const Colors
- Bright green ANSI color.
- highMagenta → const Colors
- Bright magenta ANSI color.
- highRed → const Colors
- Bright red ANSI color.
- highWhite → const Colors
- Bright white ANSI color.
- highYellow → const Colors
- Bright yellow ANSI color.
- magenta → const Colors
- Standard magenta ANSI color.
- red → const Colors
- Standard red ANSI color.
- white → const Colors
- Standard white ANSI color.
- yellow → const Colors
- Standard yellow ANSI color.