Page
Library
Module
Module type
Parameter
Class
Class type
Source
PrintBox
SourceAllows 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
Formatting for text
.
Shortcut for text
, with a list of lines. lines l
is the same as text (String.concat "\n" l)
.
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!
Transpose a matrix
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