struct

TermBuf::Color

Inherits Struct < Value < Object

Stability: stable — changes only in a major release.

A foreground, background, or underline colour.

Colours are stored exactly as the application supplied them. Reducing a 24 bit colour to the 256 colour palette, or that palette to the sixteen system colours, happens at encode time against the terminal's capability mask — so raising the mask and repainting yields better colour with no information lost along the way.

Constants

BLACK = indexed(0)

The eight basic system colours, by palette index.

BLUE = indexed(4)
BRIGHT_BLACK = indexed(8)

Their bright counterparts, which need Capability::BrightColors to come out bright rather than dim.

BRIGHT_BLUE = indexed(12)
BRIGHT_CYAN = indexed(14)
BRIGHT_GREEN = indexed(10)
BRIGHT_MAGENTA = indexed(13)
BRIGHT_RED = indexed(9)
BRIGHT_WHITE = indexed(15)
BRIGHT_YELLOW = indexed(11)
CUBE_LEVELS = StaticArray[0, 95, 135, 175, 215, 255]

The six levels each channel takes in the 6x6x6 colour cube.

CYAN = indexed(6)
GREEN = indexed(2)
MAGENTA = indexed(5)
RED = indexed(1)
SYSTEM_COLORS = StaticArray[0, 8388608, 32768, 8421376, 128, 8388736, 32896, 12632256, 8421504, 16711680, 65280, 16776960, 255, 16711935, 65535, 16777215]

The sixteen system colours as xterm renders them. Terminals are free to remap these, which is exactly why an Indexed colour is never rewritten to Rgb: only the reverse direction is a downgrade.

WHITE = indexed(7)
YELLOW = indexed(3)

Constructors

default

The terminal's default colour.

Source
indexed(index : Int) : Color

A colour from the 256 colour palette. Indices 0 through 7 are the basic colours, 8 through 15 their bright counterparts, 16 through 231 the colour cube, and 232 through 255 the grey ramp.

Source
rgb(red : Int, green : Int, blue : Int) : Color

A 24 bit colour.

Source
rgb(value : Int) : Color

A 24 bit colour from a packed 0xRRGGBB value.

Source

Instance methods

blue

Red channel, meaningful only for an Rgb colour. channels resolves a palette index instead.

Source
bright?

Whether this is one of the eight bright system colours, which some terminals reach through the 90-97 and 100-107 codes rather than the palette.

Source
channels

The colour's red, green, and blue channels. An Indexed colour resolves through the standard xterm palette; a Default colour has no channels of its own and reports black.

Source
default?

Whether this is the terminal's own default colour.

Source
green

Red channel, meaningful only for an Rgb colour. channels resolves a palette index instead.

Source
index

Palette index, meaningful only for an Indexed colour.

Source
indexed?

Whether this is a palette index.

Source
kind

Which of Kind this colour is.

Source
red

Red channel, meaningful only for an Rgb colour. channels resolves a palette index instead.

Source
rgb?

Whether this is a 24 bit colour.

Source
to_indexed16

The nearest of the sixteen system colours. A Default colour passes through unchanged; everything else resolves through its channels.

Source
to_indexed256

The nearest colour in the 256 colour palette. Default and Indexed colours are already expressible and pass through unchanged.

Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source

Nested types