package matrix
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/matrix.ansi/Ansi/Attr/index.html
Module Ansi.AttrSource
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.
Flags
type flag = | Bold(*Increased weight/brightness (SGR 1).
*)| Dim(*Decreased brightness (SGR 2).
*)| Italic(*Slanted text (SGR 3).
*)| Underline(*Single underline (SGR 4).
*)| Double_underline(*Double underline (SGR 21).
*)| Blink(*Blinking text (SGR 5).
*)| Inverse(*Swap foreground/background (SGR 7).
*)| Hidden(*Invisible text (SGR 8).
*)| Strikethrough(*Line through text (SGR 9).
*)| Overline(*Line above text (SGR 53).
*)| Framed(*Framed text (SGR 51).
*)| Encircled(*Encircled text (SGR 52).
*)
The type for individual text attribute flags.
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.
Attribute sets
The type for attribute sets. Internally a 12-bit integer bitmask.
Predefined sets
Predicates
Set operations
with_flag f enabled s adds f if enabled is true, removes it otherwise.
Converting
to_list s is the flags in s as a list. Order is deterministic but unspecified.
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 ->
tcombine ?bold ?dim ... () is a set from labelled arguments. Each parameter defaults to false.
ANSI SGR codes
to_sgr_codes s is the SGR enable codes for s. Use iter_sgr_codes or fold_sgr_codes to avoid allocation.
iter_sgr_codes f s calls f code for each SGR enable code in s.
iter_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).
fold_sgr_codes f s init folds f over SGR enable codes of s.
Iteration
Comparisons
Binary encoding
Formatting
pp formats an attribute set for inspection (e.g. "[Bold, Italic]").