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_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)
module Style : sig ... end
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
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 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
Control alignment of the given box wrt its surrounding box, if any.
Align to the right and to the bottom, as in align ~h:`Right ~v:`Bottom
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
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.
type 'a ktree = unit -> [ `Nil | `Node of 'a * 'a ktree list ]
type box = t
module Simple : sig ... end