Skip to content
Jakub Sobon edited this page Mar 3, 2019 · 3 revisions

Doc Status

The cell package exposes options that are applicable to every cell. Termdash interacts with the terminal via a cell based representation, i.e. the terminal is a 2-D buffer of cells. Each cell contains an ASCII or Unicode character and can have two options:

  • Foreground color is the color of the character.
  • Background color is the color of the non-character space in the cell.

This is a data-only package which provides types that are accepted by the infrastructure and widgets in multiple locations.

The public API surface of this package consists of the following:

The cell.Color type represents a terminal color. Terminal colors are identified by a numerical value. A terminal can support up to 256 colors, however this depends on the terminal color mode. Refer to the Terminal API for details on setting the color mode.

The supported colors are broken into the following categories:

  • 0-7: the 8 "system" colors, these are the only colors accessible in terminalapi.ColorModeNormal.
  • 8-15: the 8 "bright system" colors.
  • 16-231: the 216 different terminal colors.
  • 232-255: the 24 different shades of grey.

Refer to the following pages which provide a list of colors and their numbers:

The cell package provides predefined constants for the 8 "system" colors. Other colors can be set using one of the helper functions below. Note that the helper functions below are equivalent, it is up to the developer to choose which way of referring to the colors they prefer.

A color is then provided to either the cell.FgColor or the cell.BgColor function to create a cell option. Libraries that deal with cells accept the created cell options.

The cell.ColorNumber function converts the provided color number to the cell.Color type. This function accepts the values in the Xterm Number column on this page:

The cell.ColorRGB6 function converts 6-bit RGB values into the cell.Color type. This function accepts coordinates in the color vubes documented here:

The cell.ColorRGB24 function converts 24-bit RGB values into the cell.Color type. This function accepts the values in the RGB column on this page:

The cell.FgColor option is used to set the foreground color on a cell. The following code snippet shows how to create an option that will set the cell's foreground color to blue:

cell.FgColor(cell.ColorBlue)

The cell.BgColor option is used to set the background color on a cell. The following code snippet shows how to create an option that will set the cell's background color to red:

cell.BgColor(cell.ColorRed)
Clone this wiki locally