package matrix

  1. Overview
  2. Docs
Fast, modern terminal toolkit for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

mosaic-0.1.0.tbz
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

Sourcetype flag =
  1. | Bold
    (*

    Increased weight/brightness (SGR 1).

    *)
  2. | Dim
    (*

    Decreased brightness (SGR 2).

    *)
  3. | Italic
    (*

    Slanted text (SGR 3).

    *)
  4. | Underline
    (*

    Single underline (SGR 4).

    *)
  5. | Double_underline
    (*

    Double underline (SGR 21).

    *)
  6. | Inverse
    (*

    Swap foreground/background (SGR 7).

    *)
  7. | Hidden
    (*

    Invisible text (SGR 8).

    *)
  8. | Strikethrough
    (*

    Line through text (SGR 9).

    *)
  9. | Overline
    (*

    Line above text (SGR 53).

    *)
  10. | Framed
    (*

    Framed text (SGR 51).

    *)
  11. | Encircled
    (*

    Encircled text (SGR 52).

    *)

The type for individual text attribute flags.

Sourceval flag_to_sgr_code : flag -> int

flag_to_sgr_code f is the SGR code to enable f.

Sourceval flag_to_sgr_disable_code : flag -> int

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.

Sourceval flag_to_string : flag -> string

flag_to_string f is the name of f as a string.

Attribute sets

Sourcetype t

The type for attribute sets. Internally a 12-bit integer bitmask.

Predefined sets

Sourceval empty : t

empty is the set with no attributes.

Sourceval bold : t
Sourceval dim : t
Sourceval italic : t
Sourceval underline : t
Sourceval double_underline : t
Sourceval inverse : t
Sourceval hidden : t
Sourceval strikethrough : t
Sourceval overline : t
Sourceval framed : t
Sourceval encircled : t

Predicates

Sourceval is_empty : t -> bool

is_empty s is true iff s contains no flags.

Sourceval mem : flag -> t -> bool

mem f s is true iff f is in s.

Set operations

Sourceval add : flag -> t -> t

add f s is s with f added. Idempotent.

Sourceval remove : flag -> t -> t

remove f s is s with f removed. Idempotent.

Sourceval toggle : flag -> t -> t

toggle f s adds f if absent, removes it if present.

Sourceval union : t -> t -> t

union a b is the set containing flags in either a or b.

Sourceval intersect : t -> t -> t

intersect a b is the set containing flags in both a and b.

Sourceval diff : t -> t -> t

diff a b is the set of flags in a not in b.

Sourceval cardinal : t -> int

cardinal s is the number of flags in s.

Sourceval with_flag : flag -> bool -> t -> t

with_flag f enabled s adds f if enabled is true, removes it otherwise.

Converting

Sourceval of_list : flag list -> t

of_list fs is a set from the list fs. Duplicates are ignored.

Sourceval to_list : t -> flag list

to_list s is the flags in s as a list. Order is deterministic but unspecified.

Sourceval 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 codes

Sourceval to_sgr_codes : t -> int list

to_sgr_codes s is the SGR enable codes for s. Use iter_sgr_codes or fold_sgr_codes to avoid allocation.

Sourceval iter_sgr_codes : (int -> unit) -> t -> unit

iter_sgr_codes f s calls f code for each SGR enable code in s.

Sourceval iter_sgr_disable_codes : (int -> unit) -> t -> unit

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

Sourceval fold_sgr_codes : (int -> 'a -> 'a) -> t -> 'a -> 'a

fold_sgr_codes f s init folds f over SGR enable codes of s.

Iteration

Sourceval fold : (flag -> 'a -> 'a) -> t -> 'a -> 'a

fold f s init folds f over the flags in s.

Sourceval iter : (flag -> unit) -> t -> unit

iter f s calls f for each flag in s.

Comparisons

Sourceval equal : t -> t -> bool

equal a b is true iff a and b contain the same flags.

Sourceval compare : t -> t -> int

compare a b orders a and b. The order is compatible with equal.

Binary encoding

Sourceval pack : t -> int

pack s is the integer representation of s. Stable across releases.

Sourceval unpack : int -> t

unpack n is the attribute set from the integer n. Inverse of pack.

Formatting

Sourceval pp : Format.formatter -> t -> unit

pp formats an attribute set for inspection (e.g. "[Bold, Italic]").