Library
Module
Module type
Parameter
Class
Class type
A
is for attribute.
Construction and composition of styling characteristics of text.
Consult the basics for an overview.
TL;DR: A.(fg red ++ bg black ++ st bold)
.
An ineffable quality of light.
There are three kinds of colors:
Core 16 colors.
ANSI defines 8 color names, with the actual display colors considered an implementation detail. Historically, this palette was extended with their light (sometimes bright or high-intensity) counterparts. Their presentation is undefined too, but typically produces a brighter shade. These colors - often called the ANSI colors - tend to be unpredictable, but ubiquitously supported.
Extended 256-color palette.
This common feature extends the palette by further 240 colors. They come in two groups:
XTerm was the first to support this extension. Many terminals have since cloned it, so the support is wide, but not universal.
As the extended colors are still palette-driven they do not have a fixed presentation, and the presentation can be changed in some terminals. Default palette tends to match XTerm's.
True color
A recently established convention allows directly sending 24-bit colors to the terminal. This has been adopted by a growing minority of terminals. A reasonably up-to-date status document maintained by the community can be found here.
Some of the technical and historical background can be found in XTerm's FAQ.
Note No attempt is made to remap colors depending on the terminal. Terminals might ignore, remap, or completely misinterpret unsupported colors.
The first 8 have their standard ANSI names.
val black : color
val red : color
val green : color
val yellow : color
val blue : color
val magenta : color
val cyan : color
val white : color
val lightblack : color
val lightred : color
val lightgreen : color
val lightyellow : color
val lightblue : color
val lightmagenta : color
val lightcyan : color
val lightwhite : color
val rgb : r:int -> g:int -> b:int -> color
rgb ~r:red ~g:green ~b:blue
is an extended-palette color from the color cube.
All three channels must be in the range 0 - 5
. XTerm default palette maps this to 0x00
, 0x5f
, 0x87
, 0xaf
, 0xd7
, and 0xff
independently per channel.
val gray : int -> color
gray level
is an extended-palette color from the grayscale ramp.
level
must be in the range 0 - 23
. XTerm default palette maps this to 8 + level * 10
on all three channels.
val rgb_888 : r:int -> g:int -> b:int -> color
rgb_888 ~r:red ~g:green ~b:blue
is a 24-bit color.
All three channels must be in the range 0 - 255
.
val bold : style
val italic : style
val underline : style
val blink : style
val reverse : style
type t = attr
val empty : attr
empty
is the attribute with the default foreground and background color and empty style set.
a1 ++ a2
is the concatenation of a1
and a2
, the attribute that has a2
's foreground (resp. background), unless unset, in which case it is a1
's, and the union of both style sets.
++
and empty
form a monoid. ++
is left-associative.