Termisu::Color
Inherits Struct / Value / Object
Terminal color support with ANSI-8, ANSI-256, and RGB/TrueColor modes.
Termisu supports three color modes:
ANSI-8 (Basic Colors)
The standard 8 ANSI colors (0-7) supported by all terminals: Black, Red, Green, Yellow, Blue, Magenta, Cyan, White
ANSI-256 (Extended Palette)
256-color palette with:
- 0-7: Standard ANSI colors
- 8-15: Bright variants
- 16-231: 6×6×6 RGB color cube
- 232-255: 24-step grayscale ramp
RGB/TrueColor
24-bit true color with 16.7 million colors (requires terminal support).
Usage
# Basic ANSI colors
red = Color.red
blue = Color.blue
# 256-color palette
orange = Color.ansi256(208)
# RGB/TrueColor
custom = Color.rgb(255, 128, 64)
# Color conversion
ansi = custom.to_ansi256 # Convert RGB to closest 256-color
Constants
Named color constants (enum-style syntax).
Special value for default terminal color.
Constructors
Creates an ANSI-256 palette color (0-255).
Can be called as:
Color.ansi256(208)- method styleColor.new_ansi256(208)- alternative method style
Grayscale color from the 24-step grayscale ramp (ANSI-256 indices 232-255).
Parameters
level: Grayscale level from 0 (darkest) to 23 (brightest)
Creates an RGB/TrueColor color.
Can be called as:
Color.rgb(255, 128, 64)- method styleColor.new_rgb(255, 128, 64)- alternative method style
Instance methods
Converts this color to ANSI-256 palette index.
- ANSI8 colors are mapped to their corresponding ANSI-256 indices
- RGB colors are converted to the nearest 256-color palette entry
Converts this color to ANSI-8 (basic colors only).
- ANSI-256 colors are mapped to nearest ANSI-8 color
- RGB colors are converted to nearest ANSI-8 color
Returns RGB components for this color.
Converts ANSI palette colors to their approximate RGB values.