package progress

  1. Overview
  2. Docs

Helpers for printing values of various units.

type 'a pp := Format.formatter -> 'a -> unit
type ('a, 'b) pp_fixed = (width:int -> 'a pp -> 'b) -> 'b

A fixed-width pretty printer. Intended to be used to create progress bar segments, e.g. bytes Segment.of_pp is a segment that pretty-prints values as byte counts.

val bytes : (int64, _) pp_fixed

Prints a 64-bit integer as a byte count. e.g.

0L                  ↦  "   0.0 B  "
999L                ↦  " 999.0 B  "
1024L               ↦  "   1.0 KiB"
1024L * 1023L       ↦  "1023.0 KiB"
1024L * 1024L - 1L  ↦  "1023.9 KiB"
val percentage : (float, _) pp_fixed

Prints a proportion as a percentage. e.g.

0.      ↦  "  0%"
0.42    ↦  " 42%"
0.9999  ↦  " 99%"
1.      ↦  "100%"

Note: values will be clamped into the range [0., 1.].

val seconds : (Mtime.Span.t, _) pp_fixed

Renders a time span in fixed-width MM:SS form.

Assorted pretty-printing utilities

module Percentage : sig ... end
module Bytes : sig ... end
OCaml

Innovation. Community. Security.