Skip to content

Commit cfc19e8

Browse files
committed
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.
1 parent 8eecb8f commit cfc19e8

6 files changed

Lines changed: 316 additions & 136 deletions

File tree

include/ghostty/vt/terminal.h

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,24 @@ typedef void (*GhosttyTerminalWritePtyFn)(GhosttyTerminal terminal,
695695
typedef GhosttyString (*GhosttyTerminalXtversionFn)(GhosttyTerminal terminal,
696696
void* userdata);
697697

698+
/**
699+
* A terminal mode and boolean value used for mode configuration and queries.
700+
*
701+
* For GHOSTTY_TERMINAL_DATA_MODE, initialize `mode` before calling
702+
* ghostty_terminal_get(). On success, `value` contains the current mode value.
703+
*
704+
* This struct has a frozen layout and will not gain fields in future versions.
705+
*
706+
* @ingroup terminal
707+
*/
708+
typedef struct {
709+
/** Mode to configure or query. */
710+
GhosttyMode mode;
711+
712+
/** Value to set, or the current value returned by a query. */
713+
bool value;
714+
} GhosttyTerminalModeConfig;
715+
698716
/**
699717
* Terminal option identifiers.
700718
*
@@ -1060,6 +1078,31 @@ typedef enum GHOSTTY_ENUM_TYPED {
10601078
* Input type: bool*
10611079
*/
10621080
GHOSTTY_TERMINAL_OPT_TITLE_REPORT = 32,
1081+
1082+
/**
1083+
* Set the reset default for a terminal mode.
1084+
*
1085+
* This unconditionally updates both the current value and the value restored
1086+
* by a full terminal reset (RIS).
1087+
*
1088+
* Some recognized modes represent transitions or mirror additional terminal
1089+
* state and cannot safely be configured as reset defaults. Those modes return
1090+
* GHOSTTY_INVALID_VALUE. A NULL value pointer also returns
1091+
* GHOSTTY_INVALID_VALUE.
1092+
*
1093+
* Input type: GhosttyTerminalModeConfig*
1094+
*/
1095+
GHOSTTY_TERMINAL_OPT_MODE_DEFAULT = 33,
1096+
1097+
/**
1098+
* Set the current value of a terminal mode.
1099+
*
1100+
* This does not change the value restored by a full terminal reset (RIS).
1101+
* A NULL value pointer or unknown mode returns GHOSTTY_INVALID_VALUE.
1102+
*
1103+
* Input type: GhosttyTerminalModeConfig*
1104+
*/
1105+
GHOSTTY_TERMINAL_OPT_MODE = 34,
10631106
GHOSTTY_TERMINAL_OPT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
10641107
} GhosttyTerminalOption;
10651108

@@ -1420,6 +1463,17 @@ typedef enum GHOSTTY_ENUM_TYPED {
14201463
* Output type: size_t *
14211464
*/
14221465
GHOSTTY_TERMINAL_DATA_CONTINUATION_MAX_BYTES = 36,
1466+
1467+
/**
1468+
* Get the current value of a terminal mode.
1469+
*
1470+
* The caller must initialize the `mode` field. On success, the `value` field
1471+
* is updated with the current value. A NULL pointer or unknown mode returns
1472+
* GHOSTTY_INVALID_VALUE.
1473+
*
1474+
* Input/output type: GhosttyTerminalModeConfig *
1475+
*/
1476+
GHOSTTY_TERMINAL_DATA_MODE = 37,
14231477
GHOSTTY_TERMINAL_DATA_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
14241478
} GhosttyTerminalData;
14251479

@@ -1709,41 +1763,6 @@ GHOSTTY_API GhosttyResult ghostty_terminal_compress(
17091763
GhosttyTerminalCompressionMode mode,
17101764
GhosttyTerminalCompressionResult* out_result);
17111765

1712-
/**
1713-
* Get the current value of a terminal mode.
1714-
*
1715-
* Returns the value of the mode identified by the given mode.
1716-
*
1717-
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
1718-
* @param mode The mode identifying the mode to query
1719-
* @param[out] out_value On success, set to true if the mode is set, false
1720-
* if it is reset
1721-
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal
1722-
* is NULL or the mode does not correspond to a known mode
1723-
*
1724-
* @ingroup terminal
1725-
*/
1726-
GHOSTTY_API GhosttyResult ghostty_terminal_mode_get(GhosttyTerminal terminal,
1727-
GhosttyMode mode,
1728-
bool* out_value);
1729-
1730-
/**
1731-
* Set the value of a terminal mode.
1732-
*
1733-
* Sets the mode identified by the given mode to the specified value.
1734-
*
1735-
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
1736-
* @param mode The mode identifying the mode to set
1737-
* @param value true to set the mode, false to reset it
1738-
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal
1739-
* is NULL or the mode does not correspond to a known mode
1740-
*
1741-
* @ingroup terminal
1742-
*/
1743-
GHOSTTY_API GhosttyResult ghostty_terminal_mode_set(GhosttyTerminal terminal,
1744-
GhosttyMode mode,
1745-
bool value);
1746-
17471766
/**
17481767
* Get data from a terminal instance.
17491768
*

src/lib_vt.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ comptime {
284284
@export(&c.terminal_scroll_viewport, .{ .name = "ghostty_terminal_scroll_viewport" });
285285
@export(&c.terminal_compression_activity, .{ .name = "ghostty_terminal_compression_activity" });
286286
@export(&c.terminal_compress, .{ .name = "ghostty_terminal_compress" });
287-
@export(&c.terminal_mode_get, .{ .name = "ghostty_terminal_mode_get" });
288-
@export(&c.terminal_mode_set, .{ .name = "ghostty_terminal_mode_set" });
289287
@export(&c.terminal_get, .{ .name = "ghostty_terminal_get" });
290288
@export(&c.terminal_get_multi, .{ .name = "ghostty_terminal_get_multi" });
291289
@export(&c.terminal_continuation_write, .{ .name = "ghostty_terminal_continuation_write" });

src/terminal/c/main.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ pub const terminal_vt_write = terminal.vt_write;
187187
pub const terminal_scroll_viewport = terminal.scroll_viewport;
188188
pub const terminal_compression_activity = terminal.compression_activity;
189189
pub const terminal_compress = terminal.compress;
190-
pub const terminal_mode_get = terminal.mode_get;
191-
pub const terminal_mode_set = terminal.mode_set;
192190
pub const terminal_get = terminal.get;
193191
pub const terminal_get_multi = terminal.get_multi;
194192
pub const terminal_continuation_write = terminal.continuation_write;

0 commit comments

Comments
 (0)