-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest1.ml
151 lines (134 loc) · 3.86 KB
/
test1.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
module B = PrintBox
(* make a square *)
let square n =
Array.init n (fun i -> Array.init n (fun j -> B.sprintf "(%d,%d)" i j))
|> B.grid
let () =
for i = 1 to 20 do
Printf.printf "for %d:\n%a\n\n" i
(PrintBox_text.output ~style:true ?indent:None)
(square i)
done
let tree =
B.tree (B.text "root")
[
B.tree (B.text "a") [ B.text "a1\na1"; B.text "a2\na2\na2" ];
B.tree (B.text "b") [ B.text "b1\nb1"; B.text "b2"; B.text "b3" ];
]
let () = PrintBox_text.output stdout tree
let () = Printf.printf "\n\n"
let grid =
B.frame
@@ B.grid_l
[
[ B.text "the center of the triangle is"; B.empty ];
[
B.center_hv @@ B.text "lil' ol' me";
B.pad' ~col:0 ~lines:6 @@ B.text "t\na\nl\nl";
];
[ B.align_right (B.text "i'm aligned right"); B.empty ];
[ B.text "loooooooooooooooooooooooooooooooooong"; B.empty ];
]
let () =
PrintBox_text.output stdout grid;
print_endline ""
let b2 =
PrintBox.(
let style = Style.(fg_color Red) in
frame
@@ grid_l
[
[
text_with_style style "a\nb";
line_with_style Style.(set_bold true @@ bg_color Green) "OH!";
];
[ text "c"; text "ballot" ];
])
let () =
PrintBox_text.output stdout b2;
Printf.printf "\n\n"
let grid2 =
B.frame
@@ B.record ~pad:B.align_right [ "name1", B.int 1; "foo", B.bool true ]
let () =
PrintBox_text.output stdout grid2;
print_endline ""
let grid3 =
B.frame
@@ B.v_record ~pad:B.center_h
[ "name_int_long", B.int 1; "foo", B.bool true; "bar!", B.int 42 ]
let () =
PrintBox_text.output stdout grid3;
print_endline ""
module Box_in = struct
let b =
let open B in
frame
@@ grid_l
[
[ text "a"; text "looooooooooooooooooooooooo\noonng" ];
[
text "bx"; center_hv @@ frame @@ record [ "x", int 1; "y", int 2 ];
];
[
pad' ~col:2 ~lines:2 @@ text "?";
center_hv @@ record [ "x", int 10; "y", int 20 ];
];
]
let () = print_endline @@ PrintBox_text.to_string b
end
let _b =
let open PrintBox in
frame
@@ record
[
"subject", text_with_style Style.bold "announce: printbox 0.3";
( "explanation",
frame
@@ text
{|PrintBox is a library for rendering nested tables,
trees, and similar structures in monospace text or HTML.|}
);
( "github",
text_with_style
Style.(bg_color Blue)
"https://github.com/c-cube/printbox/releases/tag/0.3" );
( "contributors",
vlist_map
(text_with_style Style.(fg_color Green))
[ "Simon"; "Guillaume"; "Matt" ] );
( "dependencies",
tree empty
[
tree (text "mandatory") [ text "dune"; text "bytes" ];
tree (text "optional") [ text "uutf"; text "uucp"; text "tyxml" ];
] );
"expected reaction", text "🎉";
]
module Unicode = struct
let b =
B.(
frame
@@ vlist
[
text "nice unicode! 💪";
frame
@@ hlist
[
vlist
[
text "oï ωεird nums:\nπ/2\nτ/4";
center_hv
@@ tree (text "0")
[ text "1"; tree (text "ω") [ text "ω²" ] ];
];
frame @@ frame @@ frame
@@ vlist
[
text "sum=Σ_i a·xᵢ²\n—————\n1+1";
align_right @@ text "Ōₒ\nÀ";
];
];
])
let () = print_endline @@ PrintBox_text.to_string b
end