Package index
matrix
Library matrix.ansi
Ansi
. Attr
Module
Module Ansi.Attr Source Text attribute flags.
Text attribute flags.
A compact bit-flag representation for text attributes (bold, italic, underline, etc.). Attributes are stored as a 12-bit integer bitmask, enabling fast set operations and minimal memory usage.
Terminal support varies. Bold, underline, and inverse are widely supported. Blink, framed, and encircled have limited support; unsupported attributes simply have no visible effect.
FlagsSource type flag = | Bold Increased weight/brightness (SGR 1).
| Dim Decreased brightness (SGR 2).
| Italic | Underline Single underline (SGR 4).
| Double_underline Double underline (SGR 21).
| Blink | Inverse Swap foreground/background (SGR 7).
| Hidden | Strikethrough Line through text (SGR 9).
| Overline Line above text (SGR 53).
| Framed | Encircled The type for individual text attribute flags.
flag_to_sgr_code f is the SGR code to enable f.
flag_to_sgr_disable_code f is the SGR code to disable f.
Note. Some flags share disable codes: Bold and Dim both use 22, Underline and Double_underline both use 24, Framed and Encircled both use 54.
flag_to_string f is the name of f as a string.
Attribute setsThe type for attribute sets. Internally a 12-bit integer bitmask.
Predefined setsempty is the set with no attributes.
Predicatesis_empty s is true iff s contains no flags.
mem f s is true iff f is in s.
Set operationsadd f s is s with f added. Idempotent.
remove f s is s with f removed. Idempotent.
toggle f s adds f if absent, removes it if present.
union a b is the set containing flags in either a or b.
intersect a b is the set containing flags in both a and b.
diff a b is the set of flags in a not in b.
cardinal s is the number of flags in s.
with_flag f enabled s adds f if enabled is true, removes it otherwise.
Convertingof_list fs is a set from the list fs. Duplicates are ignored.
to_list s is the flags in s as a list. Order is deterministic but unspecified.
Source val combine :
?bold :bool ->
?dim :bool ->
?italic :bool ->
?underline :bool ->
?double_underline :bool ->
?blink :bool ->
?inverse :bool ->
?hidden :bool ->
?strikethrough :bool ->
?overline :bool ->
?framed :bool ->
?encircled :bool ->
unit ->
t combine ?bold ?dim ... () is a set from labelled arguments. Each parameter defaults to false.
ANSI SGR codesSource val to_sgr_codes : t -> int list Source val iter_sgr_codes : (int -> unit) -> t -> unititer_sgr_codes f s calls f code for each SGR enable code in s.
Source val iter_sgr_disable_codes : (int -> unit) -> t -> unititer_sgr_disable_codes f s calls f code for each SGR disable code in s. Shared codes are deduplicated (e.g. if both Bold and Dim are in s, code 22 is emitted once).
Source val fold_sgr_codes : (int -> 'a -> 'a ) -> t -> 'a -> 'a fold_sgr_codes f s init folds f over SGR enable codes of s.
Iterationfold f s init folds f over the flags in s.
iter f s calls f for each flag in s.
Comparisonsequal a b is true iff a and b contain the same flags.
compare a b orders a and b. The order is compatible with equal .
Binary encodingpack s is the integer representation of s. Stable across releases.
unpack n is the attribute set from the integer n. Inverse of pack .
Formattingpp formats an attribute set for inspection (e.g. "[Bold, Italic]").