package matrix
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/matrix.ansi/Ansi/Style/index.html
Module Ansi.StyleSource
Terminal text styles.
Terminal text styles.
A style aggregates foreground color, background color, text attributes, and an optional hyperlink URL into an immutable value. Styles compose with overlay semantics: colors and hyperlinks from the overlay replace those in the base, while attributes are unioned. See merge.
Styles
The type for styles. Fields are exposed for pattern matching but cannot be modified directly. Use make or the modifier functions to create new instances.
Constructors
val make :
?fg:Color.t ->
?bg:Color.t ->
?bold:bool ->
?dim:bool ->
?italic:bool ->
?underline:bool ->
?blink:bool ->
?inverse:bool ->
?hidden:bool ->
?strikethrough:bool ->
?overline:bool ->
?double_underline:bool ->
?framed:bool ->
?encircled:bool ->
?link:string ->
unit ->
tmake ?fg ?bg ... () is a style with the given properties. fg and bg default to None (inherit terminal default). Boolean attributes default to false. link defaults to None.
Modifiers
Colors
Attributes
overlay_attrs s a is s with a unioned into its existing attributes.
with_double_underline b s sets or clears double underline on s.
with_hidden b s sets or clears hidden on s.
with_strikethrough b s sets or clears strikethrough on s.
Hyperlinks
Composition
merge ~base ~overlay is the style combining base and overlay:
- Colors:
overlaytakes precedence. Ifoverlay.fgisNone,base.fgis kept. - Attributes: union of
baseandoverlayattributes. - Link:
overlaytakes precedence.
Predicates and comparisons
equal a b is true iff all colors, attributes, and links are identical.
Emission
sgr_sequence ~prev s is the ANSI escape string for to_sgr_codes ~prev s. Returns "" if no transition is needed.
emit ~prev s w writes the minimal SGR codes to w to transition from prev (defaults to default) to s.
Handles shared disable codes correctly (Bold/Dim share 22, Underline/Double_underline share 24, Framed/Encircled share 54).
Note. Emits SGR sequences only. The link field is not emitted here; use Ansi.render for hyperlink support.
styled ~reset s str is str wrapped in the escape codes for s. If reset is true (default false), appends a reset sequence.
Formatting
pp formats a style for inspection (e.g. "Style\{fg=#FF0000, attrs=[Bold, Underline]\}").