styling stuff

This commit is contained in:
Gregor Lohaus
2026-05-29 20:32:09 +02:00
parent 5bbba354ab
commit 68121d50b5
2 changed files with 51 additions and 3 deletions

View File

@@ -8,7 +8,8 @@ public record RenderCell(
Optional<RenderColor> foreground,
Optional<RenderColor> background,
Optional<KittyPlaceholder> kittyPlaceholder,
boolean selected
boolean selected,
boolean inverse
) {
public RenderCell(
int column,
@@ -17,7 +18,7 @@ public record RenderCell(
Optional<RenderColor> background,
boolean selected
) {
this(column, codepoints, foreground, background, Optional.empty(), selected);
this(column, codepoints, foreground, background, Optional.empty(), selected, false);
}
public RenderCell {

View File

@@ -284,6 +284,35 @@ public final class GhosttyLibrary {
MemoryLayout.paddingLayout(4)
);
// GhosttyStyleColor: { GhosttyStyleColorTag tag; union value; } (see ghostty/vt/style.h).
private static final GroupLayout GHOSTTY_STYLE_COLOR = MemoryLayout.structLayout(
C_INT.withName("tag"),
MemoryLayout.paddingLayout(4),
C_LONG_LONG.withName("value")
);
// GhosttyStyle sized struct. We only read the `inverse` flag, but lay out the whole
// struct so the offset and total size match the C ABI exactly.
private static final GroupLayout GHOSTTY_STYLE = MemoryLayout.structLayout(
C_SIZE_T.withName("size"),
GHOSTTY_STYLE_COLOR.withName("fg_color"),
GHOSTTY_STYLE_COLOR.withName("bg_color"),
GHOSTTY_STYLE_COLOR.withName("underline_color"),
C_BOOL.withName("bold"),
C_BOOL.withName("italic"),
C_BOOL.withName("faint"),
C_BOOL.withName("blink"),
C_BOOL.withName("inverse"),
C_BOOL.withName("invisible"),
C_BOOL.withName("strikethrough"),
C_BOOL.withName("overline"),
C_INT.withName("underline"),
MemoryLayout.paddingLayout(4)
);
private static final long STYLE_INVERSE_OFFSET =
GHOSTTY_STYLE.byteOffset(java.lang.foreign.MemoryLayout.PathElement.groupElement("inverse"));
private static final GroupLayout FORMATTER_SCREEN_EXTRA = MemoryLayout.structLayout(
C_SIZE_T.withName("size"),
C_BOOL.withName("cursor"),
@@ -1002,7 +1031,8 @@ public final class GhosttyLibrary {
renderStateRowCellColor(cells, RENDER_STATE_ROW_CELLS_DATA_FG_COLOR),
renderStateRowCellColor(cells, RENDER_STATE_ROW_CELLS_DATA_BG_COLOR),
renderStateRowCellKittyPlaceholder(cells, codepoints),
renderStateRowCellsGetBoolean(cells, RENDER_STATE_ROW_CELLS_DATA_SELECTED)
renderStateRowCellsGetBoolean(cells, RENDER_STATE_ROW_CELLS_DATA_SELECTED),
renderStateRowCellInverse(cells)
));
column++;
}
@@ -1239,6 +1269,23 @@ public final class GhosttyLibrary {
}
}
// Reads the cell's reverse/inverse flag from its GhosttyStyle. The resolved fg/bg
// colors do NOT account for inverse, so a renderer must read this and swap fg/bg.
private boolean renderStateRowCellInverse(MemorySegment cells) {
try (Arena arena = Arena.ofConfined()) {
MemorySegment out = arena.allocate(GHOSTTY_STYLE);
out.set(C_SIZE_T, 0, GHOSTTY_STYLE.byteSize());
int result = (int) renderStateRowCellsGet.invoke(cells, RENDER_STATE_ROW_CELLS_DATA_STYLE, out);
if (result == GHOSTTY_INVALID_VALUE) {
return false;
}
checkResult("ghostty_render_state_row_cells_get", result);
return out.get(C_BOOL, STYLE_INVERSE_OFFSET);
} catch (Throwable t) {
return rethrow(t);
}
}
private Optional<KittyPlaceholder> renderStateRowCellKittyPlaceholder(MemorySegment cells, int[] codepoints) {
if (codepoints.length == 0 || codepoints[0] != KittyPlaceholder.CODEPOINT) {
return Optional.empty();