Library
Module
Module type
Parameter
Class
Class type
Allows to print nested boxes, lists, arrays, tables in a nice way on any monospaced support.
# let b = PrintBox.(
frame
(vlist [ line "hello";
hlist [line "world"; line "yolo"]])
);;
val b : t = <abstr>
# PrintBox.output ~indent:2 stdout b;;
+----------+
|hello |
|----------|
|world|yolo|
+----------+
- : unit = ()
# let b2 = PrintBox.(
frame
(hlist [ text "I love\nto\npress\nenter";
grid_text [| [|"a"; "bbb"|];
[|"c"; "hello world"|] |]])
);;
val b2 : PrintBox.t = <abstr>
# PrintBox.output stdout b2;;
+--------------------+
|I love|a|bbb |
|to |-+-----------|
|press |c|hello world|
|enter | | |
+--------------------+
- : unit = ()
Positions are relative to the upper-left corner, that is, when x
increases we go toward the right, and when y
increases we go toward the bottom (same order as a printer)
The type t
is now opaque
The type view
can be used to observe the inside of the box.
A box, either empty, containing directly text, or a table or tree of sub-boxes
val empty : t
Empty box, of size 0
val line : string -> t
Make a single-line box.
val text : string -> t
Any text, possibly with several lines
val asprintf : ('a, Format.formatter, unit, t) format4 -> 'a
Formatting for text
.
val lines : string list -> t
Shortcut for text
, with a list of lines. lines l
is the same as text (String.concat "\n" l)
.
val int_ : int -> t
val bool_ : bool -> t
val float_ : float -> t
val int : int -> t
val bool : bool -> t
val float : float -> t
Pad with the given number of free cells for lines and columns
Grid of boxes (no frame between boxes). The matrix is indexed with lines first, then columns. The array must be a proper matrix, that is, all lines must have the same number of columns!
Same as grid
but takes the matrix as a function
Tree structure, with a node label and a list of children nodes
Definition of a tree with a local function that maps nodes to their content and children
type 'a ktree = unit -> [ `Nil | `Node of 'a * 'a ktree list ]
type box = t
module Simple : sig ... end