Module PrintBox
Pretty-Printing of nested Boxes
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 = ()
type position
=
{
x : int;
y : int;
}
Positions are relative to the upper-left corner, that is, when
x
increases we go toward the right, and wheny
increases we go toward the bottom (same order as a printer)
Box Combinators
type t
type view
= private
|
Empty
|
Text of string list
|
Frame of t
|
Pad of position * t
|
Grid of [ `Bars | `None ] * t array array
|
Tree of int * t * t array
val empty : t
Empty box, of size 0
val line : string -> t
Make a single-line box.
- raises Invalid_argument
if the string contains
'\n'
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 astext (String.concat "\n" l)
.
val bool : bool -> t
- since
- 0.2
val float : float -> t
- since
- 0.2
val pad' : col:int -> lines:int -> t -> t
Pad with the given number of free cells for lines and columns
val grid : ?pad:(t -> t) -> ?bars:bool -> t array array -> t
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!
- parameter framed
if
true
, each item of the grid will be framed. default value istrue
val init_grid : ?bars:bool -> line:int -> col:int -> (line:int -> col:int -> t) -> t
Same as
grid
but takes the matrix as a function
Simple Structural Interface
module Simple : sig ... end