package miaou-core

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Miaou_style.StyleSource

Core style type for terminal rendering.

A style defines visual attributes for text rendering: colors, text decorations (bold, dim, underline, etc.), and can be combined through patching/merging.

All fields are option to support inheritance: None means "inherit from parent", Some v means "use this value".

Sourcetype adaptive_color = {
  1. light : int;
    (*

    Color value for light terminal backgrounds

    *)
  2. dark : int;
    (*

    Color value for dark terminal backgrounds

    *)
}

Adaptive color that can have different values for light and dark terminals

Sourceval adaptive_color_to_yojson : adaptive_color -> Yojson.Safe.t
Sourcetype color =
  1. | Fixed of int
    (*

    Fixed 256-color value

    *)
  2. | Adaptive of adaptive_color
    (*

    Adapts to terminal background

    *)

Color specification: either a fixed color or adaptive

Sourceval color_to_yojson : color -> Yojson.Safe.t

JSON encoding/decoding for colors. Accepts multiple formats for backwards compatibility:

  • "Fixed": 75
  • "Fixed", 75
  • 75 (interpreted as Fixed)
  • "Adaptive": {"light": 15, "dark": 231

}

  • "Adaptive", {"light": 15, "dark": 231}
Sourceval color_of_yojson : Yojson.Safe.t -> (color, string) result
Sourcetype t = {
  1. fg : color option;
    (*

    Foreground color (256-color palette or adaptive)

    *)
  2. bg : color option;
    (*

    Background color

    *)
  3. bold : bool option;
    (*

    Bold text

    *)
  4. dim : bool option;
    (*

    Dim/faint text

    *)
  5. italic : bool option;
    (*

    Italic text

    *)
  6. underline : bool option;
    (*

    Underlined text

    *)
  7. reverse : bool option;
    (*

    Reverse video (swap fg/bg)

    *)
  8. strikethrough : bool option;
    (*

    Strikethrough text

    *)
}

Core style record.

All fields are optional to support style inheritance/cascade. None means "inherit from parent/default", Some v means "explicitly set".

Sourceval t_to_yojson : t -> Yojson.Safe.t

JSON encoding/decoding for styles (tolerant of missing fields).

Sourceval t_of_yojson : Yojson.Safe.t -> (t, string) result
Sourceval to_yojson : t -> Yojson.Safe.t

Backward-compatible aliases expected by other modules.

Sourceval of_yojson : Yojson.Safe.t -> (t, string) result
Sourceval empty : t

Empty style - all fields are None (inherit everything)

Sourceval default : t

Default style - concrete values for all fields

Constructors

Sourceval make : ?fg:color -> ?bg:color -> ?bold:bool -> ?dim:bool -> ?italic:bool -> ?underline:bool -> ?reverse:bool -> ?strikethrough:bool -> unit -> t

Create a style with specified attributes. Unspecified attributes are None.

Sourceval fg : int -> t

Convenience: create style with fixed foreground color

Sourceval bg : int -> t

Convenience: create style with fixed background color

Sourceval bold : t

Convenience: create bold style

Sourceval dim : t

Convenience: create dim style

Combining styles

Sourceval patch : base:t -> overlay:t -> t

patch ~base ~overlay merges two styles. Values from overlay take precedence when they are Some. This is like CSS cascade: more specific rules override general ones.

Sourceval resolve : default:t -> t -> t

resolve ~default style collapses all None values using default. Returns a style where all fields are Some.

ANSI rendering

Sourcetype resolved = {
  1. r_fg : int;
  2. r_bg : int;
  3. r_bold : bool;
  4. r_dim : bool;
  5. r_italic : bool;
  6. r_underline : bool;
  7. r_reverse : bool;
  8. r_strikethrough : bool;
}

Resolved style with all concrete values (no Options)

Sourceval resolve_color : ?dark_mode:bool -> color -> int

Resolve a color for the current terminal (dark mode assumed by default)

Sourceval to_resolved : ?dark_mode:bool -> t -> resolved

Resolve style to concrete values

Sourceval fg_ansi_code : int -> string

ANSI escape code fragment for a foreground color index. Colors 0-15 use basic ANSI codes (respects terminal color scheme). Colors 16-255 use 256-color extended codes. Returns "" for negative values (no color).

Sourceval bg_ansi_code : int -> string

Same as fg_ansi_code but for background colors.

Sourceval to_ansi_prefix : resolved -> string

Convert resolved style to ANSI escape sequence prefix

Sourceval ansi_reset : string

Convert resolved style to ANSI reset sequence

Sourceval apply : resolved -> string -> string

Apply a resolved style to a string (wrap with ANSI codes)

Sourceval render : t -> string -> string

Apply style directly to string (resolves with defaults, assumes dark mode)