struct

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

Black = ansi8(0)

Named color constants (enum-style syntax).

Blue = ansi8(4)
Cyan = ansi8(6)
Default = ansi8(DEFAULT_INDEX)
DEFAULT_INDEX = -1

Special value for default terminal color.

Green = ansi8(2)
Magenta = ansi8(5)
Red = ansi8(1)
White = ansi8(7)
Yellow = ansi8(3)

Constructors

ansi256(index : Int32) : Color

Creates an ANSI-256 palette color (0-255).

Can be called as:

  • Color.ansi256(208) - method style
  • Color.new_ansi256(208) - alternative method style
Source
ansi8(index : Int32) : Color

Creates an ANSI-8 basic color (0-7).

Source
black
Source
blue
Source
bright_black
Source
bright_blue
Source
bright_cyan
Source
bright_green
Source
bright_magenta
Source
bright_red
Source
bright_white
Source
bright_yellow
Source
cyan
Source
default

Returns the default terminal color.

Source
from_hex(hex : String) : Color

Creates a color from a hex string (#RRGGBB or RRGGBB).

Source
grayscale(level : Int32) : Color

Grayscale color from the 24-step grayscale ramp (ANSI-256 indices 232-255).

Parameters

  • level: Grayscale level from 0 (darkest) to 23 (brightest)
Source
green
Source
magenta
Source
rgb(r : Int, g : Int, b : Int) : Color

Creates an RGB/TrueColor color.

Can be called as:

  • Color.rgb(255, 128, 64) - method style
  • Color.new_rgb(255, 128, 64) - alternative method style
Source
white
Source
yellow
Source

Instance methods

==(other : Color) : Bool

Equality comparison.

Source
default?

Returns whether this is the default terminal color.

Source
index

ANSI color index (0-255) for ANSI8 and ANSI256 modes.

Source
mode
Source
r

RGB components (0-255) for RGB mode.

Source
to_ansi256

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
Source
to_ansi8

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
Source
to_rgb

Converts this color to RGB mode.

Source
to_rgb_components

Returns RGB components for this color.

Converts ANSI palette colors to their approximate RGB values.

Source
to_s(io : IO)

Returns a string representation of this color.

Source

Nested types