libghostty-vt 0.0.0
Loading...
Searching...
No Matches
Optional Features

Some parts of libghostty-vt are optional. A program that only draws a terminal doesn't need search or snapshots, for example, so the library can be built without them to make it smaller. You choose features when you build the library, with the -Dvt-features build option.

Optional features don't require program changes. Every function in our C headers exist in every build, so a program links and loads the same way against any set of enabled features. When you call a function whose feature was disabled, the function does nothing and returns GHOSTTY_UNSUPPORTED.

Feature Functions
color ghostty_color_*
formatter ghostty_formatter_*
glyph_protocol None. It lets applications register custom glyphs with Ghostty's glyph protocol.
grid_introspection ghostty_grid_ref_*, ghostty_tracked_grid_ref_*, ghostty_cell_get*, ghostty_row_get*, ghostty_terminal_grid_ref_track()
input_encode ghostty_key_event_*, ghostty_key_encoder_*, ghostty_mouse_event_*, ghostty_mouse_encoder_*, ghostty_focus_encode(), ghostty_paste_*, ghostty_terminal_paste()
kitty_graphics ghostty_kitty_graphics_*, and the Kitty options and data of ghostty_terminal_set() and ghostty_terminal_get()
render_state ghostty_render_state_*
search ghostty_search_*
selection ghostty_terminal_select_*, ghostty_terminal_selection_*, ghostty_selection_gesture_*
snapshot ghostty_snapshot_*

A few functions depend on two features:

Kitty graphics need a clock, so builds for targets without an operating system, such as wasm32-freestanding, never include kitty_graphics.

Checking for a Feature

To find out up front, for example to hide a menu item, ask ghostty_build_info() with the feature's key. Each feature has a GHOSTTY_BUILD_INFO_FEATURE_* key, except Kitty graphics, which uses GHOSTTY_BUILD_INFO_KITTY_GRAPHICS:

bool has_search = false;
if (!has_search) {
// Hide the find bar.
}
GHOSTTY_API GhosttyResult ghostty_build_info(GhosttyBuildInfo data, void *out)
@ GHOSTTY_BUILD_INFO_FEATURE_SEARCH
Definition build_info.h:170

You can also just call the function and check its result. A function that creates a handle sets the handle to NULL, so cleanup code that frees it still works:

GhosttySearch search = NULL;
GhosttyResult result = ghostty_search_new(NULL, &search, terminal);
if (result == GHOSTTY_UNSUPPORTED) {
// This library was built without search. search is NULL.
}
GhosttyResult
Definition types.h:143
@ GHOSTTY_UNSUPPORTED
Definition types.h:185
GHOSTTY_API GhosttyResult ghostty_search_new(const GhosttyAllocator *allocator, GhosttySearch *out_search, GhosttyTerminal terminal)
struct GhosttySearchImpl * GhosttySearch
Definition types.h:287

Functions Without a Result

A function that doesn't return a GhosttyResult can't report GHOSTTY_UNSUPPORTED. When its feature is left out, it returns a fixed value instead:

In practice these values rarely matter. Most of these functions take a handle that could only come from a _new function of the same feature, and that function returned GHOSTTY_UNSUPPORTED.