diff --git a/include/ghostty/vt/terminal.h b/include/ghostty/vt/terminal.h index 050ebd841..8f52565b3 100644 --- a/include/ghostty/vt/terminal.h +++ b/include/ghostty/vt/terminal.h @@ -136,26 +136,6 @@ typedef struct { uint64_t len; } GhosttyTerminalScrollbar; -/** - * Callback function type for write_pty. - * - * Called when the terminal needs to write data back to the pty, for - * example in response to a device status report or mode query. The - * data is only valid for the duration of the call; callers must copy - * it if it needs to persist. - * - * @param terminal The terminal handle - * @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA - * @param data Pointer to the response bytes - * @param len Length of the response in bytes - * - * @ingroup terminal - */ -typedef void (*GhosttyTerminalWritePtyFn)(GhosttyTerminal terminal, - void* userdata, - const uint8_t* data, - size_t len); - /** * Callback function type for bell. * @@ -169,55 +149,6 @@ typedef void (*GhosttyTerminalWritePtyFn)(GhosttyTerminal terminal, typedef void (*GhosttyTerminalBellFn)(GhosttyTerminal terminal, void* userdata); -/** - * Callback function type for enquiry (ENQ, 0x05). - * - * Called when the terminal receives an ENQ character. Return the - * response bytes as a GhosttyString. The memory must remain valid - * until the callback returns. Return a zero-length string to send - * no response. - * - * @param terminal The terminal handle - * @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA - * @return The response bytes to write back to the pty - * - * @ingroup terminal - */ -typedef GhosttyString (*GhosttyTerminalEnquiryFn)(GhosttyTerminal terminal, - void* userdata); - -/** - * Callback function type for XTVERSION. - * - * Called when the terminal receives an XTVERSION query (CSI > q). - * Return the version string (e.g. "myterm 1.0") as a GhosttyString. - * The memory must remain valid until the callback returns. Return a - * zero-length string to report the default "libghostty" version. - * - * @param terminal The terminal handle - * @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA - * @return The version string to report - * - * @ingroup terminal - */ -typedef GhosttyString (*GhosttyTerminalXtversionFn)(GhosttyTerminal terminal, - void* userdata); - -/** - * Callback function type for title_changed. - * - * Called when the terminal title changes via escape sequences - * (e.g. OSC 0 or OSC 2). The new title can be queried from the - * terminal after the callback returns. - * - * @param terminal The terminal handle - * @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA - * - * @ingroup terminal - */ -typedef void (*GhosttyTerminalTitleChangedFn)(GhosttyTerminal terminal, - void* userdata); - /** * Callback function type for color scheme queries (CSI ? 996 n). * @@ -257,6 +188,23 @@ typedef bool (*GhosttyTerminalDeviceAttributesFn)(GhosttyTerminal terminal, void* userdata, GhosttyDeviceAttributes* out_attrs); +/** + * Callback function type for enquiry (ENQ, 0x05). + * + * Called when the terminal receives an ENQ character. Return the + * response bytes as a GhosttyString. The memory must remain valid + * until the callback returns. Return a zero-length string to send + * no response. + * + * @param terminal The terminal handle + * @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA + * @return The response bytes to write back to the pty + * + * @ingroup terminal + */ +typedef GhosttyString (*GhosttyTerminalEnquiryFn)(GhosttyTerminal terminal, + void* userdata); + /** * Callback function type for size queries (XTWINOPS). * @@ -275,6 +223,58 @@ typedef bool (*GhosttyTerminalSizeFn)(GhosttyTerminal terminal, void* userdata, GhosttySizeReportSize* out_size); +/** + * Callback function type for title_changed. + * + * Called when the terminal title changes via escape sequences + * (e.g. OSC 0 or OSC 2). The new title can be queried from the + * terminal after the callback returns. + * + * @param terminal The terminal handle + * @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA + * + * @ingroup terminal + */ +typedef void (*GhosttyTerminalTitleChangedFn)(GhosttyTerminal terminal, + void* userdata); + +/** + * Callback function type for write_pty. + * + * Called when the terminal needs to write data back to the pty, for + * example in response to a device status report or mode query. The + * data is only valid for the duration of the call; callers must copy + * it if it needs to persist. + * + * @param terminal The terminal handle + * @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA + * @param data Pointer to the response bytes + * @param len Length of the response in bytes + * + * @ingroup terminal + */ +typedef void (*GhosttyTerminalWritePtyFn)(GhosttyTerminal terminal, + void* userdata, + const uint8_t* data, + size_t len); + +/** + * Callback function type for XTVERSION. + * + * Called when the terminal receives an XTVERSION query (CSI > q). + * Return the version string (e.g. "myterm 1.0") as a GhosttyString. + * The memory must remain valid until the callback returns. Return a + * zero-length string to report the default "libghostty" version. + * + * @param terminal The terminal handle + * @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA + * @return The version string to report + * + * @ingroup terminal + */ +typedef GhosttyString (*GhosttyTerminalXtversionFn)(GhosttyTerminal terminal, + void* userdata); + /** * Terminal option identifiers. * diff --git a/src/terminal/c/terminal.zig b/src/terminal/c/terminal.zig index 15850acf8..d0825d3cb 100644 --- a/src/terminal/c/terminal.zig +++ b/src/terminal/c/terminal.zig @@ -253,14 +253,16 @@ fn new_( // Setup our stream with trampolines always installed so that // setting C callbacks at any time takes effect immediately. var handler: Stream.Handler = t.vtHandler(); - handler.effects.write_pty = &Effects.writePtyTrampoline; - handler.effects.bell = &Effects.bellTrampoline; - handler.effects.color_scheme = &Effects.colorSchemeTrampoline; - handler.effects.device_attributes = &Effects.deviceAttributesTrampoline; - handler.effects.enquiry = &Effects.enquiryTrampoline; - handler.effects.xtversion = &Effects.xtversionTrampoline; - handler.effects.title_changed = &Effects.titleChangedTrampoline; - handler.effects.size = &Effects.sizeTrampoline; + handler.effects = .{ + .write_pty = &Effects.writePtyTrampoline, + .bell = &Effects.bellTrampoline, + .color_scheme = &Effects.colorSchemeTrampoline, + .device_attributes = &Effects.deviceAttributesTrampoline, + .enquiry = &Effects.enquiryTrampoline, + .xtversion = &Effects.xtversionTrampoline, + .title_changed = &Effects.titleChangedTrampoline, + .size = &Effects.sizeTrampoline, + }; wrapper.* = .{ .terminal = t,