authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-22 20:50:32 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-22 20:50:32 -07:00
log1f896246af65d2a4389a30a99af137049ce65204
tree74c6dca9009d241c65d4e0e98e8805e95de5e74c
parent930ab1f373012214e1a362a5d2b2cb2852242620

run zig fmt


1 files changed, 84 insertions(+), 56 deletions(-)

src/lib.zig+84-56
......@@ -44,10 +44,10 @@ pub const escape = struct {
4444 pub const SS3 = ascii.ESC.s() ++ "O";
4545 pub const DCS = ascii.ESC.s() ++ "P";
4646 pub const CSI = ascii.ESC.s() ++ "[";
47 pub const ST = ascii.ESC.s() ++ "\\";
47 pub const ST = ascii.ESC.s() ++ "\\";
4848 pub const OSC = ascii.ESC.s() ++ "]";
4949 pub const SOS = ascii.ESC.s() ++ "X";
50 pub const PM = ascii.ESC.s() ++ "^";
50 pub const PM = ascii.ESC.s() ++ "^";
5151 pub const APC = ascii.ESC.s() ++ "_";
5252 pub const RIS = ascii.ESC.s() ++ "c";
5353};
......@@ -65,76 +65,104 @@ fn arr_i_to_s(x: anytype) [][]const u8 {
6565}
6666
6767pub const csi = struct {
68 pub fn CursorUp(comptime n: i32) []const u8 { return make_csi_sequence("A", .{n}); }
69 pub fn CursorDown(comptime n: i32) []const u8 { return make_csi_sequence("B", .{n}); }
70 pub fn CursorForward(comptime n: i32) []const u8 { return make_csi_sequence("C", .{n}); }
71 pub fn CursorBack(comptime n: i32) []const u8 { return make_csi_sequence("D", .{n}); }
72 pub fn CursorNextLine(comptime n: i32) []const u8 { return make_csi_sequence("E", .{n}); }
73 pub fn CursorPrevLine(comptime n: i32) []const u8 { return make_csi_sequence("F", .{n}); }
74 pub fn CursorHorzAbs(comptime n: i32) []const u8 { return make_csi_sequence("G", .{n}); }
75 pub fn CursorPos(comptime n: i32, m: i32) []const u8 { return make_csi_sequence("H", .{n, m}); }
76 pub fn EraseInDisplay(comptime n: i32) []const u8 { return make_csi_sequence("J", .{n}); }
77 pub fn EraseInLine(comptime n: i32) []const u8 { return make_csi_sequence("K", .{n}); }
78 pub fn ScrollUp(comptime n: i32) []const u8 { return make_csi_sequence("S", .{n}); }
79 pub fn ScrollDown(comptime n: i32) []const u8 { return make_csi_sequence("T", .{n}); }
80 pub fn HorzVertPos(comptime n: i32, m: i32) []const u8 { return make_csi_sequence("f", .{n, m}); }
81 pub fn SGR(comptime ns: anytype) []const u8 { return make_csi_sequence("m", ns); }
68 pub fn CursorUp(comptime n: i32) []const u8 {
69 return make_csi_sequence("A", .{n});
70 }
71 pub fn CursorDown(comptime n: i32) []const u8 {
72 return make_csi_sequence("B", .{n});
73 }
74 pub fn CursorForward(comptime n: i32) []const u8 {
75 return make_csi_sequence("C", .{n});
76 }
77 pub fn CursorBack(comptime n: i32) []const u8 {
78 return make_csi_sequence("D", .{n});
79 }
80 pub fn CursorNextLine(comptime n: i32) []const u8 {
81 return make_csi_sequence("E", .{n});
82 }
83 pub fn CursorPrevLine(comptime n: i32) []const u8 {
84 return make_csi_sequence("F", .{n});
85 }
86 pub fn CursorHorzAbs(comptime n: i32) []const u8 {
87 return make_csi_sequence("G", .{n});
88 }
89 pub fn CursorPos(comptime n: i32, m: i32) []const u8 {
90 return make_csi_sequence("H", .{ n, m });
91 }
92 pub fn EraseInDisplay(comptime n: i32) []const u8 {
93 return make_csi_sequence("J", .{n});
94 }
95 pub fn EraseInLine(comptime n: i32) []const u8 {
96 return make_csi_sequence("K", .{n});
97 }
98 pub fn ScrollUp(comptime n: i32) []const u8 {
99 return make_csi_sequence("S", .{n});
100 }
101 pub fn ScrollDown(comptime n: i32) []const u8 {
102 return make_csi_sequence("T", .{n});
103 }
104 pub fn HorzVertPos(comptime n: i32, m: i32) []const u8 {
105 return make_csi_sequence("f", .{ n, m });
106 }
107 pub fn SGR(comptime ns: anytype) []const u8 {
108 return make_csi_sequence("m", ns);
109 }
82110};
83111
84112pub const style = struct {
85113 pub const ResetAll = csi.SGR(.{0});
86114
87 pub const Bold = csi.SGR(.{1});
88 pub const Faint = csi.SGR(.{2});
89 pub const Italic = csi.SGR(.{3});
115 pub const Bold = csi.SGR(.{1});
116 pub const Faint = csi.SGR(.{2});
117 pub const Italic = csi.SGR(.{3});
90118 pub const Underline = csi.SGR(.{4});
91119 pub const BlinkSlow = csi.SGR(.{5});
92120 pub const BlinkFast = csi.SGR(.{6});
93121
94122 pub const ResetFont = csi.SGR(.{10});
95 pub const Font1 = csi.SGR(.{11});
96 pub const Font2 = csi.SGR(.{12});
97 pub const Font3 = csi.SGR(.{13});
98 pub const Font4 = csi.SGR(.{14});
99 pub const Font5 = csi.SGR(.{15});
100 pub const Font6 = csi.SGR(.{16});
101 pub const Font7 = csi.SGR(.{17});
102 pub const Font8 = csi.SGR(.{18});
103 pub const Font9 = csi.SGR(.{19});
123 pub const Font1 = csi.SGR(.{11});
124 pub const Font2 = csi.SGR(.{12});
125 pub const Font3 = csi.SGR(.{13});
126 pub const Font4 = csi.SGR(.{14});
127 pub const Font5 = csi.SGR(.{15});
128 pub const Font6 = csi.SGR(.{16});
129 pub const Font7 = csi.SGR(.{17});
130 pub const Font8 = csi.SGR(.{18});
131 pub const Font9 = csi.SGR(.{19});
104132
105133 pub const UnderlineDouble = csi.SGR(.{21});
106 pub const ResetIntensity = csi.SGR(.{22});
107 pub const ResetItalic = csi.SGR(.{23});
108 pub const ResetUnderline = csi.SGR(.{24});
109 pub const ResetBlink = csi.SGR(.{25});
110
111 pub const FgBlack = csi.SGR(.{30});
112 pub const FgRed = csi.SGR(.{31});
113 pub const FgGreen = csi.SGR(.{32});
114 pub const FgYellow = csi.SGR(.{33});
115 pub const FgBlue = csi.SGR(.{34});
116 pub const FgMagenta = csi.SGR(.{35});
117 pub const FgCyan = csi.SGR(.{36});
118 pub const FgWhite = csi.SGR(.{37});
134 pub const ResetIntensity = csi.SGR(.{22});
135 pub const ResetItalic = csi.SGR(.{23});
136 pub const ResetUnderline = csi.SGR(.{24});
137 pub const ResetBlink = csi.SGR(.{25});
138
139 pub const FgBlack = csi.SGR(.{30});
140 pub const FgRed = csi.SGR(.{31});
141 pub const FgGreen = csi.SGR(.{32});
142 pub const FgYellow = csi.SGR(.{33});
143 pub const FgBlue = csi.SGR(.{34});
144 pub const FgMagenta = csi.SGR(.{35});
145 pub const FgCyan = csi.SGR(.{36});
146 pub const FgWhite = csi.SGR(.{37});
119147 // Fg8bit = func(n int) string { return csi.SGR(38, 5, n) }
120148 // Fg24bit = func(r, g, b int) string { return csi.SGR(38, 2, r, g, b) }
121149 pub const ResetFgColor = csi.SGR(.{39});
122150
123 pub const BgBlack = csi.SGR(.{40});
124 pub const BgRed = csi.SGR(.{41});
125 pub const BgGreen = csi.SGR(.{42});
126 pub const BgYellow = csi.SGR(.{43});
127 pub const BgBlue = csi.SGR(.{44});
128 pub const BgMagenta = csi.SGR(.{45});
129 pub const BgCyan = csi.SGR(.{46});
130 pub const BgWhite = csi.SGR(.{47});
151 pub const BgBlack = csi.SGR(.{40});
152 pub const BgRed = csi.SGR(.{41});
153 pub const BgGreen = csi.SGR(.{42});
154 pub const BgYellow = csi.SGR(.{43});
155 pub const BgBlue = csi.SGR(.{44});
156 pub const BgMagenta = csi.SGR(.{45});
157 pub const BgCyan = csi.SGR(.{46});
158 pub const BgWhite = csi.SGR(.{47});
131159 // Bg8bit = func(n int) string { return csi.SGR(48, 5, n) }
132160 // Bg24bit = func(r, g, b int) string { return csi.SGR(48, 2, r, g, b) }
133161 pub const ResetBgColor = csi.SGR(.{49});
134162
135 pub const Framed = csi.SGR(.{51});
136 pub const Encircled = csi.SGR(.{52});
137 pub const Overlined = csi.SGR(.{53});
163 pub const Framed = csi.SGR(.{51});
164 pub const Encircled = csi.SGR(.{52});
165 pub const Overlined = csi.SGR(.{53});
138166 pub const ResetFrameEnci = csi.SGR(.{54});
139167 pub const ResetOverlined = csi.SGR(.{55});
140168};
......@@ -152,11 +180,11 @@ pub const color = struct {
152180 };
153181
154182 pub fn Fg(s: Color, comptime m: []const u8) []const u8 {
155 return csi.SGR(.{30+@enumToInt(s)}) ++ m ++ style.ResetFgColor;
183 return csi.SGR(.{30 + @enumToInt(s)}) ++ m ++ style.ResetFgColor;
156184 }
157185
158186 pub fn Bg(s: Color, comptime m: []const u8) []const u8 {
159 return csi.SGR(.{40+@enumToInt(s)}) ++ m ++ style.ResetBgColor;
187 return csi.SGR(.{40 + @enumToInt(s)}) ++ m ++ style.ResetBgColor;
160188 }
161189};
162190
......@@ -166,9 +194,9 @@ pub const color = struct {
166194
167195fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 {
168196 var buf: []const u8 = "";
169 for (xs) |x,i| {
197 for (xs) |x, i| {
170198 buf = buf ++ x;
171 if (i < xs.len-1) buf = buf ++ delim;
199 if (i < xs.len - 1) buf = buf ++ delim;
172200 }
173201 return buf;
174202}