package textutils_kernel

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

Module Text_blockSource

Sourcetype t

Two-dimensional blocks of UTF-8 text. This module makes a naive assumption that each Unicode scalar value has a display width of 1. If this is not the case, the width calculations will be incorrect. See String.Utf8.length_in_uchars for details.

Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
include Core.Invariant.S with type t := t
Sourceval invariant : t -> unit
Sourceval nil : t

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

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

fill and space assume width and height are non-negative

Sourceval space : width:int -> height:int -> t
Sourceval fill_uchar : Core.Uchar.t -> width:int -> height:int -> t

Fill a space with a Unicode scalar value

Sourcetype valign = [
  1. | `Top
  2. | `Bottom
  3. | `Center
]

Vertical and horizontal alignment specifications

Sourcetype halign = [
  1. | `Left
  2. | `Right
  3. | `Center
]
Sourceval text : ?align:halign -> ?max_width:int -> string -> t

A basic block of UTF-8 text, split on newlines and horizontally aligned as specified.

If max_width is provided, split each line of the input on whitespace and wrap words to respect the request. So long as no words are longer than max_width, the resulting text block will be no wider than max_width.

Sourceval textf : ?align:halign -> ?max_width:int -> ('r, unit, string, t) Core.format4 -> 'r

Like text, but takes a format string like printf

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

Vertical concatenation with alignment

Sourceval hcat : ?align:valign -> ?sep:t -> t list -> t

Horizontal concatenation with alignment

Text block dimensions

Sourceval width : t -> int
Sourceval height : t -> int

Vertical and horizontal sequence alignment. Both valign and halign return a list of the same length as the input, with the corresponding elements padded to the appropriate alignment.

If you have a list of a statically known length, using With_static_lengths.valign or With_static_lengths.halign below will let the type checker know that the length of the returned list is equal to the length of the input list.

Sourceval valign : valign -> t list -> t list
Sourceval halign : halign -> t list -> t list

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

Sourceval hstrut : int -> t
Sourceval vstrut : int -> t
Sourceval 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.

Sourceval render : t -> string

render a block of text as a string

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

Alignment of a 2D grid of blocks

Sourceval 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
Sourcemodule Boxed : sig ... end

Combinators for building up cell structures separated by box characters: e.g.

Sourceval boxed : Boxed.t -> t

See comment for Boxed

Sourcemodule Up_or_down : sig ... end
Sourceval span_banner : extend_left:bool -> extend_right:bool -> length:int -> points:Up_or_down.t -> ?label:t -> unit -> t

span_banner produces text blocks that indicate the extent of something else

    extend_left
    |      extend_right
    |      |      points
    |      |      |     span_banner ...
    |      |      |     |           span_banner ~label ...
    |      |      |     |           |

    true   true   Up    ──────────  ─┬────────
                                     label

    true   false  Up    ─────────┘  ─┬───────┘
                                     label

    false  true   Up    └─────────  └┬────────
                                     label

    false  false  Up    └────────┘  └┬───────┘
                                     label

    true   true   Down               label
                        ──────────  ─┴────────

    true   false  Down               label
                        ─────────┐  ─┴───────┐

    false  true   Down               label
                        ┌─────────  ┌┴────────

    false  false  Down               label
                        ┌────────┐  ┌┴───────┐ |}];
Sourceval vsep : t

vsep = vstrut 1

Sourceval hsep : t

hsep = hstrut 1

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

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

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

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

Sourcemodule With_static_lengths : sig ... end

Versions of halign and valign with the invariant about list length encoded into the types.

OCaml

Innovation. Community. Security.