libghostty: add configurable mode defaults, remove mode_set/get

ABI BREAKING: This removes `ghostty_terminal_mode_get` and `_mode_set`.
We can now represent these operations completely with standard 
`ghostty_terminal_get` and `ghostty_terminal_set`, which makes it much
more flexible to preserve ABI in the future.

This is all centered around a new `GhosttyTerminalModeConfig` structure
that is an in or out parameter depending on use case.

This also adds a new `GHOSTTY_TERMINAL_OPT_MODE_DEFAULT` option that
can be used to set the _default_ value of mode that happens when a RIS
event (full reset) is sent.
This commit is contained in:
Mitchell Hashimoto
2026-08-05 21:57:27 -07:00
parent 8eecb8fdbf
commit cfc19e8053
6 changed files with 319 additions and 139 deletions

View File

@@ -695,6 +695,24 @@ typedef void (*GhosttyTerminalWritePtyFn)(GhosttyTerminal terminal,
typedef GhosttyString (*GhosttyTerminalXtversionFn)(GhosttyTerminal terminal,
void* userdata);
/**
* A terminal mode and boolean value used for mode configuration and queries.
*
* For GHOSTTY_TERMINAL_DATA_MODE, initialize `mode` before calling
* ghostty_terminal_get(). On success, `value` contains the current mode value.
*
* This struct has a frozen layout and will not gain fields in future versions.
*
* @ingroup terminal
*/
typedef struct {
/** Mode to configure or query. */
GhosttyMode mode;
/** Value to set, or the current value returned by a query. */
bool value;
} GhosttyTerminalModeConfig;
/**
* Terminal option identifiers.
*
@@ -1060,6 +1078,31 @@ typedef enum GHOSTTY_ENUM_TYPED {
* Input type: bool*
*/
GHOSTTY_TERMINAL_OPT_TITLE_REPORT = 32,
/**
* Set the reset default for a terminal mode.
*
* This unconditionally updates both the current value and the value restored
* by a full terminal reset (RIS).
*
* Some recognized modes represent transitions or mirror additional terminal
* state and cannot safely be configured as reset defaults. Those modes return
* GHOSTTY_INVALID_VALUE. A NULL value pointer also returns
* GHOSTTY_INVALID_VALUE.
*
* Input type: GhosttyTerminalModeConfig*
*/
GHOSTTY_TERMINAL_OPT_MODE_DEFAULT = 33,
/**
* Set the current value of a terminal mode.
*
* This does not change the value restored by a full terminal reset (RIS).
* A NULL value pointer or unknown mode returns GHOSTTY_INVALID_VALUE.
*
* Input type: GhosttyTerminalModeConfig*
*/
GHOSTTY_TERMINAL_OPT_MODE = 34,
GHOSTTY_TERMINAL_OPT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalOption;
@@ -1420,6 +1463,17 @@ typedef enum GHOSTTY_ENUM_TYPED {
* Output type: size_t *
*/
GHOSTTY_TERMINAL_DATA_CONTINUATION_MAX_BYTES = 36,
/**
* Get the current value of a terminal mode.
*
* The caller must initialize the `mode` field. On success, the `value` field
* is updated with the current value. A NULL pointer or unknown mode returns
* GHOSTTY_INVALID_VALUE.
*
* Input/output type: GhosttyTerminalModeConfig *
*/
GHOSTTY_TERMINAL_DATA_MODE = 37,
GHOSTTY_TERMINAL_DATA_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalData;
@@ -1709,41 +1763,6 @@ GHOSTTY_API GhosttyResult ghostty_terminal_compress(
GhosttyTerminalCompressionMode mode,
GhosttyTerminalCompressionResult* out_result);
/**
* Get the current value of a terminal mode.
*
* Returns the value of the mode identified by the given mode.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param mode The mode identifying the mode to query
* @param[out] out_value On success, set to true if the mode is set, false
* if it is reset
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal
* is NULL or the mode does not correspond to a known mode
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_mode_get(GhosttyTerminal terminal,
GhosttyMode mode,
bool* out_value);
/**
* Set the value of a terminal mode.
*
* Sets the mode identified by the given mode to the specified value.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param mode The mode identifying the mode to set
* @param value true to set the mode, false to reset it
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal
* is NULL or the mode does not correspond to a known mode
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_mode_set(GhosttyTerminal terminal,
GhosttyMode mode,
bool value);
/**
* Get data from a terminal instance.
*