mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-06 07:38:21 +00:00
vt: add color data getters to render state
Add individual color data kinds to GhosttyRenderStateData so callers can query background, foreground, cursor color, cursor-color presence, and the full 256-color palette through ghostty_render_state_get() without using the sized-struct colors API. COLOR_CURSOR returns GHOSTTY_INVALID_VALUE when no explicit cursor color is set; callers can check COLOR_CURSOR_HAS_VALUE first.
This commit is contained in:
@@ -126,6 +126,23 @@ typedef enum {
|
||||
* It is unsafe to use row data after updating the render state.
|
||||
* */
|
||||
GHOSTTY_RENDER_STATE_DATA_ROW_ITERATOR = 4,
|
||||
|
||||
/** Default/current background color (GhosttyColorRgb). */
|
||||
GHOSTTY_RENDER_STATE_DATA_COLOR_BACKGROUND = 5,
|
||||
|
||||
/** Default/current foreground color (GhosttyColorRgb). */
|
||||
GHOSTTY_RENDER_STATE_DATA_COLOR_FOREGROUND = 6,
|
||||
|
||||
/** Cursor color when explicitly set by terminal state (GhosttyColorRgb).
|
||||
* Returns GHOSTTY_INVALID_VALUE if no explicit cursor color is set;
|
||||
* use COLOR_CURSOR_HAS_VALUE to check first. */
|
||||
GHOSTTY_RENDER_STATE_DATA_COLOR_CURSOR = 7,
|
||||
|
||||
/** Whether an explicit cursor color is set (bool). */
|
||||
GHOSTTY_RENDER_STATE_DATA_COLOR_CURSOR_HAS_VALUE = 8,
|
||||
|
||||
/** The active 256-color palette (GhosttyColorRgb[256]). */
|
||||
GHOSTTY_RENDER_STATE_DATA_COLOR_PALETTE = 9,
|
||||
} GhosttyRenderStateData;
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,6 +60,11 @@ pub const Data = enum(c_int) {
|
||||
rows = 2,
|
||||
dirty = 3,
|
||||
row_iterator = 4,
|
||||
color_background = 5,
|
||||
color_foreground = 6,
|
||||
color_cursor = 7,
|
||||
color_cursor_has_value = 8,
|
||||
color_palette = 9,
|
||||
|
||||
/// Output type expected for querying the data of the given kind.
|
||||
pub fn OutType(comptime self: Data) type {
|
||||
@@ -68,6 +73,9 @@ pub const Data = enum(c_int) {
|
||||
.cols, .rows => size.CellCountInt,
|
||||
.dirty => Dirty,
|
||||
.row_iterator => RowIterator,
|
||||
.color_background, .color_foreground, .color_cursor => colorpkg.RGB.C,
|
||||
.color_cursor_has_value => bool,
|
||||
.color_palette => [256]colorpkg.RGB.C,
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -177,6 +185,18 @@ fn getTyped(
|
||||
.dirty = row_data.items(.dirty),
|
||||
};
|
||||
},
|
||||
.color_background => out.* = state.state.colors.background.cval(),
|
||||
.color_foreground => out.* = state.state.colors.foreground.cval(),
|
||||
.color_cursor => {
|
||||
const cursor = state.state.colors.cursor orelse return .invalid_value;
|
||||
out.* = cursor.cval();
|
||||
},
|
||||
.color_cursor_has_value => out.* = state.state.colors.cursor != null,
|
||||
.color_palette => {
|
||||
for (&out.*, state.state.colors.palette) |*dst, src| {
|
||||
dst.* = src.cval();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
return .success;
|
||||
|
||||
Reference in New Issue
Block a user