struct TermBuf::Color

Overview

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.

Defined in:

termbuf/core/color.cr

Constant Summary

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

Instance Method Summary

Constructor Detail

def self.default : Color #

The terminal's default colour.


[View source]
def self.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.


[View source]
def self.rgb(red : Int, green : Int, blue : Int) : Color #

A 24 bit colour.


[View source]
def self.rgb(value : Int) : Color #

A 24 bit colour from a packed 0xRRGGBB value.


[View source]

Instance Method Detail

def blue : Int32 #

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


[View source]
def bright? : Bool #

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.


[View source]
def channels : Tuple(Int32, Int32, Int32) #

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.


[View source]
def default? : Bool #

Whether this is the terminal's own default colour.


[View source]
def green : Int32 #

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


[View source]
def index : Int32 #

Palette index, meaningful only for an Indexed colour.


[View source]
def indexed? : Bool #

Whether this is a palette index.


[View source]
def kind : Kind #

Which of Kind this colour is.


[View source]
def red : Int32 #

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


[View source]
def rgb? : Bool #

Whether this is a 24 bit colour.


[View source]
def to_indexed16 : Color #

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


[View source]
def to_indexed256 : Color #

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


[View source]
def to_s(io : IO) : Nil #
Description copied from struct Struct

Same as #inspect(io).


[View source]