capture-pane writes U+0000 for blank and padding cells instead of a spaceSeverity: HIGH
Status: ✅ FIXED
Files: src/cmd/cmd.zig:768-774
The capture loop encodes every cell’s codepoint directly:
// src/cmd/cmd.zig:768-774
const cell = pane.screen.grid.getCell(x, y);
var utf8_buf: [4]u8 = undefined;
const len = std.unicode.utf8Encode(cell.char, &utf8_buf) catch blk: {
utf8_buf[0] = ' ';
break :blk 1;
};
server.response_buf.appendSlice(server.allocator, utf8_buf[0..len]) catch return .err;
The catch branch is unreachable for the case that actually matters, because
U+0000 is a valid codepoint: utf8Encode(0) succeeds and returns a single
0x00 byte.
Two classes of cell carry char = 0:
Cell.empty() sets char = 0
(grid.zig:35-42), and every erase path memsets with Cell.empty().char = 0, is_padding = true
(screen.zig:826-828, :930-934).So capture-pane output contains a NUL for every unwritten cell, and each wide
character is followed by an extra NUL. Piping the result to a file or another
program yields binary garbage; szn capture-pane > file.txt produces a file
that is not valid UTF-8 text.
// src/cmd/cmd.zig — cmdCapturePane
if (cell.is_padding) continue;
const cp: u21 = if (cell.char == 0) ' ' else cell.char;
Two changes to the capture loop:
char == 0 becomes ' '. Blank cells now capture as spaces, so
capture-pane produces valid text and a full-width row is exactly
width bytes.capture-pane emits spaces, not NUL bytes, for blank and padding cells — bug #512
(src/cmd/cmd.zig) writes one wide character (世) into a 20×2 pane, captures
it, and asserts:
0x00;Verified with the full suite on Zig 0.16.0 and 0.17.0: 1044/1044 passing on both.
Bug #199 established that padding cells are not content in reflow; this applies the same rule to the capture path.