package batteries

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

This module contains the types and functions for implementing custom usage message formatters.

type t = {
  1. indent : unit -> unit;
    (*

    Increase the indentation level.

    *)
  2. dedent : unit -> unit;
    (*

    Decrease the indentation level.

    *)
  3. format_usage : string -> string;
    (*

    Format usage string into style of this formatter.

    *)
  4. format_heading : string -> string;
    (*

    Format heading into style of this formatter.

    *)
  5. format_description : string -> string;
    (*

    Format description into style of this formatter.

    *)
  6. format_option : (char list * string list) -> string list -> string option -> string;
    (*

    Format option into style of this formatter (see explanation below).

    *)
}

This is the type of a formatter. The format_option has signature format_option (snames,lnames) metavars help, where snames is a list of the short option names, lnames is a list of the long option names, metavars is a list of the metavars the option takes as arguments, and help is the help string supplied by the user.

Standard formatters
val indented_formatter : ?level:int Stdlib.ref -> ?indent:int Stdlib.ref -> ?indent_increment:int -> ?max_help_position:int -> ?width:int -> ?short_first:bool -> unit -> t

Create an "indented" formatter with the given options.

  • parameter width

    Total with of the usage messages printed.

  • parameter max_help_position

    Maximum starting column for the help messages relating to each option.

  • parameter short_first

    List all the short option names first?

  • parameter indent_increment

    Number of columns to indent by when more indentation is required.

  • parameter indent

    Reference to the current indentation amount. Its value reflects changes in indentation level.

  • parameter level

    Reference to the current indentation level. Its value reflects changes in indentation level.

val titled_formatter : ?level:int Stdlib.ref -> ?indent:int Stdlib.ref -> ?indent_increment:int -> ?max_help_position:int -> ?width:int -> ?short_first:bool -> unit -> t

Creates a titled formatter which is quite similar to the indented formatter. See OptParse.Formatter.indented_formatter for a description of the options.

Low-level formatting
val wrap : ?initial_indent:int -> ?subsequent_indent:int -> string -> int -> string list

wrap text width reflows the given text paragraph into lines of width at most width (lines may exceed this if the are single words that exceed this limit).

  • parameter initial_indent

    Indentation of the first line.

  • parameter subsequent_indent

    Indentation of the following lines.

  • returns

    a list of lines making up the reformatted paragraph.

val fill : ?initial_indent:int -> ?subsequent_indent:int -> string -> int -> string

See OptParse.Formatter.wrap.

  • returns

    a string containing the reformatted paragraph.

OCaml

Innovation. Community. Security.