package printbox
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=c783dfbbc21ed9bdab04980b58efa901b149f38f9992f2cdc624abd681d8dedb
sha512=43968271141a44ab4655586bf35bb8540d1ca6312e0a93b14311ae82e6edd700be92d598677fda3bdc6fd8537890ea42cd0224fe9447a6cf8471ba915299ee36
doc/printbox/PrintBox/index.html
Module PrintBoxSource
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_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)
Box Combinators
Main type for a document composed of nested boxes.
Extensions of the representation.
type view = private | Empty| Text of {l : string list;style : Style.t;
}| Frame of {sub : t;stretch : bool;
}| 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;
}| Anchor of {id : string;inner : t;
}| Ext of {key : string;ext : ext;
}
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.
anchor ~id inner provides an anchor with the given ID, with the visible hyperlink description being inner. Will render in HTML as an "<a>" element, and as a link in ANSI stylized text. If inner is non-empty, the rendered link URI is "#" ^ id.
extension ~key ext embeds an extended representation ext as a box. ext must be recognized by the used backends as an extension registered under key.
Styling combinators
Formatting for text, with style
Formatting for text, with style.