authorgravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2023-05-20 22:30:02+01:00
committergravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2023-05-24 10:15:02+01:00
log39c2eee285f820282dedba4404cac1009a5ae2d6
tree1f36e2df6d7fa82e24f1f44c8f465a09c6c7f9a7
parent16dbb960fc8dada79cd42dd2ba1ebf0f66ccaaec

std.debug: Rename TTY.Color enum values to snake case


5 files changed, 87 insertions(+), 87 deletions(-)

lib/build_runner.zig+30-30
......@@ -476,9 +476,9 @@ fn runStepNames(
476476
477477 if (run.enable_summary != false) {
478478 const total_count = success_count + failure_count + pending_count + skipped_count;
479 ttyconf.setColor(stderr, .Cyan) catch {};
479 ttyconf.setColor(stderr, .cyan) catch {};
480480 stderr.writeAll("Build Summary:") catch {};
481 ttyconf.setColor(stderr, .Reset) catch {};
481 ttyconf.setColor(stderr, .reset) catch {};
482482 stderr.writer().print(" {d}/{d} steps succeeded", .{ success_count, total_count }) catch {};
483483 if (skipped_count > 0) stderr.writer().print("; {d} skipped", .{skipped_count}) catch {};
484484 if (failure_count > 0) stderr.writer().print("; {d} failed", .{failure_count}) catch {};
......@@ -489,9 +489,9 @@ fn runStepNames(
489489 if (test_leak_count > 0) stderr.writer().print("; {d} leaked", .{test_leak_count}) catch {};
490490
491491 if (run.enable_summary == null) {
492 ttyconf.setColor(stderr, .Dim) catch {};
492 ttyconf.setColor(stderr, .dim) catch {};
493493 stderr.writeAll(" (disable with -fno-summary)") catch {};
494 ttyconf.setColor(stderr, .Reset) catch {};
494 ttyconf.setColor(stderr, .reset) catch {};
495495 }
496496 stderr.writeAll("\n") catch {};
497497
......@@ -560,7 +560,7 @@ fn printTreeStep(
560560 const first = step_stack.swapRemove(s);
561561 try printPrefix(parent_node, stderr, ttyconf);
562562
563 if (!first) try ttyconf.setColor(stderr, .Dim);
563 if (!first) try ttyconf.setColor(stderr, .dim);
564564 if (parent_node.parent != null) {
565565 if (parent_node.last) {
566566 try stderr.writeAll(switch (ttyconf) {
......@@ -586,28 +586,28 @@ fn printTreeStep(
586586 .running => unreachable,
587587
588588 .dependency_failure => {
589 try ttyconf.setColor(stderr, .Dim);
589 try ttyconf.setColor(stderr, .dim);
590590 try stderr.writeAll(" transitive failure\n");
591 try ttyconf.setColor(stderr, .Reset);
591 try ttyconf.setColor(stderr, .reset);
592592 },
593593
594594 .success => {
595 try ttyconf.setColor(stderr, .Green);
595 try ttyconf.setColor(stderr, .green);
596596 if (s.result_cached) {
597597 try stderr.writeAll(" cached");
598598 } else if (s.test_results.test_count > 0) {
599599 const pass_count = s.test_results.passCount();
600600 try stderr.writer().print(" {d} passed", .{pass_count});
601601 if (s.test_results.skip_count > 0) {
602 try ttyconf.setColor(stderr, .Yellow);
602 try ttyconf.setColor(stderr, .yellow);
603603 try stderr.writer().print(" {d} skipped", .{s.test_results.skip_count});
604604 }
605605 } else {
606606 try stderr.writeAll(" success");
607607 }
608 try ttyconf.setColor(stderr, .Reset);
608 try ttyconf.setColor(stderr, .reset);
609609 if (s.result_duration_ns) |ns| {
610 try ttyconf.setColor(stderr, .Dim);
610 try ttyconf.setColor(stderr, .dim);
611611 if (ns >= std.time.ns_per_min) {
612612 try stderr.writer().print(" {d}m", .{ns / std.time.ns_per_min});
613613 } else if (ns >= std.time.ns_per_s) {
......@@ -619,11 +619,11 @@ fn printTreeStep(
619619 } else {
620620 try stderr.writer().print(" {d}ns", .{ns});
621621 }
622 try ttyconf.setColor(stderr, .Reset);
622 try ttyconf.setColor(stderr, .reset);
623623 }
624624 if (s.result_peak_rss != 0) {
625625 const rss = s.result_peak_rss;
626 try ttyconf.setColor(stderr, .Dim);
626 try ttyconf.setColor(stderr, .dim);
627627 if (rss >= 1000_000_000) {
628628 try stderr.writer().print(" MaxRSS:{d}G", .{rss / 1000_000_000});
629629 } else if (rss >= 1000_000) {
......@@ -633,57 +633,57 @@ fn printTreeStep(
633633 } else {
634634 try stderr.writer().print(" MaxRSS:{d}B", .{rss});
635635 }
636 try ttyconf.setColor(stderr, .Reset);
636 try ttyconf.setColor(stderr, .reset);
637637 }
638638 try stderr.writeAll("\n");
639639 },
640640
641641 .skipped => {
642 try ttyconf.setColor(stderr, .Yellow);
642 try ttyconf.setColor(stderr, .yellow);
643643 try stderr.writeAll(" skipped\n");
644 try ttyconf.setColor(stderr, .Reset);
644 try ttyconf.setColor(stderr, .reset);
645645 },
646646
647647 .failure => {
648648 if (s.result_error_bundle.errorMessageCount() > 0) {
649 try ttyconf.setColor(stderr, .Red);
649 try ttyconf.setColor(stderr, .red);
650650 try stderr.writer().print(" {d} errors\n", .{
651651 s.result_error_bundle.errorMessageCount(),
652652 });
653 try ttyconf.setColor(stderr, .Reset);
653 try ttyconf.setColor(stderr, .reset);
654654 } else if (!s.test_results.isSuccess()) {
655655 try stderr.writer().print(" {d}/{d} passed", .{
656656 s.test_results.passCount(), s.test_results.test_count,
657657 });
658658 if (s.test_results.fail_count > 0) {
659659 try stderr.writeAll(", ");
660 try ttyconf.setColor(stderr, .Red);
660 try ttyconf.setColor(stderr, .red);
661661 try stderr.writer().print("{d} failed", .{
662662 s.test_results.fail_count,
663663 });
664 try ttyconf.setColor(stderr, .Reset);
664 try ttyconf.setColor(stderr, .reset);
665665 }
666666 if (s.test_results.skip_count > 0) {
667667 try stderr.writeAll(", ");
668 try ttyconf.setColor(stderr, .Yellow);
668 try ttyconf.setColor(stderr, .yellow);
669669 try stderr.writer().print("{d} skipped", .{
670670 s.test_results.skip_count,
671671 });
672 try ttyconf.setColor(stderr, .Reset);
672 try ttyconf.setColor(stderr, .reset);
673673 }
674674 if (s.test_results.leak_count > 0) {
675675 try stderr.writeAll(", ");
676 try ttyconf.setColor(stderr, .Red);
676 try ttyconf.setColor(stderr, .red);
677677 try stderr.writer().print("{d} leaked", .{
678678 s.test_results.leak_count,
679679 });
680 try ttyconf.setColor(stderr, .Reset);
680 try ttyconf.setColor(stderr, .reset);
681681 }
682682 try stderr.writeAll("\n");
683683 } else {
684 try ttyconf.setColor(stderr, .Red);
684 try ttyconf.setColor(stderr, .red);
685685 try stderr.writeAll(" failure\n");
686 try ttyconf.setColor(stderr, .Reset);
686 try ttyconf.setColor(stderr, .reset);
687687 }
688688 },
689689 }
......@@ -703,7 +703,7 @@ fn printTreeStep(
703703 s.dependencies.items.len,
704704 });
705705 }
706 try ttyconf.setColor(stderr, .Reset);
706 try ttyconf.setColor(stderr, .reset);
707707 }
708708}
709709
......@@ -819,13 +819,13 @@ fn workerMakeOneStep(
819819 for (s.result_error_msgs.items) |msg| {
820820 // Sometimes it feels like you just can't catch a break. Finally,
821821 // with Zig, you can.
822 ttyconf.setColor(stderr, .Bold) catch break;
822 ttyconf.setColor(stderr, .bold) catch break;
823823 stderr.writeAll(s.owner.dep_prefix) catch break;
824824 stderr.writeAll(s.name) catch break;
825825 stderr.writeAll(": ") catch break;
826 ttyconf.setColor(stderr, .Red) catch break;
826 ttyconf.setColor(stderr, .red) catch break;
827827 stderr.writeAll("error: ") catch break;
828 ttyconf.setColor(stderr, .Reset) catch break;
828 ttyconf.setColor(stderr, .reset) catch break;
829829 stderr.writeAll(msg) catch break;
830830 stderr.writeAll("\n") catch break;
831831 }
lib/std/Build.zig+6-6
......@@ -1713,9 +1713,9 @@ fn dumpBadGetPathHelp(
17131713 });
17141714
17151715 const tty_config = std.debug.detectTTYConfig(stderr);
1716 tty_config.setColor(w, .Red) catch {};
1716 tty_config.setColor(w, .red) catch {};
17171717 try stderr.writeAll(" The step was created by this stack trace:\n");
1718 tty_config.setColor(w, .Reset) catch {};
1718 tty_config.setColor(w, .reset) catch {};
17191719
17201720 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
17211721 try w.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
......@@ -1727,9 +1727,9 @@ fn dumpBadGetPathHelp(
17271727 return;
17281728 };
17291729 if (asking_step) |as| {
1730 tty_config.setColor(w, .Red) catch {};
1730 tty_config.setColor(w, .red) catch {};
17311731 try stderr.writeAll(" The step that is missing a dependency on the above step was created by this stack trace:\n");
1732 tty_config.setColor(w, .Reset) catch {};
1732 tty_config.setColor(w, .reset) catch {};
17331733
17341734 std.debug.writeStackTrace(as.getStackTrace(), w, ally, debug_info, tty_config) catch |err| {
17351735 try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)});
......@@ -1737,9 +1737,9 @@ fn dumpBadGetPathHelp(
17371737 };
17381738 }
17391739
1740 tty_config.setColor(w, .Red) catch {};
1740 tty_config.setColor(w, .red) catch {};
17411741 try stderr.writeAll(" Hope that helps. Proceeding to panic.\n");
1742 tty_config.setColor(w, .Reset) catch {};
1742 tty_config.setColor(w, .reset) catch {};
17431743}
17441744
17451745/// Allocates a new string for assigning a value to a named macro.
lib/std/debug.zig+31-31
......@@ -421,9 +421,9 @@ pub fn writeStackTrace(
421421 if (stack_trace.index > stack_trace.instruction_addresses.len) {
422422 const dropped_frames = stack_trace.index - stack_trace.instruction_addresses.len;
423423
424 tty_config.setColor(out_stream, .Bold) catch {};
424 tty_config.setColor(out_stream, .bold) catch {};
425425 try out_stream.print("({d} additional stack frames skipped...)\n", .{dropped_frames});
426 tty_config.setColor(out_stream, .Reset) catch {};
426 tty_config.setColor(out_stream, .reset) catch {};
427427 }
428428}
429429
......@@ -655,14 +655,14 @@ pub fn writeCurrentStackTraceWindows(
655655/// for debugging purposes, such as coloring text, etc.
656656pub const TTY = struct {
657657 pub const Color = enum {
658 Red,
659 Green,
660 Yellow,
661 Cyan,
662 White,
663 Dim,
664 Bold,
665 Reset,
658 red,
659 green,
660 yellow,
661 cyan,
662 white,
663 dim,
664 bold,
665 reset,
666666 };
667667
668668 pub const Config = union(enum) {
......@@ -680,26 +680,26 @@ pub const TTY = struct {
680680 .no_color => return,
681681 .escape_codes => {
682682 const color_string = switch (color) {
683 .Red => "\x1b[31;1m",
684 .Green => "\x1b[32;1m",
685 .Yellow => "\x1b[33;1m",
686 .Cyan => "\x1b[36;1m",
687 .White => "\x1b[37;1m",
688 .Bold => "\x1b[1m",
689 .Dim => "\x1b[2m",
690 .Reset => "\x1b[0m",
683 .red => "\x1b[31;1m",
684 .green => "\x1b[32;1m",
685 .yellow => "\x1b[33;1m",
686 .cyan => "\x1b[36;1m",
687 .white => "\x1b[37;1m",
688 .bold => "\x1b[1m",
689 .dim => "\x1b[2m",
690 .reset => "\x1b[0m",
691691 };
692692 try out_stream.writeAll(color_string);
693693 },
694694 .windows_api => |ctx| if (native_os == .windows) {
695695 const attributes = switch (color) {
696 .Red => windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY,
697 .Green => windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY,
698 .Yellow => windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY,
699 .Cyan => windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY,
700 .White, .Bold => windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY,
701 .Dim => windows.FOREGROUND_INTENSITY,
702 .Reset => ctx.reset_attributes,
696 .red => windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY,
697 .green => windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY,
698 .yellow => windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY,
699 .cyan => windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY,
700 .white, .bold => windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY,
701 .dim => windows.FOREGROUND_INTENSITY,
702 .reset => ctx.reset_attributes,
703703 };
704704 try windows.SetConsoleTextAttribute(ctx.handle, attributes);
705705 } else {
......@@ -831,7 +831,7 @@ fn printLineInfo(
831831 comptime printLineFromFile: anytype,
832832) !void {
833833 nosuspend {
834 try tty_config.setColor(out_stream, .Bold);
834 try tty_config.setColor(out_stream, .bold);
835835
836836 if (line_info) |*li| {
837837 try out_stream.print("{s}:{d}:{d}", .{ li.file_name, li.line, li.column });
......@@ -839,11 +839,11 @@ fn printLineInfo(
839839 try out_stream.writeAll("???:?:?");
840840 }
841841
842 try tty_config.setColor(out_stream, .Reset);
842 try tty_config.setColor(out_stream, .reset);
843843 try out_stream.writeAll(": ");
844 try tty_config.setColor(out_stream, .Dim);
844 try tty_config.setColor(out_stream, .dim);
845845 try out_stream.print("0x{x} in {s} ({s})", .{ address, symbol_name, compile_unit_name });
846 try tty_config.setColor(out_stream, .Reset);
846 try tty_config.setColor(out_stream, .reset);
847847 try out_stream.writeAll("\n");
848848
849849 // Show the matching source code line if possible
......@@ -854,9 +854,9 @@ fn printLineInfo(
854854 const space_needed = @intCast(usize, li.column - 1);
855855
856856 try out_stream.writeByteNTimes(' ', space_needed);
857 try tty_config.setColor(out_stream, .Green);
857 try tty_config.setColor(out_stream, .green);
858858 try out_stream.writeAll("^");
859 try tty_config.setColor(out_stream, .Reset);
859 try tty_config.setColor(out_stream, .reset);
860860 }
861861 try out_stream.writeAll("\n");
862862 } else |err| switch (err) {
lib/std/testing.zig+4-4
......@@ -387,9 +387,9 @@ fn SliceDiffer(comptime T: type) type {
387387 for (self.expected, 0..) |value, i| {
388388 var full_index = self.start_index + i;
389389 const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true;
390 if (diff) try self.ttyconf.setColor(writer, .Red);
390 if (diff) try self.ttyconf.setColor(writer, .red);
391391 try writer.print("[{}]: {any}\n", .{ full_index, value });
392 if (diff) try self.ttyconf.setColor(writer, .Reset);
392 if (diff) try self.ttyconf.setColor(writer, .reset);
393393 }
394394 }
395395 };
......@@ -427,9 +427,9 @@ const BytesDiffer = struct {
427427 }
428428
429429 fn writeByteDiff(self: BytesDiffer, writer: anytype, comptime fmt: []const u8, byte: u8, diff: bool) !void {
430 if (diff) try self.ttyconf.setColor(writer, .Red);
430 if (diff) try self.ttyconf.setColor(writer, .red);
431431 try writer.print(fmt, .{byte});
432 if (diff) try self.ttyconf.setColor(writer, .Reset);
432 if (diff) try self.ttyconf.setColor(writer, .reset);
433433 }
434434
435435 const ChunkIterator = struct {
lib/std/zig/ErrorBundle.zig+16-16
......@@ -163,7 +163,7 @@ pub fn renderToStdErr(eb: ErrorBundle, options: RenderOptions) void {
163163
164164pub fn renderToWriter(eb: ErrorBundle, options: RenderOptions, writer: anytype) anyerror!void {
165165 for (eb.getMessages()) |err_msg| {
166 try renderErrorMessageToWriter(eb, options, err_msg, writer, "error", .Red, 0);
166 try renderErrorMessageToWriter(eb, options, err_msg, writer, "error", .red, 0);
167167 }
168168
169169 if (options.include_log_text) {
......@@ -191,7 +191,7 @@ fn renderErrorMessageToWriter(
191191 if (err_msg.src_loc != .none) {
192192 const src = eb.extraData(SourceLocation, @enumToInt(err_msg.src_loc));
193193 try counting_stderr.writeByteNTimes(' ', indent);
194 try ttyconf.setColor(stderr, .Bold);
194 try ttyconf.setColor(stderr, .bold);
195195 try counting_stderr.print("{s}:{d}:{d}: ", .{
196196 eb.nullTerminatedString(src.data.src_path),
197197 src.data.line + 1,
......@@ -203,17 +203,17 @@ fn renderErrorMessageToWriter(
203203 // This is the length of the part before the error message:
204204 // e.g. "file.zig:4:5: error: "
205205 const prefix_len = @intCast(usize, counting_stderr.context.bytes_written);
206 try ttyconf.setColor(stderr, .Reset);
207 try ttyconf.setColor(stderr, .Bold);
206 try ttyconf.setColor(stderr, .reset);
207 try ttyconf.setColor(stderr, .bold);
208208 if (err_msg.count == 1) {
209209 try writeMsg(eb, err_msg, stderr, prefix_len);
210210 try stderr.writeByte('\n');
211211 } else {
212212 try writeMsg(eb, err_msg, stderr, prefix_len);
213 try ttyconf.setColor(stderr, .Dim);
213 try ttyconf.setColor(stderr, .dim);
214214 try stderr.print(" ({d} times)\n", .{err_msg.count});
215215 }
216 try ttyconf.setColor(stderr, .Reset);
216 try ttyconf.setColor(stderr, .reset);
217217 if (src.data.source_line != 0 and options.include_source_line) {
218218 const line = eb.nullTerminatedString(src.data.source_line);
219219 for (line) |b| switch (b) {
......@@ -226,19 +226,19 @@ fn renderErrorMessageToWriter(
226226 // -1 since span.main includes the caret
227227 const after_caret = src.data.span_end - src.data.span_main -| 1;
228228 try stderr.writeByteNTimes(' ', src.data.column - before_caret);
229 try ttyconf.setColor(stderr, .Green);
229 try ttyconf.setColor(stderr, .green);
230230 try stderr.writeByteNTimes('~', before_caret);
231231 try stderr.writeByte('^');
232232 try stderr.writeByteNTimes('~', after_caret);
233233 try stderr.writeByte('\n');
234 try ttyconf.setColor(stderr, .Reset);
234 try ttyconf.setColor(stderr, .reset);
235235 }
236236 for (eb.getNotes(err_msg_index)) |note| {
237 try renderErrorMessageToWriter(eb, options, note, stderr, "note", .Cyan, indent);
237 try renderErrorMessageToWriter(eb, options, note, stderr, "note", .cyan, indent);
238238 }
239239 if (src.data.reference_trace_len > 0 and options.include_reference_trace) {
240 try ttyconf.setColor(stderr, .Reset);
241 try ttyconf.setColor(stderr, .Dim);
240 try ttyconf.setColor(stderr, .reset);
241 try ttyconf.setColor(stderr, .dim);
242242 try stderr.print("referenced by:\n", .{});
243243 var ref_index = src.end;
244244 for (0..src.data.reference_trace_len) |_| {
......@@ -266,25 +266,25 @@ fn renderErrorMessageToWriter(
266266 }
267267 }
268268 try stderr.writeByte('\n');
269 try ttyconf.setColor(stderr, .Reset);
269 try ttyconf.setColor(stderr, .reset);
270270 }
271271 } else {
272272 try ttyconf.setColor(stderr, color);
273273 try stderr.writeByteNTimes(' ', indent);
274274 try stderr.writeAll(kind);
275275 try stderr.writeAll(": ");
276 try ttyconf.setColor(stderr, .Reset);
276 try ttyconf.setColor(stderr, .reset);
277277 const msg = eb.nullTerminatedString(err_msg.msg);
278278 if (err_msg.count == 1) {
279279 try stderr.print("{s}\n", .{msg});
280280 } else {
281281 try stderr.print("{s}", .{msg});
282 try ttyconf.setColor(stderr, .Dim);
282 try ttyconf.setColor(stderr, .dim);
283283 try stderr.print(" ({d} times)\n", .{err_msg.count});
284284 }
285 try ttyconf.setColor(stderr, .Reset);
285 try ttyconf.setColor(stderr, .reset);
286286 for (eb.getNotes(err_msg_index)) |note| {
287 try renderErrorMessageToWriter(eb, options, note, stderr, "note", .Cyan, indent + 4);
287 try renderErrorMessageToWriter(eb, options, note, stderr, "note", .cyan, indent + 4);
288288 }
289289 }
290290}