package notty

  1. Overview
  2. Docs

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).

Colors

type color

One of 256 Xterm-style colors.

  • The first 16 are supported on almost all terminals. The names are standardized, but the actual colors are not. The colors are often user-definable.
  • The next 216 form a 6*6*6 color cube.
  • The final 24 are a grayscale ramp.

Colors outside of the core 16 are widely, but not universally supported.

Note No attempt is made to remap colors depending on the terminal. Colors not recognized by a particular terminal will simply be ignored in the output.

Core 16 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

Extended colors

val rgb : r:int -> g:int -> b:int -> color

rgb ~r:red ~g:green ~b:blue is an extended color from the color cube. All three components must be in the range 0-5.

  • raises Invalid_argument

    if a component is outside the range.

val gray : int -> color

gray level is an extended color from the grayscale ramp. level must be in the range 0-23.

  • raises Invalid_argument

    if the level is outside the range.

Text styles

type style

Additional text properties.

val bold : style
val italic : style
val underline : style
val reverse : style

Attribute construction and composition

type t = attr
val empty : attr

empty is the attribute with the default foreground and background color and empty style set.

val (++) : attr -> attr -> attr

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.

val fg : color -> attr

fg c is empty with foreground c.

val bg : color -> attr

bg c is empty with background c.

val st : style -> attr

st s is empty with style s.

OCaml

Innovation. Community. Security.