package rich-string

  1. Overview
  2. Docs

Module type Rich_string.TYPESource

The type of a rich string.

The enricher.

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

val (=) : 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.

val empty : t

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

val (++) : 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 = ()
val 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.

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

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

val flatten : t list -> t

flatten rss concatenates all rss into one.

It is equivalent to join~on:Empty rss.

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

val is_empty : t -> bool

is_empty rs tests whether rs is Empty.

val is_enriched : t -> bool

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

val render : t -> string

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

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