package textutils

  1. Overview
  2. Docs
type t

two dimensional blocks of text

include sig ... end
val sexp_of_t : t -> Sexplib.Sexp.t
include Core.Invariant.S with type t := t
val invariant : t -> unit
val nil : t

the empty block. a left and right unit to both hcat and vcat

val fill : char -> width:int -> height:int -> t

fill and space assume width and height are non-negative

val space : width:int -> height:int -> t
type valign = [
  1. | `Top
  2. | `Bottom
  3. | `Center
]

vertical and horizontal alignment specifications

type halign = [
  1. | `Left
  2. | `Right
  3. | `Center
]
val text : ?align:halign -> string -> t

a basic block of text, split on newlines and horizontally aligned as specified

val vcat : ?align:halign -> ?sep:t -> t list -> t

vertical and horizontal concatenation with alignment

val hcat : ?align:valign -> ?sep:t -> t list -> t
val width : t -> int

text block dimensions

val height : t -> int
val valign : valign -> t list -> t list

vertical and horizontal sequence alignment

val halign : halign -> t list -> t list
val hstrut : int -> t

empty blocks with either horizontal or vertical extent -- useful for specifing a minimum width or height in conjunction with valign or halign, respectively

val vstrut : int -> t
val ansi_escape : ?prefix:string -> ?suffix:string -> t -> t

wrap a block with an ANSI escape sequence. The prefix and suffix arguments should render with zero width and height.

val render : t -> string

render a block of text as a string

val table : ?sep_width:int -> [ `Cols of (t list * halign) list ] -> [ `Rows of t list ]
val compress_table_header : ?sep_width:int -> [ `Cols of (t * t list * halign) list ] -> [ `Header of t ] * [ `Rows of t list ]

compress table header according to column widths. Input: a list of columns of the form (title, values, column alignment). Output: one header block and row sequence. Raises: if the values lists are not the same length in each column. Example:

first name age first name last name age | last name | | | ==> | | | 30 sue smith 30 sue smith 18 bill rodriguez 18 bill rodriguez 76 rick jones 76 rick jones

val vsep : t

vsep = vstrut 1

val hsep : t

hsep = hstrut 1

val indent : ?n:int -> t -> t

indent ~n t = hcat [hstrut n; t]. n defaults to 2

val sexp : ('a -> Core.Sexp.t) -> 'a -> t

sexp sexp_of_a a = sexp_of_a a |> Sexp.to_string |> text

val textf : ('r, unit, string, t) Core.format4 -> 'r

variant of text that takes a format string

OCaml

Innovation. Community. Security.