package progress
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=7ae7f5c5a2db88107d0b3fd37d5344f066921270a3e74d56dd13457feb9e586e
sha512=3828ac568e447e5f1e59450ee48491c256d8bc77abe234190e14e2db5be7b81f379837083f0eb28ea9572fce2781fd0addd7adc1701947c0b2de9d8319ace042
doc/progress.engine/Progress_engine/Make/Printer/index.html
Module Make.Printer
Source
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
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.
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.
using ~f t
prints values v
by passing f v
to the printer t
.
val 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
Convert a pretty-printer to a Format
-compatible pretty-printer.
print_width t
is the number of terminal columns occupied by the output of t
.