mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-31 04:39:01 +00:00
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:
@@ -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;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user