package rich-string

  1. Overview
  2. Docs

Module Rich_string.MakeSource

Given an Enricher type, constructs a rich string type.

The type of a rich string.

Parameters

Signature

Sourcemodule Enricher = Enricher

The enricher.

Sourcetype t =
  1. | Empty
  2. | String of string
  3. | Enriched of Enricher.t * t
  4. | Join of t * t list

The type of a rich string.

Sourceval (=) : t -> t -> bool

rs1 = rs2 determines whether rs1 and rs2 are equal.

IMPORTANT: no pruning or optimization is performed. This means that two rich strings that render the same might not be considered equal.

Sourceval empty : t

empty is the identity string with respect to (++).

Sourceval (++) : t -> t -> t

rs1 ++ rs2 appends rs2 at the end of rs1.

It is equivalent to the built-in string operator ^.

  # print (String "hello" ++ String "world")
  "helloworld"
  - : unit = ()
Sourceval string : string -> t

string s lifts the built-in string s to the enriched world.

For example, if the enricher is an ANSI style type, this enables the ability to stylize s.

Sourceval enrich : Enricher.t -> t -> t

enrich enrichment rs adds the enrichment to the rich string rs.

For example, if the enricher is an ANSI style type, this translates to adding a new style to s.

Sourceval join : ?on:t -> t list -> t

join ?on:sep rss concatenates all rss into one, separated by sep. By default, sep is a single space.

It is equivalent to the built-in string function String.concat.

Sourceval flatten : t list -> t

flatten rss concatenates all rss into one.

It is equivalent to join~on:Empty rss.

Sourceval join_lines : t list -> t

join_lines rss concatenates all rss into one, separated by line feeds.

It is equivalent to join~on:(String "\n") rss.

Sourceval is_empty : t -> bool

is_empty rs tests whether rs is Empty.

Sourceval is_enriched : t -> bool

is_enriched rs tests whether rs is not just a plain String.

Sourceval render : t -> string

render rs generates a built-in string such that rs can be used in interfaces that expect strings, e.g. IO.

Sourceval print : ?out:out_channel -> ?ending:t option -> t -> unit

print ?out ?ending rs prints rs in out, appending ending after. out defaults to stdout and ending defaults to Some (String "\n").