package progress

  1. Overview
  2. Docs
User-definable progress bars

Install

Dune Dependency

Authors

Maintainers

Sources

progress-0.3.0.tbz
sha256=3dfd00bd4def773239159b17781d02fdbfd8ea191801681a94aa0a5be1d06b7c
sha512=fd64ff8a819b2db2460c06b7fbd5663e2a1941f9e2d4e9b921a3d5f24509fe3be543521fbe1bb6baedad9f62b579aae933efac3903db03a27385233f5461f09c

doc/progress.engine/Progress_engine/Make/Printer/index.html

Module Make.PrinterSource

Sourcetype -'a t

The type of fixed-width pretty-printers for values of type 'a. Specifically, these pretty-printers aim to emit strings that have the same rendered length in terminals (i.e. after accounting for UTF-8 encoding and ANSI escapes).

Most users don't need this module, and can use the pre-provided Line segments and Units printers directly.

Constructing printers

Sourceval int : width:int -> int t

int ~width pretty-prints integers using width characters, adding left padding if necessary. The printer will raise Invalid_argument if the integer to be printed can't be displayed in the given width.

Sourceval string : width:int -> string t

string ~width is a pretty-printer for UTF8-encoded strings using width characters, adding right padding or truncating with ellipses as necessary.

For example, string ~width:8 processes values as follows:

  ""            ↦ "        "
  "hello"       ↦ "hello   "
  "hello world" ↦ "hello..."

Note: this printer uses a heuristic function (Uucp.tty_width_hint) to guess the rendered length of supplied strings. This function is not guaranteed to be correct on all UTF-8 codepoints, and so certain "unusual" string inputs can cause progress bar rendering to go awry.

Sourceval using : f:('b -> 'a) -> 'a t -> 'b t

using ~f t prints values v by passing f v to the printer t.

Sourceval create : ?width:int -> ?pp:(Format.formatter -> 'a -> unit) -> to_string:('a -> string) -> string_len:int -> unit -> 'a t

create ~to_string ~string_len () is a printer that uses to_string to render values in string_len-many bytes.

The rendered width of the output (when displayed in a terminal) is assumed to also be string_len (i.e. the output string is assumed to be ASCII), but this can be assumption can be overridden by passing an explicit ~width (e.g. if the printer emits non-ASCII UTF-8 characters or ANSI escape sequences).

Consuming printers

Sourceval to_pp : 'a t -> Format.formatter -> 'a -> unit

Convert a pretty-printer to a Format-compatible pretty-printer.

Sourceval to_to_string : 'a t -> 'a -> string

Convert a pretty-printer to a to_string function.

Sourceval print_width : _ t -> int

print_width t is the number of terminal columns occupied by the output of t.

Internals

Sourcemodule Internals : sig ... end
OCaml

Innovation. Community. Security.