-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.zig
146 lines (132 loc) · 6.36 KB
/
example.zig
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
const std = @import("std");
const tm = tp.manipulators;
const tp = @import("teleprinter.zig");
pub fn main() !void {
var arena_impl = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena_impl.deinit();
const arena = &arena_impl.allocator;
const out = try tp.autoTTY(arena, std.fs.File.write, std.io.getStdOut(), null);
defer out.deinit();
try out.startup();
defer out.shutdown() catch {};
try printReport(out);
try out.format("\n--- hexdump:\n\n", .{});
try @import("coreutil.zig").hexDump(out, &[_]u8{
0x23, 0x23, 0x0a, 0x23, 0x20, 0x55, 0x73, 0x65, 0x72, 0x20, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61,
0x73, 0x65, 0x0a, 0x23, 0x20, 0x0a, 0x23, 0x20, 0x4e, 0x6f, 0x74, 0x65, 0x20, 0x74, 0x68, 0x61,
0x74, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69, 0x73, 0x20, 0x63,
0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x74, 0x65, 0x64, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x6c,
0x79, 0x20, 0x6f, 0x6e, 0x6c, 0x79, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20,
0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x69, 0x73, 0x20, 0x72, 0x75, 0x6e, 0x6e, 0x69, 0x6e,
0x67, 0x0a,
});
}
fn printReport(tty: *tp.TTY) !void {
{
try tty.format("\n--- HUES AND INTENSITY\n\n", .{});
try tty.push();
tty.indent();
defer tty.pop();
try tty.format("{9} {} {} {}\n", .{
tm.hue0, "hue0",
tm.low, tm.hue0, "low",
tm.med, tm.hue0, "medium",
tm.high, tm.hue0, "high",
});
try tty.format("{9} {} {} {}\n", .{
tm.hue1, "hue1",
tm.low, tm.hue1, "low",
tm.med, tm.hue1, "medium",
tm.high, tm.hue1, "high",
});
try tty.format("{9} {} {} {}\n", .{
tm.hue2, "hue2",
tm.low, tm.hue2, "low",
tm.med, tm.hue2, "medium",
tm.high, tm.hue2, "high",
});
try tty.format("{9} {} {} {}\n", .{
tm.info, "info",
tm.low, tm.info, "low",
tm.med, tm.info, "medium",
tm.high, tm.info, "high",
});
try tty.format("{9} {} {} {}\n", .{
tm.positive, "positive",
tm.low, tm.positive, "low",
tm.med, tm.positive, "medium",
tm.high, tm.positive, "high",
});
try tty.format("{9} {} {} {}\n", .{
tm.negative, "negative",
tm.low, tm.negative, "low",
tm.med, tm.negative, "medium",
tm.high, tm.negative, "high",
});
try tty.format("{9} {} {} {}\n", .{
tm.caution, "caution",
tm.low, tm.caution, "low",
tm.med, tm.caution, "medium",
tm.high, tm.caution, "high",
});
try tty.format("{9} {} {} {}\n", .{
tm.alert, "alert",
tm.low, tm.alert, "low",
tm.med, tm.alert, "medium",
tm.high, tm.alert, "high",
});
}
{
try tty.format("\n--- TYPE: bool\n\n", .{});
try tty.push();
tty.indent();
defer tty.pop();
try tty.format("format={4} → {6} / {}\n", .{tm.hue1, "{}", tm.info, true, tm.info, false});
try tty.format("format={4} → {6e} / {e}\n", .{tm.hue1, "{e}", tm.info, true, tm.info, false});
try tty.format("format={4} → {6o} / {o}\n", .{tm.hue1, "{o}", tm.info, true, tm.info, false});
try tty.format("format={4} → {6p} / {p}\n", .{tm.hue1, "{p}", tm.info, true, tm.info, false});
try tty.format("format={4} → {6t} / {t}\n", .{tm.hue1, "{t}", tm.info, true, tm.info, false});
try tty.format("format={4} → {6y} / {y}\n", .{tm.hue1, "{y}", tm.info, true, tm.info, false});
try tty.format("format={4} → {6tc} / {tc}\n", .{tm.hue1, "{tc}", tm.info, true, tm.info, false});
try tty.format("format={4} → {6tl} / {tl}\n", .{tm.hue1, "{tl}", tm.info, true, tm.info, false});
try tty.format("format={4} → {6tu} / {tu}\n", .{tm.hue1, "{tu}", tm.info, true, tm.info, false});
}
{
try tty.format("\n--- TYPE: unsigned\n\n", .{});
try tty.push();
tty.indent();
defer tty.pop();
var i: u64 = 0x4a39cc0f;
try tty.format("format={7} → {}\n", .{tm.hue1, "{}", tm.info, i});
try tty.format("format={7} → {b}\n", .{tm.hue1, "{b}", tm.info, i});
try tty.format("format={7} → {b064}\n", .{tm.hue1, "{b064}", tm.info, i});
try tty.format("format={7} → {o}\n", .{tm.hue1, "{o}", tm.info, i});
try tty.format("format={7} → {o016}\n", .{tm.hue1, "{o016}", tm.info, i});
try tty.format("format={7} → {d}\n", .{tm.hue1, "{d}", tm.info, i});
try tty.format("format={7} → {d012}\n", .{tm.hue1, "{d012}", tm.info, i});
try tty.format("format={7} → {x}\n", .{tm.hue1, "{x}", tm.info, i});
try tty.format("format={7} → {x016}\n", .{tm.hue1, "{x016}", tm.info, i});
try tty.format("format={7} → {xp}\n", .{tm.hue1, "{xp}", tm.info, i});
try tty.format("format={7} → {xp016}\n", .{tm.hue1, "{xp016}", tm.info, i});
try tty.format("format={7} → {X}\n", .{tm.hue1, "{X}", tm.info, i});
try tty.format("format={7} → {X016}\n", .{tm.hue1, "{X016}", tm.info, i});
try tty.format("format={7} → {Xp}\n", .{tm.hue1, "{Xp}", tm.info, i});
try tty.format("format={7} → {Xp016}\n", .{tm.hue1, "{Xp016}", tm.info, i});
try tty.format("format={7} → {XP016}\n", .{tm.hue1, "{XP016}", tm.info, i});
try tty.format("\nfill/center/delimit:\n\n", .{});
try tty.format("format={11} → {^40d}\n", .{tm.hue1, "{^40d}",tm.info, i});
try tty.format("format={11} → {^40d,}\n", .{tm.hue1, "{^40d,}",tm.info, i});
try tty.format("format={11} → {^40d_}\n", .{tm.hue1, "{^40d_}",tm.info, i});
try tty.format("format={11} → {^40d'}\n", .{tm.hue1, "{^40d'}",tm.info, i});
try tty.format("format={11} → {:^40d'}\n", .{tm.hue1, "{:^40d'}", tm.info, i});
}
{
try tty.format("\n--- TYPE: string\n\n", .{});
try tty.push();
tty.indent();
defer tty.pop();
var width: usize = 20;
var fill: u8 = ':';
try tty.format("runtime fill/center/width: `{}` → {*^*s}\n", .{tm.hue1, "format(\"{*^*s}\", .{\"hello\", fill, width});", tm.info, "hello", fill, width});
}
}