Skip to content

Commit 47cc1c5

Browse files
committed
use DEC graphics instead of Unicode for box drawing
1 parent 9e70bc7 commit 47cc1c5

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

lib/build_runner.zig

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,14 +532,17 @@ const PrintNode = struct {
532532
last: bool = false,
533533
};
534534

535-
fn printPrefix(node: *PrintNode, stderr: std.fs.File) !void {
535+
fn printPrefix(node: *PrintNode, stderr: std.fs.File, ttyconf: std.debug.TTY.Config) !void {
536536
const parent = node.parent orelse return;
537537
if (parent.parent == null) return;
538-
try printPrefix(parent, stderr);
538+
try printPrefix(parent, stderr, ttyconf);
539539
if (parent.last) {
540540
try stderr.writeAll(" ");
541541
} 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+
});
543546
}
544547
}
545548

@@ -552,14 +555,20 @@ fn printTreeStep(
552555
step_stack: *std.AutoArrayHashMapUnmanaged(*Step, void),
553556
) !void {
554557
const first = step_stack.swapRemove(s);
555-
try printPrefix(parent_node, stderr);
558+
try printPrefix(parent_node, stderr, ttyconf);
556559

557560
if (!first) try ttyconf.setColor(stderr, .Dim);
558561
if (parent_node.parent != null) {
559562
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+
});
561567
} 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+
});
563572
}
564573
}
565574

lib/std/debug.zig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,36 @@ pub const TTY = struct {
685685
},
686686
};
687687
}
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+
}
688718
};
689719
};
690720

0 commit comments

Comments
 (0)