styling stuff
This commit is contained in:
@@ -8,7 +8,8 @@ public record RenderCell(
|
|||||||
Optional<RenderColor> foreground,
|
Optional<RenderColor> foreground,
|
||||||
Optional<RenderColor> background,
|
Optional<RenderColor> background,
|
||||||
Optional<KittyPlaceholder> kittyPlaceholder,
|
Optional<KittyPlaceholder> kittyPlaceholder,
|
||||||
boolean selected
|
boolean selected,
|
||||||
|
boolean inverse
|
||||||
) {
|
) {
|
||||||
public RenderCell(
|
public RenderCell(
|
||||||
int column,
|
int column,
|
||||||
@@ -17,7 +18,7 @@ public record RenderCell(
|
|||||||
Optional<RenderColor> background,
|
Optional<RenderColor> background,
|
||||||
boolean selected
|
boolean selected
|
||||||
) {
|
) {
|
||||||
this(column, codepoints, foreground, background, Optional.empty(), selected);
|
this(column, codepoints, foreground, background, Optional.empty(), selected, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RenderCell {
|
public RenderCell {
|
||||||
|
|||||||
@@ -284,6 +284,35 @@ public final class GhosttyLibrary {
|
|||||||
MemoryLayout.paddingLayout(4)
|
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(
|
private static final GroupLayout FORMATTER_SCREEN_EXTRA = MemoryLayout.structLayout(
|
||||||
C_SIZE_T.withName("size"),
|
C_SIZE_T.withName("size"),
|
||||||
C_BOOL.withName("cursor"),
|
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_FG_COLOR),
|
||||||
renderStateRowCellColor(cells, RENDER_STATE_ROW_CELLS_DATA_BG_COLOR),
|
renderStateRowCellColor(cells, RENDER_STATE_ROW_CELLS_DATA_BG_COLOR),
|
||||||
renderStateRowCellKittyPlaceholder(cells, codepoints),
|
renderStateRowCellKittyPlaceholder(cells, codepoints),
|
||||||
renderStateRowCellsGetBoolean(cells, RENDER_STATE_ROW_CELLS_DATA_SELECTED)
|
renderStateRowCellsGetBoolean(cells, RENDER_STATE_ROW_CELLS_DATA_SELECTED),
|
||||||
|
renderStateRowCellInverse(cells)
|
||||||
));
|
));
|
||||||
column++;
|
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) {
|
private Optional<KittyPlaceholder> renderStateRowCellKittyPlaceholder(MemorySegment cells, int[] codepoints) {
|
||||||
if (codepoints.length == 0 || codepoints[0] != KittyPlaceholder.CODEPOINT) {
|
if (codepoints.length == 0 || codepoints[0] != KittyPlaceholder.CODEPOINT) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|||||||
Reference in New Issue
Block a user