diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-03-14 11:41:37 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-03-15 10:48:15 -0700 |
| commit | 63bd0fe58e80742d273a962c03145ce598f060b6 (patch) | |
| tree | 82c3bd2fe57721f2ebaafc894ab13e65bb948c31 /lib/std/debug.zig | |
| parent | 3e328c89b7016cb688c88ddb11a8949851500928 (diff) | |
| download | zig-63bd0fe58e80742d273a962c03145ce598f060b6.tar.gz zig-63bd0fe58e80742d273a962c03145ce598f060b6.zip | |
use DEC graphics instead of Unicode for box drawing
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 3c5f6d2edf..6abceed9b8 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -685,6 +685,36 @@ pub const TTY = struct { }, }; } + + pub fn writeDEC(conf: Config, writer: anytype, codepoint: u8) !void { + const bytes = switch (conf) { + .no_color, .windows_api => switch (codepoint) { + 0x50...0x5e => @as(*const [1]u8, &codepoint), + 0x6a => "+", // ┘ + 0x6b => "+", // ┐ + 0x6c => "+", // ┌ + 0x6d => "+", // └ + 0x6e => "+", // ┼ + 0x71 => "-", // ─ + 0x74 => "+", // ├ + 0x75 => "+", // ┤ + 0x76 => "+", // ┴ + 0x77 => "+", // ┬ + 0x78 => "|", // │ + else => " ", // TODO + }, + .escape_codes => switch (codepoint) { + // Here we avoid writing the DEC beginning sequence and + // ending sequence in separate syscalls by putting the + // beginning and ending sequence into the same string + // literals, to prevent terminals ending up in bad states + // in case a crash happens between syscalls. + inline 0x50...0x7f => |x| "\x1B\x28\x30" ++ [1]u8{x} ++ "\x1B\x28\x42", + else => unreachable, + }, + }; + return writer.writeAll(bytes); + } }; }; |
