authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-12-15 07:35:29 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-12-15 07:35:29 -08:00
logffd768cb684a6ece645bd1e6c30cf8c78345ccd7
tree49e6f0fb282e021916088f07cbe7bccbe96da8ff
parentfa79a61fd40c5bfbf9628dd3b2076f1f6159124c

use zig-ansi instead of internal code


5 files changed, 6 insertions(+), 177 deletions(-)

.gitmodules+3
...@@ -4,3 +4,6 @@...@@ -4,3 +4,6 @@
4[submodule "libs/zig-known-folders"]4[submodule "libs/zig-known-folders"]
5 path = libs/zig-known-folders5 path = libs/zig-known-folders
6 url = https://github.com/ziglibs/known-folders6 url = https://github.com/ziglibs/known-folders
7[submodule "libs/zig-ansi"]
8 path = libs/zig-ansi
9 url = https://github.com/nektro/zig-ansi
build.zig+1
...@@ -40,6 +40,7 @@ pub fn build(b: *Builder) void {...@@ -40,6 +40,7 @@ pub fn build(b: *Builder) void {
40 exe.addCSourceFile("./libs/yaml/src/writer.c", &[_][]const u8{});40 exe.addCSourceFile("./libs/yaml/src/writer.c", &[_][]const u8{});
4141
42 exe.addPackagePath("known-folders", "./libs/zig-known-folders/known-folders.zig");42 exe.addPackagePath("known-folders", "./libs/zig-known-folders/known-folders.zig");
43 exe.addPackagePath("ansi", "./libs/zig-ansi/src/lib.zig");
4344
44 exe.install();45 exe.install();
4546
src/util/ansi.zig deleted-130
...@@ -1,130 +0,0 @@
1const std = @import("std");
2const gpa = std.heap.c_allocator;
3
4const u = @import("index.zig");
5
6//
7//
8
9pub const ansi = struct {
10 pub const escape = struct {
11 pub const SS2 = u.ascii.ESC.s() ++ "N";
12 pub const SS3 = u.ascii.ESC.s() ++ "O";
13 pub const DCS = u.ascii.ESC.s() ++ "P";
14 pub const CSI = u.ascii.ESC.s() ++ "[";
15 pub const ST = u.ascii.ESC.s() ++ "\\";
16 pub const OSC = u.ascii.ESC.s() ++ "]";
17 pub const SOS = u.ascii.ESC.s() ++ "X";
18 pub const PM = u.ascii.ESC.s() ++ "^";
19 pub const APC = u.ascii.ESC.s() ++ "_";
20 pub const RIS = u.ascii.ESC.s() ++ "c";
21 };
22
23 fn make_csi_sequence(comptime c: []const u8, x: anytype) []const u8 {
24 return escape.CSI ++ u._join(";", arr_i_to_s(x)) ++ c;
25 }
26
27 fn arr_i_to_s(x: anytype) [][]const u8 {
28 var res: [x.len][]const u8 = undefined;
29 for (x) |item, i| {
30 res[i] = std.fmt.comptimePrint("{}", .{item});
31 }
32 return &res;
33 }
34
35 pub const csi = struct {
36 fn CursorUp(n: i32) []const u8 { return make_csi_sequence("A", .{n}); }
37 fn CursorDown(n: i32) []const u8 { return make_csi_sequence("B", .{n}); }
38 fn CursorForward(n: i32) []const u8 { return make_csi_sequence("C", .{n}); }
39 fn CursorBack(n: i32) []const u8 { return make_csi_sequence("D", .{n}); }
40 fn CursorNextLine(n: i32) []const u8 { return make_csi_sequence("E", .{n}); }
41 fn CursorPrevLine(n: i32) []const u8 { return make_csi_sequence("F", .{n}); }
42 fn CursorHorzAbs(n: i32) []const u8 { return make_csi_sequence("G", .{n}); }
43 fn CursorPos(n: i32, m: i32) []const u8 { return make_csi_sequence("H", .{n, m}); }
44 fn EraseInDisplay(n: i32) []const u8 { return make_csi_sequence("J", .{n}); }
45 fn EraseInLine(n: i32) []const u8 { return make_csi_sequence("K", .{n}); }
46 fn ScrollUp(n: i32) []const u8 { return make_csi_sequence("S", .{n}); }
47 fn ScrollDown(n: i32) []const u8 { return make_csi_sequence("T", .{n}); }
48 fn HorzVertPos(n: i32, m: i32) []const u8 { return make_csi_sequence("f", .{n, m}); }
49 fn SGR(ns: anytype) []const u8 { return make_csi_sequence("m", ns); }
50 };
51
52 pub const style = struct {
53 pub const ResetAll = csi.SGR(.{0});
54
55 pub const Bold = csi.SGR(.{1});
56 pub const Faint = csi.SGR(.{2});
57 pub const Italic = csi.SGR(.{3});
58 pub const Underline = csi.SGR(.{4});
59 pub const BlinkSlow = csi.SGR(.{5});
60 pub const BlinkFast = csi.SGR(.{6});
61
62 pub const ResetFont = csi.SGR(.{10});
63 pub const Font1 = csi.SGR(.{11});
64 pub const Font2 = csi.SGR(.{12});
65 pub const Font3 = csi.SGR(.{13});
66 pub const Font4 = csi.SGR(.{14});
67 pub const Font5 = csi.SGR(.{15});
68 pub const Font6 = csi.SGR(.{16});
69 pub const Font7 = csi.SGR(.{17});
70 pub const Font8 = csi.SGR(.{18});
71 pub const Font9 = csi.SGR(.{19});
72
73 pub const UnderlineDouble = csi.SGR(.{21});
74 pub const ResetIntensity = csi.SGR(.{22});
75 pub const ResetItalic = csi.SGR(.{23});
76 pub const ResetUnderline = csi.SGR(.{24});
77 pub const ResetBlink = csi.SGR(.{25});
78
79 pub const FgBlack = csi.SGR(.{30});
80 pub const FgRed = csi.SGR(.{31});
81 pub const FgGreen = csi.SGR(.{32});
82 pub const FgYellow = csi.SGR(.{33});
83 pub const FgBlue = csi.SGR(.{34});
84 pub const FgMagenta = csi.SGR(.{35});
85 pub const FgCyan = csi.SGR(.{36});
86 pub const FgWhite = csi.SGR(.{37});
87 // Fg8bit = func(n int) string { return csi.SGR(38, 5, n) }
88 // Fg24bit = func(r, g, b int) string { return csi.SGR(38, 2, r, g, b) }
89 pub const ResetFgColor = csi.SGR(.{39});
90
91 pub const BgBlack = csi.SGR(.{40});
92 pub const BgRed = csi.SGR(.{41});
93 pub const BgGreen = csi.SGR(.{42});
94 pub const BgYellow = csi.SGR(.{43});
95 pub const BgBlue = csi.SGR(.{44});
96 pub const BgMagenta = csi.SGR(.{45});
97 pub const BgCyan = csi.SGR(.{46});
98 pub const BgWhite = csi.SGR(.{47});
99 // Bg8bit = func(n int) string { return csi.SGR(48, 5, n) }
100 // Bg24bit = func(r, g, b int) string { return csi.SGR(48, 2, r, g, b) }
101 pub const ResetBgColor = csi.SGR(.{49});
102
103 pub const Framed = csi.SGR(.{51});
104 pub const Encircled = csi.SGR(.{52});
105 pub const Overlined = csi.SGR(.{53});
106 pub const ResetFrameEnci = csi.SGR(.{54});
107 pub const ResetOverlined = csi.SGR(.{55});
108 };
109
110 pub const color = struct {
111 pub const Color = enum(u8) {
112 Black,
113 Red,
114 Green,
115 Yellow,
116 Blue,
117 Magenta,
118 Cyan,
119 White,
120 };
121
122 pub fn Fg(s: Color, comptime m: []const u8) []const u8 {
123 return csi.SGR(.{30+@enumToInt(s)}) ++ m ++ style.ResetFgColor;
124 }
125
126 pub fn Bg(s: Color, comptime m: []const u8) []const u8 {
127 return csi.SGR(.{40+@enumToInt(s)}) ++ m ++ style.ResetBgColor;
128 }
129 };
130};
src/util/ascii.zig deleted-46
...@@ -1,46 +0,0 @@
1const std = @import("std");
2const gpa = std.heap.c_allocator;
3
4const u = @import("index.zig");
5
6//
7//
8
9pub const ascii = enum(u8) {
10 NUL,
11 SOH,
12 STX,
13 ETX,
14 EOT,
15 ENQ,
16 ACK,
17 BEL,
18 BS,
19 TAB,
20 LF,
21 VT,
22 FF,
23 CR,
24 SO,
25 SI,
26 DLE,
27 DC1,
28 DC2,
29 DC3,
30 DC4,
31 NAK,
32 SYN,
33 ETB,
34 CAN,
35 EM,
36 SUB,
37 ESC,
38 FS,
39 GS,
40 RS,
41 US,
42
43 pub fn s(self: ascii) []const u8 {
44 return &[_]u8{@enumToInt(self)};
45 }
46};
src/util/funcs.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const gpa = std.heap.c_allocator;2const gpa = std.heap.c_allocator;
33
4const ansi = @import("ansi");
4const u = @import("index.zig");5const u = @import("index.zig");
56
6//7//
...@@ -16,7 +17,7 @@ pub fn print(comptime fmt: []const u8, args: anytype) void {...@@ -16,7 +17,7 @@ pub fn print(comptime fmt: []const u8, args: anytype) void {
1617
17pub fn assert(ok: bool, comptime fmt: []const u8, args: anytype) void {18pub fn assert(ok: bool, comptime fmt: []const u8, args: anytype) void {
18 if (!ok) {19 if (!ok) {
19 print(comptime u.ansi.color.Fg(.Red, "error: " ++ fmt), args);20 print(comptime ansi.color.Fg(.Red, "error: " ++ fmt), args);
20 std.os.exit(1);21 std.os.exit(1);
21 }22 }
22}23}