vt: fix render state cell style and graphemes_buf APIs

The GRAPHEMES_BUF data kind previously required a double pointer
(pointer to a uint32_t*) because the OutType was [*]u32, making the
typed out parameter *[*]u32. Change OutType to u32 so that callers
pass a plain uint32_t* buffer directly, which is the natural C
calling convention. The implementation casts the out pointer to
[*]u32 internally to write into the buffer.

The STYLE data kind read directly from the render state style array
without checking whether the cell actually had non-default styling.
The style data is undefined for unstyled cells, so this caused a
panic on a corrupt enum value when the caller read the style of an
unstyled cell. Now check cell.hasStyling() first and return the
default style for unstyled cells.

Expand the c-vt-render example to exercise dirty tracking, color
retrieval, cursor state, row/cell iteration with style resolution,
and dirty state reset. Break the example into six doxygen snippet
regions and reference them from render.h.
This commit is contained in:
Mitchell Hashimoto
2026-03-20 09:14:19 -07:00
parent d9df4154db
commit e7a18ea5b3
4 changed files with 233 additions and 24 deletions

View File

@@ -435,7 +435,7 @@ pub const RowCellsData = enum(c_int) {
.raw => page.Cell.C,
.style => style_c.Style,
.graphemes_len => u32,
.graphemes_buf => [*]u32,
.graphemes_buf => u32,
};
}
};
@@ -472,7 +472,10 @@ fn rowCellsGetTyped(
switch (data) {
.invalid => return .invalid_value,
.raw => out.* = cell.cval(),
.style => out.* = style_c.Style.fromStyle(cells.styles[x]),
.style => out.* = if (cell.hasStyling())
style_c.Style.fromStyle(cells.styles[x])
else
style_c.Style.fromStyle(.{}),
.graphemes_len => {
if (!cell.hasText()) {
out.* = 0;
@@ -484,11 +487,10 @@ fn rowCellsGetTyped(
.graphemes_buf => {
if (!cell.hasText()) return .success;
const extra = if (cell.hasGrapheme()) cells.graphemes[x] else &[_]u21{};
const total = 1 + extra.len;
const out_slice = out.*[0..total];
out_slice[0] = cell.codepoint();
const buf: [*]u32 = @ptrCast(out);
buf[0] = cell.codepoint();
for (extra, 1..) |cp, i| {
out_slice[i] = cp;
buf[i] = cp;
}
},
}