authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-14 11:41:37-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:15-07:00
log63bd0fe58e80742d273a962c03145ce598f060b6
tree82c3bd2fe57721f2ebaafc894ab13e65bb948c31
parent3e328c89b7016cb688c88ddb11a8949851500928

use DEC graphics instead of Unicode for box drawing


2 files changed, 45 insertions(+), 6 deletions(-)

lib/build_runner.zig+15-6
...@@ -532,14 +532,17 @@ const PrintNode = struct {...@@ -532,14 +532,17 @@ const PrintNode = struct {
532 last: bool = false,532 last: bool = false,
533};533};
534534
535fn printPrefix(node: *PrintNode, stderr: std.fs.File) !void {535fn printPrefix(node: *PrintNode, stderr: std.fs.File, ttyconf: std.debug.TTY.Config) !void {
536 const parent = node.parent orelse return;536 const parent = node.parent orelse return;
537 if (parent.parent == null) return;537 if (parent.parent == null) return;
538 try printPrefix(parent, stderr);538 try printPrefix(parent, stderr, ttyconf);
539 if (parent.last) {539 if (parent.last) {
540 try stderr.writeAll(" ");540 try stderr.writeAll(" ");
541 } else {541 } else {
542 try stderr.writeAll("│ ");542 try stderr.writeAll(switch (ttyconf) {
543 .no_color, .windows_api => "| ",
544 .escape_codes => "\x1B\x28\x30\x78\x1B\x28\x42 ", // │
545 });
543 }546 }
544}547}
545548
...@@ -552,14 +555,20 @@ fn printTreeStep(...@@ -552,14 +555,20 @@ fn printTreeStep(
552 step_stack: *std.AutoArrayHashMapUnmanaged(*Step, void),555 step_stack: *std.AutoArrayHashMapUnmanaged(*Step, void),
553) !void {556) !void {
554 const first = step_stack.swapRemove(s);557 const first = step_stack.swapRemove(s);
555 try printPrefix(parent_node, stderr);558 try printPrefix(parent_node, stderr, ttyconf);
556559
557 if (!first) try ttyconf.setColor(stderr, .Dim);560 if (!first) try ttyconf.setColor(stderr, .Dim);
558 if (parent_node.parent != null) {561 if (parent_node.parent != null) {
559 if (parent_node.last) {562 if (parent_node.last) {
560 try stderr.writeAll("└─ ");563 try stderr.writeAll(switch (ttyconf) {
564 .no_color, .windows_api => "+- ",
565 .escape_codes => "\x1B\x28\x30\x6d\x71\x1B\x28\x42 ", // └─
566 });
561 } else {567 } else {
562 try stderr.writeAll("├─ ");568 try stderr.writeAll(switch (ttyconf) {
569 .no_color, .windows_api => "+- ",
570 .escape_codes => "\x1B\x28\x30\x74\x71\x1B\x28\x42 ", // ├─
571 });
563 }572 }
564 }573 }
565574
lib/std/debug.zig+30
...@@ -685,6 +685,36 @@ pub const TTY = struct {...@@ -685,6 +685,36 @@ pub const TTY = struct {
685 },685 },
686 };686 };
687 }687 }
688
689 pub fn writeDEC(conf: Config, writer: anytype, codepoint: u8) !void {
690 const bytes = switch (conf) {
691 .no_color, .windows_api => switch (codepoint) {
692 0x50...0x5e => @as(*const [1]u8, &codepoint),
693 0x6a => "+", // ┘
694 0x6b => "+", // ┐
695 0x6c => "+", // ┌
696 0x6d => "+", // └
697 0x6e => "+", // ┼
698 0x71 => "-", // ─
699 0x74 => "+", // ├
700 0x75 => "+", // ┤
701 0x76 => "+", // ┴
702 0x77 => "+", // ┬
703 0x78 => "|", // │
704 else => " ", // TODO
705 },
706 .escape_codes => switch (codepoint) {
707 // Here we avoid writing the DEC beginning sequence and
708 // ending sequence in separate syscalls by putting the
709 // beginning and ending sequence into the same string
710 // literals, to prevent terminals ending up in bad states
711 // in case a crash happens between syscalls.
712 inline 0x50...0x7f => |x| "\x1B\x28\x30" ++ [1]u8{x} ++ "\x1B\x28\x42",
713 else => unreachable,
714 },
715 };
716 return writer.writeAll(bytes);
717 }
688 };718 };
689};719};
690720