Page
Library
Module
Module type
Parameter
Class
Class type
Source
PrintBoxSourceAllows 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_text.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_text.output stdout b2;;
+--------------------+
|I love|a|bbb |
|to |-+-----------|
|press |c|hello world|
|enter | | |
+--------------------+
- : unit = ()
Since 0.3 there is also basic support for coloring text:
# let b = PrintBox.(
frame
(vlist [ line_with_style Style.(bg_color Green) "hello";
hlist [line "world"; line_with_style Style.(fg_color Red) "yolo"]])
);;
val b : t = <abstr>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)
Main type for a document composed of nested boxes.
type view = private | Empty| Text of {l : string list;style : Style.t;}| Frame of t| Pad of position * t| Align of {h : [ `Left | `Center | `Right ];v : [ `Top | `Center | `Bottom ];inner : t;}Alignment within the surrounding box
*)| Grid of [ `Bars | `None ] * t array array| Tree of int * t * t array| Link of {uri : string;inner : t;}The type view can be used to observe the inside of the box, now that t is opaque.
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
Control alignment of the given box wrt its surrounding box, if any.
Left-pad to the size of the surrounding box, as in align ~h:`Right ~v:`Top
Align to the right and to the bottom, as in align ~h:`Right ~v:`Bottom
Try to center within the surrounding box, as in align ~h:`Center ~v:`Center
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
Same as grid_text but from lists.
A record displayed as a table, each field being a columng (label,value).
# frame @@ record ["a", int 1; "b", float 3.14; "c", bool true];;
- : t = +-----------+
|a|b |c |
|-+----+----|
|1|3.14|true|
+-----------+Like record, but printed vertically rather than horizontally.
# frame @@ v_record ["a", int 1; "b", float 3.14; "c", bool true];;
- : t = +------+
|a|1 |
|-+----|
|b|3.14|
|-+----|
|c|true|
+------+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
link ~uri inner points to the given URI, with the visible description being inner. Will render in HTML as a "<a>" element.
Formatting for text, with style
Formatting for text, with style.