History

Add mobile native terminal

Julius Marminge committed 7 months ago

Commit 2e96efd1 parent f86d46665 files · +11187 −-1Browse files

Unified · Split

65 files
  1. apps/mobile/modules/t3-terminal/README.md +25 −0
  2. apps/mobile/modules/t3-terminal/T3TerminalNative.podspec +21 −0
  3. apps/mobile/modules/t3-terminal/THIRD_PARTY_NOTICES.md +15 −0
  4. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/Info.plist +64 −0
  5. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty.h +1187 −0
  6. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt.h +87 −0
  7. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/allocator.h +196 −0
  8. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/color.h +96 −0
  9. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/key.h +80 −0
  10. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/key/encoder.h +221 −0
  11. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/key/event.h +474 −0
  12. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/osc.h +233 −0
  13. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/paste.h +75 −0
  14. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/result.h +22 −0
  15. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/sgr.h +394 −0
  16. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/wasm.h +159 −0
  17. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/module.modulemap +7 −0
  18. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/libghostty-fat.a +0 −0
  19. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty.h +1187 −0
  20. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt.h +87 −0
  21. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/allocator.h +196 −0
  22. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/color.h +96 −0
  23. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/key.h +80 −0
  24. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/key/encoder.h +221 −0
  25. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/key/event.h +474 −0
  26. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/osc.h +233 −0
  27. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/paste.h +75 −0
  28. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/result.h +22 −0
  29. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/sgr.h +394 −0
  30. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/wasm.h +159 −0
  31. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/module.modulemap +7 −0
  32. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/libghostty-fat.a +0 −0
  33. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty.h +1187 −0
  34. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt.h +87 −0
  35. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/allocator.h +196 −0
  36. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/color.h +96 −0
  37. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/key.h +80 −0
  38. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/key/encoder.h +221 −0
  39. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/key/event.h +474 −0
  40. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/osc.h +233 −0
  41. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/paste.h +75 −0
  42. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/result.h +22 −0
  43. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/sgr.h +394 −0
  44. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/wasm.h +159 −0
  45. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/module.modulemap +7 −0
  46. apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/libghostty.a +0 −0
  47. apps/mobile/modules/t3-terminal/Vendor/libghostty/VERSION +1 −0
  48. apps/mobile/modules/t3-terminal/android/build.gradle +19 −0
  49. apps/mobile/modules/t3-terminal/android/src/main/AndroidManifest.xml +1 −0
  50. apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalModule.kt +26 −0
  51. apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalView.kt +120 −0
  52. apps/mobile/modules/t3-terminal/expo-module.config.json +10 −0
  53. apps/mobile/modules/t3-terminal/ios/T3TerminalModule.swift +23 −0
  54. apps/mobile/modules/t3-terminal/ios/T3TerminalView.swift +364 −0
  55. apps/mobile/modules/t3-terminal/package.json +17 −0
  56. apps/mobile/package.json +2 −0
  57. apps/mobile/src/features/threads/ThreadDetailScreen.tsx +46 −1
  58. apps/mobile/src/features/threads/ThreadTerminalPanel.tsx +171 −0
  59. apps/mobile/src/native/terminal/NativeTerminalSurface.tsx +199 −0
  60. apps/mobile/src/state/use-remote-environment-registry.ts +6 −1
  61. apps/mobile/src/state/use-terminal-session.ts +43 −0
  62. bun.lock +4 −0
  63. packages/client-runtime/src/index.ts +1 −0
  64. packages/client-runtime/src/terminalSessionState.test.ts +110 −0
  65. packages/client-runtime/src/terminalSessionState.ts +209 −0
apps/mobile/modules/t3-terminal/README.md+25−0
@@ -0,0 +1,25 @@
1# T3 Mobile Terminal Native Module
2
3This local Expo module owns the native terminal surface for the mobile app.
4
5The JavaScript contract is intentionally small:
6
7- input from the native surface is emitted as `{ data: string }`
8- resize from the native surface is emitted as `{ cols: number, rows: number }`
9- remote PTY output is delivered by the existing `WsRpcClient.terminal` RPC stream
10
11The iOS implementation uses the vendored `GhosttyKit.xcframework` built from the same custom-I/O
12Ghostty fork used by VVTerm. `T3TerminalView` owns a `libghostty` surface and mirrors VVTerm's
13custom I/O model:
14
151. initialize libghostty once for the process
162. create one Ghostty app and surface per native view
173. feed remote output into the surface with `ghostty_surface_feed_data`
184. send user input back to JS with the write callback
195. emit Ghostty's measured terminal size through `onResize`
20
21Android currently implements the same view name (`T3TerminalSurface`) and event payloads so the
22React Native screen and RPC code stay platform-neutral. The renderer backend can be replaced with a
23future Android Ghostty build without changing JS.
24
25Vendored Ghostty revision and license details are in `THIRD_PARTY_NOTICES.md`.
apps/mobile/modules/t3-terminal/T3TerminalNative.podspec+21−0
@@ -0,0 +1,21 @@
1require 'json'
2
3package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
5Pod::Spec.new do |s|
6 s.name = 'T3TerminalNative'
7 s.version = package['version']
8 s.summary = 'Native terminal surface for T3 Code mobile.'
9 s.description = 'Native terminal surface bridge used by the T3 Code React Native app.'
10 s.homepage = 'https://t3tools.com'
11 s.license = { :type => 'UNLICENSED' }
12 s.author = { 'T3 Tools' => 'hello@t3tools.com' }
13 s.platforms = { :ios => '16.1' }
14 s.source = { :path => '.' }
15 s.source_files = 'ios/**/*.{h,m,mm,swift}'
16 s.vendored_frameworks = 'Vendor/libghostty/GhosttyKit.xcframework'
17 s.frameworks = 'IOSurface', 'Metal', 'MetalKit', 'QuartzCore', 'UIKit'
18 s.libraries = 'c++', 'z'
19 s.swift_version = '5.9'
20 s.dependency 'ExpoModulesCore'
21end
apps/mobile/modules/t3-terminal/THIRD_PARTY_NOTICES.md+15−0
@@ -0,0 +1,15 @@
1# Third-Party Notices
2
3## Ghostty / libghostty
4
5The iOS terminal renderer vendors `GhosttyKit.xcframework`, a libghostty build produced from
6VVTerm's custom-I/O Ghostty fork.
7
8- Upstream project: https://github.com/ghostty-org/ghostty
9- Vendored source fork: https://github.com/wiedymi/ghostty
10- Vendored revision: `268a0a9d761fb19673f05d28042488e2002300f2`
11- Reference integration: https://github.com/vivy-company/vvterm
12- License: MIT
13
14Ghostty's MIT license applies to the vendored framework. Keep this notice in sync when updating
15`Vendor/libghostty`.
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/Info.plist+64−0
@@ -0,0 +1,64 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3<plist version="1.0">
4<dict>
5 <key>AvailableLibraries</key>
6 <array>
7 <dict>
8 <key>BinaryPath</key>
9 <string>libghostty-fat.a</string>
10 <key>HeadersPath</key>
11 <string>Headers</string>
12 <key>LibraryIdentifier</key>
13 <string>ios-arm64</string>
14 <key>LibraryPath</key>
15 <string>libghostty-fat.a</string>
16 <key>SupportedArchitectures</key>
17 <array>
18 <string>arm64</string>
19 </array>
20 <key>SupportedPlatform</key>
21 <string>ios</string>
22 </dict>
23 <dict>
24 <key>BinaryPath</key>
25 <string>libghostty.a</string>
26 <key>HeadersPath</key>
27 <string>Headers</string>
28 <key>LibraryIdentifier</key>
29 <string>macos-arm64_x86_64</string>
30 <key>LibraryPath</key>
31 <string>libghostty.a</string>
32 <key>SupportedArchitectures</key>
33 <array>
34 <string>arm64</string>
35 <string>x86_64</string>
36 </array>
37 <key>SupportedPlatform</key>
38 <string>macos</string>
39 </dict>
40 <dict>
41 <key>BinaryPath</key>
42 <string>libghostty-fat.a</string>
43 <key>HeadersPath</key>
44 <string>Headers</string>
45 <key>LibraryIdentifier</key>
46 <string>ios-arm64-simulator</string>
47 <key>LibraryPath</key>
48 <string>libghostty-fat.a</string>
49 <key>SupportedArchitectures</key>
50 <array>
51 <string>arm64</string>
52 </array>
53 <key>SupportedPlatform</key>
54 <string>ios</string>
55 <key>SupportedPlatformVariant</key>
56 <string>simulator</string>
57 </dict>
58 </array>
59 <key>CFBundlePackageType</key>
60 <string>XFWK</string>
61 <key>XCFrameworkFormatVersion</key>
62 <string>1.0</string>
63</dict>
64</plist>
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty.h+1187−0
@@ -0,0 +1,1187 @@
1// Ghostty embedding API. The documentation for the embedding API is
2// only within the Zig source files that define the implementations. This
3// isn't meant to be a general purpose embedding API (yet) so there hasn't
4// been documentation or example work beyond that.
5//
6// The only consumer of this API is the macOS app, but the API is built to
7// be more general purpose.
8#ifndef GHOSTTY_H
9#define GHOSTTY_H
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <stdbool.h>
16#include <stddef.h>
17#include <stdint.h>
18#include <sys/types.h>
19
20//-------------------------------------------------------------------
21// Macros
22
23#define GHOSTTY_SUCCESS 0
24
25//-------------------------------------------------------------------
26// Types
27
28// Opaque types
29typedef void* ghostty_app_t;
30typedef void* ghostty_config_t;
31typedef void* ghostty_surface_t;
32typedef void* ghostty_inspector_t;
33
34// All the types below are fully defined and must be kept in sync with
35// their Zig counterparts. Any changes to these types MUST have an associated
36// Zig change.
37typedef enum {
38 GHOSTTY_PLATFORM_INVALID,
39 GHOSTTY_PLATFORM_MACOS,
40 GHOSTTY_PLATFORM_IOS,
41} ghostty_platform_e;
42
43// Callback for custom I/O write handler.
44typedef void (*ghostty_surface_write_fn)(void* userdata,
45 const uint8_t* data,
46 size_t len);
47
48typedef enum {
49 GHOSTTY_CLIPBOARD_STANDARD,
50 GHOSTTY_CLIPBOARD_SELECTION,
51} ghostty_clipboard_e;
52
53typedef struct {
54 const char *mime;
55 const char *data;
56} ghostty_clipboard_content_s;
57
58typedef enum {
59 GHOSTTY_CLIPBOARD_REQUEST_PASTE,
60 GHOSTTY_CLIPBOARD_REQUEST_OSC_52_READ,
61 GHOSTTY_CLIPBOARD_REQUEST_OSC_52_WRITE,
62} ghostty_clipboard_request_e;
63
64typedef enum {
65 GHOSTTY_MOUSE_RELEASE,
66 GHOSTTY_MOUSE_PRESS,
67} ghostty_input_mouse_state_e;
68
69typedef enum {
70 GHOSTTY_MOUSE_UNKNOWN,
71 GHOSTTY_MOUSE_LEFT,
72 GHOSTTY_MOUSE_RIGHT,
73 GHOSTTY_MOUSE_MIDDLE,
74 GHOSTTY_MOUSE_FOUR,
75 GHOSTTY_MOUSE_FIVE,
76 GHOSTTY_MOUSE_SIX,
77 GHOSTTY_MOUSE_SEVEN,
78 GHOSTTY_MOUSE_EIGHT,
79 GHOSTTY_MOUSE_NINE,
80 GHOSTTY_MOUSE_TEN,
81 GHOSTTY_MOUSE_ELEVEN,
82} ghostty_input_mouse_button_e;
83
84typedef enum {
85 GHOSTTY_MOUSE_MOMENTUM_NONE,
86 GHOSTTY_MOUSE_MOMENTUM_BEGAN,
87 GHOSTTY_MOUSE_MOMENTUM_STATIONARY,
88 GHOSTTY_MOUSE_MOMENTUM_CHANGED,
89 GHOSTTY_MOUSE_MOMENTUM_ENDED,
90 GHOSTTY_MOUSE_MOMENTUM_CANCELLED,
91 GHOSTTY_MOUSE_MOMENTUM_MAY_BEGIN,
92} ghostty_input_mouse_momentum_e;
93
94typedef enum {
95 GHOSTTY_COLOR_SCHEME_LIGHT = 0,
96 GHOSTTY_COLOR_SCHEME_DARK = 1,
97} ghostty_color_scheme_e;
98
99// This is a packed struct (see src/input/mouse.zig) but the C standard
100// afaik doesn't let us reliably define packed structs so we build it up
101// from scratch.
102typedef int ghostty_input_scroll_mods_t;
103
104typedef enum {
105 GHOSTTY_MODS_NONE = 0,
106 GHOSTTY_MODS_SHIFT = 1 << 0,
107 GHOSTTY_MODS_CTRL = 1 << 1,
108 GHOSTTY_MODS_ALT = 1 << 2,
109 GHOSTTY_MODS_SUPER = 1 << 3,
110 GHOSTTY_MODS_CAPS = 1 << 4,
111 GHOSTTY_MODS_NUM = 1 << 5,
112 GHOSTTY_MODS_SHIFT_RIGHT = 1 << 6,
113 GHOSTTY_MODS_CTRL_RIGHT = 1 << 7,
114 GHOSTTY_MODS_ALT_RIGHT = 1 << 8,
115 GHOSTTY_MODS_SUPER_RIGHT = 1 << 9,
116} ghostty_input_mods_e;
117
118typedef enum {
119 GHOSTTY_BINDING_FLAGS_CONSUMED = 1 << 0,
120 GHOSTTY_BINDING_FLAGS_ALL = 1 << 1,
121 GHOSTTY_BINDING_FLAGS_GLOBAL = 1 << 2,
122 GHOSTTY_BINDING_FLAGS_PERFORMABLE = 1 << 3,
123} ghostty_binding_flags_e;
124
125typedef enum {
126 GHOSTTY_ACTION_RELEASE,
127 GHOSTTY_ACTION_PRESS,
128 GHOSTTY_ACTION_REPEAT,
129} ghostty_input_action_e;
130
131// Based on: https://www.w3.org/TR/uievents-code/
132typedef enum {
133 GHOSTTY_KEY_UNIDENTIFIED,
134
135 // "Writing System Keys" § 3.1.1
136 GHOSTTY_KEY_BACKQUOTE,
137 GHOSTTY_KEY_BACKSLASH,
138 GHOSTTY_KEY_BRACKET_LEFT,
139 GHOSTTY_KEY_BRACKET_RIGHT,
140 GHOSTTY_KEY_COMMA,
141 GHOSTTY_KEY_DIGIT_0,
142 GHOSTTY_KEY_DIGIT_1,
143 GHOSTTY_KEY_DIGIT_2,
144 GHOSTTY_KEY_DIGIT_3,
145 GHOSTTY_KEY_DIGIT_4,
146 GHOSTTY_KEY_DIGIT_5,
147 GHOSTTY_KEY_DIGIT_6,
148 GHOSTTY_KEY_DIGIT_7,
149 GHOSTTY_KEY_DIGIT_8,
150 GHOSTTY_KEY_DIGIT_9,
151 GHOSTTY_KEY_EQUAL,
152 GHOSTTY_KEY_INTL_BACKSLASH,
153 GHOSTTY_KEY_INTL_RO,
154 GHOSTTY_KEY_INTL_YEN,
155 GHOSTTY_KEY_A,
156 GHOSTTY_KEY_B,
157 GHOSTTY_KEY_C,
158 GHOSTTY_KEY_D,
159 GHOSTTY_KEY_E,
160 GHOSTTY_KEY_F,
161 GHOSTTY_KEY_G,
162 GHOSTTY_KEY_H,
163 GHOSTTY_KEY_I,
164 GHOSTTY_KEY_J,
165 GHOSTTY_KEY_K,
166 GHOSTTY_KEY_L,
167 GHOSTTY_KEY_M,
168 GHOSTTY_KEY_N,
169 GHOSTTY_KEY_O,
170 GHOSTTY_KEY_P,
171 GHOSTTY_KEY_Q,
172 GHOSTTY_KEY_R,
173 GHOSTTY_KEY_S,
174 GHOSTTY_KEY_T,
175 GHOSTTY_KEY_U,
176 GHOSTTY_KEY_V,
177 GHOSTTY_KEY_W,
178 GHOSTTY_KEY_X,
179 GHOSTTY_KEY_Y,
180 GHOSTTY_KEY_Z,
181 GHOSTTY_KEY_MINUS,
182 GHOSTTY_KEY_PERIOD,
183 GHOSTTY_KEY_QUOTE,
184 GHOSTTY_KEY_SEMICOLON,
185 GHOSTTY_KEY_SLASH,
186
187 // "Functional Keys" § 3.1.2
188 GHOSTTY_KEY_ALT_LEFT,
189 GHOSTTY_KEY_ALT_RIGHT,
190 GHOSTTY_KEY_BACKSPACE,
191 GHOSTTY_KEY_CAPS_LOCK,
192 GHOSTTY_KEY_CONTEXT_MENU,
193 GHOSTTY_KEY_CONTROL_LEFT,
194 GHOSTTY_KEY_CONTROL_RIGHT,
195 GHOSTTY_KEY_ENTER,
196 GHOSTTY_KEY_META_LEFT,
197 GHOSTTY_KEY_META_RIGHT,
198 GHOSTTY_KEY_SHIFT_LEFT,
199 GHOSTTY_KEY_SHIFT_RIGHT,
200 GHOSTTY_KEY_SPACE,
201 GHOSTTY_KEY_TAB,
202 GHOSTTY_KEY_CONVERT,
203 GHOSTTY_KEY_KANA_MODE,
204 GHOSTTY_KEY_NON_CONVERT,
205
206 // "Control Pad Section" § 3.2
207 GHOSTTY_KEY_DELETE,
208 GHOSTTY_KEY_END,
209 GHOSTTY_KEY_HELP,
210 GHOSTTY_KEY_HOME,
211 GHOSTTY_KEY_INSERT,
212 GHOSTTY_KEY_PAGE_DOWN,
213 GHOSTTY_KEY_PAGE_UP,
214
215 // "Arrow Pad Section" § 3.3
216 GHOSTTY_KEY_ARROW_DOWN,
217 GHOSTTY_KEY_ARROW_LEFT,
218 GHOSTTY_KEY_ARROW_RIGHT,
219 GHOSTTY_KEY_ARROW_UP,
220
221 // "Numpad Section" § 3.4
222 GHOSTTY_KEY_NUM_LOCK,
223 GHOSTTY_KEY_NUMPAD_0,
224 GHOSTTY_KEY_NUMPAD_1,
225 GHOSTTY_KEY_NUMPAD_2,
226 GHOSTTY_KEY_NUMPAD_3,
227 GHOSTTY_KEY_NUMPAD_4,
228 GHOSTTY_KEY_NUMPAD_5,
229 GHOSTTY_KEY_NUMPAD_6,
230 GHOSTTY_KEY_NUMPAD_7,
231 GHOSTTY_KEY_NUMPAD_8,
232 GHOSTTY_KEY_NUMPAD_9,
233 GHOSTTY_KEY_NUMPAD_ADD,
234 GHOSTTY_KEY_NUMPAD_BACKSPACE,
235 GHOSTTY_KEY_NUMPAD_CLEAR,
236 GHOSTTY_KEY_NUMPAD_CLEAR_ENTRY,
237 GHOSTTY_KEY_NUMPAD_COMMA,
238 GHOSTTY_KEY_NUMPAD_DECIMAL,
239 GHOSTTY_KEY_NUMPAD_DIVIDE,
240 GHOSTTY_KEY_NUMPAD_ENTER,
241 GHOSTTY_KEY_NUMPAD_EQUAL,
242 GHOSTTY_KEY_NUMPAD_MEMORY_ADD,
243 GHOSTTY_KEY_NUMPAD_MEMORY_CLEAR,
244 GHOSTTY_KEY_NUMPAD_MEMORY_RECALL,
245 GHOSTTY_KEY_NUMPAD_MEMORY_STORE,
246 GHOSTTY_KEY_NUMPAD_MEMORY_SUBTRACT,
247 GHOSTTY_KEY_NUMPAD_MULTIPLY,
248 GHOSTTY_KEY_NUMPAD_PAREN_LEFT,
249 GHOSTTY_KEY_NUMPAD_PAREN_RIGHT,
250 GHOSTTY_KEY_NUMPAD_SUBTRACT,
251 GHOSTTY_KEY_NUMPAD_SEPARATOR,
252 GHOSTTY_KEY_NUMPAD_UP,
253 GHOSTTY_KEY_NUMPAD_DOWN,
254 GHOSTTY_KEY_NUMPAD_RIGHT,
255 GHOSTTY_KEY_NUMPAD_LEFT,
256 GHOSTTY_KEY_NUMPAD_BEGIN,
257 GHOSTTY_KEY_NUMPAD_HOME,
258 GHOSTTY_KEY_NUMPAD_END,
259 GHOSTTY_KEY_NUMPAD_INSERT,
260 GHOSTTY_KEY_NUMPAD_DELETE,
261 GHOSTTY_KEY_NUMPAD_PAGE_UP,
262 GHOSTTY_KEY_NUMPAD_PAGE_DOWN,
263
264 // "Function Section" § 3.5
265 GHOSTTY_KEY_ESCAPE,
266 GHOSTTY_KEY_F1,
267 GHOSTTY_KEY_F2,
268 GHOSTTY_KEY_F3,
269 GHOSTTY_KEY_F4,
270 GHOSTTY_KEY_F5,
271 GHOSTTY_KEY_F6,
272 GHOSTTY_KEY_F7,
273 GHOSTTY_KEY_F8,
274 GHOSTTY_KEY_F9,
275 GHOSTTY_KEY_F10,
276 GHOSTTY_KEY_F11,
277 GHOSTTY_KEY_F12,
278 GHOSTTY_KEY_F13,
279 GHOSTTY_KEY_F14,
280 GHOSTTY_KEY_F15,
281 GHOSTTY_KEY_F16,
282 GHOSTTY_KEY_F17,
283 GHOSTTY_KEY_F18,
284 GHOSTTY_KEY_F19,
285 GHOSTTY_KEY_F20,
286 GHOSTTY_KEY_F21,
287 GHOSTTY_KEY_F22,
288 GHOSTTY_KEY_F23,
289 GHOSTTY_KEY_F24,
290 GHOSTTY_KEY_F25,
291 GHOSTTY_KEY_FN,
292 GHOSTTY_KEY_FN_LOCK,
293 GHOSTTY_KEY_PRINT_SCREEN,
294 GHOSTTY_KEY_SCROLL_LOCK,
295 GHOSTTY_KEY_PAUSE,
296
297 // "Media Keys" § 3.6
298 GHOSTTY_KEY_BROWSER_BACK,
299 GHOSTTY_KEY_BROWSER_FAVORITES,
300 GHOSTTY_KEY_BROWSER_FORWARD,
301 GHOSTTY_KEY_BROWSER_HOME,
302 GHOSTTY_KEY_BROWSER_REFRESH,
303 GHOSTTY_KEY_BROWSER_SEARCH,
304 GHOSTTY_KEY_BROWSER_STOP,
305 GHOSTTY_KEY_EJECT,
306 GHOSTTY_KEY_LAUNCH_APP_1,
307 GHOSTTY_KEY_LAUNCH_APP_2,
308 GHOSTTY_KEY_LAUNCH_MAIL,
309 GHOSTTY_KEY_MEDIA_PLAY_PAUSE,
310 GHOSTTY_KEY_MEDIA_SELECT,
311 GHOSTTY_KEY_MEDIA_STOP,
312 GHOSTTY_KEY_MEDIA_TRACK_NEXT,
313 GHOSTTY_KEY_MEDIA_TRACK_PREVIOUS,
314 GHOSTTY_KEY_POWER,
315 GHOSTTY_KEY_SLEEP,
316 GHOSTTY_KEY_AUDIO_VOLUME_DOWN,
317 GHOSTTY_KEY_AUDIO_VOLUME_MUTE,
318 GHOSTTY_KEY_AUDIO_VOLUME_UP,
319 GHOSTTY_KEY_WAKE_UP,
320
321 // "Legacy, Non-standard, and Special Keys" § 3.7
322 GHOSTTY_KEY_COPY,
323 GHOSTTY_KEY_CUT,
324 GHOSTTY_KEY_PASTE,
325} ghostty_input_key_e;
326
327typedef struct {
328 ghostty_input_action_e action;
329 ghostty_input_mods_e mods;
330 ghostty_input_mods_e consumed_mods;
331 uint32_t keycode;
332 const char* text;
333 uint32_t unshifted_codepoint;
334 bool composing;
335} ghostty_input_key_s;
336
337typedef enum {
338 GHOSTTY_TRIGGER_PHYSICAL,
339 GHOSTTY_TRIGGER_UNICODE,
340 GHOSTTY_TRIGGER_CATCH_ALL,
341} ghostty_input_trigger_tag_e;
342
343typedef union {
344 ghostty_input_key_e translated;
345 ghostty_input_key_e physical;
346 uint32_t unicode;
347 // catch_all has no payload
348} ghostty_input_trigger_key_u;
349
350typedef struct {
351 ghostty_input_trigger_tag_e tag;
352 ghostty_input_trigger_key_u key;
353 ghostty_input_mods_e mods;
354} ghostty_input_trigger_s;
355
356typedef struct {
357 const char* action_key;
358 const char* action;
359 const char* title;
360 const char* description;
361} ghostty_command_s;
362
363typedef enum {
364 GHOSTTY_BUILD_MODE_DEBUG,
365 GHOSTTY_BUILD_MODE_RELEASE_SAFE,
366 GHOSTTY_BUILD_MODE_RELEASE_FAST,
367 GHOSTTY_BUILD_MODE_RELEASE_SMALL,
368} ghostty_build_mode_e;
369
370typedef struct {
371 ghostty_build_mode_e build_mode;
372 const char* version;
373 uintptr_t version_len;
374} ghostty_info_s;
375
376typedef struct {
377 const char* message;
378} ghostty_diagnostic_s;
379
380typedef struct {
381 const char* ptr;
382 uintptr_t len;
383 bool sentinel;
384} ghostty_string_s;
385
386typedef struct {
387 double tl_px_x;
388 double tl_px_y;
389 uint32_t offset_start;
390 uint32_t offset_len;
391 const char* text;
392 uintptr_t text_len;
393} ghostty_text_s;
394
395typedef enum {
396 GHOSTTY_POINT_ACTIVE,
397 GHOSTTY_POINT_VIEWPORT,
398 GHOSTTY_POINT_SCREEN,
399 GHOSTTY_POINT_SURFACE,
400} ghostty_point_tag_e;
401
402typedef enum {
403 GHOSTTY_POINT_COORD_EXACT,
404 GHOSTTY_POINT_COORD_TOP_LEFT,
405 GHOSTTY_POINT_COORD_BOTTOM_RIGHT,
406} ghostty_point_coord_e;
407
408typedef struct {
409 ghostty_point_tag_e tag;
410 ghostty_point_coord_e coord;
411 uint32_t x;
412 uint32_t y;
413} ghostty_point_s;
414
415typedef struct {
416 ghostty_point_s top_left;
417 ghostty_point_s bottom_right;
418 bool rectangle;
419} ghostty_selection_s;
420
421typedef struct {
422 const char* key;
423 const char* value;
424} ghostty_env_var_s;
425
426typedef struct {
427 void* nsview;
428} ghostty_platform_macos_s;
429
430typedef struct {
431 void* uiview;
432} ghostty_platform_ios_s;
433
434typedef union {
435 ghostty_platform_macos_s macos;
436 ghostty_platform_ios_s ios;
437} ghostty_platform_u;
438
439typedef enum {
440 GHOSTTY_SURFACE_CONTEXT_WINDOW = 0,
441 GHOSTTY_SURFACE_CONTEXT_TAB = 1,
442 GHOSTTY_SURFACE_CONTEXT_SPLIT = 2,
443} ghostty_surface_context_e;
444
445typedef struct {
446 ghostty_platform_e platform_tag;
447 ghostty_platform_u platform;
448 void* userdata;
449 double scale_factor;
450 float font_size;
451 const char* working_directory;
452 const char* command;
453 ghostty_env_var_s* env_vars;
454 size_t env_var_count;
455 const char* initial_input;
456 bool wait_after_command;
457 ghostty_surface_context_e context;
458 bool use_custom_io;
459} ghostty_surface_config_s;
460
461typedef struct {
462 uint16_t columns;
463 uint16_t rows;
464 uint32_t width_px;
465 uint32_t height_px;
466 uint32_t cell_width_px;
467 uint32_t cell_height_px;
468} ghostty_surface_size_s;
469
470// Config types
471
472// config.Path
473typedef struct {
474 const char* path;
475 bool optional;
476} ghostty_config_path_s;
477
478// config.Color
479typedef struct {
480 uint8_t r;
481 uint8_t g;
482 uint8_t b;
483} ghostty_config_color_s;
484
485// config.ColorList
486typedef struct {
487 const ghostty_config_color_s* colors;
488 size_t len;
489} ghostty_config_color_list_s;
490
491// config.RepeatableCommand
492typedef struct {
493 const ghostty_command_s* commands;
494 size_t len;
495} ghostty_config_command_list_s;
496
497// config.Palette
498typedef struct {
499 ghostty_config_color_s colors[256];
500} ghostty_config_palette_s;
501
502// config.QuickTerminalSize
503typedef enum {
504 GHOSTTY_QUICK_TERMINAL_SIZE_NONE,
505 GHOSTTY_QUICK_TERMINAL_SIZE_PERCENTAGE,
506 GHOSTTY_QUICK_TERMINAL_SIZE_PIXELS,
507} ghostty_quick_terminal_size_tag_e;
508
509typedef union {
510 float percentage;
511 uint32_t pixels;
512} ghostty_quick_terminal_size_value_u;
513
514typedef struct {
515 ghostty_quick_terminal_size_tag_e tag;
516 ghostty_quick_terminal_size_value_u value;
517} ghostty_quick_terminal_size_s;
518
519typedef struct {
520 ghostty_quick_terminal_size_s primary;
521 ghostty_quick_terminal_size_s secondary;
522} ghostty_config_quick_terminal_size_s;
523
524// config.Fullscreen
525typedef enum {
526 GHOSTTY_CONFIG_FULLSCREEN_FALSE,
527 GHOSTTY_CONFIG_FULLSCREEN_TRUE,
528 GHOSTTY_CONFIG_FULLSCREEN_NON_NATIVE,
529 GHOSTTY_CONFIG_FULLSCREEN_NON_NATIVE_VISIBLE_MENU,
530 GHOSTTY_CONFIG_FULLSCREEN_NON_NATIVE_PADDED_NOTCH,
531} ghostty_config_fullscreen_e;
532
533// apprt.Target.Key
534typedef enum {
535 GHOSTTY_TARGET_APP,
536 GHOSTTY_TARGET_SURFACE,
537} ghostty_target_tag_e;
538
539typedef union {
540 ghostty_surface_t surface;
541} ghostty_target_u;
542
543typedef struct {
544 ghostty_target_tag_e tag;
545 ghostty_target_u target;
546} ghostty_target_s;
547
548// apprt.action.SplitDirection
549typedef enum {
550 GHOSTTY_SPLIT_DIRECTION_RIGHT,
551 GHOSTTY_SPLIT_DIRECTION_DOWN,
552 GHOSTTY_SPLIT_DIRECTION_LEFT,
553 GHOSTTY_SPLIT_DIRECTION_UP,
554} ghostty_action_split_direction_e;
555
556// apprt.action.GotoSplit
557typedef enum {
558 GHOSTTY_GOTO_SPLIT_PREVIOUS,
559 GHOSTTY_GOTO_SPLIT_NEXT,
560 GHOSTTY_GOTO_SPLIT_UP,
561 GHOSTTY_GOTO_SPLIT_LEFT,
562 GHOSTTY_GOTO_SPLIT_DOWN,
563 GHOSTTY_GOTO_SPLIT_RIGHT,
564} ghostty_action_goto_split_e;
565
566// apprt.action.GotoWindow
567typedef enum {
568 GHOSTTY_GOTO_WINDOW_PREVIOUS,
569 GHOSTTY_GOTO_WINDOW_NEXT,
570} ghostty_action_goto_window_e;
571
572// apprt.action.ResizeSplit.Direction
573typedef enum {
574 GHOSTTY_RESIZE_SPLIT_UP,
575 GHOSTTY_RESIZE_SPLIT_DOWN,
576 GHOSTTY_RESIZE_SPLIT_LEFT,
577 GHOSTTY_RESIZE_SPLIT_RIGHT,
578} ghostty_action_resize_split_direction_e;
579
580// apprt.action.ResizeSplit
581typedef struct {
582 uint16_t amount;
583 ghostty_action_resize_split_direction_e direction;
584} ghostty_action_resize_split_s;
585
586// apprt.action.MoveTab
587typedef struct {
588 ssize_t amount;
589} ghostty_action_move_tab_s;
590
591// apprt.action.GotoTab
592typedef enum {
593 GHOSTTY_GOTO_TAB_PREVIOUS = -1,
594 GHOSTTY_GOTO_TAB_NEXT = -2,
595 GHOSTTY_GOTO_TAB_LAST = -3,
596} ghostty_action_goto_tab_e;
597
598// apprt.action.Fullscreen
599typedef enum {
600 GHOSTTY_FULLSCREEN_NATIVE,
601 GHOSTTY_FULLSCREEN_MACOS_NON_NATIVE,
602 GHOSTTY_FULLSCREEN_MACOS_NON_NATIVE_VISIBLE_MENU,
603 GHOSTTY_FULLSCREEN_MACOS_NON_NATIVE_PADDED_NOTCH,
604} ghostty_action_fullscreen_e;
605
606// apprt.action.FloatWindow
607typedef enum {
608 GHOSTTY_FLOAT_WINDOW_ON,
609 GHOSTTY_FLOAT_WINDOW_OFF,
610 GHOSTTY_FLOAT_WINDOW_TOGGLE,
611} ghostty_action_float_window_e;
612
613// apprt.action.SecureInput
614typedef enum {
615 GHOSTTY_SECURE_INPUT_ON,
616 GHOSTTY_SECURE_INPUT_OFF,
617 GHOSTTY_SECURE_INPUT_TOGGLE,
618} ghostty_action_secure_input_e;
619
620// apprt.action.Inspector
621typedef enum {
622 GHOSTTY_INSPECTOR_TOGGLE,
623 GHOSTTY_INSPECTOR_SHOW,
624 GHOSTTY_INSPECTOR_HIDE,
625} ghostty_action_inspector_e;
626
627// apprt.action.QuitTimer
628typedef enum {
629 GHOSTTY_QUIT_TIMER_START,
630 GHOSTTY_QUIT_TIMER_STOP,
631} ghostty_action_quit_timer_e;
632
633// apprt.action.Readonly
634typedef enum {
635 GHOSTTY_READONLY_OFF,
636 GHOSTTY_READONLY_ON,
637} ghostty_action_readonly_e;
638
639// apprt.action.DesktopNotification.C
640typedef struct {
641 const char* title;
642 const char* body;
643} ghostty_action_desktop_notification_s;
644
645// apprt.action.SetTitle.C
646typedef struct {
647 const char* title;
648} ghostty_action_set_title_s;
649
650// apprt.action.PromptTitle
651typedef enum {
652 GHOSTTY_PROMPT_TITLE_SURFACE,
653 GHOSTTY_PROMPT_TITLE_TAB,
654} ghostty_action_prompt_title_e;
655
656// apprt.action.Pwd.C
657typedef struct {
658 const char* pwd;
659} ghostty_action_pwd_s;
660
661// terminal.MouseShape
662typedef enum {
663 GHOSTTY_MOUSE_SHAPE_DEFAULT,
664 GHOSTTY_MOUSE_SHAPE_CONTEXT_MENU,
665 GHOSTTY_MOUSE_SHAPE_HELP,
666 GHOSTTY_MOUSE_SHAPE_POINTER,
667 GHOSTTY_MOUSE_SHAPE_PROGRESS,
668 GHOSTTY_MOUSE_SHAPE_WAIT,
669 GHOSTTY_MOUSE_SHAPE_CELL,
670 GHOSTTY_MOUSE_SHAPE_CROSSHAIR,
671 GHOSTTY_MOUSE_SHAPE_TEXT,
672 GHOSTTY_MOUSE_SHAPE_VERTICAL_TEXT,
673 GHOSTTY_MOUSE_SHAPE_ALIAS,
674 GHOSTTY_MOUSE_SHAPE_COPY,
675 GHOSTTY_MOUSE_SHAPE_MOVE,
676 GHOSTTY_MOUSE_SHAPE_NO_DROP,
677 GHOSTTY_MOUSE_SHAPE_NOT_ALLOWED,
678 GHOSTTY_MOUSE_SHAPE_GRAB,
679 GHOSTTY_MOUSE_SHAPE_GRABBING,
680 GHOSTTY_MOUSE_SHAPE_ALL_SCROLL,
681 GHOSTTY_MOUSE_SHAPE_COL_RESIZE,
682 GHOSTTY_MOUSE_SHAPE_ROW_RESIZE,
683 GHOSTTY_MOUSE_SHAPE_N_RESIZE,
684 GHOSTTY_MOUSE_SHAPE_E_RESIZE,
685 GHOSTTY_MOUSE_SHAPE_S_RESIZE,
686 GHOSTTY_MOUSE_SHAPE_W_RESIZE,
687 GHOSTTY_MOUSE_SHAPE_NE_RESIZE,
688 GHOSTTY_MOUSE_SHAPE_NW_RESIZE,
689 GHOSTTY_MOUSE_SHAPE_SE_RESIZE,
690 GHOSTTY_MOUSE_SHAPE_SW_RESIZE,
691 GHOSTTY_MOUSE_SHAPE_EW_RESIZE,
692 GHOSTTY_MOUSE_SHAPE_NS_RESIZE,
693 GHOSTTY_MOUSE_SHAPE_NESW_RESIZE,
694 GHOSTTY_MOUSE_SHAPE_NWSE_RESIZE,
695 GHOSTTY_MOUSE_SHAPE_ZOOM_IN,
696 GHOSTTY_MOUSE_SHAPE_ZOOM_OUT,
697} ghostty_action_mouse_shape_e;
698
699// apprt.action.MouseVisibility
700typedef enum {
701 GHOSTTY_MOUSE_VISIBLE,
702 GHOSTTY_MOUSE_HIDDEN,
703} ghostty_action_mouse_visibility_e;
704
705// apprt.action.MouseOverLink
706typedef struct {
707 const char* url;
708 size_t len;
709} ghostty_action_mouse_over_link_s;
710
711// apprt.action.SizeLimit
712typedef struct {
713 uint32_t min_width;
714 uint32_t min_height;
715 uint32_t max_width;
716 uint32_t max_height;
717} ghostty_action_size_limit_s;
718
719// apprt.action.InitialSize
720typedef struct {
721 uint32_t width;
722 uint32_t height;
723} ghostty_action_initial_size_s;
724
725// apprt.action.CellSize
726typedef struct {
727 uint32_t width;
728 uint32_t height;
729} ghostty_action_cell_size_s;
730
731// renderer.Health
732typedef enum {
733 GHOSTTY_RENDERER_HEALTH_HEALTHY,
734 GHOSTTY_RENDERER_HEALTH_UNHEALTHY,
735} ghostty_action_renderer_health_e;
736
737// apprt.action.KeySequence
738typedef struct {
739 bool active;
740 ghostty_input_trigger_s trigger;
741} ghostty_action_key_sequence_s;
742
743// apprt.action.KeyTable.Tag
744typedef enum {
745 GHOSTTY_KEY_TABLE_ACTIVATE,
746 GHOSTTY_KEY_TABLE_DEACTIVATE,
747 GHOSTTY_KEY_TABLE_DEACTIVATE_ALL,
748} ghostty_action_key_table_tag_e;
749
750// apprt.action.KeyTable.CValue
751typedef union {
752 struct {
753 const char *name;
754 size_t len;
755 } activate;
756} ghostty_action_key_table_u;
757
758// apprt.action.KeyTable.C
759typedef struct {
760 ghostty_action_key_table_tag_e tag;
761 ghostty_action_key_table_u value;
762} ghostty_action_key_table_s;
763
764// apprt.action.ColorKind
765typedef enum {
766 GHOSTTY_ACTION_COLOR_KIND_FOREGROUND = -1,
767 GHOSTTY_ACTION_COLOR_KIND_BACKGROUND = -2,
768 GHOSTTY_ACTION_COLOR_KIND_CURSOR = -3,
769} ghostty_action_color_kind_e;
770
771// apprt.action.ColorChange
772typedef struct {
773 ghostty_action_color_kind_e kind;
774 uint8_t r;
775 uint8_t g;
776 uint8_t b;
777} ghostty_action_color_change_s;
778
779// apprt.action.ConfigChange
780typedef struct {
781 ghostty_config_t config;
782} ghostty_action_config_change_s;
783
784// apprt.action.ReloadConfig
785typedef struct {
786 bool soft;
787} ghostty_action_reload_config_s;
788
789// apprt.action.OpenUrlKind
790typedef enum {
791 GHOSTTY_ACTION_OPEN_URL_KIND_UNKNOWN,
792 GHOSTTY_ACTION_OPEN_URL_KIND_TEXT,
793 GHOSTTY_ACTION_OPEN_URL_KIND_HTML,
794} ghostty_action_open_url_kind_e;
795
796// apprt.action.OpenUrl.C
797typedef struct {
798 ghostty_action_open_url_kind_e kind;
799 const char* url;
800 uintptr_t len;
801} ghostty_action_open_url_s;
802
803// apprt.action.CloseTabMode
804typedef enum {
805 GHOSTTY_ACTION_CLOSE_TAB_MODE_THIS,
806 GHOSTTY_ACTION_CLOSE_TAB_MODE_OTHER,
807 GHOSTTY_ACTION_CLOSE_TAB_MODE_RIGHT,
808} ghostty_action_close_tab_mode_e;
809
810// apprt.surface.Message.ChildExited
811typedef struct {
812 uint32_t exit_code;
813 uint64_t timetime_ms;
814} ghostty_surface_message_childexited_s;
815
816// terminal.osc.Command.ProgressReport.State
817typedef enum {
818 GHOSTTY_PROGRESS_STATE_REMOVE,
819 GHOSTTY_PROGRESS_STATE_SET,
820 GHOSTTY_PROGRESS_STATE_ERROR,
821 GHOSTTY_PROGRESS_STATE_INDETERMINATE,
822 GHOSTTY_PROGRESS_STATE_PAUSE,
823} ghostty_action_progress_report_state_e;
824
825// terminal.osc.Command.ProgressReport.C
826typedef struct {
827 ghostty_action_progress_report_state_e state;
828 // -1 if no progress was reported, otherwise 0-100 indicating percent
829 // completeness.
830 int8_t progress;
831} ghostty_action_progress_report_s;
832
833// apprt.action.CommandFinished.C
834typedef struct {
835 // -1 if no exit code was reported, otherwise 0-255
836 int16_t exit_code;
837 // number of nanoseconds that command was running for
838 uint64_t duration;
839} ghostty_action_command_finished_s;
840
841// apprt.action.StartSearch.C
842typedef struct {
843 const char* needle;
844} ghostty_action_start_search_s;
845
846// apprt.action.SearchTotal
847typedef struct {
848 ssize_t total;
849} ghostty_action_search_total_s;
850
851// apprt.action.SearchSelected
852typedef struct {
853 ssize_t selected;
854} ghostty_action_search_selected_s;
855
856// terminal.Scrollbar
857typedef struct {
858 uint64_t total;
859 uint64_t offset;
860 uint64_t len;
861} ghostty_action_scrollbar_s;
862
863// apprt.Action.Key
864typedef enum {
865 GHOSTTY_ACTION_QUIT,
866 GHOSTTY_ACTION_NEW_WINDOW,
867 GHOSTTY_ACTION_NEW_TAB,
868 GHOSTTY_ACTION_CLOSE_TAB,
869 GHOSTTY_ACTION_NEW_SPLIT,
870 GHOSTTY_ACTION_CLOSE_ALL_WINDOWS,
871 GHOSTTY_ACTION_TOGGLE_MAXIMIZE,
872 GHOSTTY_ACTION_TOGGLE_FULLSCREEN,
873 GHOSTTY_ACTION_TOGGLE_TAB_OVERVIEW,
874 GHOSTTY_ACTION_TOGGLE_WINDOW_DECORATIONS,
875 GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL,
876 GHOSTTY_ACTION_TOGGLE_COMMAND_PALETTE,
877 GHOSTTY_ACTION_TOGGLE_VISIBILITY,
878 GHOSTTY_ACTION_TOGGLE_BACKGROUND_OPACITY,
879 GHOSTTY_ACTION_MOVE_TAB,
880 GHOSTTY_ACTION_GOTO_TAB,
881 GHOSTTY_ACTION_GOTO_SPLIT,
882 GHOSTTY_ACTION_GOTO_WINDOW,
883 GHOSTTY_ACTION_RESIZE_SPLIT,
884 GHOSTTY_ACTION_EQUALIZE_SPLITS,
885 GHOSTTY_ACTION_TOGGLE_SPLIT_ZOOM,
886 GHOSTTY_ACTION_PRESENT_TERMINAL,
887 GHOSTTY_ACTION_SIZE_LIMIT,
888 GHOSTTY_ACTION_RESET_WINDOW_SIZE,
889 GHOSTTY_ACTION_INITIAL_SIZE,
890 GHOSTTY_ACTION_CELL_SIZE,
891 GHOSTTY_ACTION_SCROLLBAR,
892 GHOSTTY_ACTION_RENDER,
893 GHOSTTY_ACTION_INSPECTOR,
894 GHOSTTY_ACTION_SHOW_GTK_INSPECTOR,
895 GHOSTTY_ACTION_RENDER_INSPECTOR,
896 GHOSTTY_ACTION_DESKTOP_NOTIFICATION,
897 GHOSTTY_ACTION_SET_TITLE,
898 GHOSTTY_ACTION_PROMPT_TITLE,
899 GHOSTTY_ACTION_PWD,
900 GHOSTTY_ACTION_MOUSE_SHAPE,
901 GHOSTTY_ACTION_MOUSE_VISIBILITY,
902 GHOSTTY_ACTION_MOUSE_OVER_LINK,
903 GHOSTTY_ACTION_RENDERER_HEALTH,
904 GHOSTTY_ACTION_OPEN_CONFIG,
905 GHOSTTY_ACTION_QUIT_TIMER,
906 GHOSTTY_ACTION_FLOAT_WINDOW,
907 GHOSTTY_ACTION_SECURE_INPUT,
908 GHOSTTY_ACTION_KEY_SEQUENCE,
909 GHOSTTY_ACTION_KEY_TABLE,
910 GHOSTTY_ACTION_COLOR_CHANGE,
911 GHOSTTY_ACTION_RELOAD_CONFIG,
912 GHOSTTY_ACTION_CONFIG_CHANGE,
913 GHOSTTY_ACTION_CLOSE_WINDOW,
914 GHOSTTY_ACTION_RING_BELL,
915 GHOSTTY_ACTION_UNDO,
916 GHOSTTY_ACTION_REDO,
917 GHOSTTY_ACTION_CHECK_FOR_UPDATES,
918 GHOSTTY_ACTION_OPEN_URL,
919 GHOSTTY_ACTION_SHOW_CHILD_EXITED,
920 GHOSTTY_ACTION_PROGRESS_REPORT,
921 GHOSTTY_ACTION_SHOW_ON_SCREEN_KEYBOARD,
922 GHOSTTY_ACTION_COMMAND_FINISHED,
923 GHOSTTY_ACTION_START_SEARCH,
924 GHOSTTY_ACTION_END_SEARCH,
925 GHOSTTY_ACTION_SEARCH_TOTAL,
926 GHOSTTY_ACTION_SEARCH_SELECTED,
927 GHOSTTY_ACTION_READONLY,
928 GHOSTTY_ACTION_COPY_TITLE_TO_CLIPBOARD,
929} ghostty_action_tag_e;
930
931typedef union {
932 ghostty_action_split_direction_e new_split;
933 ghostty_action_fullscreen_e toggle_fullscreen;
934 ghostty_action_move_tab_s move_tab;
935 ghostty_action_goto_tab_e goto_tab;
936 ghostty_action_goto_split_e goto_split;
937 ghostty_action_goto_window_e goto_window;
938 ghostty_action_resize_split_s resize_split;
939 ghostty_action_size_limit_s size_limit;
940 ghostty_action_initial_size_s initial_size;
941 ghostty_action_cell_size_s cell_size;
942 ghostty_action_scrollbar_s scrollbar;
943 ghostty_action_inspector_e inspector;
944 ghostty_action_desktop_notification_s desktop_notification;
945 ghostty_action_set_title_s set_title;
946 ghostty_action_prompt_title_e prompt_title;
947 ghostty_action_pwd_s pwd;
948 ghostty_action_mouse_shape_e mouse_shape;
949 ghostty_action_mouse_visibility_e mouse_visibility;
950 ghostty_action_mouse_over_link_s mouse_over_link;
951 ghostty_action_renderer_health_e renderer_health;
952 ghostty_action_quit_timer_e quit_timer;
953 ghostty_action_float_window_e float_window;
954 ghostty_action_secure_input_e secure_input;
955 ghostty_action_key_sequence_s key_sequence;
956 ghostty_action_key_table_s key_table;
957 ghostty_action_color_change_s color_change;
958 ghostty_action_reload_config_s reload_config;
959 ghostty_action_config_change_s config_change;
960 ghostty_action_open_url_s open_url;
961 ghostty_action_close_tab_mode_e close_tab_mode;
962 ghostty_surface_message_childexited_s child_exited;
963 ghostty_action_progress_report_s progress_report;
964 ghostty_action_command_finished_s command_finished;
965 ghostty_action_start_search_s start_search;
966 ghostty_action_search_total_s search_total;
967 ghostty_action_search_selected_s search_selected;
968 ghostty_action_readonly_e readonly;
969} ghostty_action_u;
970
971typedef struct {
972 ghostty_action_tag_e tag;
973 ghostty_action_u action;
974} ghostty_action_s;
975
976typedef void (*ghostty_runtime_wakeup_cb)(void*);
977typedef void (*ghostty_runtime_read_clipboard_cb)(void*,
978 ghostty_clipboard_e,
979 void*);
980typedef void (*ghostty_runtime_confirm_read_clipboard_cb)(
981 void*,
982 const char*,
983 void*,
984 ghostty_clipboard_request_e);
985typedef void (*ghostty_runtime_write_clipboard_cb)(void*,
986 ghostty_clipboard_e,
987 const ghostty_clipboard_content_s*,
988 size_t,
989 bool);
990typedef void (*ghostty_runtime_close_surface_cb)(void*, bool);
991typedef bool (*ghostty_runtime_action_cb)(ghostty_app_t,
992 ghostty_target_s,
993 ghostty_action_s);
994
995typedef struct {
996 void* userdata;
997 bool supports_selection_clipboard;
998 ghostty_runtime_wakeup_cb wakeup_cb;
999 ghostty_runtime_action_cb action_cb;
1000 ghostty_runtime_read_clipboard_cb read_clipboard_cb;
1001 ghostty_runtime_confirm_read_clipboard_cb confirm_read_clipboard_cb;
1002 ghostty_runtime_write_clipboard_cb write_clipboard_cb;
1003 ghostty_runtime_close_surface_cb close_surface_cb;
1004} ghostty_runtime_config_s;
1005
1006// apprt.ipc.Target.Key
1007typedef enum {
1008 GHOSTTY_IPC_TARGET_CLASS,
1009 GHOSTTY_IPC_TARGET_DETECT,
1010} ghostty_ipc_target_tag_e;
1011
1012typedef union {
1013 char *klass;
1014} ghostty_ipc_target_u;
1015
1016typedef struct {
1017 ghostty_ipc_target_tag_e tag;
1018 ghostty_ipc_target_u target;
1019} chostty_ipc_target_s;
1020
1021// apprt.ipc.Action.NewWindow
1022typedef struct {
1023 // This should be a null terminated list of strings.
1024 const char **arguments;
1025} ghostty_ipc_action_new_window_s;
1026
1027typedef union {
1028 ghostty_ipc_action_new_window_s new_window;
1029} ghostty_ipc_action_u;
1030
1031// apprt.ipc.Action.Key
1032typedef enum {
1033 GHOSTTY_IPC_ACTION_NEW_WINDOW,
1034} ghostty_ipc_action_tag_e;
1035
1036//-------------------------------------------------------------------
1037// Published API
1038
1039int ghostty_init(uintptr_t, char**);
1040void ghostty_cli_try_action(void);
1041ghostty_info_s ghostty_info(void);
1042const char* ghostty_translate(const char*);
1043void ghostty_string_free(ghostty_string_s);
1044
1045ghostty_config_t ghostty_config_new();
1046void ghostty_config_free(ghostty_config_t);
1047ghostty_config_t ghostty_config_clone(ghostty_config_t);
1048void ghostty_config_load_cli_args(ghostty_config_t);
1049void ghostty_config_load_file(ghostty_config_t, const char*);
1050void ghostty_config_load_default_files(ghostty_config_t);
1051void ghostty_config_load_recursive_files(ghostty_config_t);
1052void ghostty_config_finalize(ghostty_config_t);
1053bool ghostty_config_get(ghostty_config_t, void*, const char*, uintptr_t);
1054ghostty_input_trigger_s ghostty_config_trigger(ghostty_config_t,
1055 const char*,
1056 uintptr_t);
1057uint32_t ghostty_config_diagnostics_count(ghostty_config_t);
1058ghostty_diagnostic_s ghostty_config_get_diagnostic(ghostty_config_t, uint32_t);
1059ghostty_string_s ghostty_config_open_path(void);
1060
1061ghostty_app_t ghostty_app_new(const ghostty_runtime_config_s*,
1062 ghostty_config_t);
1063void ghostty_app_free(ghostty_app_t);
1064void ghostty_app_tick(ghostty_app_t);
1065void* ghostty_app_userdata(ghostty_app_t);
1066void ghostty_app_set_focus(ghostty_app_t, bool);
1067bool ghostty_app_key(ghostty_app_t, ghostty_input_key_s);
1068bool ghostty_app_key_is_binding(ghostty_app_t, ghostty_input_key_s);
1069void ghostty_app_keyboard_changed(ghostty_app_t);
1070void ghostty_app_open_config(ghostty_app_t);
1071void ghostty_app_update_config(ghostty_app_t, ghostty_config_t);
1072bool ghostty_app_needs_confirm_quit(ghostty_app_t);
1073bool ghostty_app_has_global_keybinds(ghostty_app_t);
1074void ghostty_app_set_color_scheme(ghostty_app_t, ghostty_color_scheme_e);
1075
1076ghostty_surface_config_s ghostty_surface_config_new();
1077
1078ghostty_surface_t ghostty_surface_new(ghostty_app_t,
1079 const ghostty_surface_config_s*);
1080void ghostty_surface_free(ghostty_surface_t);
1081void* ghostty_surface_userdata(ghostty_surface_t);
1082ghostty_app_t ghostty_surface_app(ghostty_surface_t);
1083ghostty_surface_config_s ghostty_surface_inherited_config(ghostty_surface_t, ghostty_surface_context_e);
1084void ghostty_surface_update_config(ghostty_surface_t, ghostty_config_t);
1085bool ghostty_surface_needs_confirm_quit(ghostty_surface_t);
1086bool ghostty_surface_process_exited(ghostty_surface_t);
1087void ghostty_surface_refresh(ghostty_surface_t);
1088void ghostty_surface_draw(ghostty_surface_t);
1089// Custom I/O API - feed output into the terminal and receive writes.
1090void ghostty_surface_feed_data(ghostty_surface_t, const uint8_t*, size_t);
1091void ghostty_surface_set_write_callback(ghostty_surface_t,
1092 ghostty_surface_write_fn,
1093 void*);
1094void ghostty_surface_set_content_scale(ghostty_surface_t, double, double);
1095void ghostty_surface_set_focus(ghostty_surface_t, bool);
1096void ghostty_surface_set_occlusion(ghostty_surface_t, bool);
1097void ghostty_surface_set_size(ghostty_surface_t, uint32_t, uint32_t);
1098ghostty_surface_size_s ghostty_surface_size(ghostty_surface_t);
1099void ghostty_surface_set_color_scheme(ghostty_surface_t,
1100 ghostty_color_scheme_e);
1101ghostty_input_mods_e ghostty_surface_key_translation_mods(ghostty_surface_t,
1102 ghostty_input_mods_e);
1103bool ghostty_surface_key(ghostty_surface_t, ghostty_input_key_s);
1104bool ghostty_surface_key_is_binding(ghostty_surface_t,
1105 ghostty_input_key_s,
1106 ghostty_binding_flags_e*);
1107void ghostty_surface_text(ghostty_surface_t, const char*, uintptr_t);
1108void ghostty_surface_preedit(ghostty_surface_t, const char*, uintptr_t);
1109bool ghostty_surface_mouse_captured(ghostty_surface_t);
1110bool ghostty_surface_mouse_button(ghostty_surface_t,
1111 ghostty_input_mouse_state_e,
1112 ghostty_input_mouse_button_e,
1113 ghostty_input_mods_e);
1114void ghostty_surface_mouse_pos(ghostty_surface_t,
1115 double,
1116 double,
1117 ghostty_input_mods_e);
1118void ghostty_surface_mouse_scroll(ghostty_surface_t,
1119 double,
1120 double,
1121 ghostty_input_scroll_mods_t);
1122void ghostty_surface_mouse_pressure(ghostty_surface_t, uint32_t, double);
1123void ghostty_surface_ime_point(ghostty_surface_t, double*, double*, double*, double*);
1124void ghostty_surface_request_close(ghostty_surface_t);
1125void ghostty_surface_split(ghostty_surface_t, ghostty_action_split_direction_e);
1126void ghostty_surface_split_focus(ghostty_surface_t,
1127 ghostty_action_goto_split_e);
1128void ghostty_surface_split_resize(ghostty_surface_t,
1129 ghostty_action_resize_split_direction_e,
1130 uint16_t);
1131void ghostty_surface_split_equalize(ghostty_surface_t);
1132bool ghostty_surface_binding_action(ghostty_surface_t, const char*, uintptr_t);
1133void ghostty_surface_complete_clipboard_request(ghostty_surface_t,
1134 const char*,
1135 void*,
1136 bool);
1137bool ghostty_surface_has_selection(ghostty_surface_t);
1138bool ghostty_surface_read_selection(ghostty_surface_t, ghostty_text_s*);
1139bool ghostty_surface_read_text(ghostty_surface_t,
1140 ghostty_selection_s,
1141 ghostty_text_s*);
1142void ghostty_surface_free_text(ghostty_surface_t, ghostty_text_s*);
1143
1144#ifdef __APPLE__
1145void ghostty_surface_set_display_id(ghostty_surface_t, uint32_t);
1146void* ghostty_surface_quicklook_font(ghostty_surface_t);
1147bool ghostty_surface_quicklook_word(ghostty_surface_t, ghostty_text_s*);
1148#endif
1149
1150ghostty_inspector_t ghostty_surface_inspector(ghostty_surface_t);
1151void ghostty_inspector_free(ghostty_surface_t);
1152void ghostty_inspector_set_focus(ghostty_inspector_t, bool);
1153void ghostty_inspector_set_content_scale(ghostty_inspector_t, double, double);
1154void ghostty_inspector_set_size(ghostty_inspector_t, uint32_t, uint32_t);
1155void ghostty_inspector_mouse_button(ghostty_inspector_t,
1156 ghostty_input_mouse_state_e,
1157 ghostty_input_mouse_button_e,
1158 ghostty_input_mods_e);
1159void ghostty_inspector_mouse_pos(ghostty_inspector_t, double, double);
1160void ghostty_inspector_mouse_scroll(ghostty_inspector_t,
1161 double,
1162 double,
1163 ghostty_input_scroll_mods_t);
1164void ghostty_inspector_key(ghostty_inspector_t,
1165 ghostty_input_action_e,
1166 ghostty_input_key_e,
1167 ghostty_input_mods_e);
1168void ghostty_inspector_text(ghostty_inspector_t, const char*);
1169
1170#ifdef __APPLE__
1171bool ghostty_inspector_metal_init(ghostty_inspector_t, void*);
1172void ghostty_inspector_metal_render(ghostty_inspector_t, void*, void*);
1173bool ghostty_inspector_metal_shutdown(ghostty_inspector_t);
1174#endif
1175
1176// APIs I'd like to get rid of eventually but are still needed for now.
1177// Don't use these unless you know what you're doing.
1178void ghostty_set_window_background_blur(ghostty_app_t, void*);
1179
1180// Benchmark API, if available.
1181bool ghostty_benchmark_cli(const char*, const char*);
1182
1183#ifdef __cplusplus
1184}
1185#endif
1186
1187#endif /* GHOSTTY_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt.h+87−0
@@ -0,0 +1,87 @@
1/**
2 * @file vt.h
3 *
4 * libghostty-vt - Virtual terminal emulator library
5 *
6 * This library provides functionality for parsing and handling terminal
7 * escape sequences as well as maintaining terminal state such as styles,
8 * cursor position, screen, scrollback, and more.
9 *
10 * WARNING: This is an incomplete, work-in-progress API. It is not yet
11 * stable and is definitely going to change.
12 */
13
14/**
15 * @mainpage libghostty-vt - Virtual Terminal Emulator Library
16 *
17 * libghostty-vt is a C library which implements a modern terminal emulator,
18 * extracted from the [Ghostty](https://ghostty.org) terminal emulator.
19 *
20 * libghostty-vt contains the logic for handling the core parts of a terminal
21 * emulator: parsing terminal escape sequences, maintaining terminal state,
22 * encoding input events, etc. It can handle scrollback, line wrapping,
23 * reflow on resize, and more.
24 *
25 * @warning This library is currently in development and the API is not yet stable.
26 * Breaking changes are expected in future versions. Use with caution in production code.
27 *
28 * @section groups_sec API Reference
29 *
30 * The API is organized into the following groups:
31 * - @ref key "Key Encoding" - Encode key events into terminal sequences
32 * - @ref osc "OSC Parser" - Parse OSC (Operating System Command) sequences
33 * - @ref sgr "SGR Parser" - Parse SGR (Select Graphic Rendition) sequences
34 * - @ref paste "Paste Utilities" - Validate paste data safety
35 * - @ref allocator "Memory Management" - Memory management and custom allocators
36 * - @ref wasm "WebAssembly Utilities" - WebAssembly convenience functions
37 *
38 * @section examples_sec Examples
39 *
40 * Complete working examples:
41 * - @ref c-vt/src/main.c - OSC parser example
42 * - @ref c-vt-key-encode/src/main.c - Key encoding example
43 * - @ref c-vt-paste/src/main.c - Paste safety check example
44 * - @ref c-vt-sgr/src/main.c - SGR parser example
45 *
46 */
47
48/** @example c-vt/src/main.c
49 * This example demonstrates how to use the OSC parser to parse an OSC sequence,
50 * extract command information, and retrieve command-specific data like window titles.
51 */
52
53/** @example c-vt-key-encode/src/main.c
54 * This example demonstrates how to use the key encoder to convert key events
55 * into terminal escape sequences using the Kitty keyboard protocol.
56 */
57
58/** @example c-vt-paste/src/main.c
59 * This example demonstrates how to use the paste utilities to check if
60 * paste data is safe before sending it to the terminal.
61 */
62
63/** @example c-vt-sgr/src/main.c
64 * This example demonstrates how to use the SGR parser to parse terminal
65 * styling sequences and extract text attributes like colors and underline styles.
66 */
67
68#ifndef GHOSTTY_VT_H
69#define GHOSTTY_VT_H
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75#include <ghostty/vt/result.h>
76#include <ghostty/vt/allocator.h>
77#include <ghostty/vt/osc.h>
78#include <ghostty/vt/sgr.h>
79#include <ghostty/vt/key.h>
80#include <ghostty/vt/paste.h>
81#include <ghostty/vt/wasm.h>
82
83#ifdef __cplusplus
84}
85#endif
86
87#endif /* GHOSTTY_VT_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/allocator.h+196−0
@@ -0,0 +1,196 @@
1/**
2 * @file allocator.h
3 *
4 * Memory management interface for libghostty-vt.
5 */
6
7#ifndef GHOSTTY_VT_ALLOCATOR_H
8#define GHOSTTY_VT_ALLOCATOR_H
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13
14/** @defgroup allocator Memory Management
15 *
16 * libghostty-vt does require memory allocation for various operations,
17 * but is resilient to allocation failures and will gracefully handle
18 * out-of-memory situations by returning error codes.
19 *
20 * The exact memory management semantics are documented in the relevant
21 * functions and data structures.
22 *
23 * libghostty-vt uses explicit memory allocation via an allocator
24 * interface provided by GhosttyAllocator. The interface is based on the
25 * [Zig](https://ziglang.org) allocator interface, since this has been
26 * shown to be a flexible and powerful interface in practice and enables
27 * a wide variety of allocation strategies.
28 *
29 * **For the common case, you can pass NULL as the allocator for any
30 * function that accepts one,** and libghostty will use a default allocator.
31 * The default allocator will be libc malloc/free if libc is linked.
32 * Otherwise, a custom allocator is used (currently Zig's SMP allocator)
33 * that doesn't require any external dependencies.
34 *
35 * ## Basic Usage
36 *
37 * For simple use cases, you can ignore this interface entirely by passing NULL
38 * as the allocator parameter to functions that accept one. This will use the
39 * default allocator (typically libc malloc/free, if libc is linked, but
40 * we provide our own default allocator if libc isn't linked).
41 *
42 * To use a custom allocator:
43 * 1. Implement the GhosttyAllocatorVtable function pointers
44 * 2. Create a GhosttyAllocator struct with your vtable and context
45 * 3. Pass the allocator to functions that accept one
46 *
47 * @{
48 */
49
50/**
51 * Function table for custom memory allocator operations.
52 *
53 * This vtable defines the interface for a custom memory allocator. All
54 * function pointers must be valid and non-NULL.
55 *
56 * @ingroup allocator
57 *
58 * If you're not going to use a custom allocator, you can ignore all of
59 * this. All functions that take an allocator pointer allow NULL to use a
60 * default allocator.
61 *
62 * The interface is based on the Zig allocator interface. I'll say up front
63 * that it is easy to look at this interface and think "wow, this is really
64 * overcomplicated". The reason for this complexity is well thought out by
65 * the Zig folks, and it enables a diverse set of allocation strategies
66 * as shown by the Zig ecosystem. As a consolation, please note that many
67 * of the arguments are only needed for advanced use cases and can be
68 * safely ignored in simple implementations. For example, if you look at
69 * the Zig implementation of the libc allocator in `lib/std/heap.zig`
70 * (search for CAllocator), you'll see it is very simple.
71 *
72 * We chose to align with the Zig allocator interface because:
73 *
74 * 1. It is a proven interface that serves a wide variety of use cases
75 * in the real world via the Zig ecosystem. It's shown to work.
76 *
77 * 2. Our core implementation itself is Zig, and this lets us very
78 * cheaply and easily convert between C and Zig allocators.
79 *
80 * NOTE(mitchellh): In the future, we can have default implementations of
81 * resize/remap and allow those to be null.
82 */
83typedef struct {
84 /**
85 * Return a pointer to `len` bytes with specified `alignment`, or return
86 * `NULL` indicating the allocation failed.
87 *
88 * @param ctx The allocator context
89 * @param len Number of bytes to allocate
90 * @param alignment Required alignment for the allocation. Guaranteed to
91 * be a power of two between 1 and 16 inclusive.
92 * @param ret_addr First return address of the allocation call stack (0 if not provided)
93 * @return Pointer to allocated memory, or NULL if allocation failed
94 */
95 void* (*alloc)(void *ctx, size_t len, uint8_t alignment, uintptr_t ret_addr);
96
97 /**
98 * Attempt to expand or shrink memory in place.
99 *
100 * `memory_len` must equal the length requested from the most recent
101 * successful call to `alloc`, `resize`, or `remap`. `alignment` must
102 * equal the same value that was passed as the `alignment` parameter to
103 * the original `alloc` call.
104 *
105 * `new_len` must be greater than zero.
106 *
107 * @param ctx The allocator context
108 * @param memory Pointer to the memory block to resize
109 * @param memory_len Current size of the memory block
110 * @param alignment Alignment (must match original allocation)
111 * @param new_len New requested size
112 * @param ret_addr First return address of the allocation call stack (0 if not provided)
113 * @return true if resize was successful in-place, false if relocation would be required
114 */
115 bool (*resize)(void *ctx, void *memory, size_t memory_len, uint8_t alignment, size_t new_len, uintptr_t ret_addr);
116
117 /**
118 * Attempt to expand or shrink memory, allowing relocation.
119 *
120 * `memory_len` must equal the length requested from the most recent
121 * successful call to `alloc`, `resize`, or `remap`. `alignment` must
122 * equal the same value that was passed as the `alignment` parameter to
123 * the original `alloc` call.
124 *
125 * A non-`NULL` return value indicates the resize was successful. The
126 * allocation may have same address, or may have been relocated. In either
127 * case, the allocation now has size of `new_len`. A `NULL` return value
128 * indicates that the resize would be equivalent to allocating new memory,
129 * copying the bytes from the old memory, and then freeing the old memory.
130 * In such case, it is more efficient for the caller to perform the copy.
131 *
132 * `new_len` must be greater than zero.
133 *
134 * @param ctx The allocator context
135 * @param memory Pointer to the memory block to remap
136 * @param memory_len Current size of the memory block
137 * @param alignment Alignment (must match original allocation)
138 * @param new_len New requested size
139 * @param ret_addr First return address of the allocation call stack (0 if not provided)
140 * @return Pointer to resized memory (may be relocated), or NULL if manual copy is needed
141 */
142 void* (*remap)(void *ctx, void *memory, size_t memory_len, uint8_t alignment, size_t new_len, uintptr_t ret_addr);
143
144 /**
145 * Free and invalidate a region of memory.
146 *
147 * `memory_len` must equal the length requested from the most recent
148 * successful call to `alloc`, `resize`, or `remap`. `alignment` must
149 * equal the same value that was passed as the `alignment` parameter to
150 * the original `alloc` call.
151 *
152 * @param ctx The allocator context
153 * @param memory Pointer to the memory block to free
154 * @param memory_len Size of the memory block
155 * @param alignment Alignment (must match original allocation)
156 * @param ret_addr First return address of the allocation call stack (0 if not provided)
157 */
158 void (*free)(void *ctx, void *memory, size_t memory_len, uint8_t alignment, uintptr_t ret_addr);
159} GhosttyAllocatorVtable;
160
161/**
162 * Custom memory allocator.
163 *
164 * For functions that take an allocator pointer, a NULL pointer indicates
165 * that the default allocator should be used. The default allocator will
166 * be libc malloc/free if we're linking to libc. If libc isn't linked,
167 * a custom allocator is used (currently Zig's SMP allocator).
168 *
169 * @ingroup allocator
170 *
171 * Usage example:
172 * @code
173 * GhosttyAllocator allocator = {
174 * .vtable = &my_allocator_vtable,
175 * .ctx = my_allocator_state
176 * };
177 * @endcode
178 */
179typedef struct GhosttyAllocator {
180 /**
181 * Opaque context pointer passed to all vtable functions.
182 * This allows the allocator implementation to maintain state
183 * or reference external resources needed for memory management.
184 */
185 void *ctx;
186
187 /**
188 * Pointer to the allocator's vtable containing function pointers
189 * for memory operations (alloc, resize, remap, free).
190 */
191 const GhosttyAllocatorVtable *vtable;
192} GhosttyAllocator;
193
194/** @} */
195
196#endif /* GHOSTTY_VT_ALLOCATOR_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/color.h+96−0
@@ -0,0 +1,96 @@
1/**
2 * @file color.h
3 *
4 * Color types and utilities.
5 */
6
7#ifndef GHOSTTY_VT_COLOR_H
8#define GHOSTTY_VT_COLOR_H
9
10#include <stdint.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/**
17 * RGB color value.
18 *
19 * @ingroup sgr
20 */
21typedef struct {
22 uint8_t r; /**< Red component (0-255) */
23 uint8_t g; /**< Green component (0-255) */
24 uint8_t b; /**< Blue component (0-255) */
25} GhosttyColorRgb;
26
27/**
28 * Palette color index (0-255).
29 *
30 * @ingroup sgr
31 */
32typedef uint8_t GhosttyColorPaletteIndex;
33
34/** @addtogroup sgr
35 * @{
36 */
37
38/** Black color (0) @ingroup sgr */
39#define GHOSTTY_COLOR_NAMED_BLACK 0
40/** Red color (1) @ingroup sgr */
41#define GHOSTTY_COLOR_NAMED_RED 1
42/** Green color (2) @ingroup sgr */
43#define GHOSTTY_COLOR_NAMED_GREEN 2
44/** Yellow color (3) @ingroup sgr */
45#define GHOSTTY_COLOR_NAMED_YELLOW 3
46/** Blue color (4) @ingroup sgr */
47#define GHOSTTY_COLOR_NAMED_BLUE 4
48/** Magenta color (5) @ingroup sgr */
49#define GHOSTTY_COLOR_NAMED_MAGENTA 5
50/** Cyan color (6) @ingroup sgr */
51#define GHOSTTY_COLOR_NAMED_CYAN 6
52/** White color (7) @ingroup sgr */
53#define GHOSTTY_COLOR_NAMED_WHITE 7
54/** Bright black color (8) @ingroup sgr */
55#define GHOSTTY_COLOR_NAMED_BRIGHT_BLACK 8
56/** Bright red color (9) @ingroup sgr */
57#define GHOSTTY_COLOR_NAMED_BRIGHT_RED 9
58/** Bright green color (10) @ingroup sgr */
59#define GHOSTTY_COLOR_NAMED_BRIGHT_GREEN 10
60/** Bright yellow color (11) @ingroup sgr */
61#define GHOSTTY_COLOR_NAMED_BRIGHT_YELLOW 11
62/** Bright blue color (12) @ingroup sgr */
63#define GHOSTTY_COLOR_NAMED_BRIGHT_BLUE 12
64/** Bright magenta color (13) @ingroup sgr */
65#define GHOSTTY_COLOR_NAMED_BRIGHT_MAGENTA 13
66/** Bright cyan color (14) @ingroup sgr */
67#define GHOSTTY_COLOR_NAMED_BRIGHT_CYAN 14
68/** Bright white color (15) @ingroup sgr */
69#define GHOSTTY_COLOR_NAMED_BRIGHT_WHITE 15
70
71/** @} */
72
73/**
74 * Get the RGB color components.
75 *
76 * This function extracts the individual red, green, and blue components
77 * from a GhosttyColorRgb value. Primarily useful in WebAssembly environments
78 * where accessing struct fields directly is difficult.
79 *
80 * @param color The RGB color value
81 * @param r Pointer to store the red component (0-255)
82 * @param g Pointer to store the green component (0-255)
83 * @param b Pointer to store the blue component (0-255)
84 *
85 * @ingroup sgr
86 */
87void ghostty_color_rgb_get(GhosttyColorRgb color,
88 uint8_t* r,
89 uint8_t* g,
90 uint8_t* b);
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif /* GHOSTTY_VT_COLOR_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/key.h+80−0
@@ -0,0 +1,80 @@
1/**
2 * @file key.h
3 *
4 * Key encoding module - encode key events into terminal escape sequences.
5 */
6
7#ifndef GHOSTTY_VT_KEY_H
8#define GHOSTTY_VT_KEY_H
9
10/** @defgroup key Key Encoding
11 *
12 * Utilities for encoding key events into terminal escape sequences,
13 * supporting both legacy encoding as well as Kitty Keyboard Protocol.
14 *
15 * ## Basic Usage
16 *
17 * 1. Create an encoder instance with ghostty_key_encoder_new()
18 * 2. Configure encoder options with ghostty_key_encoder_setopt().
19 * 3. For each key event:
20 * - Create a key event with ghostty_key_event_new()
21 * - Set event properties (action, key, modifiers, etc.)
22 * - Encode with ghostty_key_encoder_encode()
23 * - Free the event with ghostty_key_event_free()
24 * - Note: You can also reuse the same key event multiple times by
25 * changing its properties.
26 * 4. Free the encoder with ghostty_key_encoder_free() when done
27 *
28 * ## Example
29 *
30 * @code{.c}
31 * #include <assert.h>
32 * #include <stdio.h>
33 * #include <ghostty/vt.h>
34 *
35 * int main() {
36 * // Create encoder
37 * GhosttyKeyEncoder encoder;
38 * GhosttyResult result = ghostty_key_encoder_new(NULL, &encoder);
39 * assert(result == GHOSTTY_SUCCESS);
40 *
41 * // Enable Kitty keyboard protocol with all features
42 * ghostty_key_encoder_setopt(encoder, GHOSTTY_KEY_ENCODER_OPT_KITTY_FLAGS,
43 * &(uint8_t){GHOSTTY_KITTY_KEY_ALL});
44 *
45 * // Create and configure key event for Ctrl+C press
46 * GhosttyKeyEvent event;
47 * result = ghostty_key_event_new(NULL, &event);
48 * assert(result == GHOSTTY_SUCCESS);
49 * ghostty_key_event_set_action(event, GHOSTTY_KEY_ACTION_PRESS);
50 * ghostty_key_event_set_key(event, GHOSTTY_KEY_C);
51 * ghostty_key_event_set_mods(event, GHOSTTY_MODS_CTRL);
52 *
53 * // Encode the key event
54 * char buf[128];
55 * size_t written = 0;
56 * result = ghostty_key_encoder_encode(encoder, event, buf, sizeof(buf), &written);
57 * assert(result == GHOSTTY_SUCCESS);
58 *
59 * // Use the encoded sequence (e.g., write to terminal)
60 * fwrite(buf, 1, written, stdout);
61 *
62 * // Cleanup
63 * ghostty_key_event_free(event);
64 * ghostty_key_encoder_free(encoder);
65 * return 0;
66 * }
67 * @endcode
68 *
69 * For a complete working example, see example/c-vt-key-encode in the
70 * repository.
71 *
72 * @{
73 */
74
75#include <ghostty/vt/key/event.h>
76#include <ghostty/vt/key/encoder.h>
77
78/** @} */
79
80#endif /* GHOSTTY_VT_KEY_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/key/encoder.h+221−0
@@ -0,0 +1,221 @@
1/**
2 * @file encoder.h
3 *
4 * Key event encoding to terminal escape sequences.
5 */
6
7#ifndef GHOSTTY_VT_KEY_ENCODER_H
8#define GHOSTTY_VT_KEY_ENCODER_H
9
10#include <stddef.h>
11#include <stdint.h>
12#include <ghostty/vt/result.h>
13#include <ghostty/vt/allocator.h>
14#include <ghostty/vt/key/event.h>
15
16/**
17 * Opaque handle to a key encoder instance.
18 *
19 * This handle represents a key encoder that converts key events into terminal
20 * escape sequences.
21 *
22 * @ingroup key
23 */
24typedef struct GhosttyKeyEncoder *GhosttyKeyEncoder;
25
26/**
27 * Kitty keyboard protocol flags.
28 *
29 * Bitflags representing the various modes of the Kitty keyboard protocol.
30 * These can be combined using bitwise OR operations. Valid values all
31 * start with `GHOSTTY_KITTY_KEY_`.
32 *
33 * @ingroup key
34 */
35typedef uint8_t GhosttyKittyKeyFlags;
36
37/** Kitty keyboard protocol disabled (all flags off) */
38#define GHOSTTY_KITTY_KEY_DISABLED 0
39
40/** Disambiguate escape codes */
41#define GHOSTTY_KITTY_KEY_DISAMBIGUATE (1 << 0)
42
43/** Report key press and release events */
44#define GHOSTTY_KITTY_KEY_REPORT_EVENTS (1 << 1)
45
46/** Report alternate key codes */
47#define GHOSTTY_KITTY_KEY_REPORT_ALTERNATES (1 << 2)
48
49/** Report all key events including those normally handled by the terminal */
50#define GHOSTTY_KITTY_KEY_REPORT_ALL (1 << 3)
51
52/** Report associated text with key events */
53#define GHOSTTY_KITTY_KEY_REPORT_ASSOCIATED (1 << 4)
54
55/** All Kitty keyboard protocol flags enabled */
56#define GHOSTTY_KITTY_KEY_ALL (GHOSTTY_KITTY_KEY_DISAMBIGUATE | GHOSTTY_KITTY_KEY_REPORT_EVENTS | GHOSTTY_KITTY_KEY_REPORT_ALTERNATES | GHOSTTY_KITTY_KEY_REPORT_ALL | GHOSTTY_KITTY_KEY_REPORT_ASSOCIATED)
57
58/**
59 * macOS option key behavior.
60 *
61 * Determines whether the "option" key on macOS is treated as "alt" or not.
62 * See the Ghostty `macos-option-as-alt` configuration option for more details.
63 *
64 * @ingroup key
65 */
66typedef enum {
67 /** Option key is not treated as alt */
68 GHOSTTY_OPTION_AS_ALT_FALSE = 0,
69 /** Option key is treated as alt */
70 GHOSTTY_OPTION_AS_ALT_TRUE = 1,
71 /** Only left option key is treated as alt */
72 GHOSTTY_OPTION_AS_ALT_LEFT = 2,
73 /** Only right option key is treated as alt */
74 GHOSTTY_OPTION_AS_ALT_RIGHT = 3,
75} GhosttyOptionAsAlt;
76
77/**
78 * Key encoder option identifiers.
79 *
80 * These values are used with ghostty_key_encoder_setopt() to configure
81 * the behavior of the key encoder.
82 *
83 * @ingroup key
84 */
85typedef enum {
86 /** Terminal DEC mode 1: cursor key application mode (value: bool) */
87 GHOSTTY_KEY_ENCODER_OPT_CURSOR_KEY_APPLICATION = 0,
88
89 /** Terminal DEC mode 66: keypad key application mode (value: bool) */
90 GHOSTTY_KEY_ENCODER_OPT_KEYPAD_KEY_APPLICATION = 1,
91
92 /** Terminal DEC mode 1035: ignore keypad with numlock (value: bool) */
93 GHOSTTY_KEY_ENCODER_OPT_IGNORE_KEYPAD_WITH_NUMLOCK = 2,
94
95 /** Terminal DEC mode 1036: alt sends escape prefix (value: bool) */
96 GHOSTTY_KEY_ENCODER_OPT_ALT_ESC_PREFIX = 3,
97
98 /** xterm modifyOtherKeys mode 2 (value: bool) */
99 GHOSTTY_KEY_ENCODER_OPT_MODIFY_OTHER_KEYS_STATE_2 = 4,
100
101 /** Kitty keyboard protocol flags (value: GhosttyKittyKeyFlags bitmask) */
102 GHOSTTY_KEY_ENCODER_OPT_KITTY_FLAGS = 5,
103
104 /** macOS option-as-alt setting (value: GhosttyOptionAsAlt) */
105 GHOSTTY_KEY_ENCODER_OPT_MACOS_OPTION_AS_ALT = 6,
106} GhosttyKeyEncoderOption;
107
108/**
109 * Create a new key encoder instance.
110 *
111 * Creates a new key encoder with default options. The encoder can be configured
112 * using ghostty_key_encoder_setopt() and must be freed using
113 * ghostty_key_encoder_free() when no longer needed.
114 *
115 * @param allocator Pointer to the allocator to use for memory management, or NULL to use the default allocator
116 * @param encoder Pointer to store the created encoder handle
117 * @return GHOSTTY_SUCCESS on success, or an error code on failure
118 *
119 * @ingroup key
120 */
121GhosttyResult ghostty_key_encoder_new(const GhosttyAllocator *allocator, GhosttyKeyEncoder *encoder);
122
123/**
124 * Free a key encoder instance.
125 *
126 * Releases all resources associated with the key encoder. After this call,
127 * the encoder handle becomes invalid and must not be used.
128 *
129 * @param encoder The encoder handle to free (may be NULL)
130 *
131 * @ingroup key
132 */
133void ghostty_key_encoder_free(GhosttyKeyEncoder encoder);
134
135/**
136 * Set an option on the key encoder.
137 *
138 * Configures the behavior of the key encoder. Options control various aspects
139 * of encoding such as terminal modes (cursor key application mode, keypad mode),
140 * protocol selection (Kitty keyboard protocol flags), and platform-specific
141 * behaviors (macOS option-as-alt).
142 *
143 * A null pointer value does nothing. It does not reset the value to the
144 * default. The setopt call will do nothing.
145 *
146 * @param encoder The encoder handle, must not be NULL
147 * @param option The option to set
148 * @param value Pointer to the value to set (type depends on the option)
149 *
150 * @ingroup key
151 */
152void ghostty_key_encoder_setopt(GhosttyKeyEncoder encoder, GhosttyKeyEncoderOption option, const void *value);
153
154/**
155 * Encode a key event into a terminal escape sequence.
156 *
157 * Converts a key event into the appropriate terminal escape sequence based on
158 * the encoder's current options. The sequence is written to the provided buffer.
159 *
160 * Not all key events produce output. For example, unmodified modifier keys
161 * typically don't generate escape sequences. Check the out_len parameter to
162 * determine if any data was written.
163 *
164 * If the output buffer is too small, this function returns GHOSTTY_OUT_OF_MEMORY
165 * and out_len will contain the required buffer size. The caller can then
166 * allocate a larger buffer and call the function again.
167 *
168 * @param encoder The encoder handle, must not be NULL
169 * @param event The key event to encode, must not be NULL
170 * @param out_buf Buffer to write the encoded sequence to
171 * @param out_buf_size Size of the output buffer in bytes
172 * @param out_len Pointer to store the number of bytes written (may be NULL)
173 * @return GHOSTTY_SUCCESS on success, GHOSTTY_OUT_OF_MEMORY if buffer too small, or other error code
174 *
175 * ## Example: Calculate required buffer size
176 *
177 * @code{.c}
178 * // Query the required size with a NULL buffer (always returns OUT_OF_MEMORY)
179 * size_t required = 0;
180 * GhosttyResult result = ghostty_key_encoder_encode(encoder, event, NULL, 0, &required);
181 * assert(result == GHOSTTY_OUT_OF_MEMORY);
182 *
183 * // Allocate buffer of required size
184 * char *buf = malloc(required);
185 *
186 * // Encode with properly sized buffer
187 * size_t written = 0;
188 * result = ghostty_key_encoder_encode(encoder, event, buf, required, &written);
189 * assert(result == GHOSTTY_SUCCESS);
190 *
191 * // Use the encoded sequence...
192 *
193 * free(buf);
194 * @endcode
195 *
196 * ## Example: Direct encoding with static buffer
197 *
198 * @code{.c}
199 * // Most escape sequences are short, so a static buffer often suffices
200 * char buf[128];
201 * size_t written = 0;
202 * GhosttyResult result = ghostty_key_encoder_encode(encoder, event, buf, sizeof(buf), &written);
203 *
204 * if (result == GHOSTTY_SUCCESS) {
205 * // Write the encoded sequence to the terminal
206 * write(pty_fd, buf, written);
207 * } else if (result == GHOSTTY_OUT_OF_MEMORY) {
208 * // Buffer too small, written contains required size
209 * char *dynamic_buf = malloc(written);
210 * result = ghostty_key_encoder_encode(encoder, event, dynamic_buf, written, &written);
211 * assert(result == GHOSTTY_SUCCESS);
212 * write(pty_fd, dynamic_buf, written);
213 * free(dynamic_buf);
214 * }
215 * @endcode
216 *
217 * @ingroup key
218 */
219GhosttyResult ghostty_key_encoder_encode(GhosttyKeyEncoder encoder, GhosttyKeyEvent event, char *out_buf, size_t out_buf_size, size_t *out_len);
220
221#endif /* GHOSTTY_VT_KEY_ENCODER_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/key/event.h+474−0
@@ -0,0 +1,474 @@
1/**
2 * @file event.h
3 *
4 * Key event representation and manipulation.
5 */
6
7#ifndef GHOSTTY_VT_KEY_EVENT_H
8#define GHOSTTY_VT_KEY_EVENT_H
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <ghostty/vt/result.h>
14#include <ghostty/vt/allocator.h>
15
16/**
17 * Opaque handle to a key event.
18 *
19 * This handle represents a keyboard input event containing information about
20 * the physical key pressed, modifiers, and generated text.
21 *
22 * @ingroup key
23 */
24typedef struct GhosttyKeyEvent *GhosttyKeyEvent;
25
26/**
27 * Keyboard input event types.
28 *
29 * @ingroup key
30 */
31typedef enum {
32 /** Key was released */
33 GHOSTTY_KEY_ACTION_RELEASE = 0,
34 /** Key was pressed */
35 GHOSTTY_KEY_ACTION_PRESS = 1,
36 /** Key is being repeated (held down) */
37 GHOSTTY_KEY_ACTION_REPEAT = 2,
38} GhosttyKeyAction;
39
40/**
41 * Keyboard modifier keys bitmask.
42 *
43 * A bitmask representing all keyboard modifiers. This tracks which modifier keys
44 * are pressed and, where supported by the platform, which side (left or right)
45 * of each modifier is active.
46 *
47 * Use the GHOSTTY_MODS_* constants to test and set individual modifiers.
48 *
49 * Modifier side bits are only meaningful when the corresponding modifier bit is set.
50 * Not all platforms support distinguishing between left and right modifier
51 * keys and Ghostty is built to expect that some platforms may not provide this
52 * information.
53 *
54 * @ingroup key
55 */
56typedef uint16_t GhosttyMods;
57
58/** Shift key is pressed */
59#define GHOSTTY_MODS_SHIFT (1 << 0)
60/** Control key is pressed */
61#define GHOSTTY_MODS_CTRL (1 << 1)
62/** Alt/Option key is pressed */
63#define GHOSTTY_MODS_ALT (1 << 2)
64/** Super/Command/Windows key is pressed */
65#define GHOSTTY_MODS_SUPER (1 << 3)
66/** Caps Lock is active */
67#define GHOSTTY_MODS_CAPS_LOCK (1 << 4)
68/** Num Lock is active */
69#define GHOSTTY_MODS_NUM_LOCK (1 << 5)
70
71/**
72 * Right shift is pressed (0 = left, 1 = right).
73 * Only meaningful when GHOSTTY_MODS_SHIFT is set.
74 */
75#define GHOSTTY_MODS_SHIFT_SIDE (1 << 6)
76/**
77 * Right ctrl is pressed (0 = left, 1 = right).
78 * Only meaningful when GHOSTTY_MODS_CTRL is set.
79 */
80#define GHOSTTY_MODS_CTRL_SIDE (1 << 7)
81/**
82 * Right alt is pressed (0 = left, 1 = right).
83 * Only meaningful when GHOSTTY_MODS_ALT is set.
84 */
85#define GHOSTTY_MODS_ALT_SIDE (1 << 8)
86/**
87 * Right super is pressed (0 = left, 1 = right).
88 * Only meaningful when GHOSTTY_MODS_SUPER is set.
89 */
90#define GHOSTTY_MODS_SUPER_SIDE (1 << 9)
91
92/**
93 * Physical key codes.
94 *
95 * The set of key codes that Ghostty is aware of. These represent physical keys
96 * on the keyboard and are layout-independent. For example, the "a" key on a US
97 * keyboard is the same as the "ф" key on a Russian keyboard, but both will
98 * report the same key_a value.
99 *
100 * Layout-dependent strings are provided separately as UTF-8 text and are produced
101 * by the platform. These values are based on the W3C UI Events KeyboardEvent code
102 * standard. See: https://www.w3.org/TR/uievents-code
103 *
104 * @ingroup key
105 */
106typedef enum {
107 GHOSTTY_KEY_UNIDENTIFIED = 0,
108
109 // Writing System Keys (W3C § 3.1.1)
110 GHOSTTY_KEY_BACKQUOTE,
111 GHOSTTY_KEY_BACKSLASH,
112 GHOSTTY_KEY_BRACKET_LEFT,
113 GHOSTTY_KEY_BRACKET_RIGHT,
114 GHOSTTY_KEY_COMMA,
115 GHOSTTY_KEY_DIGIT_0,
116 GHOSTTY_KEY_DIGIT_1,
117 GHOSTTY_KEY_DIGIT_2,
118 GHOSTTY_KEY_DIGIT_3,
119 GHOSTTY_KEY_DIGIT_4,
120 GHOSTTY_KEY_DIGIT_5,
121 GHOSTTY_KEY_DIGIT_6,
122 GHOSTTY_KEY_DIGIT_7,
123 GHOSTTY_KEY_DIGIT_8,
124 GHOSTTY_KEY_DIGIT_9,
125 GHOSTTY_KEY_EQUAL,
126 GHOSTTY_KEY_INTL_BACKSLASH,
127 GHOSTTY_KEY_INTL_RO,
128 GHOSTTY_KEY_INTL_YEN,
129 GHOSTTY_KEY_A,
130 GHOSTTY_KEY_B,
131 GHOSTTY_KEY_C,
132 GHOSTTY_KEY_D,
133 GHOSTTY_KEY_E,
134 GHOSTTY_KEY_F,
135 GHOSTTY_KEY_G,
136 GHOSTTY_KEY_H,
137 GHOSTTY_KEY_I,
138 GHOSTTY_KEY_J,
139 GHOSTTY_KEY_K,
140 GHOSTTY_KEY_L,
141 GHOSTTY_KEY_M,
142 GHOSTTY_KEY_N,
143 GHOSTTY_KEY_O,
144 GHOSTTY_KEY_P,
145 GHOSTTY_KEY_Q,
146 GHOSTTY_KEY_R,
147 GHOSTTY_KEY_S,
148 GHOSTTY_KEY_T,
149 GHOSTTY_KEY_U,
150 GHOSTTY_KEY_V,
151 GHOSTTY_KEY_W,
152 GHOSTTY_KEY_X,
153 GHOSTTY_KEY_Y,
154 GHOSTTY_KEY_Z,
155 GHOSTTY_KEY_MINUS,
156 GHOSTTY_KEY_PERIOD,
157 GHOSTTY_KEY_QUOTE,
158 GHOSTTY_KEY_SEMICOLON,
159 GHOSTTY_KEY_SLASH,
160
161 // Functional Keys (W3C § 3.1.2)
162 GHOSTTY_KEY_ALT_LEFT,
163 GHOSTTY_KEY_ALT_RIGHT,
164 GHOSTTY_KEY_BACKSPACE,
165 GHOSTTY_KEY_CAPS_LOCK,
166 GHOSTTY_KEY_CONTEXT_MENU,
167 GHOSTTY_KEY_CONTROL_LEFT,
168 GHOSTTY_KEY_CONTROL_RIGHT,
169 GHOSTTY_KEY_ENTER,
170 GHOSTTY_KEY_META_LEFT,
171 GHOSTTY_KEY_META_RIGHT,
172 GHOSTTY_KEY_SHIFT_LEFT,
173 GHOSTTY_KEY_SHIFT_RIGHT,
174 GHOSTTY_KEY_SPACE,
175 GHOSTTY_KEY_TAB,
176 GHOSTTY_KEY_CONVERT,
177 GHOSTTY_KEY_KANA_MODE,
178 GHOSTTY_KEY_NON_CONVERT,
179
180 // Control Pad Section (W3C § 3.2)
181 GHOSTTY_KEY_DELETE,
182 GHOSTTY_KEY_END,
183 GHOSTTY_KEY_HELP,
184 GHOSTTY_KEY_HOME,
185 GHOSTTY_KEY_INSERT,
186 GHOSTTY_KEY_PAGE_DOWN,
187 GHOSTTY_KEY_PAGE_UP,
188
189 // Arrow Pad Section (W3C § 3.3)
190 GHOSTTY_KEY_ARROW_DOWN,
191 GHOSTTY_KEY_ARROW_LEFT,
192 GHOSTTY_KEY_ARROW_RIGHT,
193 GHOSTTY_KEY_ARROW_UP,
194
195 // Numpad Section (W3C § 3.4)
196 GHOSTTY_KEY_NUM_LOCK,
197 GHOSTTY_KEY_NUMPAD_0,
198 GHOSTTY_KEY_NUMPAD_1,
199 GHOSTTY_KEY_NUMPAD_2,
200 GHOSTTY_KEY_NUMPAD_3,
201 GHOSTTY_KEY_NUMPAD_4,
202 GHOSTTY_KEY_NUMPAD_5,
203 GHOSTTY_KEY_NUMPAD_6,
204 GHOSTTY_KEY_NUMPAD_7,
205 GHOSTTY_KEY_NUMPAD_8,
206 GHOSTTY_KEY_NUMPAD_9,
207 GHOSTTY_KEY_NUMPAD_ADD,
208 GHOSTTY_KEY_NUMPAD_BACKSPACE,
209 GHOSTTY_KEY_NUMPAD_CLEAR,
210 GHOSTTY_KEY_NUMPAD_CLEAR_ENTRY,
211 GHOSTTY_KEY_NUMPAD_COMMA,
212 GHOSTTY_KEY_NUMPAD_DECIMAL,
213 GHOSTTY_KEY_NUMPAD_DIVIDE,
214 GHOSTTY_KEY_NUMPAD_ENTER,
215 GHOSTTY_KEY_NUMPAD_EQUAL,
216 GHOSTTY_KEY_NUMPAD_MEMORY_ADD,
217 GHOSTTY_KEY_NUMPAD_MEMORY_CLEAR,
218 GHOSTTY_KEY_NUMPAD_MEMORY_RECALL,
219 GHOSTTY_KEY_NUMPAD_MEMORY_STORE,
220 GHOSTTY_KEY_NUMPAD_MEMORY_SUBTRACT,
221 GHOSTTY_KEY_NUMPAD_MULTIPLY,
222 GHOSTTY_KEY_NUMPAD_PAREN_LEFT,
223 GHOSTTY_KEY_NUMPAD_PAREN_RIGHT,
224 GHOSTTY_KEY_NUMPAD_SUBTRACT,
225 GHOSTTY_KEY_NUMPAD_SEPARATOR,
226 GHOSTTY_KEY_NUMPAD_UP,
227 GHOSTTY_KEY_NUMPAD_DOWN,
228 GHOSTTY_KEY_NUMPAD_RIGHT,
229 GHOSTTY_KEY_NUMPAD_LEFT,
230 GHOSTTY_KEY_NUMPAD_BEGIN,
231 GHOSTTY_KEY_NUMPAD_HOME,
232 GHOSTTY_KEY_NUMPAD_END,
233 GHOSTTY_KEY_NUMPAD_INSERT,
234 GHOSTTY_KEY_NUMPAD_DELETE,
235 GHOSTTY_KEY_NUMPAD_PAGE_UP,
236 GHOSTTY_KEY_NUMPAD_PAGE_DOWN,
237
238 // Function Section (W3C § 3.5)
239 GHOSTTY_KEY_ESCAPE,
240 GHOSTTY_KEY_F1,
241 GHOSTTY_KEY_F2,
242 GHOSTTY_KEY_F3,
243 GHOSTTY_KEY_F4,
244 GHOSTTY_KEY_F5,
245 GHOSTTY_KEY_F6,
246 GHOSTTY_KEY_F7,
247 GHOSTTY_KEY_F8,
248 GHOSTTY_KEY_F9,
249 GHOSTTY_KEY_F10,
250 GHOSTTY_KEY_F11,
251 GHOSTTY_KEY_F12,
252 GHOSTTY_KEY_F13,
253 GHOSTTY_KEY_F14,
254 GHOSTTY_KEY_F15,
255 GHOSTTY_KEY_F16,
256 GHOSTTY_KEY_F17,
257 GHOSTTY_KEY_F18,
258 GHOSTTY_KEY_F19,
259 GHOSTTY_KEY_F20,
260 GHOSTTY_KEY_F21,
261 GHOSTTY_KEY_F22,
262 GHOSTTY_KEY_F23,
263 GHOSTTY_KEY_F24,
264 GHOSTTY_KEY_F25,
265 GHOSTTY_KEY_FN,
266 GHOSTTY_KEY_FN_LOCK,
267 GHOSTTY_KEY_PRINT_SCREEN,
268 GHOSTTY_KEY_SCROLL_LOCK,
269 GHOSTTY_KEY_PAUSE,
270
271 // Media Keys (W3C § 3.6)
272 GHOSTTY_KEY_BROWSER_BACK,
273 GHOSTTY_KEY_BROWSER_FAVORITES,
274 GHOSTTY_KEY_BROWSER_FORWARD,
275 GHOSTTY_KEY_BROWSER_HOME,
276 GHOSTTY_KEY_BROWSER_REFRESH,
277 GHOSTTY_KEY_BROWSER_SEARCH,
278 GHOSTTY_KEY_BROWSER_STOP,
279 GHOSTTY_KEY_EJECT,
280 GHOSTTY_KEY_LAUNCH_APP_1,
281 GHOSTTY_KEY_LAUNCH_APP_2,
282 GHOSTTY_KEY_LAUNCH_MAIL,
283 GHOSTTY_KEY_MEDIA_PLAY_PAUSE,
284 GHOSTTY_KEY_MEDIA_SELECT,
285 GHOSTTY_KEY_MEDIA_STOP,
286 GHOSTTY_KEY_MEDIA_TRACK_NEXT,
287 GHOSTTY_KEY_MEDIA_TRACK_PREVIOUS,
288 GHOSTTY_KEY_POWER,
289 GHOSTTY_KEY_SLEEP,
290 GHOSTTY_KEY_AUDIO_VOLUME_DOWN,
291 GHOSTTY_KEY_AUDIO_VOLUME_MUTE,
292 GHOSTTY_KEY_AUDIO_VOLUME_UP,
293 GHOSTTY_KEY_WAKE_UP,
294
295 // Legacy, Non-standard, and Special Keys (W3C § 3.7)
296 GHOSTTY_KEY_COPY,
297 GHOSTTY_KEY_CUT,
298 GHOSTTY_KEY_PASTE,
299} GhosttyKey;
300
301/**
302 * Create a new key event instance.
303 *
304 * Creates a new key event with default values. The event must be freed using
305 * ghostty_key_event_free() when no longer needed.
306 *
307 * @param allocator Pointer to the allocator to use for memory management, or NULL to use the default allocator
308 * @param event Pointer to store the created key event handle
309 * @return GHOSTTY_SUCCESS on success, or an error code on failure
310 *
311 * @ingroup key
312 */
313GhosttyResult ghostty_key_event_new(const GhosttyAllocator *allocator, GhosttyKeyEvent *event);
314
315/**
316 * Free a key event instance.
317 *
318 * Releases all resources associated with the key event. After this call,
319 * the event handle becomes invalid and must not be used.
320 *
321 * @param event The key event handle to free (may be NULL)
322 *
323 * @ingroup key
324 */
325void ghostty_key_event_free(GhosttyKeyEvent event);
326
327/**
328 * Set the key action (press, release, repeat).
329 *
330 * @param event The key event handle, must not be NULL
331 * @param action The action to set
332 *
333 * @ingroup key
334 */
335void ghostty_key_event_set_action(GhosttyKeyEvent event, GhosttyKeyAction action);
336
337/**
338 * Get the key action (press, release, repeat).
339 *
340 * @param event The key event handle, must not be NULL
341 * @return The key action
342 *
343 * @ingroup key
344 */
345GhosttyKeyAction ghostty_key_event_get_action(GhosttyKeyEvent event);
346
347/**
348 * Set the physical key code.
349 *
350 * @param event The key event handle, must not be NULL
351 * @param key The physical key code to set
352 *
353 * @ingroup key
354 */
355void ghostty_key_event_set_key(GhosttyKeyEvent event, GhosttyKey key);
356
357/**
358 * Get the physical key code.
359 *
360 * @param event The key event handle, must not be NULL
361 * @return The physical key code
362 *
363 * @ingroup key
364 */
365GhosttyKey ghostty_key_event_get_key(GhosttyKeyEvent event);
366
367/**
368 * Set the modifier keys bitmask.
369 *
370 * @param event The key event handle, must not be NULL
371 * @param mods The modifier keys bitmask to set
372 *
373 * @ingroup key
374 */
375void ghostty_key_event_set_mods(GhosttyKeyEvent event, GhosttyMods mods);
376
377/**
378 * Get the modifier keys bitmask.
379 *
380 * @param event The key event handle, must not be NULL
381 * @return The modifier keys bitmask
382 *
383 * @ingroup key
384 */
385GhosttyMods ghostty_key_event_get_mods(GhosttyKeyEvent event);
386
387/**
388 * Set the consumed modifiers bitmask.
389 *
390 * @param event The key event handle, must not be NULL
391 * @param consumed_mods The consumed modifiers bitmask to set
392 *
393 * @ingroup key
394 */
395void ghostty_key_event_set_consumed_mods(GhosttyKeyEvent event, GhosttyMods consumed_mods);
396
397/**
398 * Get the consumed modifiers bitmask.
399 *
400 * @param event The key event handle, must not be NULL
401 * @return The consumed modifiers bitmask
402 *
403 * @ingroup key
404 */
405GhosttyMods ghostty_key_event_get_consumed_mods(GhosttyKeyEvent event);
406
407/**
408 * Set whether the key event is part of a composition sequence.
409 *
410 * @param event The key event handle, must not be NULL
411 * @param composing Whether the key event is part of a composition sequence
412 *
413 * @ingroup key
414 */
415void ghostty_key_event_set_composing(GhosttyKeyEvent event, bool composing);
416
417/**
418 * Get whether the key event is part of a composition sequence.
419 *
420 * @param event The key event handle, must not be NULL
421 * @return Whether the key event is part of a composition sequence
422 *
423 * @ingroup key
424 */
425bool ghostty_key_event_get_composing(GhosttyKeyEvent event);
426
427/**
428 * Set the UTF-8 text generated by the key event.
429 *
430 * The key event does NOT take ownership of the text pointer. The caller
431 * must ensure the string remains valid for the lifetime needed by the event.
432 *
433 * @param event The key event handle, must not be NULL
434 * @param utf8 The UTF-8 text to set (or NULL for empty)
435 * @param len Length of the UTF-8 text in bytes
436 *
437 * @ingroup key
438 */
439void ghostty_key_event_set_utf8(GhosttyKeyEvent event, const char *utf8, size_t len);
440
441/**
442 * Get the UTF-8 text generated by the key event.
443 *
444 * The returned pointer is valid until the event is freed or the UTF-8 text is modified.
445 *
446 * @param event The key event handle, must not be NULL
447 * @param len Pointer to store the length of the UTF-8 text in bytes (may be NULL)
448 * @return The UTF-8 text (or NULL for empty)
449 *
450 * @ingroup key
451 */
452const char *ghostty_key_event_get_utf8(GhosttyKeyEvent event, size_t *len);
453
454/**
455 * Set the unshifted Unicode codepoint.
456 *
457 * @param event The key event handle, must not be NULL
458 * @param codepoint The unshifted Unicode codepoint to set
459 *
460 * @ingroup key
461 */
462void ghostty_key_event_set_unshifted_codepoint(GhosttyKeyEvent event, uint32_t codepoint);
463
464/**
465 * Get the unshifted Unicode codepoint.
466 *
467 * @param event The key event handle, must not be NULL
468 * @return The unshifted Unicode codepoint
469 *
470 * @ingroup key
471 */
472uint32_t ghostty_key_event_get_unshifted_codepoint(GhosttyKeyEvent event);
473
474#endif /* GHOSTTY_VT_KEY_EVENT_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/osc.h+233−0
@@ -0,0 +1,233 @@
1/**
2 * @file osc.h
3 *
4 * OSC (Operating System Command) sequence parser and command handling.
5 */
6
7#ifndef GHOSTTY_VT_OSC_H
8#define GHOSTTY_VT_OSC_H
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <ghostty/vt/result.h>
14#include <ghostty/vt/allocator.h>
15
16/**
17 * Opaque handle to an OSC parser instance.
18 *
19 * This handle represents an OSC (Operating System Command) parser that can
20 * be used to parse the contents of OSC sequences.
21 *
22 * @ingroup osc
23 */
24typedef struct GhosttyOscParser *GhosttyOscParser;
25
26/**
27 * Opaque handle to a single OSC command.
28 *
29 * This handle represents a parsed OSC (Operating System Command) command.
30 * The command can be queried for its type and associated data.
31 *
32 * @ingroup osc
33 */
34typedef struct GhosttyOscCommand *GhosttyOscCommand;
35
36/** @defgroup osc OSC Parser
37 *
38 * OSC (Operating System Command) sequence parser and command handling.
39 *
40 * The parser operates in a streaming fashion, processing input byte-by-byte
41 * to handle OSC sequences that may arrive in fragments across multiple reads.
42 * This interface makes it easy to integrate into most environments and avoids
43 * over-allocating buffers.
44 *
45 * ## Basic Usage
46 *
47 * 1. Create a parser instance with ghostty_osc_new()
48 * 2. Feed bytes to the parser using ghostty_osc_next()
49 * 3. Finalize parsing with ghostty_osc_end() to get the command
50 * 4. Query command type and extract data using ghostty_osc_command_type()
51 * and ghostty_osc_command_data()
52 * 5. Free the parser with ghostty_osc_free() when done
53 *
54 * @{
55 */
56
57/**
58 * OSC command types.
59 *
60 * @ingroup osc
61 */
62typedef enum {
63 GHOSTTY_OSC_COMMAND_INVALID = 0,
64 GHOSTTY_OSC_COMMAND_CHANGE_WINDOW_TITLE = 1,
65 GHOSTTY_OSC_COMMAND_CHANGE_WINDOW_ICON = 2,
66 GHOSTTY_OSC_COMMAND_SEMANTIC_PROMPT = 3,
67 GHOSTTY_OSC_COMMAND_CLIPBOARD_CONTENTS = 4,
68 GHOSTTY_OSC_COMMAND_REPORT_PWD = 5,
69 GHOSTTY_OSC_COMMAND_MOUSE_SHAPE = 6,
70 GHOSTTY_OSC_COMMAND_COLOR_OPERATION = 7,
71 GHOSTTY_OSC_COMMAND_KITTY_COLOR_PROTOCOL = 8,
72 GHOSTTY_OSC_COMMAND_SHOW_DESKTOP_NOTIFICATION = 9,
73 GHOSTTY_OSC_COMMAND_HYPERLINK_START = 10,
74 GHOSTTY_OSC_COMMAND_HYPERLINK_END = 11,
75 GHOSTTY_OSC_COMMAND_CONEMU_SLEEP = 12,
76 GHOSTTY_OSC_COMMAND_CONEMU_SHOW_MESSAGE_BOX = 13,
77 GHOSTTY_OSC_COMMAND_CONEMU_CHANGE_TAB_TITLE = 14,
78 GHOSTTY_OSC_COMMAND_CONEMU_PROGRESS_REPORT = 15,
79 GHOSTTY_OSC_COMMAND_CONEMU_WAIT_INPUT = 16,
80 GHOSTTY_OSC_COMMAND_CONEMU_GUIMACRO = 17,
81 GHOSTTY_OSC_COMMAND_CONEMU_RUN_PROCESS = 18,
82 GHOSTTY_OSC_COMMAND_CONEMU_OUTPUT_ENVIRONMENT_VARIABLE = 19,
83 GHOSTTY_OSC_COMMAND_CONEMU_XTERM_EMULATION = 20,
84 GHOSTTY_OSC_COMMAND_CONEMU_COMMENT = 21,
85 GHOSTTY_OSC_COMMAND_KITTY_TEXT_SIZING = 22,
86} GhosttyOscCommandType;
87
88/**
89 * OSC command data types.
90 *
91 * These values specify what type of data to extract from an OSC command
92 * using `ghostty_osc_command_data`.
93 *
94 * @ingroup osc
95 */
96typedef enum {
97 /** Invalid data type. Never results in any data extraction. */
98 GHOSTTY_OSC_DATA_INVALID = 0,
99
100 /**
101 * Window title string data.
102 *
103 * Valid for: GHOSTTY_OSC_COMMAND_CHANGE_WINDOW_TITLE
104 *
105 * Output type: const char ** (pointer to null-terminated string)
106 *
107 * Lifetime: Valid until the next call to any ghostty_osc_* function with
108 * the same parser instance. Memory is owned by the parser.
109 */
110 GHOSTTY_OSC_DATA_CHANGE_WINDOW_TITLE_STR = 1,
111} GhosttyOscCommandData;
112
113/**
114 * Create a new OSC parser instance.
115 *
116 * Creates a new OSC (Operating System Command) parser using the provided
117 * allocator. The parser must be freed using ghostty_vt_osc_free() when
118 * no longer needed.
119 *
120 * @param allocator Pointer to the allocator to use for memory management, or NULL to use the default allocator
121 * @param parser Pointer to store the created parser handle
122 * @return GHOSTTY_SUCCESS on success, or an error code on failure
123 *
124 * @ingroup osc
125 */
126GhosttyResult ghostty_osc_new(const GhosttyAllocator *allocator, GhosttyOscParser *parser);
127
128/**
129 * Free an OSC parser instance.
130 *
131 * Releases all resources associated with the OSC parser. After this call,
132 * the parser handle becomes invalid and must not be used.
133 *
134 * @param parser The parser handle to free (may be NULL)
135 *
136 * @ingroup osc
137 */
138void ghostty_osc_free(GhosttyOscParser parser);
139
140/**
141 * Reset an OSC parser instance to its initial state.
142 *
143 * Resets the parser state, clearing any partially parsed OSC sequences
144 * and returning the parser to its initial state. This is useful for
145 * reusing a parser instance or recovering from parse errors.
146 *
147 * @param parser The parser handle to reset, must not be null.
148 *
149 * @ingroup osc
150 */
151void ghostty_osc_reset(GhosttyOscParser parser);
152
153/**
154 * Parse the next byte in an OSC sequence.
155 *
156 * Processes a single byte as part of an OSC sequence. The parser maintains
157 * internal state to track the progress through the sequence. Call this
158 * function for each byte in the sequence data.
159 *
160 * When finished pumping the parser with bytes, call ghostty_osc_end
161 * to get the final result.
162 *
163 * @param parser The parser handle, must not be null.
164 * @param byte The next byte to parse
165 *
166 * @ingroup osc
167 */
168void ghostty_osc_next(GhosttyOscParser parser, uint8_t byte);
169
170/**
171 * Finalize OSC parsing and retrieve the parsed command.
172 *
173 * Call this function after feeding all bytes of an OSC sequence to the parser
174 * using ghostty_osc_next() with the exception of the terminating character
175 * (ESC or ST). This function finalizes the parsing process and returns the
176 * parsed OSC command.
177 *
178 * The return value is never NULL. Invalid commands will return a command
179 * with type GHOSTTY_OSC_COMMAND_INVALID.
180 *
181 * The terminator parameter specifies the byte that terminated the OSC sequence
182 * (typically 0x07 for BEL or 0x5C for ST after ESC). This information is
183 * preserved in the parsed command so that responses can use the same terminator
184 * format for better compatibility with the calling program. For commands that
185 * do not require a response, this parameter is ignored and the resulting
186 * command will not retain the terminator information.
187 *
188 * The returned command handle is valid until the next call to any
189 * `ghostty_osc_*` function with the same parser instance with the exception
190 * of command introspection functions such as `ghostty_osc_command_type`.
191 *
192 * @param parser The parser handle, must not be null.
193 * @param terminator The terminating byte of the OSC sequence (0x07 for BEL, 0x5C for ST)
194 * @return Handle to the parsed OSC command
195 *
196 * @ingroup osc
197 */
198GhosttyOscCommand ghostty_osc_end(GhosttyOscParser parser, uint8_t terminator);
199
200/**
201 * Get the type of an OSC command.
202 *
203 * Returns the type identifier for the given OSC command. This can be used
204 * to determine what kind of command was parsed and what data might be
205 * available from it.
206 *
207 * @param command The OSC command handle to query (may be NULL)
208 * @return The command type, or GHOSTTY_OSC_COMMAND_INVALID if command is NULL
209 *
210 * @ingroup osc
211 */
212GhosttyOscCommandType ghostty_osc_command_type(GhosttyOscCommand command);
213
214/**
215 * Extract data from an OSC command.
216 *
217 * Extracts typed data from the given OSC command based on the specified
218 * data type. The output pointer must be of the appropriate type for the
219 * requested data kind. Valid command types, output types, and memory
220 * safety information are documented in the `GhosttyOscCommandData` enum.
221 *
222 * @param command The OSC command handle to query (may be NULL)
223 * @param data The type of data to extract
224 * @param out Pointer to store the extracted data (type depends on data parameter)
225 * @return true if data extraction was successful, false otherwise
226 *
227 * @ingroup osc
228 */
229bool ghostty_osc_command_data(GhosttyOscCommand command, GhosttyOscCommandData data, void *out);
230
231/** @} */
232
233#endif /* GHOSTTY_VT_OSC_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/paste.h+75−0
@@ -0,0 +1,75 @@
1/**
2 * @file paste.h
3 *
4 * Paste utilities - validate and encode paste data for terminal input.
5 */
6
7#ifndef GHOSTTY_VT_PASTE_H
8#define GHOSTTY_VT_PASTE_H
9
10/** @defgroup paste Paste Utilities
11 *
12 * Utilities for validating paste data safety.
13 *
14 * ## Basic Usage
15 *
16 * Use ghostty_paste_is_safe() to check if paste data contains potentially
17 * dangerous sequences before sending it to the terminal.
18 *
19 * ## Example
20 *
21 * @code{.c}
22 * #include <stdio.h>
23 * #include <string.h>
24 * #include <ghostty/vt.h>
25 *
26 * int main() {
27 * const char* safe_data = "hello world";
28 * const char* unsafe_data = "rm -rf /\n";
29 *
30 * if (ghostty_paste_is_safe(safe_data, strlen(safe_data))) {
31 * printf("Safe to paste\n");
32 * }
33 *
34 * if (!ghostty_paste_is_safe(unsafe_data, strlen(unsafe_data))) {
35 * printf("Unsafe! Contains newline\n");
36 * }
37 *
38 * return 0;
39 * }
40 * @endcode
41 *
42 * @{
43 */
44
45#include <stdbool.h>
46#include <stddef.h>
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/**
53 * Check if paste data is safe to paste into the terminal.
54 *
55 * Data is considered unsafe if it contains:
56 * - Newlines (`\n`) which can inject commands
57 * - The bracketed paste end sequence (`\x1b[201~`) which can be used
58 * to exit bracketed paste mode and inject commands
59 *
60 * This check is conservative and considers data unsafe regardless of
61 * current terminal state.
62 *
63 * @param data The paste data to check (must not be NULL)
64 * @param len The length of the data in bytes
65 * @return true if the data is safe to paste, false otherwise
66 */
67bool ghostty_paste_is_safe(const char* data, size_t len);
68
69#ifdef __cplusplus
70}
71#endif
72
73/** @} */
74
75#endif /* GHOSTTY_VT_PASTE_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/result.h+22−0
@@ -0,0 +1,22 @@
1/**
2 * @file result.h
3 *
4 * Result codes for libghostty-vt operations.
5 */
6
7#ifndef GHOSTTY_VT_RESULT_H
8#define GHOSTTY_VT_RESULT_H
9
10/**
11 * Result codes for libghostty-vt operations.
12 */
13typedef enum {
14 /** Operation completed successfully */
15 GHOSTTY_SUCCESS = 0,
16 /** Operation failed due to failed allocation */
17 GHOSTTY_OUT_OF_MEMORY = -1,
18 /** Operation failed due to invalid value */
19 GHOSTTY_INVALID_VALUE = -2,
20} GhosttyResult;
21
22#endif /* GHOSTTY_VT_RESULT_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/sgr.h+394−0
@@ -0,0 +1,394 @@
1/**
2 * @file sgr.h
3 *
4 * SGR (Select Graphic Rendition) attribute parsing and handling.
5 */
6
7#ifndef GHOSTTY_VT_SGR_H
8#define GHOSTTY_VT_SGR_H
9
10/** @defgroup sgr SGR Parser
11 *
12 * SGR (Select Graphic Rendition) attribute parser.
13 *
14 * SGR sequences are the syntax used to set styling attributes such as
15 * bold, italic, underline, and colors for text in terminal emulators.
16 * For example, you may be familiar with sequences like `ESC[1;31m`. The
17 * `1;31` is the SGR attribute list.
18 *
19 * The parser processes SGR parameters from CSI sequences (e.g., `ESC[1;31m`)
20 * and returns individual text attributes like bold, italic, colors, etc.
21 * It supports both semicolon (`;`) and colon (`:`) separators, possibly mixed,
22 * and handles various color formats including 8-color, 16-color, 256-color,
23 * X11 named colors, and RGB in multiple formats.
24 *
25 * ## Basic Usage
26 *
27 * 1. Create a parser instance with ghostty_sgr_new()
28 * 2. Set SGR parameters with ghostty_sgr_set_params()
29 * 3. Iterate through attributes using ghostty_sgr_next()
30 * 4. Free the parser with ghostty_sgr_free() when done
31 *
32 * ## Example
33 *
34 * @code{.c}
35 * #include <assert.h>
36 * #include <stdio.h>
37 * #include <ghostty/vt.h>
38 *
39 * int main() {
40 * // Create parser
41 * GhosttySgrParser parser;
42 * GhosttyResult result = ghostty_sgr_new(NULL, &parser);
43 * assert(result == GHOSTTY_SUCCESS);
44 *
45 * // Parse "bold, red foreground" sequence: ESC[1;31m
46 * uint16_t params[] = {1, 31};
47 * result = ghostty_sgr_set_params(parser, params, NULL, 2);
48 * assert(result == GHOSTTY_SUCCESS);
49 *
50 * // Iterate through attributes
51 * GhosttySgrAttribute attr;
52 * while (ghostty_sgr_next(parser, &attr)) {
53 * switch (attr.tag) {
54 * case GHOSTTY_SGR_ATTR_BOLD:
55 * printf("Bold enabled\n");
56 * break;
57 * case GHOSTTY_SGR_ATTR_FG_8:
58 * printf("Foreground color: %d\n", attr.value.fg_8);
59 * break;
60 * default:
61 * break;
62 * }
63 * }
64 *
65 * // Cleanup
66 * ghostty_sgr_free(parser);
67 * return 0;
68 * }
69 * @endcode
70 *
71 * @{
72 */
73
74#include <ghostty/vt/allocator.h>
75#include <ghostty/vt/color.h>
76#include <ghostty/vt/result.h>
77#include <stdbool.h>
78#include <stddef.h>
79#include <stdint.h>
80
81#ifdef __cplusplus
82extern "C" {
83#endif
84
85/**
86 * Opaque handle to an SGR parser instance.
87 *
88 * This handle represents an SGR (Select Graphic Rendition) parser that can
89 * be used to parse SGR sequences and extract individual text attributes.
90 *
91 * @ingroup sgr
92 */
93typedef struct GhosttySgrParser* GhosttySgrParser;
94
95/**
96 * SGR attribute tags.
97 *
98 * These values identify the type of an SGR attribute in a tagged union.
99 * Use the tag to determine which field in the attribute value union to access.
100 *
101 * @ingroup sgr
102 */
103typedef enum {
104 GHOSTTY_SGR_ATTR_UNSET = 0,
105 GHOSTTY_SGR_ATTR_UNKNOWN = 1,
106 GHOSTTY_SGR_ATTR_BOLD = 2,
107 GHOSTTY_SGR_ATTR_RESET_BOLD = 3,
108 GHOSTTY_SGR_ATTR_ITALIC = 4,
109 GHOSTTY_SGR_ATTR_RESET_ITALIC = 5,
110 GHOSTTY_SGR_ATTR_FAINT = 6,
111 GHOSTTY_SGR_ATTR_UNDERLINE = 7,
112 GHOSTTY_SGR_ATTR_RESET_UNDERLINE = 8,
113 GHOSTTY_SGR_ATTR_UNDERLINE_COLOR = 9,
114 GHOSTTY_SGR_ATTR_UNDERLINE_COLOR_256 = 10,
115 GHOSTTY_SGR_ATTR_RESET_UNDERLINE_COLOR = 11,
116 GHOSTTY_SGR_ATTR_OVERLINE = 12,
117 GHOSTTY_SGR_ATTR_RESET_OVERLINE = 13,
118 GHOSTTY_SGR_ATTR_BLINK = 14,
119 GHOSTTY_SGR_ATTR_RESET_BLINK = 15,
120 GHOSTTY_SGR_ATTR_INVERSE = 16,
121 GHOSTTY_SGR_ATTR_RESET_INVERSE = 17,
122 GHOSTTY_SGR_ATTR_INVISIBLE = 18,
123 GHOSTTY_SGR_ATTR_RESET_INVISIBLE = 19,
124 GHOSTTY_SGR_ATTR_STRIKETHROUGH = 20,
125 GHOSTTY_SGR_ATTR_RESET_STRIKETHROUGH = 21,
126 GHOSTTY_SGR_ATTR_DIRECT_COLOR_FG = 22,
127 GHOSTTY_SGR_ATTR_DIRECT_COLOR_BG = 23,
128 GHOSTTY_SGR_ATTR_BG_8 = 24,
129 GHOSTTY_SGR_ATTR_FG_8 = 25,
130 GHOSTTY_SGR_ATTR_RESET_FG = 26,
131 GHOSTTY_SGR_ATTR_RESET_BG = 27,
132 GHOSTTY_SGR_ATTR_BRIGHT_BG_8 = 28,
133 GHOSTTY_SGR_ATTR_BRIGHT_FG_8 = 29,
134 GHOSTTY_SGR_ATTR_BG_256 = 30,
135 GHOSTTY_SGR_ATTR_FG_256 = 31,
136} GhosttySgrAttributeTag;
137
138/**
139 * Underline style types.
140 *
141 * @ingroup sgr
142 */
143typedef enum {
144 GHOSTTY_SGR_UNDERLINE_NONE = 0,
145 GHOSTTY_SGR_UNDERLINE_SINGLE = 1,
146 GHOSTTY_SGR_UNDERLINE_DOUBLE = 2,
147 GHOSTTY_SGR_UNDERLINE_CURLY = 3,
148 GHOSTTY_SGR_UNDERLINE_DOTTED = 4,
149 GHOSTTY_SGR_UNDERLINE_DASHED = 5,
150} GhosttySgrUnderline;
151
152/**
153 * Unknown SGR attribute data.
154 *
155 * Contains the full parameter list and the partial list where parsing
156 * encountered an unknown or invalid sequence.
157 *
158 * @ingroup sgr
159 */
160typedef struct {
161 const uint16_t* full_ptr;
162 size_t full_len;
163 const uint16_t* partial_ptr;
164 size_t partial_len;
165} GhosttySgrUnknown;
166
167/**
168 * SGR attribute value union.
169 *
170 * This union contains all possible attribute values. Use the tag field
171 * to determine which union member is active. Attributes without associated
172 * data (like bold, italic) don't use the union value.
173 *
174 * @ingroup sgr
175 */
176typedef union {
177 GhosttySgrUnknown unknown;
178 GhosttySgrUnderline underline;
179 GhosttyColorRgb underline_color;
180 GhosttyColorPaletteIndex underline_color_256;
181 GhosttyColorRgb direct_color_fg;
182 GhosttyColorRgb direct_color_bg;
183 GhosttyColorPaletteIndex bg_8;
184 GhosttyColorPaletteIndex fg_8;
185 GhosttyColorPaletteIndex bright_bg_8;
186 GhosttyColorPaletteIndex bright_fg_8;
187 GhosttyColorPaletteIndex bg_256;
188 GhosttyColorPaletteIndex fg_256;
189 uint64_t _padding[8];
190} GhosttySgrAttributeValue;
191
192/**
193 * SGR attribute (tagged union).
194 *
195 * A complete SGR attribute with both its type tag and associated value.
196 * Always check the tag field to determine which value union member is valid.
197 *
198 * Attributes without associated data (e.g., GHOSTTY_SGR_ATTR_BOLD) can be
199 * identified by tag alone; the value union is not used for these and
200 * the memory in the value field is undefined.
201 *
202 * @ingroup sgr
203 */
204typedef struct {
205 GhosttySgrAttributeTag tag;
206 GhosttySgrAttributeValue value;
207} GhosttySgrAttribute;
208
209/**
210 * Create a new SGR parser instance.
211 *
212 * Creates a new SGR (Select Graphic Rendition) parser using the provided
213 * allocator. The parser must be freed using ghostty_sgr_free() when
214 * no longer needed.
215 *
216 * @param allocator Pointer to the allocator to use for memory management, or
217 * NULL to use the default allocator
218 * @param parser Pointer to store the created parser handle
219 * @return GHOSTTY_SUCCESS on success, or an error code on failure
220 *
221 * @ingroup sgr
222 */
223GhosttyResult ghostty_sgr_new(const GhosttyAllocator* allocator,
224 GhosttySgrParser* parser);
225
226/**
227 * Free an SGR parser instance.
228 *
229 * Releases all resources associated with the SGR parser. After this call,
230 * the parser handle becomes invalid and must not be used. This includes
231 * any attributes previously returned by ghostty_sgr_next().
232 *
233 * @param parser The parser handle to free (may be NULL)
234 *
235 * @ingroup sgr
236 */
237void ghostty_sgr_free(GhosttySgrParser parser);
238
239/**
240 * Reset an SGR parser instance to the beginning of the parameter list.
241 *
242 * Resets the parser's iteration state without clearing the parameters.
243 * After calling this, ghostty_sgr_next() will start from the beginning
244 * of the parameter list again.
245 *
246 * @param parser The parser handle to reset, must not be NULL
247 *
248 * @ingroup sgr
249 */
250void ghostty_sgr_reset(GhosttySgrParser parser);
251
252/**
253 * Set SGR parameters for parsing.
254 *
255 * Sets the SGR parameter list to parse. Parameters are the numeric values
256 * from a CSI SGR sequence (e.g., for `ESC[1;31m`, params would be {1, 31}).
257 *
258 * The separators array optionally specifies the separator type for each
259 * parameter position. Each byte should be either ';' for semicolon or ':'
260 * for colon. This is needed for certain color formats that use colon
261 * separators (e.g., `ESC[4:3m` for curly underline). Any invalid separator
262 * values are treated as semicolons. The separators array must have the same
263 * length as the params array, if it is not NULL.
264 *
265 * If separators is NULL, all parameters are assumed to be semicolon-separated.
266 *
267 * This function makes an internal copy of the parameter and separator data,
268 * so the caller can safely free or modify the input arrays after this call.
269 *
270 * After calling this function, the parser is automatically reset and ready
271 * to iterate from the beginning.
272 *
273 * @param parser The parser handle, must not be NULL
274 * @param params Array of SGR parameter values
275 * @param separators Optional array of separator characters (';' or ':'), or
276 * NULL
277 * @param len Number of parameters (and separators if provided)
278 * @return GHOSTTY_SUCCESS on success, or an error code on failure
279 *
280 * @ingroup sgr
281 */
282GhosttyResult ghostty_sgr_set_params(GhosttySgrParser parser,
283 const uint16_t* params,
284 const char* separators,
285 size_t len);
286
287/**
288 * Get the next SGR attribute.
289 *
290 * Parses and returns the next attribute from the parameter list.
291 * Call this function repeatedly until it returns false to process
292 * all attributes in the sequence.
293 *
294 * @param parser The parser handle, must not be NULL
295 * @param attr Pointer to store the next attribute
296 * @return true if an attribute was returned, false if no more attributes
297 *
298 * @ingroup sgr
299 */
300bool ghostty_sgr_next(GhosttySgrParser parser, GhosttySgrAttribute* attr);
301
302/**
303 * Get the full parameter list from an unknown SGR attribute.
304 *
305 * This function retrieves the full parameter list that was provided to the
306 * parser when an unknown attribute was encountered. Primarily useful in
307 * WebAssembly environments where accessing struct fields directly is difficult.
308 *
309 * @param unknown The unknown attribute data
310 * @param ptr Pointer to store the pointer to the parameter array (may be NULL)
311 * @return The length of the full parameter array
312 *
313 * @ingroup sgr
314 */
315size_t ghostty_sgr_unknown_full(GhosttySgrUnknown unknown,
316 const uint16_t** ptr);
317
318/**
319 * Get the partial parameter list from an unknown SGR attribute.
320 *
321 * This function retrieves the partial parameter list where parsing stopped
322 * when an unknown attribute was encountered. Primarily useful in WebAssembly
323 * environments where accessing struct fields directly is difficult.
324 *
325 * @param unknown The unknown attribute data
326 * @param ptr Pointer to store the pointer to the parameter array (may be NULL)
327 * @return The length of the partial parameter array
328 *
329 * @ingroup sgr
330 */
331size_t ghostty_sgr_unknown_partial(GhosttySgrUnknown unknown,
332 const uint16_t** ptr);
333
334/**
335 * Get the tag from an SGR attribute.
336 *
337 * This function extracts the tag that identifies which type of attribute
338 * this is. Primarily useful in WebAssembly environments where accessing
339 * struct fields directly is difficult.
340 *
341 * @param attr The SGR attribute
342 * @return The attribute tag
343 *
344 * @ingroup sgr
345 */
346GhosttySgrAttributeTag ghostty_sgr_attribute_tag(GhosttySgrAttribute attr);
347
348/**
349 * Get the value from an SGR attribute.
350 *
351 * This function returns a pointer to the value union from an SGR attribute. Use
352 * the tag to determine which field of the union is valid. Primarily useful in
353 * WebAssembly environments where accessing struct fields directly is difficult.
354 *
355 * @param attr Pointer to the SGR attribute
356 * @return Pointer to the attribute value union
357 *
358 * @ingroup sgr
359 */
360GhosttySgrAttributeValue* ghostty_sgr_attribute_value(
361 GhosttySgrAttribute* attr);
362
363#ifdef __wasm__
364/**
365 * Allocate memory for an SGR attribute (WebAssembly only).
366 *
367 * This is a convenience function for WebAssembly environments to allocate
368 * memory for an SGR attribute structure that can be passed to ghostty_sgr_next.
369 *
370 * @return Pointer to the allocated attribute structure
371 *
372 * @ingroup wasm
373 */
374GhosttySgrAttribute* ghostty_wasm_alloc_sgr_attribute(void);
375
376/**
377 * Free memory for an SGR attribute (WebAssembly only).
378 *
379 * Frees memory allocated by ghostty_wasm_alloc_sgr_attribute.
380 *
381 * @param attr Pointer to the attribute structure to free
382 *
383 * @ingroup wasm
384 */
385void ghostty_wasm_free_sgr_attribute(GhosttySgrAttribute* attr);
386#endif
387
388#ifdef __cplusplus
389}
390#endif
391
392/** @} */
393
394#endif /* GHOSTTY_VT_SGR_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/ghostty/vt/wasm.h+159−0
@@ -0,0 +1,159 @@
1/**
2 * @file wasm.h
3 *
4 * WebAssembly utility functions for libghostty-vt.
5 */
6
7#ifndef GHOSTTY_VT_WASM_H
8#define GHOSTTY_VT_WASM_H
9
10#ifdef __wasm__
11
12#include <stddef.h>
13#include <stdint.h>
14
15/** @defgroup wasm WebAssembly Utilities
16 *
17 * Convenience functions for allocating various types in WebAssembly builds.
18 * **These are only available the libghostty-vt wasm module.**
19 *
20 * Ghostty relies on pointers to various types for ABI compatibility, and
21 * creating those pointers in Wasm can be tedious. These functions provide
22 * a purely additive set of utilities that simplify memory management in
23 * Wasm environments without changing the core C library API.
24 *
25 * @note These functions always use the default allocator. If you need
26 * custom allocation strategies, you should allocate types manually using
27 * your custom allocator. This is a very rare use case in the WebAssembly
28 * world so these are optimized for simplicity.
29 *
30 * ## Example Usage
31 *
32 * Here's a simple example of using the Wasm utilities with the key encoder:
33 *
34 * @code
35 * const { exports } = wasmInstance;
36 * const view = new DataView(wasmMemory.buffer);
37 *
38 * // Create key encoder
39 * const encoderPtr = exports.ghostty_wasm_alloc_opaque();
40 * exports.ghostty_key_encoder_new(null, encoderPtr);
41 * const encoder = view.getUint32(encoder, true);
42 *
43 * // Configure encoder with Kitty protocol flags
44 * const flagsPtr = exports.ghostty_wasm_alloc_u8();
45 * view.setUint8(flagsPtr, 0x1F);
46 * exports.ghostty_key_encoder_setopt(encoder, 5, flagsPtr);
47 *
48 * // Allocate output buffer and size pointer
49 * const bufferSize = 32;
50 * const bufPtr = exports.ghostty_wasm_alloc_u8_array(bufferSize);
51 * const writtenPtr = exports.ghostty_wasm_alloc_usize();
52 *
53 * // Encode the key event
54 * exports.ghostty_key_encoder_encode(
55 * encoder, eventPtr, bufPtr, bufferSize, writtenPtr
56 * );
57 *
58 * // Read encoded output
59 * const bytesWritten = view.getUint32(writtenPtr, true);
60 * const encoded = new Uint8Array(wasmMemory.buffer, bufPtr, bytesWritten);
61 * @endcode
62 *
63 * @remark The code above is pretty ugly! This is the lowest level interface
64 * to the libghostty-vt Wasm module. In practice, this should be wrapped
65 * in a higher-level API that abstracts away all this.
66 *
67 * @{
68 */
69
70/**
71 * Allocate an opaque pointer. This can be used for any opaque pointer
72 * types such as GhosttyKeyEncoder, GhosttyKeyEvent, etc.
73 *
74 * @return Pointer to allocated opaque pointer, or NULL if allocation failed
75 * @ingroup wasm
76 */
77void** ghostty_wasm_alloc_opaque(void);
78
79/**
80 * Free an opaque pointer allocated by ghostty_wasm_alloc_opaque().
81 *
82 * @param ptr Pointer to free, or NULL (NULL is safely ignored)
83 * @ingroup wasm
84 */
85void ghostty_wasm_free_opaque(void **ptr);
86
87/**
88 * Allocate an array of uint8_t values.
89 *
90 * @param len Number of uint8_t elements to allocate
91 * @return Pointer to allocated array, or NULL if allocation failed
92 * @ingroup wasm
93 */
94uint8_t* ghostty_wasm_alloc_u8_array(size_t len);
95
96/**
97 * Free an array allocated by ghostty_wasm_alloc_u8_array().
98 *
99 * @param ptr Pointer to the array to free, or NULL (NULL is safely ignored)
100 * @param len Length of the array (must match the length passed to alloc)
101 * @ingroup wasm
102 */
103void ghostty_wasm_free_u8_array(uint8_t *ptr, size_t len);
104
105/**
106 * Allocate an array of uint16_t values.
107 *
108 * @param len Number of uint16_t elements to allocate
109 * @return Pointer to allocated array, or NULL if allocation failed
110 * @ingroup wasm
111 */
112uint16_t* ghostty_wasm_alloc_u16_array(size_t len);
113
114/**
115 * Free an array allocated by ghostty_wasm_alloc_u16_array().
116 *
117 * @param ptr Pointer to the array to free, or NULL (NULL is safely ignored)
118 * @param len Length of the array (must match the length passed to alloc)
119 * @ingroup wasm
120 */
121void ghostty_wasm_free_u16_array(uint16_t *ptr, size_t len);
122
123/**
124 * Allocate a single uint8_t value.
125 *
126 * @return Pointer to allocated uint8_t, or NULL if allocation failed
127 * @ingroup wasm
128 */
129uint8_t* ghostty_wasm_alloc_u8(void);
130
131/**
132 * Free a uint8_t allocated by ghostty_wasm_alloc_u8().
133 *
134 * @param ptr Pointer to free, or NULL (NULL is safely ignored)
135 * @ingroup wasm
136 */
137void ghostty_wasm_free_u8(uint8_t *ptr);
138
139/**
140 * Allocate a single size_t value.
141 *
142 * @return Pointer to allocated size_t, or NULL if allocation failed
143 * @ingroup wasm
144 */
145size_t* ghostty_wasm_alloc_usize(void);
146
147/**
148 * Free a size_t allocated by ghostty_wasm_alloc_usize().
149 *
150 * @param ptr Pointer to free, or NULL (NULL is safely ignored)
151 * @ingroup wasm
152 */
153void ghostty_wasm_free_usize(size_t *ptr);
154
155/** @} */
156
157#endif /* __wasm__ */
158
159#endif /* GHOSTTY_VT_WASM_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/Headers/module.modulemap+7−0
@@ -0,0 +1,7 @@
1// This makes Ghostty available to the XCode build for the macOS app.
2// We append "Kit" to it not to be cute, but because targets have to have
3// unique names and we use Ghostty for other things.
4module GhosttyKit {
5 umbrella header "ghostty.h"
6 export *
7}
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64-simulator/libghostty-fat.a+0−0

Binary file not shown.

apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty.h+1187−0
@@ -0,0 +1,1187 @@
1// Ghostty embedding API. The documentation for the embedding API is
2// only within the Zig source files that define the implementations. This
3// isn't meant to be a general purpose embedding API (yet) so there hasn't
4// been documentation or example work beyond that.
5//
6// The only consumer of this API is the macOS app, but the API is built to
7// be more general purpose.
8#ifndef GHOSTTY_H
9#define GHOSTTY_H
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <stdbool.h>
16#include <stddef.h>
17#include <stdint.h>
18#include <sys/types.h>
19
20//-------------------------------------------------------------------
21// Macros
22
23#define GHOSTTY_SUCCESS 0
24
25//-------------------------------------------------------------------
26// Types
27
28// Opaque types
29typedef void* ghostty_app_t;
30typedef void* ghostty_config_t;
31typedef void* ghostty_surface_t;
32typedef void* ghostty_inspector_t;
33
34// All the types below are fully defined and must be kept in sync with
35// their Zig counterparts. Any changes to these types MUST have an associated
36// Zig change.
37typedef enum {
38 GHOSTTY_PLATFORM_INVALID,
39 GHOSTTY_PLATFORM_MACOS,
40 GHOSTTY_PLATFORM_IOS,
41} ghostty_platform_e;
42
43// Callback for custom I/O write handler.
44typedef void (*ghostty_surface_write_fn)(void* userdata,
45 const uint8_t* data,
46 size_t len);
47
48typedef enum {
49 GHOSTTY_CLIPBOARD_STANDARD,
50 GHOSTTY_CLIPBOARD_SELECTION,
51} ghostty_clipboard_e;
52
53typedef struct {
54 const char *mime;
55 const char *data;
56} ghostty_clipboard_content_s;
57
58typedef enum {
59 GHOSTTY_CLIPBOARD_REQUEST_PASTE,
60 GHOSTTY_CLIPBOARD_REQUEST_OSC_52_READ,
61 GHOSTTY_CLIPBOARD_REQUEST_OSC_52_WRITE,
62} ghostty_clipboard_request_e;
63
64typedef enum {
65 GHOSTTY_MOUSE_RELEASE,
66 GHOSTTY_MOUSE_PRESS,
67} ghostty_input_mouse_state_e;
68
69typedef enum {
70 GHOSTTY_MOUSE_UNKNOWN,
71 GHOSTTY_MOUSE_LEFT,
72 GHOSTTY_MOUSE_RIGHT,
73 GHOSTTY_MOUSE_MIDDLE,
74 GHOSTTY_MOUSE_FOUR,
75 GHOSTTY_MOUSE_FIVE,
76 GHOSTTY_MOUSE_SIX,
77 GHOSTTY_MOUSE_SEVEN,
78 GHOSTTY_MOUSE_EIGHT,
79 GHOSTTY_MOUSE_NINE,
80 GHOSTTY_MOUSE_TEN,
81 GHOSTTY_MOUSE_ELEVEN,
82} ghostty_input_mouse_button_e;
83
84typedef enum {
85 GHOSTTY_MOUSE_MOMENTUM_NONE,
86 GHOSTTY_MOUSE_MOMENTUM_BEGAN,
87 GHOSTTY_MOUSE_MOMENTUM_STATIONARY,
88 GHOSTTY_MOUSE_MOMENTUM_CHANGED,
89 GHOSTTY_MOUSE_MOMENTUM_ENDED,
90 GHOSTTY_MOUSE_MOMENTUM_CANCELLED,
91 GHOSTTY_MOUSE_MOMENTUM_MAY_BEGIN,
92} ghostty_input_mouse_momentum_e;
93
94typedef enum {
95 GHOSTTY_COLOR_SCHEME_LIGHT = 0,
96 GHOSTTY_COLOR_SCHEME_DARK = 1,
97} ghostty_color_scheme_e;
98
99// This is a packed struct (see src/input/mouse.zig) but the C standard
100// afaik doesn't let us reliably define packed structs so we build it up
101// from scratch.
102typedef int ghostty_input_scroll_mods_t;
103
104typedef enum {
105 GHOSTTY_MODS_NONE = 0,
106 GHOSTTY_MODS_SHIFT = 1 << 0,
107 GHOSTTY_MODS_CTRL = 1 << 1,
108 GHOSTTY_MODS_ALT = 1 << 2,
109 GHOSTTY_MODS_SUPER = 1 << 3,
110 GHOSTTY_MODS_CAPS = 1 << 4,
111 GHOSTTY_MODS_NUM = 1 << 5,
112 GHOSTTY_MODS_SHIFT_RIGHT = 1 << 6,
113 GHOSTTY_MODS_CTRL_RIGHT = 1 << 7,
114 GHOSTTY_MODS_ALT_RIGHT = 1 << 8,
115 GHOSTTY_MODS_SUPER_RIGHT = 1 << 9,
116} ghostty_input_mods_e;
117
118typedef enum {
119 GHOSTTY_BINDING_FLAGS_CONSUMED = 1 << 0,
120 GHOSTTY_BINDING_FLAGS_ALL = 1 << 1,
121 GHOSTTY_BINDING_FLAGS_GLOBAL = 1 << 2,
122 GHOSTTY_BINDING_FLAGS_PERFORMABLE = 1 << 3,
123} ghostty_binding_flags_e;
124
125typedef enum {
126 GHOSTTY_ACTION_RELEASE,
127 GHOSTTY_ACTION_PRESS,
128 GHOSTTY_ACTION_REPEAT,
129} ghostty_input_action_e;
130
131// Based on: https://www.w3.org/TR/uievents-code/
132typedef enum {
133 GHOSTTY_KEY_UNIDENTIFIED,
134
135 // "Writing System Keys" § 3.1.1
136 GHOSTTY_KEY_BACKQUOTE,
137 GHOSTTY_KEY_BACKSLASH,
138 GHOSTTY_KEY_BRACKET_LEFT,
139 GHOSTTY_KEY_BRACKET_RIGHT,
140 GHOSTTY_KEY_COMMA,
141 GHOSTTY_KEY_DIGIT_0,
142 GHOSTTY_KEY_DIGIT_1,
143 GHOSTTY_KEY_DIGIT_2,
144 GHOSTTY_KEY_DIGIT_3,
145 GHOSTTY_KEY_DIGIT_4,
146 GHOSTTY_KEY_DIGIT_5,
147 GHOSTTY_KEY_DIGIT_6,
148 GHOSTTY_KEY_DIGIT_7,
149 GHOSTTY_KEY_DIGIT_8,
150 GHOSTTY_KEY_DIGIT_9,
151 GHOSTTY_KEY_EQUAL,
152 GHOSTTY_KEY_INTL_BACKSLASH,
153 GHOSTTY_KEY_INTL_RO,
154 GHOSTTY_KEY_INTL_YEN,
155 GHOSTTY_KEY_A,
156 GHOSTTY_KEY_B,
157 GHOSTTY_KEY_C,
158 GHOSTTY_KEY_D,
159 GHOSTTY_KEY_E,
160 GHOSTTY_KEY_F,
161 GHOSTTY_KEY_G,
162 GHOSTTY_KEY_H,
163 GHOSTTY_KEY_I,
164 GHOSTTY_KEY_J,
165 GHOSTTY_KEY_K,
166 GHOSTTY_KEY_L,
167 GHOSTTY_KEY_M,
168 GHOSTTY_KEY_N,
169 GHOSTTY_KEY_O,
170 GHOSTTY_KEY_P,
171 GHOSTTY_KEY_Q,
172 GHOSTTY_KEY_R,
173 GHOSTTY_KEY_S,
174 GHOSTTY_KEY_T,
175 GHOSTTY_KEY_U,
176 GHOSTTY_KEY_V,
177 GHOSTTY_KEY_W,
178 GHOSTTY_KEY_X,
179 GHOSTTY_KEY_Y,
180 GHOSTTY_KEY_Z,
181 GHOSTTY_KEY_MINUS,
182 GHOSTTY_KEY_PERIOD,
183 GHOSTTY_KEY_QUOTE,
184 GHOSTTY_KEY_SEMICOLON,
185 GHOSTTY_KEY_SLASH,
186
187 // "Functional Keys" § 3.1.2
188 GHOSTTY_KEY_ALT_LEFT,
189 GHOSTTY_KEY_ALT_RIGHT,
190 GHOSTTY_KEY_BACKSPACE,
191 GHOSTTY_KEY_CAPS_LOCK,
192 GHOSTTY_KEY_CONTEXT_MENU,
193 GHOSTTY_KEY_CONTROL_LEFT,
194 GHOSTTY_KEY_CONTROL_RIGHT,
195 GHOSTTY_KEY_ENTER,
196 GHOSTTY_KEY_META_LEFT,
197 GHOSTTY_KEY_META_RIGHT,
198 GHOSTTY_KEY_SHIFT_LEFT,
199 GHOSTTY_KEY_SHIFT_RIGHT,
200 GHOSTTY_KEY_SPACE,
201 GHOSTTY_KEY_TAB,
202 GHOSTTY_KEY_CONVERT,
203 GHOSTTY_KEY_KANA_MODE,
204 GHOSTTY_KEY_NON_CONVERT,
205
206 // "Control Pad Section" § 3.2
207 GHOSTTY_KEY_DELETE,
208 GHOSTTY_KEY_END,
209 GHOSTTY_KEY_HELP,
210 GHOSTTY_KEY_HOME,
211 GHOSTTY_KEY_INSERT,
212 GHOSTTY_KEY_PAGE_DOWN,
213 GHOSTTY_KEY_PAGE_UP,
214
215 // "Arrow Pad Section" § 3.3
216 GHOSTTY_KEY_ARROW_DOWN,
217 GHOSTTY_KEY_ARROW_LEFT,
218 GHOSTTY_KEY_ARROW_RIGHT,
219 GHOSTTY_KEY_ARROW_UP,
220
221 // "Numpad Section" § 3.4
222 GHOSTTY_KEY_NUM_LOCK,
223 GHOSTTY_KEY_NUMPAD_0,
224 GHOSTTY_KEY_NUMPAD_1,
225 GHOSTTY_KEY_NUMPAD_2,
226 GHOSTTY_KEY_NUMPAD_3,
227 GHOSTTY_KEY_NUMPAD_4,
228 GHOSTTY_KEY_NUMPAD_5,
229 GHOSTTY_KEY_NUMPAD_6,
230 GHOSTTY_KEY_NUMPAD_7,
231 GHOSTTY_KEY_NUMPAD_8,
232 GHOSTTY_KEY_NUMPAD_9,
233 GHOSTTY_KEY_NUMPAD_ADD,
234 GHOSTTY_KEY_NUMPAD_BACKSPACE,
235 GHOSTTY_KEY_NUMPAD_CLEAR,
236 GHOSTTY_KEY_NUMPAD_CLEAR_ENTRY,
237 GHOSTTY_KEY_NUMPAD_COMMA,
238 GHOSTTY_KEY_NUMPAD_DECIMAL,
239 GHOSTTY_KEY_NUMPAD_DIVIDE,
240 GHOSTTY_KEY_NUMPAD_ENTER,
241 GHOSTTY_KEY_NUMPAD_EQUAL,
242 GHOSTTY_KEY_NUMPAD_MEMORY_ADD,
243 GHOSTTY_KEY_NUMPAD_MEMORY_CLEAR,
244 GHOSTTY_KEY_NUMPAD_MEMORY_RECALL,
245 GHOSTTY_KEY_NUMPAD_MEMORY_STORE,
246 GHOSTTY_KEY_NUMPAD_MEMORY_SUBTRACT,
247 GHOSTTY_KEY_NUMPAD_MULTIPLY,
248 GHOSTTY_KEY_NUMPAD_PAREN_LEFT,
249 GHOSTTY_KEY_NUMPAD_PAREN_RIGHT,
250 GHOSTTY_KEY_NUMPAD_SUBTRACT,
251 GHOSTTY_KEY_NUMPAD_SEPARATOR,
252 GHOSTTY_KEY_NUMPAD_UP,
253 GHOSTTY_KEY_NUMPAD_DOWN,
254 GHOSTTY_KEY_NUMPAD_RIGHT,
255 GHOSTTY_KEY_NUMPAD_LEFT,
256 GHOSTTY_KEY_NUMPAD_BEGIN,
257 GHOSTTY_KEY_NUMPAD_HOME,
258 GHOSTTY_KEY_NUMPAD_END,
259 GHOSTTY_KEY_NUMPAD_INSERT,
260 GHOSTTY_KEY_NUMPAD_DELETE,
261 GHOSTTY_KEY_NUMPAD_PAGE_UP,
262 GHOSTTY_KEY_NUMPAD_PAGE_DOWN,
263
264 // "Function Section" § 3.5
265 GHOSTTY_KEY_ESCAPE,
266 GHOSTTY_KEY_F1,
267 GHOSTTY_KEY_F2,
268 GHOSTTY_KEY_F3,
269 GHOSTTY_KEY_F4,
270 GHOSTTY_KEY_F5,
271 GHOSTTY_KEY_F6,
272 GHOSTTY_KEY_F7,
273 GHOSTTY_KEY_F8,
274 GHOSTTY_KEY_F9,
275 GHOSTTY_KEY_F10,
276 GHOSTTY_KEY_F11,
277 GHOSTTY_KEY_F12,
278 GHOSTTY_KEY_F13,
279 GHOSTTY_KEY_F14,
280 GHOSTTY_KEY_F15,
281 GHOSTTY_KEY_F16,
282 GHOSTTY_KEY_F17,
283 GHOSTTY_KEY_F18,
284 GHOSTTY_KEY_F19,
285 GHOSTTY_KEY_F20,
286 GHOSTTY_KEY_F21,
287 GHOSTTY_KEY_F22,
288 GHOSTTY_KEY_F23,
289 GHOSTTY_KEY_F24,
290 GHOSTTY_KEY_F25,
291 GHOSTTY_KEY_FN,
292 GHOSTTY_KEY_FN_LOCK,
293 GHOSTTY_KEY_PRINT_SCREEN,
294 GHOSTTY_KEY_SCROLL_LOCK,
295 GHOSTTY_KEY_PAUSE,
296
297 // "Media Keys" § 3.6
298 GHOSTTY_KEY_BROWSER_BACK,
299 GHOSTTY_KEY_BROWSER_FAVORITES,
300 GHOSTTY_KEY_BROWSER_FORWARD,
301 GHOSTTY_KEY_BROWSER_HOME,
302 GHOSTTY_KEY_BROWSER_REFRESH,
303 GHOSTTY_KEY_BROWSER_SEARCH,
304 GHOSTTY_KEY_BROWSER_STOP,
305 GHOSTTY_KEY_EJECT,
306 GHOSTTY_KEY_LAUNCH_APP_1,
307 GHOSTTY_KEY_LAUNCH_APP_2,
308 GHOSTTY_KEY_LAUNCH_MAIL,
309 GHOSTTY_KEY_MEDIA_PLAY_PAUSE,
310 GHOSTTY_KEY_MEDIA_SELECT,
311 GHOSTTY_KEY_MEDIA_STOP,
312 GHOSTTY_KEY_MEDIA_TRACK_NEXT,
313 GHOSTTY_KEY_MEDIA_TRACK_PREVIOUS,
314 GHOSTTY_KEY_POWER,
315 GHOSTTY_KEY_SLEEP,
316 GHOSTTY_KEY_AUDIO_VOLUME_DOWN,
317 GHOSTTY_KEY_AUDIO_VOLUME_MUTE,
318 GHOSTTY_KEY_AUDIO_VOLUME_UP,
319 GHOSTTY_KEY_WAKE_UP,
320
321 // "Legacy, Non-standard, and Special Keys" § 3.7
322 GHOSTTY_KEY_COPY,
323 GHOSTTY_KEY_CUT,
324 GHOSTTY_KEY_PASTE,
325} ghostty_input_key_e;
326
327typedef struct {
328 ghostty_input_action_e action;
329 ghostty_input_mods_e mods;
330 ghostty_input_mods_e consumed_mods;
331 uint32_t keycode;
332 const char* text;
333 uint32_t unshifted_codepoint;
334 bool composing;
335} ghostty_input_key_s;
336
337typedef enum {
338 GHOSTTY_TRIGGER_PHYSICAL,
339 GHOSTTY_TRIGGER_UNICODE,
340 GHOSTTY_TRIGGER_CATCH_ALL,
341} ghostty_input_trigger_tag_e;
342
343typedef union {
344 ghostty_input_key_e translated;
345 ghostty_input_key_e physical;
346 uint32_t unicode;
347 // catch_all has no payload
348} ghostty_input_trigger_key_u;
349
350typedef struct {
351 ghostty_input_trigger_tag_e tag;
352 ghostty_input_trigger_key_u key;
353 ghostty_input_mods_e mods;
354} ghostty_input_trigger_s;
355
356typedef struct {
357 const char* action_key;
358 const char* action;
359 const char* title;
360 const char* description;
361} ghostty_command_s;
362
363typedef enum {
364 GHOSTTY_BUILD_MODE_DEBUG,
365 GHOSTTY_BUILD_MODE_RELEASE_SAFE,
366 GHOSTTY_BUILD_MODE_RELEASE_FAST,
367 GHOSTTY_BUILD_MODE_RELEASE_SMALL,
368} ghostty_build_mode_e;
369
370typedef struct {
371 ghostty_build_mode_e build_mode;
372 const char* version;
373 uintptr_t version_len;
374} ghostty_info_s;
375
376typedef struct {
377 const char* message;
378} ghostty_diagnostic_s;
379
380typedef struct {
381 const char* ptr;
382 uintptr_t len;
383 bool sentinel;
384} ghostty_string_s;
385
386typedef struct {
387 double tl_px_x;
388 double tl_px_y;
389 uint32_t offset_start;
390 uint32_t offset_len;
391 const char* text;
392 uintptr_t text_len;
393} ghostty_text_s;
394
395typedef enum {
396 GHOSTTY_POINT_ACTIVE,
397 GHOSTTY_POINT_VIEWPORT,
398 GHOSTTY_POINT_SCREEN,
399 GHOSTTY_POINT_SURFACE,
400} ghostty_point_tag_e;
401
402typedef enum {
403 GHOSTTY_POINT_COORD_EXACT,
404 GHOSTTY_POINT_COORD_TOP_LEFT,
405 GHOSTTY_POINT_COORD_BOTTOM_RIGHT,
406} ghostty_point_coord_e;
407
408typedef struct {
409 ghostty_point_tag_e tag;
410 ghostty_point_coord_e coord;
411 uint32_t x;
412 uint32_t y;
413} ghostty_point_s;
414
415typedef struct {
416 ghostty_point_s top_left;
417 ghostty_point_s bottom_right;
418 bool rectangle;
419} ghostty_selection_s;
420
421typedef struct {
422 const char* key;
423 const char* value;
424} ghostty_env_var_s;
425
426typedef struct {
427 void* nsview;
428} ghostty_platform_macos_s;
429
430typedef struct {
431 void* uiview;
432} ghostty_platform_ios_s;
433
434typedef union {
435 ghostty_platform_macos_s macos;
436 ghostty_platform_ios_s ios;
437} ghostty_platform_u;
438
439typedef enum {
440 GHOSTTY_SURFACE_CONTEXT_WINDOW = 0,
441 GHOSTTY_SURFACE_CONTEXT_TAB = 1,
442 GHOSTTY_SURFACE_CONTEXT_SPLIT = 2,
443} ghostty_surface_context_e;
444
445typedef struct {
446 ghostty_platform_e platform_tag;
447 ghostty_platform_u platform;
448 void* userdata;
449 double scale_factor;
450 float font_size;
451 const char* working_directory;
452 const char* command;
453 ghostty_env_var_s* env_vars;
454 size_t env_var_count;
455 const char* initial_input;
456 bool wait_after_command;
457 ghostty_surface_context_e context;
458 bool use_custom_io;
459} ghostty_surface_config_s;
460
461typedef struct {
462 uint16_t columns;
463 uint16_t rows;
464 uint32_t width_px;
465 uint32_t height_px;
466 uint32_t cell_width_px;
467 uint32_t cell_height_px;
468} ghostty_surface_size_s;
469
470// Config types
471
472// config.Path
473typedef struct {
474 const char* path;
475 bool optional;
476} ghostty_config_path_s;
477
478// config.Color
479typedef struct {
480 uint8_t r;
481 uint8_t g;
482 uint8_t b;
483} ghostty_config_color_s;
484
485// config.ColorList
486typedef struct {
487 const ghostty_config_color_s* colors;
488 size_t len;
489} ghostty_config_color_list_s;
490
491// config.RepeatableCommand
492typedef struct {
493 const ghostty_command_s* commands;
494 size_t len;
495} ghostty_config_command_list_s;
496
497// config.Palette
498typedef struct {
499 ghostty_config_color_s colors[256];
500} ghostty_config_palette_s;
501
502// config.QuickTerminalSize
503typedef enum {
504 GHOSTTY_QUICK_TERMINAL_SIZE_NONE,
505 GHOSTTY_QUICK_TERMINAL_SIZE_PERCENTAGE,
506 GHOSTTY_QUICK_TERMINAL_SIZE_PIXELS,
507} ghostty_quick_terminal_size_tag_e;
508
509typedef union {
510 float percentage;
511 uint32_t pixels;
512} ghostty_quick_terminal_size_value_u;
513
514typedef struct {
515 ghostty_quick_terminal_size_tag_e tag;
516 ghostty_quick_terminal_size_value_u value;
517} ghostty_quick_terminal_size_s;
518
519typedef struct {
520 ghostty_quick_terminal_size_s primary;
521 ghostty_quick_terminal_size_s secondary;
522} ghostty_config_quick_terminal_size_s;
523
524// config.Fullscreen
525typedef enum {
526 GHOSTTY_CONFIG_FULLSCREEN_FALSE,
527 GHOSTTY_CONFIG_FULLSCREEN_TRUE,
528 GHOSTTY_CONFIG_FULLSCREEN_NON_NATIVE,
529 GHOSTTY_CONFIG_FULLSCREEN_NON_NATIVE_VISIBLE_MENU,
530 GHOSTTY_CONFIG_FULLSCREEN_NON_NATIVE_PADDED_NOTCH,
531} ghostty_config_fullscreen_e;
532
533// apprt.Target.Key
534typedef enum {
535 GHOSTTY_TARGET_APP,
536 GHOSTTY_TARGET_SURFACE,
537} ghostty_target_tag_e;
538
539typedef union {
540 ghostty_surface_t surface;
541} ghostty_target_u;
542
543typedef struct {
544 ghostty_target_tag_e tag;
545 ghostty_target_u target;
546} ghostty_target_s;
547
548// apprt.action.SplitDirection
549typedef enum {
550 GHOSTTY_SPLIT_DIRECTION_RIGHT,
551 GHOSTTY_SPLIT_DIRECTION_DOWN,
552 GHOSTTY_SPLIT_DIRECTION_LEFT,
553 GHOSTTY_SPLIT_DIRECTION_UP,
554} ghostty_action_split_direction_e;
555
556// apprt.action.GotoSplit
557typedef enum {
558 GHOSTTY_GOTO_SPLIT_PREVIOUS,
559 GHOSTTY_GOTO_SPLIT_NEXT,
560 GHOSTTY_GOTO_SPLIT_UP,
561 GHOSTTY_GOTO_SPLIT_LEFT,
562 GHOSTTY_GOTO_SPLIT_DOWN,
563 GHOSTTY_GOTO_SPLIT_RIGHT,
564} ghostty_action_goto_split_e;
565
566// apprt.action.GotoWindow
567typedef enum {
568 GHOSTTY_GOTO_WINDOW_PREVIOUS,
569 GHOSTTY_GOTO_WINDOW_NEXT,
570} ghostty_action_goto_window_e;
571
572// apprt.action.ResizeSplit.Direction
573typedef enum {
574 GHOSTTY_RESIZE_SPLIT_UP,
575 GHOSTTY_RESIZE_SPLIT_DOWN,
576 GHOSTTY_RESIZE_SPLIT_LEFT,
577 GHOSTTY_RESIZE_SPLIT_RIGHT,
578} ghostty_action_resize_split_direction_e;
579
580// apprt.action.ResizeSplit
581typedef struct {
582 uint16_t amount;
583 ghostty_action_resize_split_direction_e direction;
584} ghostty_action_resize_split_s;
585
586// apprt.action.MoveTab
587typedef struct {
588 ssize_t amount;
589} ghostty_action_move_tab_s;
590
591// apprt.action.GotoTab
592typedef enum {
593 GHOSTTY_GOTO_TAB_PREVIOUS = -1,
594 GHOSTTY_GOTO_TAB_NEXT = -2,
595 GHOSTTY_GOTO_TAB_LAST = -3,
596} ghostty_action_goto_tab_e;
597
598// apprt.action.Fullscreen
599typedef enum {
600 GHOSTTY_FULLSCREEN_NATIVE,
601 GHOSTTY_FULLSCREEN_MACOS_NON_NATIVE,
602 GHOSTTY_FULLSCREEN_MACOS_NON_NATIVE_VISIBLE_MENU,
603 GHOSTTY_FULLSCREEN_MACOS_NON_NATIVE_PADDED_NOTCH,
604} ghostty_action_fullscreen_e;
605
606// apprt.action.FloatWindow
607typedef enum {
608 GHOSTTY_FLOAT_WINDOW_ON,
609 GHOSTTY_FLOAT_WINDOW_OFF,
610 GHOSTTY_FLOAT_WINDOW_TOGGLE,
611} ghostty_action_float_window_e;
612
613// apprt.action.SecureInput
614typedef enum {
615 GHOSTTY_SECURE_INPUT_ON,
616 GHOSTTY_SECURE_INPUT_OFF,
617 GHOSTTY_SECURE_INPUT_TOGGLE,
618} ghostty_action_secure_input_e;
619
620// apprt.action.Inspector
621typedef enum {
622 GHOSTTY_INSPECTOR_TOGGLE,
623 GHOSTTY_INSPECTOR_SHOW,
624 GHOSTTY_INSPECTOR_HIDE,
625} ghostty_action_inspector_e;
626
627// apprt.action.QuitTimer
628typedef enum {
629 GHOSTTY_QUIT_TIMER_START,
630 GHOSTTY_QUIT_TIMER_STOP,
631} ghostty_action_quit_timer_e;
632
633// apprt.action.Readonly
634typedef enum {
635 GHOSTTY_READONLY_OFF,
636 GHOSTTY_READONLY_ON,
637} ghostty_action_readonly_e;
638
639// apprt.action.DesktopNotification.C
640typedef struct {
641 const char* title;
642 const char* body;
643} ghostty_action_desktop_notification_s;
644
645// apprt.action.SetTitle.C
646typedef struct {
647 const char* title;
648} ghostty_action_set_title_s;
649
650// apprt.action.PromptTitle
651typedef enum {
652 GHOSTTY_PROMPT_TITLE_SURFACE,
653 GHOSTTY_PROMPT_TITLE_TAB,
654} ghostty_action_prompt_title_e;
655
656// apprt.action.Pwd.C
657typedef struct {
658 const char* pwd;
659} ghostty_action_pwd_s;
660
661// terminal.MouseShape
662typedef enum {
663 GHOSTTY_MOUSE_SHAPE_DEFAULT,
664 GHOSTTY_MOUSE_SHAPE_CONTEXT_MENU,
665 GHOSTTY_MOUSE_SHAPE_HELP,
666 GHOSTTY_MOUSE_SHAPE_POINTER,
667 GHOSTTY_MOUSE_SHAPE_PROGRESS,
668 GHOSTTY_MOUSE_SHAPE_WAIT,
669 GHOSTTY_MOUSE_SHAPE_CELL,
670 GHOSTTY_MOUSE_SHAPE_CROSSHAIR,
671 GHOSTTY_MOUSE_SHAPE_TEXT,
672 GHOSTTY_MOUSE_SHAPE_VERTICAL_TEXT,
673 GHOSTTY_MOUSE_SHAPE_ALIAS,
674 GHOSTTY_MOUSE_SHAPE_COPY,
675 GHOSTTY_MOUSE_SHAPE_MOVE,
676 GHOSTTY_MOUSE_SHAPE_NO_DROP,
677 GHOSTTY_MOUSE_SHAPE_NOT_ALLOWED,
678 GHOSTTY_MOUSE_SHAPE_GRAB,
679 GHOSTTY_MOUSE_SHAPE_GRABBING,
680 GHOSTTY_MOUSE_SHAPE_ALL_SCROLL,
681 GHOSTTY_MOUSE_SHAPE_COL_RESIZE,
682 GHOSTTY_MOUSE_SHAPE_ROW_RESIZE,
683 GHOSTTY_MOUSE_SHAPE_N_RESIZE,
684 GHOSTTY_MOUSE_SHAPE_E_RESIZE,
685 GHOSTTY_MOUSE_SHAPE_S_RESIZE,
686 GHOSTTY_MOUSE_SHAPE_W_RESIZE,
687 GHOSTTY_MOUSE_SHAPE_NE_RESIZE,
688 GHOSTTY_MOUSE_SHAPE_NW_RESIZE,
689 GHOSTTY_MOUSE_SHAPE_SE_RESIZE,
690 GHOSTTY_MOUSE_SHAPE_SW_RESIZE,
691 GHOSTTY_MOUSE_SHAPE_EW_RESIZE,
692 GHOSTTY_MOUSE_SHAPE_NS_RESIZE,
693 GHOSTTY_MOUSE_SHAPE_NESW_RESIZE,
694 GHOSTTY_MOUSE_SHAPE_NWSE_RESIZE,
695 GHOSTTY_MOUSE_SHAPE_ZOOM_IN,
696 GHOSTTY_MOUSE_SHAPE_ZOOM_OUT,
697} ghostty_action_mouse_shape_e;
698
699// apprt.action.MouseVisibility
700typedef enum {
701 GHOSTTY_MOUSE_VISIBLE,
702 GHOSTTY_MOUSE_HIDDEN,
703} ghostty_action_mouse_visibility_e;
704
705// apprt.action.MouseOverLink
706typedef struct {
707 const char* url;
708 size_t len;
709} ghostty_action_mouse_over_link_s;
710
711// apprt.action.SizeLimit
712typedef struct {
713 uint32_t min_width;
714 uint32_t min_height;
715 uint32_t max_width;
716 uint32_t max_height;
717} ghostty_action_size_limit_s;
718
719// apprt.action.InitialSize
720typedef struct {
721 uint32_t width;
722 uint32_t height;
723} ghostty_action_initial_size_s;
724
725// apprt.action.CellSize
726typedef struct {
727 uint32_t width;
728 uint32_t height;
729} ghostty_action_cell_size_s;
730
731// renderer.Health
732typedef enum {
733 GHOSTTY_RENDERER_HEALTH_HEALTHY,
734 GHOSTTY_RENDERER_HEALTH_UNHEALTHY,
735} ghostty_action_renderer_health_e;
736
737// apprt.action.KeySequence
738typedef struct {
739 bool active;
740 ghostty_input_trigger_s trigger;
741} ghostty_action_key_sequence_s;
742
743// apprt.action.KeyTable.Tag
744typedef enum {
745 GHOSTTY_KEY_TABLE_ACTIVATE,
746 GHOSTTY_KEY_TABLE_DEACTIVATE,
747 GHOSTTY_KEY_TABLE_DEACTIVATE_ALL,
748} ghostty_action_key_table_tag_e;
749
750// apprt.action.KeyTable.CValue
751typedef union {
752 struct {
753 const char *name;
754 size_t len;
755 } activate;
756} ghostty_action_key_table_u;
757
758// apprt.action.KeyTable.C
759typedef struct {
760 ghostty_action_key_table_tag_e tag;
761 ghostty_action_key_table_u value;
762} ghostty_action_key_table_s;
763
764// apprt.action.ColorKind
765typedef enum {
766 GHOSTTY_ACTION_COLOR_KIND_FOREGROUND = -1,
767 GHOSTTY_ACTION_COLOR_KIND_BACKGROUND = -2,
768 GHOSTTY_ACTION_COLOR_KIND_CURSOR = -3,
769} ghostty_action_color_kind_e;
770
771// apprt.action.ColorChange
772typedef struct {
773 ghostty_action_color_kind_e kind;
774 uint8_t r;
775 uint8_t g;
776 uint8_t b;
777} ghostty_action_color_change_s;
778
779// apprt.action.ConfigChange
780typedef struct {
781 ghostty_config_t config;
782} ghostty_action_config_change_s;
783
784// apprt.action.ReloadConfig
785typedef struct {
786 bool soft;
787} ghostty_action_reload_config_s;
788
789// apprt.action.OpenUrlKind
790typedef enum {
791 GHOSTTY_ACTION_OPEN_URL_KIND_UNKNOWN,
792 GHOSTTY_ACTION_OPEN_URL_KIND_TEXT,
793 GHOSTTY_ACTION_OPEN_URL_KIND_HTML,
794} ghostty_action_open_url_kind_e;
795
796// apprt.action.OpenUrl.C
797typedef struct {
798 ghostty_action_open_url_kind_e kind;
799 const char* url;
800 uintptr_t len;
801} ghostty_action_open_url_s;
802
803// apprt.action.CloseTabMode
804typedef enum {
805 GHOSTTY_ACTION_CLOSE_TAB_MODE_THIS,
806 GHOSTTY_ACTION_CLOSE_TAB_MODE_OTHER,
807 GHOSTTY_ACTION_CLOSE_TAB_MODE_RIGHT,
808} ghostty_action_close_tab_mode_e;
809
810// apprt.surface.Message.ChildExited
811typedef struct {
812 uint32_t exit_code;
813 uint64_t timetime_ms;
814} ghostty_surface_message_childexited_s;
815
816// terminal.osc.Command.ProgressReport.State
817typedef enum {
818 GHOSTTY_PROGRESS_STATE_REMOVE,
819 GHOSTTY_PROGRESS_STATE_SET,
820 GHOSTTY_PROGRESS_STATE_ERROR,
821 GHOSTTY_PROGRESS_STATE_INDETERMINATE,
822 GHOSTTY_PROGRESS_STATE_PAUSE,
823} ghostty_action_progress_report_state_e;
824
825// terminal.osc.Command.ProgressReport.C
826typedef struct {
827 ghostty_action_progress_report_state_e state;
828 // -1 if no progress was reported, otherwise 0-100 indicating percent
829 // completeness.
830 int8_t progress;
831} ghostty_action_progress_report_s;
832
833// apprt.action.CommandFinished.C
834typedef struct {
835 // -1 if no exit code was reported, otherwise 0-255
836 int16_t exit_code;
837 // number of nanoseconds that command was running for
838 uint64_t duration;
839} ghostty_action_command_finished_s;
840
841// apprt.action.StartSearch.C
842typedef struct {
843 const char* needle;
844} ghostty_action_start_search_s;
845
846// apprt.action.SearchTotal
847typedef struct {
848 ssize_t total;
849} ghostty_action_search_total_s;
850
851// apprt.action.SearchSelected
852typedef struct {
853 ssize_t selected;
854} ghostty_action_search_selected_s;
855
856// terminal.Scrollbar
857typedef struct {
858 uint64_t total;
859 uint64_t offset;
860 uint64_t len;
861} ghostty_action_scrollbar_s;
862
863// apprt.Action.Key
864typedef enum {
865 GHOSTTY_ACTION_QUIT,
866 GHOSTTY_ACTION_NEW_WINDOW,
867 GHOSTTY_ACTION_NEW_TAB,
868 GHOSTTY_ACTION_CLOSE_TAB,
869 GHOSTTY_ACTION_NEW_SPLIT,
870 GHOSTTY_ACTION_CLOSE_ALL_WINDOWS,
871 GHOSTTY_ACTION_TOGGLE_MAXIMIZE,
872 GHOSTTY_ACTION_TOGGLE_FULLSCREEN,
873 GHOSTTY_ACTION_TOGGLE_TAB_OVERVIEW,
874 GHOSTTY_ACTION_TOGGLE_WINDOW_DECORATIONS,
875 GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL,
876 GHOSTTY_ACTION_TOGGLE_COMMAND_PALETTE,
877 GHOSTTY_ACTION_TOGGLE_VISIBILITY,
878 GHOSTTY_ACTION_TOGGLE_BACKGROUND_OPACITY,
879 GHOSTTY_ACTION_MOVE_TAB,
880 GHOSTTY_ACTION_GOTO_TAB,
881 GHOSTTY_ACTION_GOTO_SPLIT,
882 GHOSTTY_ACTION_GOTO_WINDOW,
883 GHOSTTY_ACTION_RESIZE_SPLIT,
884 GHOSTTY_ACTION_EQUALIZE_SPLITS,
885 GHOSTTY_ACTION_TOGGLE_SPLIT_ZOOM,
886 GHOSTTY_ACTION_PRESENT_TERMINAL,
887 GHOSTTY_ACTION_SIZE_LIMIT,
888 GHOSTTY_ACTION_RESET_WINDOW_SIZE,
889 GHOSTTY_ACTION_INITIAL_SIZE,
890 GHOSTTY_ACTION_CELL_SIZE,
891 GHOSTTY_ACTION_SCROLLBAR,
892 GHOSTTY_ACTION_RENDER,
893 GHOSTTY_ACTION_INSPECTOR,
894 GHOSTTY_ACTION_SHOW_GTK_INSPECTOR,
895 GHOSTTY_ACTION_RENDER_INSPECTOR,
896 GHOSTTY_ACTION_DESKTOP_NOTIFICATION,
897 GHOSTTY_ACTION_SET_TITLE,
898 GHOSTTY_ACTION_PROMPT_TITLE,
899 GHOSTTY_ACTION_PWD,
900 GHOSTTY_ACTION_MOUSE_SHAPE,
901 GHOSTTY_ACTION_MOUSE_VISIBILITY,
902 GHOSTTY_ACTION_MOUSE_OVER_LINK,
903 GHOSTTY_ACTION_RENDERER_HEALTH,
904 GHOSTTY_ACTION_OPEN_CONFIG,
905 GHOSTTY_ACTION_QUIT_TIMER,
906 GHOSTTY_ACTION_FLOAT_WINDOW,
907 GHOSTTY_ACTION_SECURE_INPUT,
908 GHOSTTY_ACTION_KEY_SEQUENCE,
909 GHOSTTY_ACTION_KEY_TABLE,
910 GHOSTTY_ACTION_COLOR_CHANGE,
911 GHOSTTY_ACTION_RELOAD_CONFIG,
912 GHOSTTY_ACTION_CONFIG_CHANGE,
913 GHOSTTY_ACTION_CLOSE_WINDOW,
914 GHOSTTY_ACTION_RING_BELL,
915 GHOSTTY_ACTION_UNDO,
916 GHOSTTY_ACTION_REDO,
917 GHOSTTY_ACTION_CHECK_FOR_UPDATES,
918 GHOSTTY_ACTION_OPEN_URL,
919 GHOSTTY_ACTION_SHOW_CHILD_EXITED,
920 GHOSTTY_ACTION_PROGRESS_REPORT,
921 GHOSTTY_ACTION_SHOW_ON_SCREEN_KEYBOARD,
922 GHOSTTY_ACTION_COMMAND_FINISHED,
923 GHOSTTY_ACTION_START_SEARCH,
924 GHOSTTY_ACTION_END_SEARCH,
925 GHOSTTY_ACTION_SEARCH_TOTAL,
926 GHOSTTY_ACTION_SEARCH_SELECTED,
927 GHOSTTY_ACTION_READONLY,
928 GHOSTTY_ACTION_COPY_TITLE_TO_CLIPBOARD,
929} ghostty_action_tag_e;
930
931typedef union {
932 ghostty_action_split_direction_e new_split;
933 ghostty_action_fullscreen_e toggle_fullscreen;
934 ghostty_action_move_tab_s move_tab;
935 ghostty_action_goto_tab_e goto_tab;
936 ghostty_action_goto_split_e goto_split;
937 ghostty_action_goto_window_e goto_window;
938 ghostty_action_resize_split_s resize_split;
939 ghostty_action_size_limit_s size_limit;
940 ghostty_action_initial_size_s initial_size;
941 ghostty_action_cell_size_s cell_size;
942 ghostty_action_scrollbar_s scrollbar;
943 ghostty_action_inspector_e inspector;
944 ghostty_action_desktop_notification_s desktop_notification;
945 ghostty_action_set_title_s set_title;
946 ghostty_action_prompt_title_e prompt_title;
947 ghostty_action_pwd_s pwd;
948 ghostty_action_mouse_shape_e mouse_shape;
949 ghostty_action_mouse_visibility_e mouse_visibility;
950 ghostty_action_mouse_over_link_s mouse_over_link;
951 ghostty_action_renderer_health_e renderer_health;
952 ghostty_action_quit_timer_e quit_timer;
953 ghostty_action_float_window_e float_window;
954 ghostty_action_secure_input_e secure_input;
955 ghostty_action_key_sequence_s key_sequence;
956 ghostty_action_key_table_s key_table;
957 ghostty_action_color_change_s color_change;
958 ghostty_action_reload_config_s reload_config;
959 ghostty_action_config_change_s config_change;
960 ghostty_action_open_url_s open_url;
961 ghostty_action_close_tab_mode_e close_tab_mode;
962 ghostty_surface_message_childexited_s child_exited;
963 ghostty_action_progress_report_s progress_report;
964 ghostty_action_command_finished_s command_finished;
965 ghostty_action_start_search_s start_search;
966 ghostty_action_search_total_s search_total;
967 ghostty_action_search_selected_s search_selected;
968 ghostty_action_readonly_e readonly;
969} ghostty_action_u;
970
971typedef struct {
972 ghostty_action_tag_e tag;
973 ghostty_action_u action;
974} ghostty_action_s;
975
976typedef void (*ghostty_runtime_wakeup_cb)(void*);
977typedef void (*ghostty_runtime_read_clipboard_cb)(void*,
978 ghostty_clipboard_e,
979 void*);
980typedef void (*ghostty_runtime_confirm_read_clipboard_cb)(
981 void*,
982 const char*,
983 void*,
984 ghostty_clipboard_request_e);
985typedef void (*ghostty_runtime_write_clipboard_cb)(void*,
986 ghostty_clipboard_e,
987 const ghostty_clipboard_content_s*,
988 size_t,
989 bool);
990typedef void (*ghostty_runtime_close_surface_cb)(void*, bool);
991typedef bool (*ghostty_runtime_action_cb)(ghostty_app_t,
992 ghostty_target_s,
993 ghostty_action_s);
994
995typedef struct {
996 void* userdata;
997 bool supports_selection_clipboard;
998 ghostty_runtime_wakeup_cb wakeup_cb;
999 ghostty_runtime_action_cb action_cb;
1000 ghostty_runtime_read_clipboard_cb read_clipboard_cb;
1001 ghostty_runtime_confirm_read_clipboard_cb confirm_read_clipboard_cb;
1002 ghostty_runtime_write_clipboard_cb write_clipboard_cb;
1003 ghostty_runtime_close_surface_cb close_surface_cb;
1004} ghostty_runtime_config_s;
1005
1006// apprt.ipc.Target.Key
1007typedef enum {
1008 GHOSTTY_IPC_TARGET_CLASS,
1009 GHOSTTY_IPC_TARGET_DETECT,
1010} ghostty_ipc_target_tag_e;
1011
1012typedef union {
1013 char *klass;
1014} ghostty_ipc_target_u;
1015
1016typedef struct {
1017 ghostty_ipc_target_tag_e tag;
1018 ghostty_ipc_target_u target;
1019} chostty_ipc_target_s;
1020
1021// apprt.ipc.Action.NewWindow
1022typedef struct {
1023 // This should be a null terminated list of strings.
1024 const char **arguments;
1025} ghostty_ipc_action_new_window_s;
1026
1027typedef union {
1028 ghostty_ipc_action_new_window_s new_window;
1029} ghostty_ipc_action_u;
1030
1031// apprt.ipc.Action.Key
1032typedef enum {
1033 GHOSTTY_IPC_ACTION_NEW_WINDOW,
1034} ghostty_ipc_action_tag_e;
1035
1036//-------------------------------------------------------------------
1037// Published API
1038
1039int ghostty_init(uintptr_t, char**);
1040void ghostty_cli_try_action(void);
1041ghostty_info_s ghostty_info(void);
1042const char* ghostty_translate(const char*);
1043void ghostty_string_free(ghostty_string_s);
1044
1045ghostty_config_t ghostty_config_new();
1046void ghostty_config_free(ghostty_config_t);
1047ghostty_config_t ghostty_config_clone(ghostty_config_t);
1048void ghostty_config_load_cli_args(ghostty_config_t);
1049void ghostty_config_load_file(ghostty_config_t, const char*);
1050void ghostty_config_load_default_files(ghostty_config_t);
1051void ghostty_config_load_recursive_files(ghostty_config_t);
1052void ghostty_config_finalize(ghostty_config_t);
1053bool ghostty_config_get(ghostty_config_t, void*, const char*, uintptr_t);
1054ghostty_input_trigger_s ghostty_config_trigger(ghostty_config_t,
1055 const char*,
1056 uintptr_t);
1057uint32_t ghostty_config_diagnostics_count(ghostty_config_t);
1058ghostty_diagnostic_s ghostty_config_get_diagnostic(ghostty_config_t, uint32_t);
1059ghostty_string_s ghostty_config_open_path(void);
1060
1061ghostty_app_t ghostty_app_new(const ghostty_runtime_config_s*,
1062 ghostty_config_t);
1063void ghostty_app_free(ghostty_app_t);
1064void ghostty_app_tick(ghostty_app_t);
1065void* ghostty_app_userdata(ghostty_app_t);
1066void ghostty_app_set_focus(ghostty_app_t, bool);
1067bool ghostty_app_key(ghostty_app_t, ghostty_input_key_s);
1068bool ghostty_app_key_is_binding(ghostty_app_t, ghostty_input_key_s);
1069void ghostty_app_keyboard_changed(ghostty_app_t);
1070void ghostty_app_open_config(ghostty_app_t);
1071void ghostty_app_update_config(ghostty_app_t, ghostty_config_t);
1072bool ghostty_app_needs_confirm_quit(ghostty_app_t);
1073bool ghostty_app_has_global_keybinds(ghostty_app_t);
1074void ghostty_app_set_color_scheme(ghostty_app_t, ghostty_color_scheme_e);
1075
1076ghostty_surface_config_s ghostty_surface_config_new();
1077
1078ghostty_surface_t ghostty_surface_new(ghostty_app_t,
1079 const ghostty_surface_config_s*);
1080void ghostty_surface_free(ghostty_surface_t);
1081void* ghostty_surface_userdata(ghostty_surface_t);
1082ghostty_app_t ghostty_surface_app(ghostty_surface_t);
1083ghostty_surface_config_s ghostty_surface_inherited_config(ghostty_surface_t, ghostty_surface_context_e);
1084void ghostty_surface_update_config(ghostty_surface_t, ghostty_config_t);
1085bool ghostty_surface_needs_confirm_quit(ghostty_surface_t);
1086bool ghostty_surface_process_exited(ghostty_surface_t);
1087void ghostty_surface_refresh(ghostty_surface_t);
1088void ghostty_surface_draw(ghostty_surface_t);
1089// Custom I/O API - feed output into the terminal and receive writes.
1090void ghostty_surface_feed_data(ghostty_surface_t, const uint8_t*, size_t);
1091void ghostty_surface_set_write_callback(ghostty_surface_t,
1092 ghostty_surface_write_fn,
1093 void*);
1094void ghostty_surface_set_content_scale(ghostty_surface_t, double, double);
1095void ghostty_surface_set_focus(ghostty_surface_t, bool);
1096void ghostty_surface_set_occlusion(ghostty_surface_t, bool);
1097void ghostty_surface_set_size(ghostty_surface_t, uint32_t, uint32_t);
1098ghostty_surface_size_s ghostty_surface_size(ghostty_surface_t);
1099void ghostty_surface_set_color_scheme(ghostty_surface_t,
1100 ghostty_color_scheme_e);
1101ghostty_input_mods_e ghostty_surface_key_translation_mods(ghostty_surface_t,
1102 ghostty_input_mods_e);
1103bool ghostty_surface_key(ghostty_surface_t, ghostty_input_key_s);
1104bool ghostty_surface_key_is_binding(ghostty_surface_t,
1105 ghostty_input_key_s,
1106 ghostty_binding_flags_e*);
1107void ghostty_surface_text(ghostty_surface_t, const char*, uintptr_t);
1108void ghostty_surface_preedit(ghostty_surface_t, const char*, uintptr_t);
1109bool ghostty_surface_mouse_captured(ghostty_surface_t);
1110bool ghostty_surface_mouse_button(ghostty_surface_t,
1111 ghostty_input_mouse_state_e,
1112 ghostty_input_mouse_button_e,
1113 ghostty_input_mods_e);
1114void ghostty_surface_mouse_pos(ghostty_surface_t,
1115 double,
1116 double,
1117 ghostty_input_mods_e);
1118void ghostty_surface_mouse_scroll(ghostty_surface_t,
1119 double,
1120 double,
1121 ghostty_input_scroll_mods_t);
1122void ghostty_surface_mouse_pressure(ghostty_surface_t, uint32_t, double);
1123void ghostty_surface_ime_point(ghostty_surface_t, double*, double*, double*, double*);
1124void ghostty_surface_request_close(ghostty_surface_t);
1125void ghostty_surface_split(ghostty_surface_t, ghostty_action_split_direction_e);
1126void ghostty_surface_split_focus(ghostty_surface_t,
1127 ghostty_action_goto_split_e);
1128void ghostty_surface_split_resize(ghostty_surface_t,
1129 ghostty_action_resize_split_direction_e,
1130 uint16_t);
1131void ghostty_surface_split_equalize(ghostty_surface_t);
1132bool ghostty_surface_binding_action(ghostty_surface_t, const char*, uintptr_t);
1133void ghostty_surface_complete_clipboard_request(ghostty_surface_t,
1134 const char*,
1135 void*,
1136 bool);
1137bool ghostty_surface_has_selection(ghostty_surface_t);
1138bool ghostty_surface_read_selection(ghostty_surface_t, ghostty_text_s*);
1139bool ghostty_surface_read_text(ghostty_surface_t,
1140 ghostty_selection_s,
1141 ghostty_text_s*);
1142void ghostty_surface_free_text(ghostty_surface_t, ghostty_text_s*);
1143
1144#ifdef __APPLE__
1145void ghostty_surface_set_display_id(ghostty_surface_t, uint32_t);
1146void* ghostty_surface_quicklook_font(ghostty_surface_t);
1147bool ghostty_surface_quicklook_word(ghostty_surface_t, ghostty_text_s*);
1148#endif
1149
1150ghostty_inspector_t ghostty_surface_inspector(ghostty_surface_t);
1151void ghostty_inspector_free(ghostty_surface_t);
1152void ghostty_inspector_set_focus(ghostty_inspector_t, bool);
1153void ghostty_inspector_set_content_scale(ghostty_inspector_t, double, double);
1154void ghostty_inspector_set_size(ghostty_inspector_t, uint32_t, uint32_t);
1155void ghostty_inspector_mouse_button(ghostty_inspector_t,
1156 ghostty_input_mouse_state_e,
1157 ghostty_input_mouse_button_e,
1158 ghostty_input_mods_e);
1159void ghostty_inspector_mouse_pos(ghostty_inspector_t, double, double);
1160void ghostty_inspector_mouse_scroll(ghostty_inspector_t,
1161 double,
1162 double,
1163 ghostty_input_scroll_mods_t);
1164void ghostty_inspector_key(ghostty_inspector_t,
1165 ghostty_input_action_e,
1166 ghostty_input_key_e,
1167 ghostty_input_mods_e);
1168void ghostty_inspector_text(ghostty_inspector_t, const char*);
1169
1170#ifdef __APPLE__
1171bool ghostty_inspector_metal_init(ghostty_inspector_t, void*);
1172void ghostty_inspector_metal_render(ghostty_inspector_t, void*, void*);
1173bool ghostty_inspector_metal_shutdown(ghostty_inspector_t);
1174#endif
1175
1176// APIs I'd like to get rid of eventually but are still needed for now.
1177// Don't use these unless you know what you're doing.
1178void ghostty_set_window_background_blur(ghostty_app_t, void*);
1179
1180// Benchmark API, if available.
1181bool ghostty_benchmark_cli(const char*, const char*);
1182
1183#ifdef __cplusplus
1184}
1185#endif
1186
1187#endif /* GHOSTTY_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt.h+87−0
@@ -0,0 +1,87 @@
1/**
2 * @file vt.h
3 *
4 * libghostty-vt - Virtual terminal emulator library
5 *
6 * This library provides functionality for parsing and handling terminal
7 * escape sequences as well as maintaining terminal state such as styles,
8 * cursor position, screen, scrollback, and more.
9 *
10 * WARNING: This is an incomplete, work-in-progress API. It is not yet
11 * stable and is definitely going to change.
12 */
13
14/**
15 * @mainpage libghostty-vt - Virtual Terminal Emulator Library
16 *
17 * libghostty-vt is a C library which implements a modern terminal emulator,
18 * extracted from the [Ghostty](https://ghostty.org) terminal emulator.
19 *
20 * libghostty-vt contains the logic for handling the core parts of a terminal
21 * emulator: parsing terminal escape sequences, maintaining terminal state,
22 * encoding input events, etc. It can handle scrollback, line wrapping,
23 * reflow on resize, and more.
24 *
25 * @warning This library is currently in development and the API is not yet stable.
26 * Breaking changes are expected in future versions. Use with caution in production code.
27 *
28 * @section groups_sec API Reference
29 *
30 * The API is organized into the following groups:
31 * - @ref key "Key Encoding" - Encode key events into terminal sequences
32 * - @ref osc "OSC Parser" - Parse OSC (Operating System Command) sequences
33 * - @ref sgr "SGR Parser" - Parse SGR (Select Graphic Rendition) sequences
34 * - @ref paste "Paste Utilities" - Validate paste data safety
35 * - @ref allocator "Memory Management" - Memory management and custom allocators
36 * - @ref wasm "WebAssembly Utilities" - WebAssembly convenience functions
37 *
38 * @section examples_sec Examples
39 *
40 * Complete working examples:
41 * - @ref c-vt/src/main.c - OSC parser example
42 * - @ref c-vt-key-encode/src/main.c - Key encoding example
43 * - @ref c-vt-paste/src/main.c - Paste safety check example
44 * - @ref c-vt-sgr/src/main.c - SGR parser example
45 *
46 */
47
48/** @example c-vt/src/main.c
49 * This example demonstrates how to use the OSC parser to parse an OSC sequence,
50 * extract command information, and retrieve command-specific data like window titles.
51 */
52
53/** @example c-vt-key-encode/src/main.c
54 * This example demonstrates how to use the key encoder to convert key events
55 * into terminal escape sequences using the Kitty keyboard protocol.
56 */
57
58/** @example c-vt-paste/src/main.c
59 * This example demonstrates how to use the paste utilities to check if
60 * paste data is safe before sending it to the terminal.
61 */
62
63/** @example c-vt-sgr/src/main.c
64 * This example demonstrates how to use the SGR parser to parse terminal
65 * styling sequences and extract text attributes like colors and underline styles.
66 */
67
68#ifndef GHOSTTY_VT_H
69#define GHOSTTY_VT_H
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75#include <ghostty/vt/result.h>
76#include <ghostty/vt/allocator.h>
77#include <ghostty/vt/osc.h>
78#include <ghostty/vt/sgr.h>
79#include <ghostty/vt/key.h>
80#include <ghostty/vt/paste.h>
81#include <ghostty/vt/wasm.h>
82
83#ifdef __cplusplus
84}
85#endif
86
87#endif /* GHOSTTY_VT_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/allocator.h+196−0
@@ -0,0 +1,196 @@
1/**
2 * @file allocator.h
3 *
4 * Memory management interface for libghostty-vt.
5 */
6
7#ifndef GHOSTTY_VT_ALLOCATOR_H
8#define GHOSTTY_VT_ALLOCATOR_H
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13
14/** @defgroup allocator Memory Management
15 *
16 * libghostty-vt does require memory allocation for various operations,
17 * but is resilient to allocation failures and will gracefully handle
18 * out-of-memory situations by returning error codes.
19 *
20 * The exact memory management semantics are documented in the relevant
21 * functions and data structures.
22 *
23 * libghostty-vt uses explicit memory allocation via an allocator
24 * interface provided by GhosttyAllocator. The interface is based on the
25 * [Zig](https://ziglang.org) allocator interface, since this has been
26 * shown to be a flexible and powerful interface in practice and enables
27 * a wide variety of allocation strategies.
28 *
29 * **For the common case, you can pass NULL as the allocator for any
30 * function that accepts one,** and libghostty will use a default allocator.
31 * The default allocator will be libc malloc/free if libc is linked.
32 * Otherwise, a custom allocator is used (currently Zig's SMP allocator)
33 * that doesn't require any external dependencies.
34 *
35 * ## Basic Usage
36 *
37 * For simple use cases, you can ignore this interface entirely by passing NULL
38 * as the allocator parameter to functions that accept one. This will use the
39 * default allocator (typically libc malloc/free, if libc is linked, but
40 * we provide our own default allocator if libc isn't linked).
41 *
42 * To use a custom allocator:
43 * 1. Implement the GhosttyAllocatorVtable function pointers
44 * 2. Create a GhosttyAllocator struct with your vtable and context
45 * 3. Pass the allocator to functions that accept one
46 *
47 * @{
48 */
49
50/**
51 * Function table for custom memory allocator operations.
52 *
53 * This vtable defines the interface for a custom memory allocator. All
54 * function pointers must be valid and non-NULL.
55 *
56 * @ingroup allocator
57 *
58 * If you're not going to use a custom allocator, you can ignore all of
59 * this. All functions that take an allocator pointer allow NULL to use a
60 * default allocator.
61 *
62 * The interface is based on the Zig allocator interface. I'll say up front
63 * that it is easy to look at this interface and think "wow, this is really
64 * overcomplicated". The reason for this complexity is well thought out by
65 * the Zig folks, and it enables a diverse set of allocation strategies
66 * as shown by the Zig ecosystem. As a consolation, please note that many
67 * of the arguments are only needed for advanced use cases and can be
68 * safely ignored in simple implementations. For example, if you look at
69 * the Zig implementation of the libc allocator in `lib/std/heap.zig`
70 * (search for CAllocator), you'll see it is very simple.
71 *
72 * We chose to align with the Zig allocator interface because:
73 *
74 * 1. It is a proven interface that serves a wide variety of use cases
75 * in the real world via the Zig ecosystem. It's shown to work.
76 *
77 * 2. Our core implementation itself is Zig, and this lets us very
78 * cheaply and easily convert between C and Zig allocators.
79 *
80 * NOTE(mitchellh): In the future, we can have default implementations of
81 * resize/remap and allow those to be null.
82 */
83typedef struct {
84 /**
85 * Return a pointer to `len` bytes with specified `alignment`, or return
86 * `NULL` indicating the allocation failed.
87 *
88 * @param ctx The allocator context
89 * @param len Number of bytes to allocate
90 * @param alignment Required alignment for the allocation. Guaranteed to
91 * be a power of two between 1 and 16 inclusive.
92 * @param ret_addr First return address of the allocation call stack (0 if not provided)
93 * @return Pointer to allocated memory, or NULL if allocation failed
94 */
95 void* (*alloc)(void *ctx, size_t len, uint8_t alignment, uintptr_t ret_addr);
96
97 /**
98 * Attempt to expand or shrink memory in place.
99 *
100 * `memory_len` must equal the length requested from the most recent
101 * successful call to `alloc`, `resize`, or `remap`. `alignment` must
102 * equal the same value that was passed as the `alignment` parameter to
103 * the original `alloc` call.
104 *
105 * `new_len` must be greater than zero.
106 *
107 * @param ctx The allocator context
108 * @param memory Pointer to the memory block to resize
109 * @param memory_len Current size of the memory block
110 * @param alignment Alignment (must match original allocation)
111 * @param new_len New requested size
112 * @param ret_addr First return address of the allocation call stack (0 if not provided)
113 * @return true if resize was successful in-place, false if relocation would be required
114 */
115 bool (*resize)(void *ctx, void *memory, size_t memory_len, uint8_t alignment, size_t new_len, uintptr_t ret_addr);
116
117 /**
118 * Attempt to expand or shrink memory, allowing relocation.
119 *
120 * `memory_len` must equal the length requested from the most recent
121 * successful call to `alloc`, `resize`, or `remap`. `alignment` must
122 * equal the same value that was passed as the `alignment` parameter to
123 * the original `alloc` call.
124 *
125 * A non-`NULL` return value indicates the resize was successful. The
126 * allocation may have same address, or may have been relocated. In either
127 * case, the allocation now has size of `new_len`. A `NULL` return value
128 * indicates that the resize would be equivalent to allocating new memory,
129 * copying the bytes from the old memory, and then freeing the old memory.
130 * In such case, it is more efficient for the caller to perform the copy.
131 *
132 * `new_len` must be greater than zero.
133 *
134 * @param ctx The allocator context
135 * @param memory Pointer to the memory block to remap
136 * @param memory_len Current size of the memory block
137 * @param alignment Alignment (must match original allocation)
138 * @param new_len New requested size
139 * @param ret_addr First return address of the allocation call stack (0 if not provided)
140 * @return Pointer to resized memory (may be relocated), or NULL if manual copy is needed
141 */
142 void* (*remap)(void *ctx, void *memory, size_t memory_len, uint8_t alignment, size_t new_len, uintptr_t ret_addr);
143
144 /**
145 * Free and invalidate a region of memory.
146 *
147 * `memory_len` must equal the length requested from the most recent
148 * successful call to `alloc`, `resize`, or `remap`. `alignment` must
149 * equal the same value that was passed as the `alignment` parameter to
150 * the original `alloc` call.
151 *
152 * @param ctx The allocator context
153 * @param memory Pointer to the memory block to free
154 * @param memory_len Size of the memory block
155 * @param alignment Alignment (must match original allocation)
156 * @param ret_addr First return address of the allocation call stack (0 if not provided)
157 */
158 void (*free)(void *ctx, void *memory, size_t memory_len, uint8_t alignment, uintptr_t ret_addr);
159} GhosttyAllocatorVtable;
160
161/**
162 * Custom memory allocator.
163 *
164 * For functions that take an allocator pointer, a NULL pointer indicates
165 * that the default allocator should be used. The default allocator will
166 * be libc malloc/free if we're linking to libc. If libc isn't linked,
167 * a custom allocator is used (currently Zig's SMP allocator).
168 *
169 * @ingroup allocator
170 *
171 * Usage example:
172 * @code
173 * GhosttyAllocator allocator = {
174 * .vtable = &my_allocator_vtable,
175 * .ctx = my_allocator_state
176 * };
177 * @endcode
178 */
179typedef struct GhosttyAllocator {
180 /**
181 * Opaque context pointer passed to all vtable functions.
182 * This allows the allocator implementation to maintain state
183 * or reference external resources needed for memory management.
184 */
185 void *ctx;
186
187 /**
188 * Pointer to the allocator's vtable containing function pointers
189 * for memory operations (alloc, resize, remap, free).
190 */
191 const GhosttyAllocatorVtable *vtable;
192} GhosttyAllocator;
193
194/** @} */
195
196#endif /* GHOSTTY_VT_ALLOCATOR_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/color.h+96−0
@@ -0,0 +1,96 @@
1/**
2 * @file color.h
3 *
4 * Color types and utilities.
5 */
6
7#ifndef GHOSTTY_VT_COLOR_H
8#define GHOSTTY_VT_COLOR_H
9
10#include <stdint.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/**
17 * RGB color value.
18 *
19 * @ingroup sgr
20 */
21typedef struct {
22 uint8_t r; /**< Red component (0-255) */
23 uint8_t g; /**< Green component (0-255) */
24 uint8_t b; /**< Blue component (0-255) */
25} GhosttyColorRgb;
26
27/**
28 * Palette color index (0-255).
29 *
30 * @ingroup sgr
31 */
32typedef uint8_t GhosttyColorPaletteIndex;
33
34/** @addtogroup sgr
35 * @{
36 */
37
38/** Black color (0) @ingroup sgr */
39#define GHOSTTY_COLOR_NAMED_BLACK 0
40/** Red color (1) @ingroup sgr */
41#define GHOSTTY_COLOR_NAMED_RED 1
42/** Green color (2) @ingroup sgr */
43#define GHOSTTY_COLOR_NAMED_GREEN 2
44/** Yellow color (3) @ingroup sgr */
45#define GHOSTTY_COLOR_NAMED_YELLOW 3
46/** Blue color (4) @ingroup sgr */
47#define GHOSTTY_COLOR_NAMED_BLUE 4
48/** Magenta color (5) @ingroup sgr */
49#define GHOSTTY_COLOR_NAMED_MAGENTA 5
50/** Cyan color (6) @ingroup sgr */
51#define GHOSTTY_COLOR_NAMED_CYAN 6
52/** White color (7) @ingroup sgr */
53#define GHOSTTY_COLOR_NAMED_WHITE 7
54/** Bright black color (8) @ingroup sgr */
55#define GHOSTTY_COLOR_NAMED_BRIGHT_BLACK 8
56/** Bright red color (9) @ingroup sgr */
57#define GHOSTTY_COLOR_NAMED_BRIGHT_RED 9
58/** Bright green color (10) @ingroup sgr */
59#define GHOSTTY_COLOR_NAMED_BRIGHT_GREEN 10
60/** Bright yellow color (11) @ingroup sgr */
61#define GHOSTTY_COLOR_NAMED_BRIGHT_YELLOW 11
62/** Bright blue color (12) @ingroup sgr */
63#define GHOSTTY_COLOR_NAMED_BRIGHT_BLUE 12
64/** Bright magenta color (13) @ingroup sgr */
65#define GHOSTTY_COLOR_NAMED_BRIGHT_MAGENTA 13
66/** Bright cyan color (14) @ingroup sgr */
67#define GHOSTTY_COLOR_NAMED_BRIGHT_CYAN 14
68/** Bright white color (15) @ingroup sgr */
69#define GHOSTTY_COLOR_NAMED_BRIGHT_WHITE 15
70
71/** @} */
72
73/**
74 * Get the RGB color components.
75 *
76 * This function extracts the individual red, green, and blue components
77 * from a GhosttyColorRgb value. Primarily useful in WebAssembly environments
78 * where accessing struct fields directly is difficult.
79 *
80 * @param color The RGB color value
81 * @param r Pointer to store the red component (0-255)
82 * @param g Pointer to store the green component (0-255)
83 * @param b Pointer to store the blue component (0-255)
84 *
85 * @ingroup sgr
86 */
87void ghostty_color_rgb_get(GhosttyColorRgb color,
88 uint8_t* r,
89 uint8_t* g,
90 uint8_t* b);
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif /* GHOSTTY_VT_COLOR_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/key.h+80−0
@@ -0,0 +1,80 @@
1/**
2 * @file key.h
3 *
4 * Key encoding module - encode key events into terminal escape sequences.
5 */
6
7#ifndef GHOSTTY_VT_KEY_H
8#define GHOSTTY_VT_KEY_H
9
10/** @defgroup key Key Encoding
11 *
12 * Utilities for encoding key events into terminal escape sequences,
13 * supporting both legacy encoding as well as Kitty Keyboard Protocol.
14 *
15 * ## Basic Usage
16 *
17 * 1. Create an encoder instance with ghostty_key_encoder_new()
18 * 2. Configure encoder options with ghostty_key_encoder_setopt().
19 * 3. For each key event:
20 * - Create a key event with ghostty_key_event_new()
21 * - Set event properties (action, key, modifiers, etc.)
22 * - Encode with ghostty_key_encoder_encode()
23 * - Free the event with ghostty_key_event_free()
24 * - Note: You can also reuse the same key event multiple times by
25 * changing its properties.
26 * 4. Free the encoder with ghostty_key_encoder_free() when done
27 *
28 * ## Example
29 *
30 * @code{.c}
31 * #include <assert.h>
32 * #include <stdio.h>
33 * #include <ghostty/vt.h>
34 *
35 * int main() {
36 * // Create encoder
37 * GhosttyKeyEncoder encoder;
38 * GhosttyResult result = ghostty_key_encoder_new(NULL, &encoder);
39 * assert(result == GHOSTTY_SUCCESS);
40 *
41 * // Enable Kitty keyboard protocol with all features
42 * ghostty_key_encoder_setopt(encoder, GHOSTTY_KEY_ENCODER_OPT_KITTY_FLAGS,
43 * &(uint8_t){GHOSTTY_KITTY_KEY_ALL});
44 *
45 * // Create and configure key event for Ctrl+C press
46 * GhosttyKeyEvent event;
47 * result = ghostty_key_event_new(NULL, &event);
48 * assert(result == GHOSTTY_SUCCESS);
49 * ghostty_key_event_set_action(event, GHOSTTY_KEY_ACTION_PRESS);
50 * ghostty_key_event_set_key(event, GHOSTTY_KEY_C);
51 * ghostty_key_event_set_mods(event, GHOSTTY_MODS_CTRL);
52 *
53 * // Encode the key event
54 * char buf[128];
55 * size_t written = 0;
56 * result = ghostty_key_encoder_encode(encoder, event, buf, sizeof(buf), &written);
57 * assert(result == GHOSTTY_SUCCESS);
58 *
59 * // Use the encoded sequence (e.g., write to terminal)
60 * fwrite(buf, 1, written, stdout);
61 *
62 * // Cleanup
63 * ghostty_key_event_free(event);
64 * ghostty_key_encoder_free(encoder);
65 * return 0;
66 * }
67 * @endcode
68 *
69 * For a complete working example, see example/c-vt-key-encode in the
70 * repository.
71 *
72 * @{
73 */
74
75#include <ghostty/vt/key/event.h>
76#include <ghostty/vt/key/encoder.h>
77
78/** @} */
79
80#endif /* GHOSTTY_VT_KEY_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/key/encoder.h+221−0
@@ -0,0 +1,221 @@
1/**
2 * @file encoder.h
3 *
4 * Key event encoding to terminal escape sequences.
5 */
6
7#ifndef GHOSTTY_VT_KEY_ENCODER_H
8#define GHOSTTY_VT_KEY_ENCODER_H
9
10#include <stddef.h>
11#include <stdint.h>
12#include <ghostty/vt/result.h>
13#include <ghostty/vt/allocator.h>
14#include <ghostty/vt/key/event.h>
15
16/**
17 * Opaque handle to a key encoder instance.
18 *
19 * This handle represents a key encoder that converts key events into terminal
20 * escape sequences.
21 *
22 * @ingroup key
23 */
24typedef struct GhosttyKeyEncoder *GhosttyKeyEncoder;
25
26/**
27 * Kitty keyboard protocol flags.
28 *
29 * Bitflags representing the various modes of the Kitty keyboard protocol.
30 * These can be combined using bitwise OR operations. Valid values all
31 * start with `GHOSTTY_KITTY_KEY_`.
32 *
33 * @ingroup key
34 */
35typedef uint8_t GhosttyKittyKeyFlags;
36
37/** Kitty keyboard protocol disabled (all flags off) */
38#define GHOSTTY_KITTY_KEY_DISABLED 0
39
40/** Disambiguate escape codes */
41#define GHOSTTY_KITTY_KEY_DISAMBIGUATE (1 << 0)
42
43/** Report key press and release events */
44#define GHOSTTY_KITTY_KEY_REPORT_EVENTS (1 << 1)
45
46/** Report alternate key codes */
47#define GHOSTTY_KITTY_KEY_REPORT_ALTERNATES (1 << 2)
48
49/** Report all key events including those normally handled by the terminal */
50#define GHOSTTY_KITTY_KEY_REPORT_ALL (1 << 3)
51
52/** Report associated text with key events */
53#define GHOSTTY_KITTY_KEY_REPORT_ASSOCIATED (1 << 4)
54
55/** All Kitty keyboard protocol flags enabled */
56#define GHOSTTY_KITTY_KEY_ALL (GHOSTTY_KITTY_KEY_DISAMBIGUATE | GHOSTTY_KITTY_KEY_REPORT_EVENTS | GHOSTTY_KITTY_KEY_REPORT_ALTERNATES | GHOSTTY_KITTY_KEY_REPORT_ALL | GHOSTTY_KITTY_KEY_REPORT_ASSOCIATED)
57
58/**
59 * macOS option key behavior.
60 *
61 * Determines whether the "option" key on macOS is treated as "alt" or not.
62 * See the Ghostty `macos-option-as-alt` configuration option for more details.
63 *
64 * @ingroup key
65 */
66typedef enum {
67 /** Option key is not treated as alt */
68 GHOSTTY_OPTION_AS_ALT_FALSE = 0,
69 /** Option key is treated as alt */
70 GHOSTTY_OPTION_AS_ALT_TRUE = 1,
71 /** Only left option key is treated as alt */
72 GHOSTTY_OPTION_AS_ALT_LEFT = 2,
73 /** Only right option key is treated as alt */
74 GHOSTTY_OPTION_AS_ALT_RIGHT = 3,
75} GhosttyOptionAsAlt;
76
77/**
78 * Key encoder option identifiers.
79 *
80 * These values are used with ghostty_key_encoder_setopt() to configure
81 * the behavior of the key encoder.
82 *
83 * @ingroup key
84 */
85typedef enum {
86 /** Terminal DEC mode 1: cursor key application mode (value: bool) */
87 GHOSTTY_KEY_ENCODER_OPT_CURSOR_KEY_APPLICATION = 0,
88
89 /** Terminal DEC mode 66: keypad key application mode (value: bool) */
90 GHOSTTY_KEY_ENCODER_OPT_KEYPAD_KEY_APPLICATION = 1,
91
92 /** Terminal DEC mode 1035: ignore keypad with numlock (value: bool) */
93 GHOSTTY_KEY_ENCODER_OPT_IGNORE_KEYPAD_WITH_NUMLOCK = 2,
94
95 /** Terminal DEC mode 1036: alt sends escape prefix (value: bool) */
96 GHOSTTY_KEY_ENCODER_OPT_ALT_ESC_PREFIX = 3,
97
98 /** xterm modifyOtherKeys mode 2 (value: bool) */
99 GHOSTTY_KEY_ENCODER_OPT_MODIFY_OTHER_KEYS_STATE_2 = 4,
100
101 /** Kitty keyboard protocol flags (value: GhosttyKittyKeyFlags bitmask) */
102 GHOSTTY_KEY_ENCODER_OPT_KITTY_FLAGS = 5,
103
104 /** macOS option-as-alt setting (value: GhosttyOptionAsAlt) */
105 GHOSTTY_KEY_ENCODER_OPT_MACOS_OPTION_AS_ALT = 6,
106} GhosttyKeyEncoderOption;
107
108/**
109 * Create a new key encoder instance.
110 *
111 * Creates a new key encoder with default options. The encoder can be configured
112 * using ghostty_key_encoder_setopt() and must be freed using
113 * ghostty_key_encoder_free() when no longer needed.
114 *
115 * @param allocator Pointer to the allocator to use for memory management, or NULL to use the default allocator
116 * @param encoder Pointer to store the created encoder handle
117 * @return GHOSTTY_SUCCESS on success, or an error code on failure
118 *
119 * @ingroup key
120 */
121GhosttyResult ghostty_key_encoder_new(const GhosttyAllocator *allocator, GhosttyKeyEncoder *encoder);
122
123/**
124 * Free a key encoder instance.
125 *
126 * Releases all resources associated with the key encoder. After this call,
127 * the encoder handle becomes invalid and must not be used.
128 *
129 * @param encoder The encoder handle to free (may be NULL)
130 *
131 * @ingroup key
132 */
133void ghostty_key_encoder_free(GhosttyKeyEncoder encoder);
134
135/**
136 * Set an option on the key encoder.
137 *
138 * Configures the behavior of the key encoder. Options control various aspects
139 * of encoding such as terminal modes (cursor key application mode, keypad mode),
140 * protocol selection (Kitty keyboard protocol flags), and platform-specific
141 * behaviors (macOS option-as-alt).
142 *
143 * A null pointer value does nothing. It does not reset the value to the
144 * default. The setopt call will do nothing.
145 *
146 * @param encoder The encoder handle, must not be NULL
147 * @param option The option to set
148 * @param value Pointer to the value to set (type depends on the option)
149 *
150 * @ingroup key
151 */
152void ghostty_key_encoder_setopt(GhosttyKeyEncoder encoder, GhosttyKeyEncoderOption option, const void *value);
153
154/**
155 * Encode a key event into a terminal escape sequence.
156 *
157 * Converts a key event into the appropriate terminal escape sequence based on
158 * the encoder's current options. The sequence is written to the provided buffer.
159 *
160 * Not all key events produce output. For example, unmodified modifier keys
161 * typically don't generate escape sequences. Check the out_len parameter to
162 * determine if any data was written.
163 *
164 * If the output buffer is too small, this function returns GHOSTTY_OUT_OF_MEMORY
165 * and out_len will contain the required buffer size. The caller can then
166 * allocate a larger buffer and call the function again.
167 *
168 * @param encoder The encoder handle, must not be NULL
169 * @param event The key event to encode, must not be NULL
170 * @param out_buf Buffer to write the encoded sequence to
171 * @param out_buf_size Size of the output buffer in bytes
172 * @param out_len Pointer to store the number of bytes written (may be NULL)
173 * @return GHOSTTY_SUCCESS on success, GHOSTTY_OUT_OF_MEMORY if buffer too small, or other error code
174 *
175 * ## Example: Calculate required buffer size
176 *
177 * @code{.c}
178 * // Query the required size with a NULL buffer (always returns OUT_OF_MEMORY)
179 * size_t required = 0;
180 * GhosttyResult result = ghostty_key_encoder_encode(encoder, event, NULL, 0, &required);
181 * assert(result == GHOSTTY_OUT_OF_MEMORY);
182 *
183 * // Allocate buffer of required size
184 * char *buf = malloc(required);
185 *
186 * // Encode with properly sized buffer
187 * size_t written = 0;
188 * result = ghostty_key_encoder_encode(encoder, event, buf, required, &written);
189 * assert(result == GHOSTTY_SUCCESS);
190 *
191 * // Use the encoded sequence...
192 *
193 * free(buf);
194 * @endcode
195 *
196 * ## Example: Direct encoding with static buffer
197 *
198 * @code{.c}
199 * // Most escape sequences are short, so a static buffer often suffices
200 * char buf[128];
201 * size_t written = 0;
202 * GhosttyResult result = ghostty_key_encoder_encode(encoder, event, buf, sizeof(buf), &written);
203 *
204 * if (result == GHOSTTY_SUCCESS) {
205 * // Write the encoded sequence to the terminal
206 * write(pty_fd, buf, written);
207 * } else if (result == GHOSTTY_OUT_OF_MEMORY) {
208 * // Buffer too small, written contains required size
209 * char *dynamic_buf = malloc(written);
210 * result = ghostty_key_encoder_encode(encoder, event, dynamic_buf, written, &written);
211 * assert(result == GHOSTTY_SUCCESS);
212 * write(pty_fd, dynamic_buf, written);
213 * free(dynamic_buf);
214 * }
215 * @endcode
216 *
217 * @ingroup key
218 */
219GhosttyResult ghostty_key_encoder_encode(GhosttyKeyEncoder encoder, GhosttyKeyEvent event, char *out_buf, size_t out_buf_size, size_t *out_len);
220
221#endif /* GHOSTTY_VT_KEY_ENCODER_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/key/event.h+474−0
@@ -0,0 +1,474 @@
1/**
2 * @file event.h
3 *
4 * Key event representation and manipulation.
5 */
6
7#ifndef GHOSTTY_VT_KEY_EVENT_H
8#define GHOSTTY_VT_KEY_EVENT_H
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <ghostty/vt/result.h>
14#include <ghostty/vt/allocator.h>
15
16/**
17 * Opaque handle to a key event.
18 *
19 * This handle represents a keyboard input event containing information about
20 * the physical key pressed, modifiers, and generated text.
21 *
22 * @ingroup key
23 */
24typedef struct GhosttyKeyEvent *GhosttyKeyEvent;
25
26/**
27 * Keyboard input event types.
28 *
29 * @ingroup key
30 */
31typedef enum {
32 /** Key was released */
33 GHOSTTY_KEY_ACTION_RELEASE = 0,
34 /** Key was pressed */
35 GHOSTTY_KEY_ACTION_PRESS = 1,
36 /** Key is being repeated (held down) */
37 GHOSTTY_KEY_ACTION_REPEAT = 2,
38} GhosttyKeyAction;
39
40/**
41 * Keyboard modifier keys bitmask.
42 *
43 * A bitmask representing all keyboard modifiers. This tracks which modifier keys
44 * are pressed and, where supported by the platform, which side (left or right)
45 * of each modifier is active.
46 *
47 * Use the GHOSTTY_MODS_* constants to test and set individual modifiers.
48 *
49 * Modifier side bits are only meaningful when the corresponding modifier bit is set.
50 * Not all platforms support distinguishing between left and right modifier
51 * keys and Ghostty is built to expect that some platforms may not provide this
52 * information.
53 *
54 * @ingroup key
55 */
56typedef uint16_t GhosttyMods;
57
58/** Shift key is pressed */
59#define GHOSTTY_MODS_SHIFT (1 << 0)
60/** Control key is pressed */
61#define GHOSTTY_MODS_CTRL (1 << 1)
62/** Alt/Option key is pressed */
63#define GHOSTTY_MODS_ALT (1 << 2)
64/** Super/Command/Windows key is pressed */
65#define GHOSTTY_MODS_SUPER (1 << 3)
66/** Caps Lock is active */
67#define GHOSTTY_MODS_CAPS_LOCK (1 << 4)
68/** Num Lock is active */
69#define GHOSTTY_MODS_NUM_LOCK (1 << 5)
70
71/**
72 * Right shift is pressed (0 = left, 1 = right).
73 * Only meaningful when GHOSTTY_MODS_SHIFT is set.
74 */
75#define GHOSTTY_MODS_SHIFT_SIDE (1 << 6)
76/**
77 * Right ctrl is pressed (0 = left, 1 = right).
78 * Only meaningful when GHOSTTY_MODS_CTRL is set.
79 */
80#define GHOSTTY_MODS_CTRL_SIDE (1 << 7)
81/**
82 * Right alt is pressed (0 = left, 1 = right).
83 * Only meaningful when GHOSTTY_MODS_ALT is set.
84 */
85#define GHOSTTY_MODS_ALT_SIDE (1 << 8)
86/**
87 * Right super is pressed (0 = left, 1 = right).
88 * Only meaningful when GHOSTTY_MODS_SUPER is set.
89 */
90#define GHOSTTY_MODS_SUPER_SIDE (1 << 9)
91
92/**
93 * Physical key codes.
94 *
95 * The set of key codes that Ghostty is aware of. These represent physical keys
96 * on the keyboard and are layout-independent. For example, the "a" key on a US
97 * keyboard is the same as the "ф" key on a Russian keyboard, but both will
98 * report the same key_a value.
99 *
100 * Layout-dependent strings are provided separately as UTF-8 text and are produced
101 * by the platform. These values are based on the W3C UI Events KeyboardEvent code
102 * standard. See: https://www.w3.org/TR/uievents-code
103 *
104 * @ingroup key
105 */
106typedef enum {
107 GHOSTTY_KEY_UNIDENTIFIED = 0,
108
109 // Writing System Keys (W3C § 3.1.1)
110 GHOSTTY_KEY_BACKQUOTE,
111 GHOSTTY_KEY_BACKSLASH,
112 GHOSTTY_KEY_BRACKET_LEFT,
113 GHOSTTY_KEY_BRACKET_RIGHT,
114 GHOSTTY_KEY_COMMA,
115 GHOSTTY_KEY_DIGIT_0,
116 GHOSTTY_KEY_DIGIT_1,
117 GHOSTTY_KEY_DIGIT_2,
118 GHOSTTY_KEY_DIGIT_3,
119 GHOSTTY_KEY_DIGIT_4,
120 GHOSTTY_KEY_DIGIT_5,
121 GHOSTTY_KEY_DIGIT_6,
122 GHOSTTY_KEY_DIGIT_7,
123 GHOSTTY_KEY_DIGIT_8,
124 GHOSTTY_KEY_DIGIT_9,
125 GHOSTTY_KEY_EQUAL,
126 GHOSTTY_KEY_INTL_BACKSLASH,
127 GHOSTTY_KEY_INTL_RO,
128 GHOSTTY_KEY_INTL_YEN,
129 GHOSTTY_KEY_A,
130 GHOSTTY_KEY_B,
131 GHOSTTY_KEY_C,
132 GHOSTTY_KEY_D,
133 GHOSTTY_KEY_E,
134 GHOSTTY_KEY_F,
135 GHOSTTY_KEY_G,
136 GHOSTTY_KEY_H,
137 GHOSTTY_KEY_I,
138 GHOSTTY_KEY_J,
139 GHOSTTY_KEY_K,
140 GHOSTTY_KEY_L,
141 GHOSTTY_KEY_M,
142 GHOSTTY_KEY_N,
143 GHOSTTY_KEY_O,
144 GHOSTTY_KEY_P,
145 GHOSTTY_KEY_Q,
146 GHOSTTY_KEY_R,
147 GHOSTTY_KEY_S,
148 GHOSTTY_KEY_T,
149 GHOSTTY_KEY_U,
150 GHOSTTY_KEY_V,
151 GHOSTTY_KEY_W,
152 GHOSTTY_KEY_X,
153 GHOSTTY_KEY_Y,
154 GHOSTTY_KEY_Z,
155 GHOSTTY_KEY_MINUS,
156 GHOSTTY_KEY_PERIOD,
157 GHOSTTY_KEY_QUOTE,
158 GHOSTTY_KEY_SEMICOLON,
159 GHOSTTY_KEY_SLASH,
160
161 // Functional Keys (W3C § 3.1.2)
162 GHOSTTY_KEY_ALT_LEFT,
163 GHOSTTY_KEY_ALT_RIGHT,
164 GHOSTTY_KEY_BACKSPACE,
165 GHOSTTY_KEY_CAPS_LOCK,
166 GHOSTTY_KEY_CONTEXT_MENU,
167 GHOSTTY_KEY_CONTROL_LEFT,
168 GHOSTTY_KEY_CONTROL_RIGHT,
169 GHOSTTY_KEY_ENTER,
170 GHOSTTY_KEY_META_LEFT,
171 GHOSTTY_KEY_META_RIGHT,
172 GHOSTTY_KEY_SHIFT_LEFT,
173 GHOSTTY_KEY_SHIFT_RIGHT,
174 GHOSTTY_KEY_SPACE,
175 GHOSTTY_KEY_TAB,
176 GHOSTTY_KEY_CONVERT,
177 GHOSTTY_KEY_KANA_MODE,
178 GHOSTTY_KEY_NON_CONVERT,
179
180 // Control Pad Section (W3C § 3.2)
181 GHOSTTY_KEY_DELETE,
182 GHOSTTY_KEY_END,
183 GHOSTTY_KEY_HELP,
184 GHOSTTY_KEY_HOME,
185 GHOSTTY_KEY_INSERT,
186 GHOSTTY_KEY_PAGE_DOWN,
187 GHOSTTY_KEY_PAGE_UP,
188
189 // Arrow Pad Section (W3C § 3.3)
190 GHOSTTY_KEY_ARROW_DOWN,
191 GHOSTTY_KEY_ARROW_LEFT,
192 GHOSTTY_KEY_ARROW_RIGHT,
193 GHOSTTY_KEY_ARROW_UP,
194
195 // Numpad Section (W3C § 3.4)
196 GHOSTTY_KEY_NUM_LOCK,
197 GHOSTTY_KEY_NUMPAD_0,
198 GHOSTTY_KEY_NUMPAD_1,
199 GHOSTTY_KEY_NUMPAD_2,
200 GHOSTTY_KEY_NUMPAD_3,
201 GHOSTTY_KEY_NUMPAD_4,
202 GHOSTTY_KEY_NUMPAD_5,
203 GHOSTTY_KEY_NUMPAD_6,
204 GHOSTTY_KEY_NUMPAD_7,
205 GHOSTTY_KEY_NUMPAD_8,
206 GHOSTTY_KEY_NUMPAD_9,
207 GHOSTTY_KEY_NUMPAD_ADD,
208 GHOSTTY_KEY_NUMPAD_BACKSPACE,
209 GHOSTTY_KEY_NUMPAD_CLEAR,
210 GHOSTTY_KEY_NUMPAD_CLEAR_ENTRY,
211 GHOSTTY_KEY_NUMPAD_COMMA,
212 GHOSTTY_KEY_NUMPAD_DECIMAL,
213 GHOSTTY_KEY_NUMPAD_DIVIDE,
214 GHOSTTY_KEY_NUMPAD_ENTER,
215 GHOSTTY_KEY_NUMPAD_EQUAL,
216 GHOSTTY_KEY_NUMPAD_MEMORY_ADD,
217 GHOSTTY_KEY_NUMPAD_MEMORY_CLEAR,
218 GHOSTTY_KEY_NUMPAD_MEMORY_RECALL,
219 GHOSTTY_KEY_NUMPAD_MEMORY_STORE,
220 GHOSTTY_KEY_NUMPAD_MEMORY_SUBTRACT,
221 GHOSTTY_KEY_NUMPAD_MULTIPLY,
222 GHOSTTY_KEY_NUMPAD_PAREN_LEFT,
223 GHOSTTY_KEY_NUMPAD_PAREN_RIGHT,
224 GHOSTTY_KEY_NUMPAD_SUBTRACT,
225 GHOSTTY_KEY_NUMPAD_SEPARATOR,
226 GHOSTTY_KEY_NUMPAD_UP,
227 GHOSTTY_KEY_NUMPAD_DOWN,
228 GHOSTTY_KEY_NUMPAD_RIGHT,
229 GHOSTTY_KEY_NUMPAD_LEFT,
230 GHOSTTY_KEY_NUMPAD_BEGIN,
231 GHOSTTY_KEY_NUMPAD_HOME,
232 GHOSTTY_KEY_NUMPAD_END,
233 GHOSTTY_KEY_NUMPAD_INSERT,
234 GHOSTTY_KEY_NUMPAD_DELETE,
235 GHOSTTY_KEY_NUMPAD_PAGE_UP,
236 GHOSTTY_KEY_NUMPAD_PAGE_DOWN,
237
238 // Function Section (W3C § 3.5)
239 GHOSTTY_KEY_ESCAPE,
240 GHOSTTY_KEY_F1,
241 GHOSTTY_KEY_F2,
242 GHOSTTY_KEY_F3,
243 GHOSTTY_KEY_F4,
244 GHOSTTY_KEY_F5,
245 GHOSTTY_KEY_F6,
246 GHOSTTY_KEY_F7,
247 GHOSTTY_KEY_F8,
248 GHOSTTY_KEY_F9,
249 GHOSTTY_KEY_F10,
250 GHOSTTY_KEY_F11,
251 GHOSTTY_KEY_F12,
252 GHOSTTY_KEY_F13,
253 GHOSTTY_KEY_F14,
254 GHOSTTY_KEY_F15,
255 GHOSTTY_KEY_F16,
256 GHOSTTY_KEY_F17,
257 GHOSTTY_KEY_F18,
258 GHOSTTY_KEY_F19,
259 GHOSTTY_KEY_F20,
260 GHOSTTY_KEY_F21,
261 GHOSTTY_KEY_F22,
262 GHOSTTY_KEY_F23,
263 GHOSTTY_KEY_F24,
264 GHOSTTY_KEY_F25,
265 GHOSTTY_KEY_FN,
266 GHOSTTY_KEY_FN_LOCK,
267 GHOSTTY_KEY_PRINT_SCREEN,
268 GHOSTTY_KEY_SCROLL_LOCK,
269 GHOSTTY_KEY_PAUSE,
270
271 // Media Keys (W3C § 3.6)
272 GHOSTTY_KEY_BROWSER_BACK,
273 GHOSTTY_KEY_BROWSER_FAVORITES,
274 GHOSTTY_KEY_BROWSER_FORWARD,
275 GHOSTTY_KEY_BROWSER_HOME,
276 GHOSTTY_KEY_BROWSER_REFRESH,
277 GHOSTTY_KEY_BROWSER_SEARCH,
278 GHOSTTY_KEY_BROWSER_STOP,
279 GHOSTTY_KEY_EJECT,
280 GHOSTTY_KEY_LAUNCH_APP_1,
281 GHOSTTY_KEY_LAUNCH_APP_2,
282 GHOSTTY_KEY_LAUNCH_MAIL,
283 GHOSTTY_KEY_MEDIA_PLAY_PAUSE,
284 GHOSTTY_KEY_MEDIA_SELECT,
285 GHOSTTY_KEY_MEDIA_STOP,
286 GHOSTTY_KEY_MEDIA_TRACK_NEXT,
287 GHOSTTY_KEY_MEDIA_TRACK_PREVIOUS,
288 GHOSTTY_KEY_POWER,
289 GHOSTTY_KEY_SLEEP,
290 GHOSTTY_KEY_AUDIO_VOLUME_DOWN,
291 GHOSTTY_KEY_AUDIO_VOLUME_MUTE,
292 GHOSTTY_KEY_AUDIO_VOLUME_UP,
293 GHOSTTY_KEY_WAKE_UP,
294
295 // Legacy, Non-standard, and Special Keys (W3C § 3.7)
296 GHOSTTY_KEY_COPY,
297 GHOSTTY_KEY_CUT,
298 GHOSTTY_KEY_PASTE,
299} GhosttyKey;
300
301/**
302 * Create a new key event instance.
303 *
304 * Creates a new key event with default values. The event must be freed using
305 * ghostty_key_event_free() when no longer needed.
306 *
307 * @param allocator Pointer to the allocator to use for memory management, or NULL to use the default allocator
308 * @param event Pointer to store the created key event handle
309 * @return GHOSTTY_SUCCESS on success, or an error code on failure
310 *
311 * @ingroup key
312 */
313GhosttyResult ghostty_key_event_new(const GhosttyAllocator *allocator, GhosttyKeyEvent *event);
314
315/**
316 * Free a key event instance.
317 *
318 * Releases all resources associated with the key event. After this call,
319 * the event handle becomes invalid and must not be used.
320 *
321 * @param event The key event handle to free (may be NULL)
322 *
323 * @ingroup key
324 */
325void ghostty_key_event_free(GhosttyKeyEvent event);
326
327/**
328 * Set the key action (press, release, repeat).
329 *
330 * @param event The key event handle, must not be NULL
331 * @param action The action to set
332 *
333 * @ingroup key
334 */
335void ghostty_key_event_set_action(GhosttyKeyEvent event, GhosttyKeyAction action);
336
337/**
338 * Get the key action (press, release, repeat).
339 *
340 * @param event The key event handle, must not be NULL
341 * @return The key action
342 *
343 * @ingroup key
344 */
345GhosttyKeyAction ghostty_key_event_get_action(GhosttyKeyEvent event);
346
347/**
348 * Set the physical key code.
349 *
350 * @param event The key event handle, must not be NULL
351 * @param key The physical key code to set
352 *
353 * @ingroup key
354 */
355void ghostty_key_event_set_key(GhosttyKeyEvent event, GhosttyKey key);
356
357/**
358 * Get the physical key code.
359 *
360 * @param event The key event handle, must not be NULL
361 * @return The physical key code
362 *
363 * @ingroup key
364 */
365GhosttyKey ghostty_key_event_get_key(GhosttyKeyEvent event);
366
367/**
368 * Set the modifier keys bitmask.
369 *
370 * @param event The key event handle, must not be NULL
371 * @param mods The modifier keys bitmask to set
372 *
373 * @ingroup key
374 */
375void ghostty_key_event_set_mods(GhosttyKeyEvent event, GhosttyMods mods);
376
377/**
378 * Get the modifier keys bitmask.
379 *
380 * @param event The key event handle, must not be NULL
381 * @return The modifier keys bitmask
382 *
383 * @ingroup key
384 */
385GhosttyMods ghostty_key_event_get_mods(GhosttyKeyEvent event);
386
387/**
388 * Set the consumed modifiers bitmask.
389 *
390 * @param event The key event handle, must not be NULL
391 * @param consumed_mods The consumed modifiers bitmask to set
392 *
393 * @ingroup key
394 */
395void ghostty_key_event_set_consumed_mods(GhosttyKeyEvent event, GhosttyMods consumed_mods);
396
397/**
398 * Get the consumed modifiers bitmask.
399 *
400 * @param event The key event handle, must not be NULL
401 * @return The consumed modifiers bitmask
402 *
403 * @ingroup key
404 */
405GhosttyMods ghostty_key_event_get_consumed_mods(GhosttyKeyEvent event);
406
407/**
408 * Set whether the key event is part of a composition sequence.
409 *
410 * @param event The key event handle, must not be NULL
411 * @param composing Whether the key event is part of a composition sequence
412 *
413 * @ingroup key
414 */
415void ghostty_key_event_set_composing(GhosttyKeyEvent event, bool composing);
416
417/**
418 * Get whether the key event is part of a composition sequence.
419 *
420 * @param event The key event handle, must not be NULL
421 * @return Whether the key event is part of a composition sequence
422 *
423 * @ingroup key
424 */
425bool ghostty_key_event_get_composing(GhosttyKeyEvent event);
426
427/**
428 * Set the UTF-8 text generated by the key event.
429 *
430 * The key event does NOT take ownership of the text pointer. The caller
431 * must ensure the string remains valid for the lifetime needed by the event.
432 *
433 * @param event The key event handle, must not be NULL
434 * @param utf8 The UTF-8 text to set (or NULL for empty)
435 * @param len Length of the UTF-8 text in bytes
436 *
437 * @ingroup key
438 */
439void ghostty_key_event_set_utf8(GhosttyKeyEvent event, const char *utf8, size_t len);
440
441/**
442 * Get the UTF-8 text generated by the key event.
443 *
444 * The returned pointer is valid until the event is freed or the UTF-8 text is modified.
445 *
446 * @param event The key event handle, must not be NULL
447 * @param len Pointer to store the length of the UTF-8 text in bytes (may be NULL)
448 * @return The UTF-8 text (or NULL for empty)
449 *
450 * @ingroup key
451 */
452const char *ghostty_key_event_get_utf8(GhosttyKeyEvent event, size_t *len);
453
454/**
455 * Set the unshifted Unicode codepoint.
456 *
457 * @param event The key event handle, must not be NULL
458 * @param codepoint The unshifted Unicode codepoint to set
459 *
460 * @ingroup key
461 */
462void ghostty_key_event_set_unshifted_codepoint(GhosttyKeyEvent event, uint32_t codepoint);
463
464/**
465 * Get the unshifted Unicode codepoint.
466 *
467 * @param event The key event handle, must not be NULL
468 * @return The unshifted Unicode codepoint
469 *
470 * @ingroup key
471 */
472uint32_t ghostty_key_event_get_unshifted_codepoint(GhosttyKeyEvent event);
473
474#endif /* GHOSTTY_VT_KEY_EVENT_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/osc.h+233−0
@@ -0,0 +1,233 @@
1/**
2 * @file osc.h
3 *
4 * OSC (Operating System Command) sequence parser and command handling.
5 */
6
7#ifndef GHOSTTY_VT_OSC_H
8#define GHOSTTY_VT_OSC_H
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <ghostty/vt/result.h>
14#include <ghostty/vt/allocator.h>
15
16/**
17 * Opaque handle to an OSC parser instance.
18 *
19 * This handle represents an OSC (Operating System Command) parser that can
20 * be used to parse the contents of OSC sequences.
21 *
22 * @ingroup osc
23 */
24typedef struct GhosttyOscParser *GhosttyOscParser;
25
26/**
27 * Opaque handle to a single OSC command.
28 *
29 * This handle represents a parsed OSC (Operating System Command) command.
30 * The command can be queried for its type and associated data.
31 *
32 * @ingroup osc
33 */
34typedef struct GhosttyOscCommand *GhosttyOscCommand;
35
36/** @defgroup osc OSC Parser
37 *
38 * OSC (Operating System Command) sequence parser and command handling.
39 *
40 * The parser operates in a streaming fashion, processing input byte-by-byte
41 * to handle OSC sequences that may arrive in fragments across multiple reads.
42 * This interface makes it easy to integrate into most environments and avoids
43 * over-allocating buffers.
44 *
45 * ## Basic Usage
46 *
47 * 1. Create a parser instance with ghostty_osc_new()
48 * 2. Feed bytes to the parser using ghostty_osc_next()
49 * 3. Finalize parsing with ghostty_osc_end() to get the command
50 * 4. Query command type and extract data using ghostty_osc_command_type()
51 * and ghostty_osc_command_data()
52 * 5. Free the parser with ghostty_osc_free() when done
53 *
54 * @{
55 */
56
57/**
58 * OSC command types.
59 *
60 * @ingroup osc
61 */
62typedef enum {
63 GHOSTTY_OSC_COMMAND_INVALID = 0,
64 GHOSTTY_OSC_COMMAND_CHANGE_WINDOW_TITLE = 1,
65 GHOSTTY_OSC_COMMAND_CHANGE_WINDOW_ICON = 2,
66 GHOSTTY_OSC_COMMAND_SEMANTIC_PROMPT = 3,
67 GHOSTTY_OSC_COMMAND_CLIPBOARD_CONTENTS = 4,
68 GHOSTTY_OSC_COMMAND_REPORT_PWD = 5,
69 GHOSTTY_OSC_COMMAND_MOUSE_SHAPE = 6,
70 GHOSTTY_OSC_COMMAND_COLOR_OPERATION = 7,
71 GHOSTTY_OSC_COMMAND_KITTY_COLOR_PROTOCOL = 8,
72 GHOSTTY_OSC_COMMAND_SHOW_DESKTOP_NOTIFICATION = 9,
73 GHOSTTY_OSC_COMMAND_HYPERLINK_START = 10,
74 GHOSTTY_OSC_COMMAND_HYPERLINK_END = 11,
75 GHOSTTY_OSC_COMMAND_CONEMU_SLEEP = 12,
76 GHOSTTY_OSC_COMMAND_CONEMU_SHOW_MESSAGE_BOX = 13,
77 GHOSTTY_OSC_COMMAND_CONEMU_CHANGE_TAB_TITLE = 14,
78 GHOSTTY_OSC_COMMAND_CONEMU_PROGRESS_REPORT = 15,
79 GHOSTTY_OSC_COMMAND_CONEMU_WAIT_INPUT = 16,
80 GHOSTTY_OSC_COMMAND_CONEMU_GUIMACRO = 17,
81 GHOSTTY_OSC_COMMAND_CONEMU_RUN_PROCESS = 18,
82 GHOSTTY_OSC_COMMAND_CONEMU_OUTPUT_ENVIRONMENT_VARIABLE = 19,
83 GHOSTTY_OSC_COMMAND_CONEMU_XTERM_EMULATION = 20,
84 GHOSTTY_OSC_COMMAND_CONEMU_COMMENT = 21,
85 GHOSTTY_OSC_COMMAND_KITTY_TEXT_SIZING = 22,
86} GhosttyOscCommandType;
87
88/**
89 * OSC command data types.
90 *
91 * These values specify what type of data to extract from an OSC command
92 * using `ghostty_osc_command_data`.
93 *
94 * @ingroup osc
95 */
96typedef enum {
97 /** Invalid data type. Never results in any data extraction. */
98 GHOSTTY_OSC_DATA_INVALID = 0,
99
100 /**
101 * Window title string data.
102 *
103 * Valid for: GHOSTTY_OSC_COMMAND_CHANGE_WINDOW_TITLE
104 *
105 * Output type: const char ** (pointer to null-terminated string)
106 *
107 * Lifetime: Valid until the next call to any ghostty_osc_* function with
108 * the same parser instance. Memory is owned by the parser.
109 */
110 GHOSTTY_OSC_DATA_CHANGE_WINDOW_TITLE_STR = 1,
111} GhosttyOscCommandData;
112
113/**
114 * Create a new OSC parser instance.
115 *
116 * Creates a new OSC (Operating System Command) parser using the provided
117 * allocator. The parser must be freed using ghostty_vt_osc_free() when
118 * no longer needed.
119 *
120 * @param allocator Pointer to the allocator to use for memory management, or NULL to use the default allocator
121 * @param parser Pointer to store the created parser handle
122 * @return GHOSTTY_SUCCESS on success, or an error code on failure
123 *
124 * @ingroup osc
125 */
126GhosttyResult ghostty_osc_new(const GhosttyAllocator *allocator, GhosttyOscParser *parser);
127
128/**
129 * Free an OSC parser instance.
130 *
131 * Releases all resources associated with the OSC parser. After this call,
132 * the parser handle becomes invalid and must not be used.
133 *
134 * @param parser The parser handle to free (may be NULL)
135 *
136 * @ingroup osc
137 */
138void ghostty_osc_free(GhosttyOscParser parser);
139
140/**
141 * Reset an OSC parser instance to its initial state.
142 *
143 * Resets the parser state, clearing any partially parsed OSC sequences
144 * and returning the parser to its initial state. This is useful for
145 * reusing a parser instance or recovering from parse errors.
146 *
147 * @param parser The parser handle to reset, must not be null.
148 *
149 * @ingroup osc
150 */
151void ghostty_osc_reset(GhosttyOscParser parser);
152
153/**
154 * Parse the next byte in an OSC sequence.
155 *
156 * Processes a single byte as part of an OSC sequence. The parser maintains
157 * internal state to track the progress through the sequence. Call this
158 * function for each byte in the sequence data.
159 *
160 * When finished pumping the parser with bytes, call ghostty_osc_end
161 * to get the final result.
162 *
163 * @param parser The parser handle, must not be null.
164 * @param byte The next byte to parse
165 *
166 * @ingroup osc
167 */
168void ghostty_osc_next(GhosttyOscParser parser, uint8_t byte);
169
170/**
171 * Finalize OSC parsing and retrieve the parsed command.
172 *
173 * Call this function after feeding all bytes of an OSC sequence to the parser
174 * using ghostty_osc_next() with the exception of the terminating character
175 * (ESC or ST). This function finalizes the parsing process and returns the
176 * parsed OSC command.
177 *
178 * The return value is never NULL. Invalid commands will return a command
179 * with type GHOSTTY_OSC_COMMAND_INVALID.
180 *
181 * The terminator parameter specifies the byte that terminated the OSC sequence
182 * (typically 0x07 for BEL or 0x5C for ST after ESC). This information is
183 * preserved in the parsed command so that responses can use the same terminator
184 * format for better compatibility with the calling program. For commands that
185 * do not require a response, this parameter is ignored and the resulting
186 * command will not retain the terminator information.
187 *
188 * The returned command handle is valid until the next call to any
189 * `ghostty_osc_*` function with the same parser instance with the exception
190 * of command introspection functions such as `ghostty_osc_command_type`.
191 *
192 * @param parser The parser handle, must not be null.
193 * @param terminator The terminating byte of the OSC sequence (0x07 for BEL, 0x5C for ST)
194 * @return Handle to the parsed OSC command
195 *
196 * @ingroup osc
197 */
198GhosttyOscCommand ghostty_osc_end(GhosttyOscParser parser, uint8_t terminator);
199
200/**
201 * Get the type of an OSC command.
202 *
203 * Returns the type identifier for the given OSC command. This can be used
204 * to determine what kind of command was parsed and what data might be
205 * available from it.
206 *
207 * @param command The OSC command handle to query (may be NULL)
208 * @return The command type, or GHOSTTY_OSC_COMMAND_INVALID if command is NULL
209 *
210 * @ingroup osc
211 */
212GhosttyOscCommandType ghostty_osc_command_type(GhosttyOscCommand command);
213
214/**
215 * Extract data from an OSC command.
216 *
217 * Extracts typed data from the given OSC command based on the specified
218 * data type. The output pointer must be of the appropriate type for the
219 * requested data kind. Valid command types, output types, and memory
220 * safety information are documented in the `GhosttyOscCommandData` enum.
221 *
222 * @param command The OSC command handle to query (may be NULL)
223 * @param data The type of data to extract
224 * @param out Pointer to store the extracted data (type depends on data parameter)
225 * @return true if data extraction was successful, false otherwise
226 *
227 * @ingroup osc
228 */
229bool ghostty_osc_command_data(GhosttyOscCommand command, GhosttyOscCommandData data, void *out);
230
231/** @} */
232
233#endif /* GHOSTTY_VT_OSC_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/paste.h+75−0
@@ -0,0 +1,75 @@
1/**
2 * @file paste.h
3 *
4 * Paste utilities - validate and encode paste data for terminal input.
5 */
6
7#ifndef GHOSTTY_VT_PASTE_H
8#define GHOSTTY_VT_PASTE_H
9
10/** @defgroup paste Paste Utilities
11 *
12 * Utilities for validating paste data safety.
13 *
14 * ## Basic Usage
15 *
16 * Use ghostty_paste_is_safe() to check if paste data contains potentially
17 * dangerous sequences before sending it to the terminal.
18 *
19 * ## Example
20 *
21 * @code{.c}
22 * #include <stdio.h>
23 * #include <string.h>
24 * #include <ghostty/vt.h>
25 *
26 * int main() {
27 * const char* safe_data = "hello world";
28 * const char* unsafe_data = "rm -rf /\n";
29 *
30 * if (ghostty_paste_is_safe(safe_data, strlen(safe_data))) {
31 * printf("Safe to paste\n");
32 * }
33 *
34 * if (!ghostty_paste_is_safe(unsafe_data, strlen(unsafe_data))) {
35 * printf("Unsafe! Contains newline\n");
36 * }
37 *
38 * return 0;
39 * }
40 * @endcode
41 *
42 * @{
43 */
44
45#include <stdbool.h>
46#include <stddef.h>
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/**
53 * Check if paste data is safe to paste into the terminal.
54 *
55 * Data is considered unsafe if it contains:
56 * - Newlines (`\n`) which can inject commands
57 * - The bracketed paste end sequence (`\x1b[201~`) which can be used
58 * to exit bracketed paste mode and inject commands
59 *
60 * This check is conservative and considers data unsafe regardless of
61 * current terminal state.
62 *
63 * @param data The paste data to check (must not be NULL)
64 * @param len The length of the data in bytes
65 * @return true if the data is safe to paste, false otherwise
66 */
67bool ghostty_paste_is_safe(const char* data, size_t len);
68
69#ifdef __cplusplus
70}
71#endif
72
73/** @} */
74
75#endif /* GHOSTTY_VT_PASTE_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/result.h+22−0
@@ -0,0 +1,22 @@
1/**
2 * @file result.h
3 *
4 * Result codes for libghostty-vt operations.
5 */
6
7#ifndef GHOSTTY_VT_RESULT_H
8#define GHOSTTY_VT_RESULT_H
9
10/**
11 * Result codes for libghostty-vt operations.
12 */
13typedef enum {
14 /** Operation completed successfully */
15 GHOSTTY_SUCCESS = 0,
16 /** Operation failed due to failed allocation */
17 GHOSTTY_OUT_OF_MEMORY = -1,
18 /** Operation failed due to invalid value */
19 GHOSTTY_INVALID_VALUE = -2,
20} GhosttyResult;
21
22#endif /* GHOSTTY_VT_RESULT_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/sgr.h+394−0
@@ -0,0 +1,394 @@
1/**
2 * @file sgr.h
3 *
4 * SGR (Select Graphic Rendition) attribute parsing and handling.
5 */
6
7#ifndef GHOSTTY_VT_SGR_H
8#define GHOSTTY_VT_SGR_H
9
10/** @defgroup sgr SGR Parser
11 *
12 * SGR (Select Graphic Rendition) attribute parser.
13 *
14 * SGR sequences are the syntax used to set styling attributes such as
15 * bold, italic, underline, and colors for text in terminal emulators.
16 * For example, you may be familiar with sequences like `ESC[1;31m`. The
17 * `1;31` is the SGR attribute list.
18 *
19 * The parser processes SGR parameters from CSI sequences (e.g., `ESC[1;31m`)
20 * and returns individual text attributes like bold, italic, colors, etc.
21 * It supports both semicolon (`;`) and colon (`:`) separators, possibly mixed,
22 * and handles various color formats including 8-color, 16-color, 256-color,
23 * X11 named colors, and RGB in multiple formats.
24 *
25 * ## Basic Usage
26 *
27 * 1. Create a parser instance with ghostty_sgr_new()
28 * 2. Set SGR parameters with ghostty_sgr_set_params()
29 * 3. Iterate through attributes using ghostty_sgr_next()
30 * 4. Free the parser with ghostty_sgr_free() when done
31 *
32 * ## Example
33 *
34 * @code{.c}
35 * #include <assert.h>
36 * #include <stdio.h>
37 * #include <ghostty/vt.h>
38 *
39 * int main() {
40 * // Create parser
41 * GhosttySgrParser parser;
42 * GhosttyResult result = ghostty_sgr_new(NULL, &parser);
43 * assert(result == GHOSTTY_SUCCESS);
44 *
45 * // Parse "bold, red foreground" sequence: ESC[1;31m
46 * uint16_t params[] = {1, 31};
47 * result = ghostty_sgr_set_params(parser, params, NULL, 2);
48 * assert(result == GHOSTTY_SUCCESS);
49 *
50 * // Iterate through attributes
51 * GhosttySgrAttribute attr;
52 * while (ghostty_sgr_next(parser, &attr)) {
53 * switch (attr.tag) {
54 * case GHOSTTY_SGR_ATTR_BOLD:
55 * printf("Bold enabled\n");
56 * break;
57 * case GHOSTTY_SGR_ATTR_FG_8:
58 * printf("Foreground color: %d\n", attr.value.fg_8);
59 * break;
60 * default:
61 * break;
62 * }
63 * }
64 *
65 * // Cleanup
66 * ghostty_sgr_free(parser);
67 * return 0;
68 * }
69 * @endcode
70 *
71 * @{
72 */
73
74#include <ghostty/vt/allocator.h>
75#include <ghostty/vt/color.h>
76#include <ghostty/vt/result.h>
77#include <stdbool.h>
78#include <stddef.h>
79#include <stdint.h>
80
81#ifdef __cplusplus
82extern "C" {
83#endif
84
85/**
86 * Opaque handle to an SGR parser instance.
87 *
88 * This handle represents an SGR (Select Graphic Rendition) parser that can
89 * be used to parse SGR sequences and extract individual text attributes.
90 *
91 * @ingroup sgr
92 */
93typedef struct GhosttySgrParser* GhosttySgrParser;
94
95/**
96 * SGR attribute tags.
97 *
98 * These values identify the type of an SGR attribute in a tagged union.
99 * Use the tag to determine which field in the attribute value union to access.
100 *
101 * @ingroup sgr
102 */
103typedef enum {
104 GHOSTTY_SGR_ATTR_UNSET = 0,
105 GHOSTTY_SGR_ATTR_UNKNOWN = 1,
106 GHOSTTY_SGR_ATTR_BOLD = 2,
107 GHOSTTY_SGR_ATTR_RESET_BOLD = 3,
108 GHOSTTY_SGR_ATTR_ITALIC = 4,
109 GHOSTTY_SGR_ATTR_RESET_ITALIC = 5,
110 GHOSTTY_SGR_ATTR_FAINT = 6,
111 GHOSTTY_SGR_ATTR_UNDERLINE = 7,
112 GHOSTTY_SGR_ATTR_RESET_UNDERLINE = 8,
113 GHOSTTY_SGR_ATTR_UNDERLINE_COLOR = 9,
114 GHOSTTY_SGR_ATTR_UNDERLINE_COLOR_256 = 10,
115 GHOSTTY_SGR_ATTR_RESET_UNDERLINE_COLOR = 11,
116 GHOSTTY_SGR_ATTR_OVERLINE = 12,
117 GHOSTTY_SGR_ATTR_RESET_OVERLINE = 13,
118 GHOSTTY_SGR_ATTR_BLINK = 14,
119 GHOSTTY_SGR_ATTR_RESET_BLINK = 15,
120 GHOSTTY_SGR_ATTR_INVERSE = 16,
121 GHOSTTY_SGR_ATTR_RESET_INVERSE = 17,
122 GHOSTTY_SGR_ATTR_INVISIBLE = 18,
123 GHOSTTY_SGR_ATTR_RESET_INVISIBLE = 19,
124 GHOSTTY_SGR_ATTR_STRIKETHROUGH = 20,
125 GHOSTTY_SGR_ATTR_RESET_STRIKETHROUGH = 21,
126 GHOSTTY_SGR_ATTR_DIRECT_COLOR_FG = 22,
127 GHOSTTY_SGR_ATTR_DIRECT_COLOR_BG = 23,
128 GHOSTTY_SGR_ATTR_BG_8 = 24,
129 GHOSTTY_SGR_ATTR_FG_8 = 25,
130 GHOSTTY_SGR_ATTR_RESET_FG = 26,
131 GHOSTTY_SGR_ATTR_RESET_BG = 27,
132 GHOSTTY_SGR_ATTR_BRIGHT_BG_8 = 28,
133 GHOSTTY_SGR_ATTR_BRIGHT_FG_8 = 29,
134 GHOSTTY_SGR_ATTR_BG_256 = 30,
135 GHOSTTY_SGR_ATTR_FG_256 = 31,
136} GhosttySgrAttributeTag;
137
138/**
139 * Underline style types.
140 *
141 * @ingroup sgr
142 */
143typedef enum {
144 GHOSTTY_SGR_UNDERLINE_NONE = 0,
145 GHOSTTY_SGR_UNDERLINE_SINGLE = 1,
146 GHOSTTY_SGR_UNDERLINE_DOUBLE = 2,
147 GHOSTTY_SGR_UNDERLINE_CURLY = 3,
148 GHOSTTY_SGR_UNDERLINE_DOTTED = 4,
149 GHOSTTY_SGR_UNDERLINE_DASHED = 5,
150} GhosttySgrUnderline;
151
152/**
153 * Unknown SGR attribute data.
154 *
155 * Contains the full parameter list and the partial list where parsing
156 * encountered an unknown or invalid sequence.
157 *
158 * @ingroup sgr
159 */
160typedef struct {
161 const uint16_t* full_ptr;
162 size_t full_len;
163 const uint16_t* partial_ptr;
164 size_t partial_len;
165} GhosttySgrUnknown;
166
167/**
168 * SGR attribute value union.
169 *
170 * This union contains all possible attribute values. Use the tag field
171 * to determine which union member is active. Attributes without associated
172 * data (like bold, italic) don't use the union value.
173 *
174 * @ingroup sgr
175 */
176typedef union {
177 GhosttySgrUnknown unknown;
178 GhosttySgrUnderline underline;
179 GhosttyColorRgb underline_color;
180 GhosttyColorPaletteIndex underline_color_256;
181 GhosttyColorRgb direct_color_fg;
182 GhosttyColorRgb direct_color_bg;
183 GhosttyColorPaletteIndex bg_8;
184 GhosttyColorPaletteIndex fg_8;
185 GhosttyColorPaletteIndex bright_bg_8;
186 GhosttyColorPaletteIndex bright_fg_8;
187 GhosttyColorPaletteIndex bg_256;
188 GhosttyColorPaletteIndex fg_256;
189 uint64_t _padding[8];
190} GhosttySgrAttributeValue;
191
192/**
193 * SGR attribute (tagged union).
194 *
195 * A complete SGR attribute with both its type tag and associated value.
196 * Always check the tag field to determine which value union member is valid.
197 *
198 * Attributes without associated data (e.g., GHOSTTY_SGR_ATTR_BOLD) can be
199 * identified by tag alone; the value union is not used for these and
200 * the memory in the value field is undefined.
201 *
202 * @ingroup sgr
203 */
204typedef struct {
205 GhosttySgrAttributeTag tag;
206 GhosttySgrAttributeValue value;
207} GhosttySgrAttribute;
208
209/**
210 * Create a new SGR parser instance.
211 *
212 * Creates a new SGR (Select Graphic Rendition) parser using the provided
213 * allocator. The parser must be freed using ghostty_sgr_free() when
214 * no longer needed.
215 *
216 * @param allocator Pointer to the allocator to use for memory management, or
217 * NULL to use the default allocator
218 * @param parser Pointer to store the created parser handle
219 * @return GHOSTTY_SUCCESS on success, or an error code on failure
220 *
221 * @ingroup sgr
222 */
223GhosttyResult ghostty_sgr_new(const GhosttyAllocator* allocator,
224 GhosttySgrParser* parser);
225
226/**
227 * Free an SGR parser instance.
228 *
229 * Releases all resources associated with the SGR parser. After this call,
230 * the parser handle becomes invalid and must not be used. This includes
231 * any attributes previously returned by ghostty_sgr_next().
232 *
233 * @param parser The parser handle to free (may be NULL)
234 *
235 * @ingroup sgr
236 */
237void ghostty_sgr_free(GhosttySgrParser parser);
238
239/**
240 * Reset an SGR parser instance to the beginning of the parameter list.
241 *
242 * Resets the parser's iteration state without clearing the parameters.
243 * After calling this, ghostty_sgr_next() will start from the beginning
244 * of the parameter list again.
245 *
246 * @param parser The parser handle to reset, must not be NULL
247 *
248 * @ingroup sgr
249 */
250void ghostty_sgr_reset(GhosttySgrParser parser);
251
252/**
253 * Set SGR parameters for parsing.
254 *
255 * Sets the SGR parameter list to parse. Parameters are the numeric values
256 * from a CSI SGR sequence (e.g., for `ESC[1;31m`, params would be {1, 31}).
257 *
258 * The separators array optionally specifies the separator type for each
259 * parameter position. Each byte should be either ';' for semicolon or ':'
260 * for colon. This is needed for certain color formats that use colon
261 * separators (e.g., `ESC[4:3m` for curly underline). Any invalid separator
262 * values are treated as semicolons. The separators array must have the same
263 * length as the params array, if it is not NULL.
264 *
265 * If separators is NULL, all parameters are assumed to be semicolon-separated.
266 *
267 * This function makes an internal copy of the parameter and separator data,
268 * so the caller can safely free or modify the input arrays after this call.
269 *
270 * After calling this function, the parser is automatically reset and ready
271 * to iterate from the beginning.
272 *
273 * @param parser The parser handle, must not be NULL
274 * @param params Array of SGR parameter values
275 * @param separators Optional array of separator characters (';' or ':'), or
276 * NULL
277 * @param len Number of parameters (and separators if provided)
278 * @return GHOSTTY_SUCCESS on success, or an error code on failure
279 *
280 * @ingroup sgr
281 */
282GhosttyResult ghostty_sgr_set_params(GhosttySgrParser parser,
283 const uint16_t* params,
284 const char* separators,
285 size_t len);
286
287/**
288 * Get the next SGR attribute.
289 *
290 * Parses and returns the next attribute from the parameter list.
291 * Call this function repeatedly until it returns false to process
292 * all attributes in the sequence.
293 *
294 * @param parser The parser handle, must not be NULL
295 * @param attr Pointer to store the next attribute
296 * @return true if an attribute was returned, false if no more attributes
297 *
298 * @ingroup sgr
299 */
300bool ghostty_sgr_next(GhosttySgrParser parser, GhosttySgrAttribute* attr);
301
302/**
303 * Get the full parameter list from an unknown SGR attribute.
304 *
305 * This function retrieves the full parameter list that was provided to the
306 * parser when an unknown attribute was encountered. Primarily useful in
307 * WebAssembly environments where accessing struct fields directly is difficult.
308 *
309 * @param unknown The unknown attribute data
310 * @param ptr Pointer to store the pointer to the parameter array (may be NULL)
311 * @return The length of the full parameter array
312 *
313 * @ingroup sgr
314 */
315size_t ghostty_sgr_unknown_full(GhosttySgrUnknown unknown,
316 const uint16_t** ptr);
317
318/**
319 * Get the partial parameter list from an unknown SGR attribute.
320 *
321 * This function retrieves the partial parameter list where parsing stopped
322 * when an unknown attribute was encountered. Primarily useful in WebAssembly
323 * environments where accessing struct fields directly is difficult.
324 *
325 * @param unknown The unknown attribute data
326 * @param ptr Pointer to store the pointer to the parameter array (may be NULL)
327 * @return The length of the partial parameter array
328 *
329 * @ingroup sgr
330 */
331size_t ghostty_sgr_unknown_partial(GhosttySgrUnknown unknown,
332 const uint16_t** ptr);
333
334/**
335 * Get the tag from an SGR attribute.
336 *
337 * This function extracts the tag that identifies which type of attribute
338 * this is. Primarily useful in WebAssembly environments where accessing
339 * struct fields directly is difficult.
340 *
341 * @param attr The SGR attribute
342 * @return The attribute tag
343 *
344 * @ingroup sgr
345 */
346GhosttySgrAttributeTag ghostty_sgr_attribute_tag(GhosttySgrAttribute attr);
347
348/**
349 * Get the value from an SGR attribute.
350 *
351 * This function returns a pointer to the value union from an SGR attribute. Use
352 * the tag to determine which field of the union is valid. Primarily useful in
353 * WebAssembly environments where accessing struct fields directly is difficult.
354 *
355 * @param attr Pointer to the SGR attribute
356 * @return Pointer to the attribute value union
357 *
358 * @ingroup sgr
359 */
360GhosttySgrAttributeValue* ghostty_sgr_attribute_value(
361 GhosttySgrAttribute* attr);
362
363#ifdef __wasm__
364/**
365 * Allocate memory for an SGR attribute (WebAssembly only).
366 *
367 * This is a convenience function for WebAssembly environments to allocate
368 * memory for an SGR attribute structure that can be passed to ghostty_sgr_next.
369 *
370 * @return Pointer to the allocated attribute structure
371 *
372 * @ingroup wasm
373 */
374GhosttySgrAttribute* ghostty_wasm_alloc_sgr_attribute(void);
375
376/**
377 * Free memory for an SGR attribute (WebAssembly only).
378 *
379 * Frees memory allocated by ghostty_wasm_alloc_sgr_attribute.
380 *
381 * @param attr Pointer to the attribute structure to free
382 *
383 * @ingroup wasm
384 */
385void ghostty_wasm_free_sgr_attribute(GhosttySgrAttribute* attr);
386#endif
387
388#ifdef __cplusplus
389}
390#endif
391
392/** @} */
393
394#endif /* GHOSTTY_VT_SGR_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/ghostty/vt/wasm.h+159−0
@@ -0,0 +1,159 @@
1/**
2 * @file wasm.h
3 *
4 * WebAssembly utility functions for libghostty-vt.
5 */
6
7#ifndef GHOSTTY_VT_WASM_H
8#define GHOSTTY_VT_WASM_H
9
10#ifdef __wasm__
11
12#include <stddef.h>
13#include <stdint.h>
14
15/** @defgroup wasm WebAssembly Utilities
16 *
17 * Convenience functions for allocating various types in WebAssembly builds.
18 * **These are only available the libghostty-vt wasm module.**
19 *
20 * Ghostty relies on pointers to various types for ABI compatibility, and
21 * creating those pointers in Wasm can be tedious. These functions provide
22 * a purely additive set of utilities that simplify memory management in
23 * Wasm environments without changing the core C library API.
24 *
25 * @note These functions always use the default allocator. If you need
26 * custom allocation strategies, you should allocate types manually using
27 * your custom allocator. This is a very rare use case in the WebAssembly
28 * world so these are optimized for simplicity.
29 *
30 * ## Example Usage
31 *
32 * Here's a simple example of using the Wasm utilities with the key encoder:
33 *
34 * @code
35 * const { exports } = wasmInstance;
36 * const view = new DataView(wasmMemory.buffer);
37 *
38 * // Create key encoder
39 * const encoderPtr = exports.ghostty_wasm_alloc_opaque();
40 * exports.ghostty_key_encoder_new(null, encoderPtr);
41 * const encoder = view.getUint32(encoder, true);
42 *
43 * // Configure encoder with Kitty protocol flags
44 * const flagsPtr = exports.ghostty_wasm_alloc_u8();
45 * view.setUint8(flagsPtr, 0x1F);
46 * exports.ghostty_key_encoder_setopt(encoder, 5, flagsPtr);
47 *
48 * // Allocate output buffer and size pointer
49 * const bufferSize = 32;
50 * const bufPtr = exports.ghostty_wasm_alloc_u8_array(bufferSize);
51 * const writtenPtr = exports.ghostty_wasm_alloc_usize();
52 *
53 * // Encode the key event
54 * exports.ghostty_key_encoder_encode(
55 * encoder, eventPtr, bufPtr, bufferSize, writtenPtr
56 * );
57 *
58 * // Read encoded output
59 * const bytesWritten = view.getUint32(writtenPtr, true);
60 * const encoded = new Uint8Array(wasmMemory.buffer, bufPtr, bytesWritten);
61 * @endcode
62 *
63 * @remark The code above is pretty ugly! This is the lowest level interface
64 * to the libghostty-vt Wasm module. In practice, this should be wrapped
65 * in a higher-level API that abstracts away all this.
66 *
67 * @{
68 */
69
70/**
71 * Allocate an opaque pointer. This can be used for any opaque pointer
72 * types such as GhosttyKeyEncoder, GhosttyKeyEvent, etc.
73 *
74 * @return Pointer to allocated opaque pointer, or NULL if allocation failed
75 * @ingroup wasm
76 */
77void** ghostty_wasm_alloc_opaque(void);
78
79/**
80 * Free an opaque pointer allocated by ghostty_wasm_alloc_opaque().
81 *
82 * @param ptr Pointer to free, or NULL (NULL is safely ignored)
83 * @ingroup wasm
84 */
85void ghostty_wasm_free_opaque(void **ptr);
86
87/**
88 * Allocate an array of uint8_t values.
89 *
90 * @param len Number of uint8_t elements to allocate
91 * @return Pointer to allocated array, or NULL if allocation failed
92 * @ingroup wasm
93 */
94uint8_t* ghostty_wasm_alloc_u8_array(size_t len);
95
96/**
97 * Free an array allocated by ghostty_wasm_alloc_u8_array().
98 *
99 * @param ptr Pointer to the array to free, or NULL (NULL is safely ignored)
100 * @param len Length of the array (must match the length passed to alloc)
101 * @ingroup wasm
102 */
103void ghostty_wasm_free_u8_array(uint8_t *ptr, size_t len);
104
105/**
106 * Allocate an array of uint16_t values.
107 *
108 * @param len Number of uint16_t elements to allocate
109 * @return Pointer to allocated array, or NULL if allocation failed
110 * @ingroup wasm
111 */
112uint16_t* ghostty_wasm_alloc_u16_array(size_t len);
113
114/**
115 * Free an array allocated by ghostty_wasm_alloc_u16_array().
116 *
117 * @param ptr Pointer to the array to free, or NULL (NULL is safely ignored)
118 * @param len Length of the array (must match the length passed to alloc)
119 * @ingroup wasm
120 */
121void ghostty_wasm_free_u16_array(uint16_t *ptr, size_t len);
122
123/**
124 * Allocate a single uint8_t value.
125 *
126 * @return Pointer to allocated uint8_t, or NULL if allocation failed
127 * @ingroup wasm
128 */
129uint8_t* ghostty_wasm_alloc_u8(void);
130
131/**
132 * Free a uint8_t allocated by ghostty_wasm_alloc_u8().
133 *
134 * @param ptr Pointer to free, or NULL (NULL is safely ignored)
135 * @ingroup wasm
136 */
137void ghostty_wasm_free_u8(uint8_t *ptr);
138
139/**
140 * Allocate a single size_t value.
141 *
142 * @return Pointer to allocated size_t, or NULL if allocation failed
143 * @ingroup wasm
144 */
145size_t* ghostty_wasm_alloc_usize(void);
146
147/**
148 * Free a size_t allocated by ghostty_wasm_alloc_usize().
149 *
150 * @param ptr Pointer to free, or NULL (NULL is safely ignored)
151 * @ingroup wasm
152 */
153void ghostty_wasm_free_usize(size_t *ptr);
154
155/** @} */
156
157#endif /* __wasm__ */
158
159#endif /* GHOSTTY_VT_WASM_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/Headers/module.modulemap+7−0
@@ -0,0 +1,7 @@
1// This makes Ghostty available to the XCode build for the macOS app.
2// We append "Kit" to it not to be cute, but because targets have to have
3// unique names and we use Ghostty for other things.
4module GhosttyKit {
5 umbrella header "ghostty.h"
6 export *
7}
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/ios-arm64/libghostty-fat.a+0−0

Binary file not shown.

apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty.h+1187−0
@@ -0,0 +1,1187 @@
1// Ghostty embedding API. The documentation for the embedding API is
2// only within the Zig source files that define the implementations. This
3// isn't meant to be a general purpose embedding API (yet) so there hasn't
4// been documentation or example work beyond that.
5//
6// The only consumer of this API is the macOS app, but the API is built to
7// be more general purpose.
8#ifndef GHOSTTY_H
9#define GHOSTTY_H
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <stdbool.h>
16#include <stddef.h>
17#include <stdint.h>
18#include <sys/types.h>
19
20//-------------------------------------------------------------------
21// Macros
22
23#define GHOSTTY_SUCCESS 0
24
25//-------------------------------------------------------------------
26// Types
27
28// Opaque types
29typedef void* ghostty_app_t;
30typedef void* ghostty_config_t;
31typedef void* ghostty_surface_t;
32typedef void* ghostty_inspector_t;
33
34// All the types below are fully defined and must be kept in sync with
35// their Zig counterparts. Any changes to these types MUST have an associated
36// Zig change.
37typedef enum {
38 GHOSTTY_PLATFORM_INVALID,
39 GHOSTTY_PLATFORM_MACOS,
40 GHOSTTY_PLATFORM_IOS,
41} ghostty_platform_e;
42
43// Callback for custom I/O write handler.
44typedef void (*ghostty_surface_write_fn)(void* userdata,
45 const uint8_t* data,
46 size_t len);
47
48typedef enum {
49 GHOSTTY_CLIPBOARD_STANDARD,
50 GHOSTTY_CLIPBOARD_SELECTION,
51} ghostty_clipboard_e;
52
53typedef struct {
54 const char *mime;
55 const char *data;
56} ghostty_clipboard_content_s;
57
58typedef enum {
59 GHOSTTY_CLIPBOARD_REQUEST_PASTE,
60 GHOSTTY_CLIPBOARD_REQUEST_OSC_52_READ,
61 GHOSTTY_CLIPBOARD_REQUEST_OSC_52_WRITE,
62} ghostty_clipboard_request_e;
63
64typedef enum {
65 GHOSTTY_MOUSE_RELEASE,
66 GHOSTTY_MOUSE_PRESS,
67} ghostty_input_mouse_state_e;
68
69typedef enum {
70 GHOSTTY_MOUSE_UNKNOWN,
71 GHOSTTY_MOUSE_LEFT,
72 GHOSTTY_MOUSE_RIGHT,
73 GHOSTTY_MOUSE_MIDDLE,
74 GHOSTTY_MOUSE_FOUR,
75 GHOSTTY_MOUSE_FIVE,
76 GHOSTTY_MOUSE_SIX,
77 GHOSTTY_MOUSE_SEVEN,
78 GHOSTTY_MOUSE_EIGHT,
79 GHOSTTY_MOUSE_NINE,
80 GHOSTTY_MOUSE_TEN,
81 GHOSTTY_MOUSE_ELEVEN,
82} ghostty_input_mouse_button_e;
83
84typedef enum {
85 GHOSTTY_MOUSE_MOMENTUM_NONE,
86 GHOSTTY_MOUSE_MOMENTUM_BEGAN,
87 GHOSTTY_MOUSE_MOMENTUM_STATIONARY,
88 GHOSTTY_MOUSE_MOMENTUM_CHANGED,
89 GHOSTTY_MOUSE_MOMENTUM_ENDED,
90 GHOSTTY_MOUSE_MOMENTUM_CANCELLED,
91 GHOSTTY_MOUSE_MOMENTUM_MAY_BEGIN,
92} ghostty_input_mouse_momentum_e;
93
94typedef enum {
95 GHOSTTY_COLOR_SCHEME_LIGHT = 0,
96 GHOSTTY_COLOR_SCHEME_DARK = 1,
97} ghostty_color_scheme_e;
98
99// This is a packed struct (see src/input/mouse.zig) but the C standard
100// afaik doesn't let us reliably define packed structs so we build it up
101// from scratch.
102typedef int ghostty_input_scroll_mods_t;
103
104typedef enum {
105 GHOSTTY_MODS_NONE = 0,
106 GHOSTTY_MODS_SHIFT = 1 << 0,
107 GHOSTTY_MODS_CTRL = 1 << 1,
108 GHOSTTY_MODS_ALT = 1 << 2,
109 GHOSTTY_MODS_SUPER = 1 << 3,
110 GHOSTTY_MODS_CAPS = 1 << 4,
111 GHOSTTY_MODS_NUM = 1 << 5,
112 GHOSTTY_MODS_SHIFT_RIGHT = 1 << 6,
113 GHOSTTY_MODS_CTRL_RIGHT = 1 << 7,
114 GHOSTTY_MODS_ALT_RIGHT = 1 << 8,
115 GHOSTTY_MODS_SUPER_RIGHT = 1 << 9,
116} ghostty_input_mods_e;
117
118typedef enum {
119 GHOSTTY_BINDING_FLAGS_CONSUMED = 1 << 0,
120 GHOSTTY_BINDING_FLAGS_ALL = 1 << 1,
121 GHOSTTY_BINDING_FLAGS_GLOBAL = 1 << 2,
122 GHOSTTY_BINDING_FLAGS_PERFORMABLE = 1 << 3,
123} ghostty_binding_flags_e;
124
125typedef enum {
126 GHOSTTY_ACTION_RELEASE,
127 GHOSTTY_ACTION_PRESS,
128 GHOSTTY_ACTION_REPEAT,
129} ghostty_input_action_e;
130
131// Based on: https://www.w3.org/TR/uievents-code/
132typedef enum {
133 GHOSTTY_KEY_UNIDENTIFIED,
134
135 // "Writing System Keys" § 3.1.1
136 GHOSTTY_KEY_BACKQUOTE,
137 GHOSTTY_KEY_BACKSLASH,
138 GHOSTTY_KEY_BRACKET_LEFT,
139 GHOSTTY_KEY_BRACKET_RIGHT,
140 GHOSTTY_KEY_COMMA,
141 GHOSTTY_KEY_DIGIT_0,
142 GHOSTTY_KEY_DIGIT_1,
143 GHOSTTY_KEY_DIGIT_2,
144 GHOSTTY_KEY_DIGIT_3,
145 GHOSTTY_KEY_DIGIT_4,
146 GHOSTTY_KEY_DIGIT_5,
147 GHOSTTY_KEY_DIGIT_6,
148 GHOSTTY_KEY_DIGIT_7,
149 GHOSTTY_KEY_DIGIT_8,
150 GHOSTTY_KEY_DIGIT_9,
151 GHOSTTY_KEY_EQUAL,
152 GHOSTTY_KEY_INTL_BACKSLASH,
153 GHOSTTY_KEY_INTL_RO,
154 GHOSTTY_KEY_INTL_YEN,
155 GHOSTTY_KEY_A,
156 GHOSTTY_KEY_B,
157 GHOSTTY_KEY_C,
158 GHOSTTY_KEY_D,
159 GHOSTTY_KEY_E,
160 GHOSTTY_KEY_F,
161 GHOSTTY_KEY_G,
162 GHOSTTY_KEY_H,
163 GHOSTTY_KEY_I,
164 GHOSTTY_KEY_J,
165 GHOSTTY_KEY_K,
166 GHOSTTY_KEY_L,
167 GHOSTTY_KEY_M,
168 GHOSTTY_KEY_N,
169 GHOSTTY_KEY_O,
170 GHOSTTY_KEY_P,
171 GHOSTTY_KEY_Q,
172 GHOSTTY_KEY_R,
173 GHOSTTY_KEY_S,
174 GHOSTTY_KEY_T,
175 GHOSTTY_KEY_U,
176 GHOSTTY_KEY_V,
177 GHOSTTY_KEY_W,
178 GHOSTTY_KEY_X,
179 GHOSTTY_KEY_Y,
180 GHOSTTY_KEY_Z,
181 GHOSTTY_KEY_MINUS,
182 GHOSTTY_KEY_PERIOD,
183 GHOSTTY_KEY_QUOTE,
184 GHOSTTY_KEY_SEMICOLON,
185 GHOSTTY_KEY_SLASH,
186
187 // "Functional Keys" § 3.1.2
188 GHOSTTY_KEY_ALT_LEFT,
189 GHOSTTY_KEY_ALT_RIGHT,
190 GHOSTTY_KEY_BACKSPACE,
191 GHOSTTY_KEY_CAPS_LOCK,
192 GHOSTTY_KEY_CONTEXT_MENU,
193 GHOSTTY_KEY_CONTROL_LEFT,
194 GHOSTTY_KEY_CONTROL_RIGHT,
195 GHOSTTY_KEY_ENTER,
196 GHOSTTY_KEY_META_LEFT,
197 GHOSTTY_KEY_META_RIGHT,
198 GHOSTTY_KEY_SHIFT_LEFT,
199 GHOSTTY_KEY_SHIFT_RIGHT,
200 GHOSTTY_KEY_SPACE,
201 GHOSTTY_KEY_TAB,
202 GHOSTTY_KEY_CONVERT,
203 GHOSTTY_KEY_KANA_MODE,
204 GHOSTTY_KEY_NON_CONVERT,
205
206 // "Control Pad Section" § 3.2
207 GHOSTTY_KEY_DELETE,
208 GHOSTTY_KEY_END,
209 GHOSTTY_KEY_HELP,
210 GHOSTTY_KEY_HOME,
211 GHOSTTY_KEY_INSERT,
212 GHOSTTY_KEY_PAGE_DOWN,
213 GHOSTTY_KEY_PAGE_UP,
214
215 // "Arrow Pad Section" § 3.3
216 GHOSTTY_KEY_ARROW_DOWN,
217 GHOSTTY_KEY_ARROW_LEFT,
218 GHOSTTY_KEY_ARROW_RIGHT,
219 GHOSTTY_KEY_ARROW_UP,
220
221 // "Numpad Section" § 3.4
222 GHOSTTY_KEY_NUM_LOCK,
223 GHOSTTY_KEY_NUMPAD_0,
224 GHOSTTY_KEY_NUMPAD_1,
225 GHOSTTY_KEY_NUMPAD_2,
226 GHOSTTY_KEY_NUMPAD_3,
227 GHOSTTY_KEY_NUMPAD_4,
228 GHOSTTY_KEY_NUMPAD_5,
229 GHOSTTY_KEY_NUMPAD_6,
230 GHOSTTY_KEY_NUMPAD_7,
231 GHOSTTY_KEY_NUMPAD_8,
232 GHOSTTY_KEY_NUMPAD_9,
233 GHOSTTY_KEY_NUMPAD_ADD,
234 GHOSTTY_KEY_NUMPAD_BACKSPACE,
235 GHOSTTY_KEY_NUMPAD_CLEAR,
236 GHOSTTY_KEY_NUMPAD_CLEAR_ENTRY,
237 GHOSTTY_KEY_NUMPAD_COMMA,
238 GHOSTTY_KEY_NUMPAD_DECIMAL,
239 GHOSTTY_KEY_NUMPAD_DIVIDE,
240 GHOSTTY_KEY_NUMPAD_ENTER,
241 GHOSTTY_KEY_NUMPAD_EQUAL,
242 GHOSTTY_KEY_NUMPAD_MEMORY_ADD,
243 GHOSTTY_KEY_NUMPAD_MEMORY_CLEAR,
244 GHOSTTY_KEY_NUMPAD_MEMORY_RECALL,
245 GHOSTTY_KEY_NUMPAD_MEMORY_STORE,
246 GHOSTTY_KEY_NUMPAD_MEMORY_SUBTRACT,
247 GHOSTTY_KEY_NUMPAD_MULTIPLY,
248 GHOSTTY_KEY_NUMPAD_PAREN_LEFT,
249 GHOSTTY_KEY_NUMPAD_PAREN_RIGHT,
250 GHOSTTY_KEY_NUMPAD_SUBTRACT,
251 GHOSTTY_KEY_NUMPAD_SEPARATOR,
252 GHOSTTY_KEY_NUMPAD_UP,
253 GHOSTTY_KEY_NUMPAD_DOWN,
254 GHOSTTY_KEY_NUMPAD_RIGHT,
255 GHOSTTY_KEY_NUMPAD_LEFT,
256 GHOSTTY_KEY_NUMPAD_BEGIN,
257 GHOSTTY_KEY_NUMPAD_HOME,
258 GHOSTTY_KEY_NUMPAD_END,
259 GHOSTTY_KEY_NUMPAD_INSERT,
260 GHOSTTY_KEY_NUMPAD_DELETE,
261 GHOSTTY_KEY_NUMPAD_PAGE_UP,
262 GHOSTTY_KEY_NUMPAD_PAGE_DOWN,
263
264 // "Function Section" § 3.5
265 GHOSTTY_KEY_ESCAPE,
266 GHOSTTY_KEY_F1,
267 GHOSTTY_KEY_F2,
268 GHOSTTY_KEY_F3,
269 GHOSTTY_KEY_F4,
270 GHOSTTY_KEY_F5,
271 GHOSTTY_KEY_F6,
272 GHOSTTY_KEY_F7,
273 GHOSTTY_KEY_F8,
274 GHOSTTY_KEY_F9,
275 GHOSTTY_KEY_F10,
276 GHOSTTY_KEY_F11,
277 GHOSTTY_KEY_F12,
278 GHOSTTY_KEY_F13,
279 GHOSTTY_KEY_F14,
280 GHOSTTY_KEY_F15,
281 GHOSTTY_KEY_F16,
282 GHOSTTY_KEY_F17,
283 GHOSTTY_KEY_F18,
284 GHOSTTY_KEY_F19,
285 GHOSTTY_KEY_F20,
286 GHOSTTY_KEY_F21,
287 GHOSTTY_KEY_F22,
288 GHOSTTY_KEY_F23,
289 GHOSTTY_KEY_F24,
290 GHOSTTY_KEY_F25,
291 GHOSTTY_KEY_FN,
292 GHOSTTY_KEY_FN_LOCK,
293 GHOSTTY_KEY_PRINT_SCREEN,
294 GHOSTTY_KEY_SCROLL_LOCK,
295 GHOSTTY_KEY_PAUSE,
296
297 // "Media Keys" § 3.6
298 GHOSTTY_KEY_BROWSER_BACK,
299 GHOSTTY_KEY_BROWSER_FAVORITES,
300 GHOSTTY_KEY_BROWSER_FORWARD,
301 GHOSTTY_KEY_BROWSER_HOME,
302 GHOSTTY_KEY_BROWSER_REFRESH,
303 GHOSTTY_KEY_BROWSER_SEARCH,
304 GHOSTTY_KEY_BROWSER_STOP,
305 GHOSTTY_KEY_EJECT,
306 GHOSTTY_KEY_LAUNCH_APP_1,
307 GHOSTTY_KEY_LAUNCH_APP_2,
308 GHOSTTY_KEY_LAUNCH_MAIL,
309 GHOSTTY_KEY_MEDIA_PLAY_PAUSE,
310 GHOSTTY_KEY_MEDIA_SELECT,
311 GHOSTTY_KEY_MEDIA_STOP,
312 GHOSTTY_KEY_MEDIA_TRACK_NEXT,
313 GHOSTTY_KEY_MEDIA_TRACK_PREVIOUS,
314 GHOSTTY_KEY_POWER,
315 GHOSTTY_KEY_SLEEP,
316 GHOSTTY_KEY_AUDIO_VOLUME_DOWN,
317 GHOSTTY_KEY_AUDIO_VOLUME_MUTE,
318 GHOSTTY_KEY_AUDIO_VOLUME_UP,
319 GHOSTTY_KEY_WAKE_UP,
320
321 // "Legacy, Non-standard, and Special Keys" § 3.7
322 GHOSTTY_KEY_COPY,
323 GHOSTTY_KEY_CUT,
324 GHOSTTY_KEY_PASTE,
325} ghostty_input_key_e;
326
327typedef struct {
328 ghostty_input_action_e action;
329 ghostty_input_mods_e mods;
330 ghostty_input_mods_e consumed_mods;
331 uint32_t keycode;
332 const char* text;
333 uint32_t unshifted_codepoint;
334 bool composing;
335} ghostty_input_key_s;
336
337typedef enum {
338 GHOSTTY_TRIGGER_PHYSICAL,
339 GHOSTTY_TRIGGER_UNICODE,
340 GHOSTTY_TRIGGER_CATCH_ALL,
341} ghostty_input_trigger_tag_e;
342
343typedef union {
344 ghostty_input_key_e translated;
345 ghostty_input_key_e physical;
346 uint32_t unicode;
347 // catch_all has no payload
348} ghostty_input_trigger_key_u;
349
350typedef struct {
351 ghostty_input_trigger_tag_e tag;
352 ghostty_input_trigger_key_u key;
353 ghostty_input_mods_e mods;
354} ghostty_input_trigger_s;
355
356typedef struct {
357 const char* action_key;
358 const char* action;
359 const char* title;
360 const char* description;
361} ghostty_command_s;
362
363typedef enum {
364 GHOSTTY_BUILD_MODE_DEBUG,
365 GHOSTTY_BUILD_MODE_RELEASE_SAFE,
366 GHOSTTY_BUILD_MODE_RELEASE_FAST,
367 GHOSTTY_BUILD_MODE_RELEASE_SMALL,
368} ghostty_build_mode_e;
369
370typedef struct {
371 ghostty_build_mode_e build_mode;
372 const char* version;
373 uintptr_t version_len;
374} ghostty_info_s;
375
376typedef struct {
377 const char* message;
378} ghostty_diagnostic_s;
379
380typedef struct {
381 const char* ptr;
382 uintptr_t len;
383 bool sentinel;
384} ghostty_string_s;
385
386typedef struct {
387 double tl_px_x;
388 double tl_px_y;
389 uint32_t offset_start;
390 uint32_t offset_len;
391 const char* text;
392 uintptr_t text_len;
393} ghostty_text_s;
394
395typedef enum {
396 GHOSTTY_POINT_ACTIVE,
397 GHOSTTY_POINT_VIEWPORT,
398 GHOSTTY_POINT_SCREEN,
399 GHOSTTY_POINT_SURFACE,
400} ghostty_point_tag_e;
401
402typedef enum {
403 GHOSTTY_POINT_COORD_EXACT,
404 GHOSTTY_POINT_COORD_TOP_LEFT,
405 GHOSTTY_POINT_COORD_BOTTOM_RIGHT,
406} ghostty_point_coord_e;
407
408typedef struct {
409 ghostty_point_tag_e tag;
410 ghostty_point_coord_e coord;
411 uint32_t x;
412 uint32_t y;
413} ghostty_point_s;
414
415typedef struct {
416 ghostty_point_s top_left;
417 ghostty_point_s bottom_right;
418 bool rectangle;
419} ghostty_selection_s;
420
421typedef struct {
422 const char* key;
423 const char* value;
424} ghostty_env_var_s;
425
426typedef struct {
427 void* nsview;
428} ghostty_platform_macos_s;
429
430typedef struct {
431 void* uiview;
432} ghostty_platform_ios_s;
433
434typedef union {
435 ghostty_platform_macos_s macos;
436 ghostty_platform_ios_s ios;
437} ghostty_platform_u;
438
439typedef enum {
440 GHOSTTY_SURFACE_CONTEXT_WINDOW = 0,
441 GHOSTTY_SURFACE_CONTEXT_TAB = 1,
442 GHOSTTY_SURFACE_CONTEXT_SPLIT = 2,
443} ghostty_surface_context_e;
444
445typedef struct {
446 ghostty_platform_e platform_tag;
447 ghostty_platform_u platform;
448 void* userdata;
449 double scale_factor;
450 float font_size;
451 const char* working_directory;
452 const char* command;
453 ghostty_env_var_s* env_vars;
454 size_t env_var_count;
455 const char* initial_input;
456 bool wait_after_command;
457 ghostty_surface_context_e context;
458 bool use_custom_io;
459} ghostty_surface_config_s;
460
461typedef struct {
462 uint16_t columns;
463 uint16_t rows;
464 uint32_t width_px;
465 uint32_t height_px;
466 uint32_t cell_width_px;
467 uint32_t cell_height_px;
468} ghostty_surface_size_s;
469
470// Config types
471
472// config.Path
473typedef struct {
474 const char* path;
475 bool optional;
476} ghostty_config_path_s;
477
478// config.Color
479typedef struct {
480 uint8_t r;
481 uint8_t g;
482 uint8_t b;
483} ghostty_config_color_s;
484
485// config.ColorList
486typedef struct {
487 const ghostty_config_color_s* colors;
488 size_t len;
489} ghostty_config_color_list_s;
490
491// config.RepeatableCommand
492typedef struct {
493 const ghostty_command_s* commands;
494 size_t len;
495} ghostty_config_command_list_s;
496
497// config.Palette
498typedef struct {
499 ghostty_config_color_s colors[256];
500} ghostty_config_palette_s;
501
502// config.QuickTerminalSize
503typedef enum {
504 GHOSTTY_QUICK_TERMINAL_SIZE_NONE,
505 GHOSTTY_QUICK_TERMINAL_SIZE_PERCENTAGE,
506 GHOSTTY_QUICK_TERMINAL_SIZE_PIXELS,
507} ghostty_quick_terminal_size_tag_e;
508
509typedef union {
510 float percentage;
511 uint32_t pixels;
512} ghostty_quick_terminal_size_value_u;
513
514typedef struct {
515 ghostty_quick_terminal_size_tag_e tag;
516 ghostty_quick_terminal_size_value_u value;
517} ghostty_quick_terminal_size_s;
518
519typedef struct {
520 ghostty_quick_terminal_size_s primary;
521 ghostty_quick_terminal_size_s secondary;
522} ghostty_config_quick_terminal_size_s;
523
524// config.Fullscreen
525typedef enum {
526 GHOSTTY_CONFIG_FULLSCREEN_FALSE,
527 GHOSTTY_CONFIG_FULLSCREEN_TRUE,
528 GHOSTTY_CONFIG_FULLSCREEN_NON_NATIVE,
529 GHOSTTY_CONFIG_FULLSCREEN_NON_NATIVE_VISIBLE_MENU,
530 GHOSTTY_CONFIG_FULLSCREEN_NON_NATIVE_PADDED_NOTCH,
531} ghostty_config_fullscreen_e;
532
533// apprt.Target.Key
534typedef enum {
535 GHOSTTY_TARGET_APP,
536 GHOSTTY_TARGET_SURFACE,
537} ghostty_target_tag_e;
538
539typedef union {
540 ghostty_surface_t surface;
541} ghostty_target_u;
542
543typedef struct {
544 ghostty_target_tag_e tag;
545 ghostty_target_u target;
546} ghostty_target_s;
547
548// apprt.action.SplitDirection
549typedef enum {
550 GHOSTTY_SPLIT_DIRECTION_RIGHT,
551 GHOSTTY_SPLIT_DIRECTION_DOWN,
552 GHOSTTY_SPLIT_DIRECTION_LEFT,
553 GHOSTTY_SPLIT_DIRECTION_UP,
554} ghostty_action_split_direction_e;
555
556// apprt.action.GotoSplit
557typedef enum {
558 GHOSTTY_GOTO_SPLIT_PREVIOUS,
559 GHOSTTY_GOTO_SPLIT_NEXT,
560 GHOSTTY_GOTO_SPLIT_UP,
561 GHOSTTY_GOTO_SPLIT_LEFT,
562 GHOSTTY_GOTO_SPLIT_DOWN,
563 GHOSTTY_GOTO_SPLIT_RIGHT,
564} ghostty_action_goto_split_e;
565
566// apprt.action.GotoWindow
567typedef enum {
568 GHOSTTY_GOTO_WINDOW_PREVIOUS,
569 GHOSTTY_GOTO_WINDOW_NEXT,
570} ghostty_action_goto_window_e;
571
572// apprt.action.ResizeSplit.Direction
573typedef enum {
574 GHOSTTY_RESIZE_SPLIT_UP,
575 GHOSTTY_RESIZE_SPLIT_DOWN,
576 GHOSTTY_RESIZE_SPLIT_LEFT,
577 GHOSTTY_RESIZE_SPLIT_RIGHT,
578} ghostty_action_resize_split_direction_e;
579
580// apprt.action.ResizeSplit
581typedef struct {
582 uint16_t amount;
583 ghostty_action_resize_split_direction_e direction;
584} ghostty_action_resize_split_s;
585
586// apprt.action.MoveTab
587typedef struct {
588 ssize_t amount;
589} ghostty_action_move_tab_s;
590
591// apprt.action.GotoTab
592typedef enum {
593 GHOSTTY_GOTO_TAB_PREVIOUS = -1,
594 GHOSTTY_GOTO_TAB_NEXT = -2,
595 GHOSTTY_GOTO_TAB_LAST = -3,
596} ghostty_action_goto_tab_e;
597
598// apprt.action.Fullscreen
599typedef enum {
600 GHOSTTY_FULLSCREEN_NATIVE,
601 GHOSTTY_FULLSCREEN_MACOS_NON_NATIVE,
602 GHOSTTY_FULLSCREEN_MACOS_NON_NATIVE_VISIBLE_MENU,
603 GHOSTTY_FULLSCREEN_MACOS_NON_NATIVE_PADDED_NOTCH,
604} ghostty_action_fullscreen_e;
605
606// apprt.action.FloatWindow
607typedef enum {
608 GHOSTTY_FLOAT_WINDOW_ON,
609 GHOSTTY_FLOAT_WINDOW_OFF,
610 GHOSTTY_FLOAT_WINDOW_TOGGLE,
611} ghostty_action_float_window_e;
612
613// apprt.action.SecureInput
614typedef enum {
615 GHOSTTY_SECURE_INPUT_ON,
616 GHOSTTY_SECURE_INPUT_OFF,
617 GHOSTTY_SECURE_INPUT_TOGGLE,
618} ghostty_action_secure_input_e;
619
620// apprt.action.Inspector
621typedef enum {
622 GHOSTTY_INSPECTOR_TOGGLE,
623 GHOSTTY_INSPECTOR_SHOW,
624 GHOSTTY_INSPECTOR_HIDE,
625} ghostty_action_inspector_e;
626
627// apprt.action.QuitTimer
628typedef enum {
629 GHOSTTY_QUIT_TIMER_START,
630 GHOSTTY_QUIT_TIMER_STOP,
631} ghostty_action_quit_timer_e;
632
633// apprt.action.Readonly
634typedef enum {
635 GHOSTTY_READONLY_OFF,
636 GHOSTTY_READONLY_ON,
637} ghostty_action_readonly_e;
638
639// apprt.action.DesktopNotification.C
640typedef struct {
641 const char* title;
642 const char* body;
643} ghostty_action_desktop_notification_s;
644
645// apprt.action.SetTitle.C
646typedef struct {
647 const char* title;
648} ghostty_action_set_title_s;
649
650// apprt.action.PromptTitle
651typedef enum {
652 GHOSTTY_PROMPT_TITLE_SURFACE,
653 GHOSTTY_PROMPT_TITLE_TAB,
654} ghostty_action_prompt_title_e;
655
656// apprt.action.Pwd.C
657typedef struct {
658 const char* pwd;
659} ghostty_action_pwd_s;
660
661// terminal.MouseShape
662typedef enum {
663 GHOSTTY_MOUSE_SHAPE_DEFAULT,
664 GHOSTTY_MOUSE_SHAPE_CONTEXT_MENU,
665 GHOSTTY_MOUSE_SHAPE_HELP,
666 GHOSTTY_MOUSE_SHAPE_POINTER,
667 GHOSTTY_MOUSE_SHAPE_PROGRESS,
668 GHOSTTY_MOUSE_SHAPE_WAIT,
669 GHOSTTY_MOUSE_SHAPE_CELL,
670 GHOSTTY_MOUSE_SHAPE_CROSSHAIR,
671 GHOSTTY_MOUSE_SHAPE_TEXT,
672 GHOSTTY_MOUSE_SHAPE_VERTICAL_TEXT,
673 GHOSTTY_MOUSE_SHAPE_ALIAS,
674 GHOSTTY_MOUSE_SHAPE_COPY,
675 GHOSTTY_MOUSE_SHAPE_MOVE,
676 GHOSTTY_MOUSE_SHAPE_NO_DROP,
677 GHOSTTY_MOUSE_SHAPE_NOT_ALLOWED,
678 GHOSTTY_MOUSE_SHAPE_GRAB,
679 GHOSTTY_MOUSE_SHAPE_GRABBING,
680 GHOSTTY_MOUSE_SHAPE_ALL_SCROLL,
681 GHOSTTY_MOUSE_SHAPE_COL_RESIZE,
682 GHOSTTY_MOUSE_SHAPE_ROW_RESIZE,
683 GHOSTTY_MOUSE_SHAPE_N_RESIZE,
684 GHOSTTY_MOUSE_SHAPE_E_RESIZE,
685 GHOSTTY_MOUSE_SHAPE_S_RESIZE,
686 GHOSTTY_MOUSE_SHAPE_W_RESIZE,
687 GHOSTTY_MOUSE_SHAPE_NE_RESIZE,
688 GHOSTTY_MOUSE_SHAPE_NW_RESIZE,
689 GHOSTTY_MOUSE_SHAPE_SE_RESIZE,
690 GHOSTTY_MOUSE_SHAPE_SW_RESIZE,
691 GHOSTTY_MOUSE_SHAPE_EW_RESIZE,
692 GHOSTTY_MOUSE_SHAPE_NS_RESIZE,
693 GHOSTTY_MOUSE_SHAPE_NESW_RESIZE,
694 GHOSTTY_MOUSE_SHAPE_NWSE_RESIZE,
695 GHOSTTY_MOUSE_SHAPE_ZOOM_IN,
696 GHOSTTY_MOUSE_SHAPE_ZOOM_OUT,
697} ghostty_action_mouse_shape_e;
698
699// apprt.action.MouseVisibility
700typedef enum {
701 GHOSTTY_MOUSE_VISIBLE,
702 GHOSTTY_MOUSE_HIDDEN,
703} ghostty_action_mouse_visibility_e;
704
705// apprt.action.MouseOverLink
706typedef struct {
707 const char* url;
708 size_t len;
709} ghostty_action_mouse_over_link_s;
710
711// apprt.action.SizeLimit
712typedef struct {
713 uint32_t min_width;
714 uint32_t min_height;
715 uint32_t max_width;
716 uint32_t max_height;
717} ghostty_action_size_limit_s;
718
719// apprt.action.InitialSize
720typedef struct {
721 uint32_t width;
722 uint32_t height;
723} ghostty_action_initial_size_s;
724
725// apprt.action.CellSize
726typedef struct {
727 uint32_t width;
728 uint32_t height;
729} ghostty_action_cell_size_s;
730
731// renderer.Health
732typedef enum {
733 GHOSTTY_RENDERER_HEALTH_HEALTHY,
734 GHOSTTY_RENDERER_HEALTH_UNHEALTHY,
735} ghostty_action_renderer_health_e;
736
737// apprt.action.KeySequence
738typedef struct {
739 bool active;
740 ghostty_input_trigger_s trigger;
741} ghostty_action_key_sequence_s;
742
743// apprt.action.KeyTable.Tag
744typedef enum {
745 GHOSTTY_KEY_TABLE_ACTIVATE,
746 GHOSTTY_KEY_TABLE_DEACTIVATE,
747 GHOSTTY_KEY_TABLE_DEACTIVATE_ALL,
748} ghostty_action_key_table_tag_e;
749
750// apprt.action.KeyTable.CValue
751typedef union {
752 struct {
753 const char *name;
754 size_t len;
755 } activate;
756} ghostty_action_key_table_u;
757
758// apprt.action.KeyTable.C
759typedef struct {
760 ghostty_action_key_table_tag_e tag;
761 ghostty_action_key_table_u value;
762} ghostty_action_key_table_s;
763
764// apprt.action.ColorKind
765typedef enum {
766 GHOSTTY_ACTION_COLOR_KIND_FOREGROUND = -1,
767 GHOSTTY_ACTION_COLOR_KIND_BACKGROUND = -2,
768 GHOSTTY_ACTION_COLOR_KIND_CURSOR = -3,
769} ghostty_action_color_kind_e;
770
771// apprt.action.ColorChange
772typedef struct {
773 ghostty_action_color_kind_e kind;
774 uint8_t r;
775 uint8_t g;
776 uint8_t b;
777} ghostty_action_color_change_s;
778
779// apprt.action.ConfigChange
780typedef struct {
781 ghostty_config_t config;
782} ghostty_action_config_change_s;
783
784// apprt.action.ReloadConfig
785typedef struct {
786 bool soft;
787} ghostty_action_reload_config_s;
788
789// apprt.action.OpenUrlKind
790typedef enum {
791 GHOSTTY_ACTION_OPEN_URL_KIND_UNKNOWN,
792 GHOSTTY_ACTION_OPEN_URL_KIND_TEXT,
793 GHOSTTY_ACTION_OPEN_URL_KIND_HTML,
794} ghostty_action_open_url_kind_e;
795
796// apprt.action.OpenUrl.C
797typedef struct {
798 ghostty_action_open_url_kind_e kind;
799 const char* url;
800 uintptr_t len;
801} ghostty_action_open_url_s;
802
803// apprt.action.CloseTabMode
804typedef enum {
805 GHOSTTY_ACTION_CLOSE_TAB_MODE_THIS,
806 GHOSTTY_ACTION_CLOSE_TAB_MODE_OTHER,
807 GHOSTTY_ACTION_CLOSE_TAB_MODE_RIGHT,
808} ghostty_action_close_tab_mode_e;
809
810// apprt.surface.Message.ChildExited
811typedef struct {
812 uint32_t exit_code;
813 uint64_t timetime_ms;
814} ghostty_surface_message_childexited_s;
815
816// terminal.osc.Command.ProgressReport.State
817typedef enum {
818 GHOSTTY_PROGRESS_STATE_REMOVE,
819 GHOSTTY_PROGRESS_STATE_SET,
820 GHOSTTY_PROGRESS_STATE_ERROR,
821 GHOSTTY_PROGRESS_STATE_INDETERMINATE,
822 GHOSTTY_PROGRESS_STATE_PAUSE,
823} ghostty_action_progress_report_state_e;
824
825// terminal.osc.Command.ProgressReport.C
826typedef struct {
827 ghostty_action_progress_report_state_e state;
828 // -1 if no progress was reported, otherwise 0-100 indicating percent
829 // completeness.
830 int8_t progress;
831} ghostty_action_progress_report_s;
832
833// apprt.action.CommandFinished.C
834typedef struct {
835 // -1 if no exit code was reported, otherwise 0-255
836 int16_t exit_code;
837 // number of nanoseconds that command was running for
838 uint64_t duration;
839} ghostty_action_command_finished_s;
840
841// apprt.action.StartSearch.C
842typedef struct {
843 const char* needle;
844} ghostty_action_start_search_s;
845
846// apprt.action.SearchTotal
847typedef struct {
848 ssize_t total;
849} ghostty_action_search_total_s;
850
851// apprt.action.SearchSelected
852typedef struct {
853 ssize_t selected;
854} ghostty_action_search_selected_s;
855
856// terminal.Scrollbar
857typedef struct {
858 uint64_t total;
859 uint64_t offset;
860 uint64_t len;
861} ghostty_action_scrollbar_s;
862
863// apprt.Action.Key
864typedef enum {
865 GHOSTTY_ACTION_QUIT,
866 GHOSTTY_ACTION_NEW_WINDOW,
867 GHOSTTY_ACTION_NEW_TAB,
868 GHOSTTY_ACTION_CLOSE_TAB,
869 GHOSTTY_ACTION_NEW_SPLIT,
870 GHOSTTY_ACTION_CLOSE_ALL_WINDOWS,
871 GHOSTTY_ACTION_TOGGLE_MAXIMIZE,
872 GHOSTTY_ACTION_TOGGLE_FULLSCREEN,
873 GHOSTTY_ACTION_TOGGLE_TAB_OVERVIEW,
874 GHOSTTY_ACTION_TOGGLE_WINDOW_DECORATIONS,
875 GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL,
876 GHOSTTY_ACTION_TOGGLE_COMMAND_PALETTE,
877 GHOSTTY_ACTION_TOGGLE_VISIBILITY,
878 GHOSTTY_ACTION_TOGGLE_BACKGROUND_OPACITY,
879 GHOSTTY_ACTION_MOVE_TAB,
880 GHOSTTY_ACTION_GOTO_TAB,
881 GHOSTTY_ACTION_GOTO_SPLIT,
882 GHOSTTY_ACTION_GOTO_WINDOW,
883 GHOSTTY_ACTION_RESIZE_SPLIT,
884 GHOSTTY_ACTION_EQUALIZE_SPLITS,
885 GHOSTTY_ACTION_TOGGLE_SPLIT_ZOOM,
886 GHOSTTY_ACTION_PRESENT_TERMINAL,
887 GHOSTTY_ACTION_SIZE_LIMIT,
888 GHOSTTY_ACTION_RESET_WINDOW_SIZE,
889 GHOSTTY_ACTION_INITIAL_SIZE,
890 GHOSTTY_ACTION_CELL_SIZE,
891 GHOSTTY_ACTION_SCROLLBAR,
892 GHOSTTY_ACTION_RENDER,
893 GHOSTTY_ACTION_INSPECTOR,
894 GHOSTTY_ACTION_SHOW_GTK_INSPECTOR,
895 GHOSTTY_ACTION_RENDER_INSPECTOR,
896 GHOSTTY_ACTION_DESKTOP_NOTIFICATION,
897 GHOSTTY_ACTION_SET_TITLE,
898 GHOSTTY_ACTION_PROMPT_TITLE,
899 GHOSTTY_ACTION_PWD,
900 GHOSTTY_ACTION_MOUSE_SHAPE,
901 GHOSTTY_ACTION_MOUSE_VISIBILITY,
902 GHOSTTY_ACTION_MOUSE_OVER_LINK,
903 GHOSTTY_ACTION_RENDERER_HEALTH,
904 GHOSTTY_ACTION_OPEN_CONFIG,
905 GHOSTTY_ACTION_QUIT_TIMER,
906 GHOSTTY_ACTION_FLOAT_WINDOW,
907 GHOSTTY_ACTION_SECURE_INPUT,
908 GHOSTTY_ACTION_KEY_SEQUENCE,
909 GHOSTTY_ACTION_KEY_TABLE,
910 GHOSTTY_ACTION_COLOR_CHANGE,
911 GHOSTTY_ACTION_RELOAD_CONFIG,
912 GHOSTTY_ACTION_CONFIG_CHANGE,
913 GHOSTTY_ACTION_CLOSE_WINDOW,
914 GHOSTTY_ACTION_RING_BELL,
915 GHOSTTY_ACTION_UNDO,
916 GHOSTTY_ACTION_REDO,
917 GHOSTTY_ACTION_CHECK_FOR_UPDATES,
918 GHOSTTY_ACTION_OPEN_URL,
919 GHOSTTY_ACTION_SHOW_CHILD_EXITED,
920 GHOSTTY_ACTION_PROGRESS_REPORT,
921 GHOSTTY_ACTION_SHOW_ON_SCREEN_KEYBOARD,
922 GHOSTTY_ACTION_COMMAND_FINISHED,
923 GHOSTTY_ACTION_START_SEARCH,
924 GHOSTTY_ACTION_END_SEARCH,
925 GHOSTTY_ACTION_SEARCH_TOTAL,
926 GHOSTTY_ACTION_SEARCH_SELECTED,
927 GHOSTTY_ACTION_READONLY,
928 GHOSTTY_ACTION_COPY_TITLE_TO_CLIPBOARD,
929} ghostty_action_tag_e;
930
931typedef union {
932 ghostty_action_split_direction_e new_split;
933 ghostty_action_fullscreen_e toggle_fullscreen;
934 ghostty_action_move_tab_s move_tab;
935 ghostty_action_goto_tab_e goto_tab;
936 ghostty_action_goto_split_e goto_split;
937 ghostty_action_goto_window_e goto_window;
938 ghostty_action_resize_split_s resize_split;
939 ghostty_action_size_limit_s size_limit;
940 ghostty_action_initial_size_s initial_size;
941 ghostty_action_cell_size_s cell_size;
942 ghostty_action_scrollbar_s scrollbar;
943 ghostty_action_inspector_e inspector;
944 ghostty_action_desktop_notification_s desktop_notification;
945 ghostty_action_set_title_s set_title;
946 ghostty_action_prompt_title_e prompt_title;
947 ghostty_action_pwd_s pwd;
948 ghostty_action_mouse_shape_e mouse_shape;
949 ghostty_action_mouse_visibility_e mouse_visibility;
950 ghostty_action_mouse_over_link_s mouse_over_link;
951 ghostty_action_renderer_health_e renderer_health;
952 ghostty_action_quit_timer_e quit_timer;
953 ghostty_action_float_window_e float_window;
954 ghostty_action_secure_input_e secure_input;
955 ghostty_action_key_sequence_s key_sequence;
956 ghostty_action_key_table_s key_table;
957 ghostty_action_color_change_s color_change;
958 ghostty_action_reload_config_s reload_config;
959 ghostty_action_config_change_s config_change;
960 ghostty_action_open_url_s open_url;
961 ghostty_action_close_tab_mode_e close_tab_mode;
962 ghostty_surface_message_childexited_s child_exited;
963 ghostty_action_progress_report_s progress_report;
964 ghostty_action_command_finished_s command_finished;
965 ghostty_action_start_search_s start_search;
966 ghostty_action_search_total_s search_total;
967 ghostty_action_search_selected_s search_selected;
968 ghostty_action_readonly_e readonly;
969} ghostty_action_u;
970
971typedef struct {
972 ghostty_action_tag_e tag;
973 ghostty_action_u action;
974} ghostty_action_s;
975
976typedef void (*ghostty_runtime_wakeup_cb)(void*);
977typedef void (*ghostty_runtime_read_clipboard_cb)(void*,
978 ghostty_clipboard_e,
979 void*);
980typedef void (*ghostty_runtime_confirm_read_clipboard_cb)(
981 void*,
982 const char*,
983 void*,
984 ghostty_clipboard_request_e);
985typedef void (*ghostty_runtime_write_clipboard_cb)(void*,
986 ghostty_clipboard_e,
987 const ghostty_clipboard_content_s*,
988 size_t,
989 bool);
990typedef void (*ghostty_runtime_close_surface_cb)(void*, bool);
991typedef bool (*ghostty_runtime_action_cb)(ghostty_app_t,
992 ghostty_target_s,
993 ghostty_action_s);
994
995typedef struct {
996 void* userdata;
997 bool supports_selection_clipboard;
998 ghostty_runtime_wakeup_cb wakeup_cb;
999 ghostty_runtime_action_cb action_cb;
1000 ghostty_runtime_read_clipboard_cb read_clipboard_cb;
1001 ghostty_runtime_confirm_read_clipboard_cb confirm_read_clipboard_cb;
1002 ghostty_runtime_write_clipboard_cb write_clipboard_cb;
1003 ghostty_runtime_close_surface_cb close_surface_cb;
1004} ghostty_runtime_config_s;
1005
1006// apprt.ipc.Target.Key
1007typedef enum {
1008 GHOSTTY_IPC_TARGET_CLASS,
1009 GHOSTTY_IPC_TARGET_DETECT,
1010} ghostty_ipc_target_tag_e;
1011
1012typedef union {
1013 char *klass;
1014} ghostty_ipc_target_u;
1015
1016typedef struct {
1017 ghostty_ipc_target_tag_e tag;
1018 ghostty_ipc_target_u target;
1019} chostty_ipc_target_s;
1020
1021// apprt.ipc.Action.NewWindow
1022typedef struct {
1023 // This should be a null terminated list of strings.
1024 const char **arguments;
1025} ghostty_ipc_action_new_window_s;
1026
1027typedef union {
1028 ghostty_ipc_action_new_window_s new_window;
1029} ghostty_ipc_action_u;
1030
1031// apprt.ipc.Action.Key
1032typedef enum {
1033 GHOSTTY_IPC_ACTION_NEW_WINDOW,
1034} ghostty_ipc_action_tag_e;
1035
1036//-------------------------------------------------------------------
1037// Published API
1038
1039int ghostty_init(uintptr_t, char**);
1040void ghostty_cli_try_action(void);
1041ghostty_info_s ghostty_info(void);
1042const char* ghostty_translate(const char*);
1043void ghostty_string_free(ghostty_string_s);
1044
1045ghostty_config_t ghostty_config_new();
1046void ghostty_config_free(ghostty_config_t);
1047ghostty_config_t ghostty_config_clone(ghostty_config_t);
1048void ghostty_config_load_cli_args(ghostty_config_t);
1049void ghostty_config_load_file(ghostty_config_t, const char*);
1050void ghostty_config_load_default_files(ghostty_config_t);
1051void ghostty_config_load_recursive_files(ghostty_config_t);
1052void ghostty_config_finalize(ghostty_config_t);
1053bool ghostty_config_get(ghostty_config_t, void*, const char*, uintptr_t);
1054ghostty_input_trigger_s ghostty_config_trigger(ghostty_config_t,
1055 const char*,
1056 uintptr_t);
1057uint32_t ghostty_config_diagnostics_count(ghostty_config_t);
1058ghostty_diagnostic_s ghostty_config_get_diagnostic(ghostty_config_t, uint32_t);
1059ghostty_string_s ghostty_config_open_path(void);
1060
1061ghostty_app_t ghostty_app_new(const ghostty_runtime_config_s*,
1062 ghostty_config_t);
1063void ghostty_app_free(ghostty_app_t);
1064void ghostty_app_tick(ghostty_app_t);
1065void* ghostty_app_userdata(ghostty_app_t);
1066void ghostty_app_set_focus(ghostty_app_t, bool);
1067bool ghostty_app_key(ghostty_app_t, ghostty_input_key_s);
1068bool ghostty_app_key_is_binding(ghostty_app_t, ghostty_input_key_s);
1069void ghostty_app_keyboard_changed(ghostty_app_t);
1070void ghostty_app_open_config(ghostty_app_t);
1071void ghostty_app_update_config(ghostty_app_t, ghostty_config_t);
1072bool ghostty_app_needs_confirm_quit(ghostty_app_t);
1073bool ghostty_app_has_global_keybinds(ghostty_app_t);
1074void ghostty_app_set_color_scheme(ghostty_app_t, ghostty_color_scheme_e);
1075
1076ghostty_surface_config_s ghostty_surface_config_new();
1077
1078ghostty_surface_t ghostty_surface_new(ghostty_app_t,
1079 const ghostty_surface_config_s*);
1080void ghostty_surface_free(ghostty_surface_t);
1081void* ghostty_surface_userdata(ghostty_surface_t);
1082ghostty_app_t ghostty_surface_app(ghostty_surface_t);
1083ghostty_surface_config_s ghostty_surface_inherited_config(ghostty_surface_t, ghostty_surface_context_e);
1084void ghostty_surface_update_config(ghostty_surface_t, ghostty_config_t);
1085bool ghostty_surface_needs_confirm_quit(ghostty_surface_t);
1086bool ghostty_surface_process_exited(ghostty_surface_t);
1087void ghostty_surface_refresh(ghostty_surface_t);
1088void ghostty_surface_draw(ghostty_surface_t);
1089// Custom I/O API - feed output into the terminal and receive writes.
1090void ghostty_surface_feed_data(ghostty_surface_t, const uint8_t*, size_t);
1091void ghostty_surface_set_write_callback(ghostty_surface_t,
1092 ghostty_surface_write_fn,
1093 void*);
1094void ghostty_surface_set_content_scale(ghostty_surface_t, double, double);
1095void ghostty_surface_set_focus(ghostty_surface_t, bool);
1096void ghostty_surface_set_occlusion(ghostty_surface_t, bool);
1097void ghostty_surface_set_size(ghostty_surface_t, uint32_t, uint32_t);
1098ghostty_surface_size_s ghostty_surface_size(ghostty_surface_t);
1099void ghostty_surface_set_color_scheme(ghostty_surface_t,
1100 ghostty_color_scheme_e);
1101ghostty_input_mods_e ghostty_surface_key_translation_mods(ghostty_surface_t,
1102 ghostty_input_mods_e);
1103bool ghostty_surface_key(ghostty_surface_t, ghostty_input_key_s);
1104bool ghostty_surface_key_is_binding(ghostty_surface_t,
1105 ghostty_input_key_s,
1106 ghostty_binding_flags_e*);
1107void ghostty_surface_text(ghostty_surface_t, const char*, uintptr_t);
1108void ghostty_surface_preedit(ghostty_surface_t, const char*, uintptr_t);
1109bool ghostty_surface_mouse_captured(ghostty_surface_t);
1110bool ghostty_surface_mouse_button(ghostty_surface_t,
1111 ghostty_input_mouse_state_e,
1112 ghostty_input_mouse_button_e,
1113 ghostty_input_mods_e);
1114void ghostty_surface_mouse_pos(ghostty_surface_t,
1115 double,
1116 double,
1117 ghostty_input_mods_e);
1118void ghostty_surface_mouse_scroll(ghostty_surface_t,
1119 double,
1120 double,
1121 ghostty_input_scroll_mods_t);
1122void ghostty_surface_mouse_pressure(ghostty_surface_t, uint32_t, double);
1123void ghostty_surface_ime_point(ghostty_surface_t, double*, double*, double*, double*);
1124void ghostty_surface_request_close(ghostty_surface_t);
1125void ghostty_surface_split(ghostty_surface_t, ghostty_action_split_direction_e);
1126void ghostty_surface_split_focus(ghostty_surface_t,
1127 ghostty_action_goto_split_e);
1128void ghostty_surface_split_resize(ghostty_surface_t,
1129 ghostty_action_resize_split_direction_e,
1130 uint16_t);
1131void ghostty_surface_split_equalize(ghostty_surface_t);
1132bool ghostty_surface_binding_action(ghostty_surface_t, const char*, uintptr_t);
1133void ghostty_surface_complete_clipboard_request(ghostty_surface_t,
1134 const char*,
1135 void*,
1136 bool);
1137bool ghostty_surface_has_selection(ghostty_surface_t);
1138bool ghostty_surface_read_selection(ghostty_surface_t, ghostty_text_s*);
1139bool ghostty_surface_read_text(ghostty_surface_t,
1140 ghostty_selection_s,
1141 ghostty_text_s*);
1142void ghostty_surface_free_text(ghostty_surface_t, ghostty_text_s*);
1143
1144#ifdef __APPLE__
1145void ghostty_surface_set_display_id(ghostty_surface_t, uint32_t);
1146void* ghostty_surface_quicklook_font(ghostty_surface_t);
1147bool ghostty_surface_quicklook_word(ghostty_surface_t, ghostty_text_s*);
1148#endif
1149
1150ghostty_inspector_t ghostty_surface_inspector(ghostty_surface_t);
1151void ghostty_inspector_free(ghostty_surface_t);
1152void ghostty_inspector_set_focus(ghostty_inspector_t, bool);
1153void ghostty_inspector_set_content_scale(ghostty_inspector_t, double, double);
1154void ghostty_inspector_set_size(ghostty_inspector_t, uint32_t, uint32_t);
1155void ghostty_inspector_mouse_button(ghostty_inspector_t,
1156 ghostty_input_mouse_state_e,
1157 ghostty_input_mouse_button_e,
1158 ghostty_input_mods_e);
1159void ghostty_inspector_mouse_pos(ghostty_inspector_t, double, double);
1160void ghostty_inspector_mouse_scroll(ghostty_inspector_t,
1161 double,
1162 double,
1163 ghostty_input_scroll_mods_t);
1164void ghostty_inspector_key(ghostty_inspector_t,
1165 ghostty_input_action_e,
1166 ghostty_input_key_e,
1167 ghostty_input_mods_e);
1168void ghostty_inspector_text(ghostty_inspector_t, const char*);
1169
1170#ifdef __APPLE__
1171bool ghostty_inspector_metal_init(ghostty_inspector_t, void*);
1172void ghostty_inspector_metal_render(ghostty_inspector_t, void*, void*);
1173bool ghostty_inspector_metal_shutdown(ghostty_inspector_t);
1174#endif
1175
1176// APIs I'd like to get rid of eventually but are still needed for now.
1177// Don't use these unless you know what you're doing.
1178void ghostty_set_window_background_blur(ghostty_app_t, void*);
1179
1180// Benchmark API, if available.
1181bool ghostty_benchmark_cli(const char*, const char*);
1182
1183#ifdef __cplusplus
1184}
1185#endif
1186
1187#endif /* GHOSTTY_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt.h+87−0
@@ -0,0 +1,87 @@
1/**
2 * @file vt.h
3 *
4 * libghostty-vt - Virtual terminal emulator library
5 *
6 * This library provides functionality for parsing and handling terminal
7 * escape sequences as well as maintaining terminal state such as styles,
8 * cursor position, screen, scrollback, and more.
9 *
10 * WARNING: This is an incomplete, work-in-progress API. It is not yet
11 * stable and is definitely going to change.
12 */
13
14/**
15 * @mainpage libghostty-vt - Virtual Terminal Emulator Library
16 *
17 * libghostty-vt is a C library which implements a modern terminal emulator,
18 * extracted from the [Ghostty](https://ghostty.org) terminal emulator.
19 *
20 * libghostty-vt contains the logic for handling the core parts of a terminal
21 * emulator: parsing terminal escape sequences, maintaining terminal state,
22 * encoding input events, etc. It can handle scrollback, line wrapping,
23 * reflow on resize, and more.
24 *
25 * @warning This library is currently in development and the API is not yet stable.
26 * Breaking changes are expected in future versions. Use with caution in production code.
27 *
28 * @section groups_sec API Reference
29 *
30 * The API is organized into the following groups:
31 * - @ref key "Key Encoding" - Encode key events into terminal sequences
32 * - @ref osc "OSC Parser" - Parse OSC (Operating System Command) sequences
33 * - @ref sgr "SGR Parser" - Parse SGR (Select Graphic Rendition) sequences
34 * - @ref paste "Paste Utilities" - Validate paste data safety
35 * - @ref allocator "Memory Management" - Memory management and custom allocators
36 * - @ref wasm "WebAssembly Utilities" - WebAssembly convenience functions
37 *
38 * @section examples_sec Examples
39 *
40 * Complete working examples:
41 * - @ref c-vt/src/main.c - OSC parser example
42 * - @ref c-vt-key-encode/src/main.c - Key encoding example
43 * - @ref c-vt-paste/src/main.c - Paste safety check example
44 * - @ref c-vt-sgr/src/main.c - SGR parser example
45 *
46 */
47
48/** @example c-vt/src/main.c
49 * This example demonstrates how to use the OSC parser to parse an OSC sequence,
50 * extract command information, and retrieve command-specific data like window titles.
51 */
52
53/** @example c-vt-key-encode/src/main.c
54 * This example demonstrates how to use the key encoder to convert key events
55 * into terminal escape sequences using the Kitty keyboard protocol.
56 */
57
58/** @example c-vt-paste/src/main.c
59 * This example demonstrates how to use the paste utilities to check if
60 * paste data is safe before sending it to the terminal.
61 */
62
63/** @example c-vt-sgr/src/main.c
64 * This example demonstrates how to use the SGR parser to parse terminal
65 * styling sequences and extract text attributes like colors and underline styles.
66 */
67
68#ifndef GHOSTTY_VT_H
69#define GHOSTTY_VT_H
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75#include <ghostty/vt/result.h>
76#include <ghostty/vt/allocator.h>
77#include <ghostty/vt/osc.h>
78#include <ghostty/vt/sgr.h>
79#include <ghostty/vt/key.h>
80#include <ghostty/vt/paste.h>
81#include <ghostty/vt/wasm.h>
82
83#ifdef __cplusplus
84}
85#endif
86
87#endif /* GHOSTTY_VT_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/allocator.h+196−0
@@ -0,0 +1,196 @@
1/**
2 * @file allocator.h
3 *
4 * Memory management interface for libghostty-vt.
5 */
6
7#ifndef GHOSTTY_VT_ALLOCATOR_H
8#define GHOSTTY_VT_ALLOCATOR_H
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13
14/** @defgroup allocator Memory Management
15 *
16 * libghostty-vt does require memory allocation for various operations,
17 * but is resilient to allocation failures and will gracefully handle
18 * out-of-memory situations by returning error codes.
19 *
20 * The exact memory management semantics are documented in the relevant
21 * functions and data structures.
22 *
23 * libghostty-vt uses explicit memory allocation via an allocator
24 * interface provided by GhosttyAllocator. The interface is based on the
25 * [Zig](https://ziglang.org) allocator interface, since this has been
26 * shown to be a flexible and powerful interface in practice and enables
27 * a wide variety of allocation strategies.
28 *
29 * **For the common case, you can pass NULL as the allocator for any
30 * function that accepts one,** and libghostty will use a default allocator.
31 * The default allocator will be libc malloc/free if libc is linked.
32 * Otherwise, a custom allocator is used (currently Zig's SMP allocator)
33 * that doesn't require any external dependencies.
34 *
35 * ## Basic Usage
36 *
37 * For simple use cases, you can ignore this interface entirely by passing NULL
38 * as the allocator parameter to functions that accept one. This will use the
39 * default allocator (typically libc malloc/free, if libc is linked, but
40 * we provide our own default allocator if libc isn't linked).
41 *
42 * To use a custom allocator:
43 * 1. Implement the GhosttyAllocatorVtable function pointers
44 * 2. Create a GhosttyAllocator struct with your vtable and context
45 * 3. Pass the allocator to functions that accept one
46 *
47 * @{
48 */
49
50/**
51 * Function table for custom memory allocator operations.
52 *
53 * This vtable defines the interface for a custom memory allocator. All
54 * function pointers must be valid and non-NULL.
55 *
56 * @ingroup allocator
57 *
58 * If you're not going to use a custom allocator, you can ignore all of
59 * this. All functions that take an allocator pointer allow NULL to use a
60 * default allocator.
61 *
62 * The interface is based on the Zig allocator interface. I'll say up front
63 * that it is easy to look at this interface and think "wow, this is really
64 * overcomplicated". The reason for this complexity is well thought out by
65 * the Zig folks, and it enables a diverse set of allocation strategies
66 * as shown by the Zig ecosystem. As a consolation, please note that many
67 * of the arguments are only needed for advanced use cases and can be
68 * safely ignored in simple implementations. For example, if you look at
69 * the Zig implementation of the libc allocator in `lib/std/heap.zig`
70 * (search for CAllocator), you'll see it is very simple.
71 *
72 * We chose to align with the Zig allocator interface because:
73 *
74 * 1. It is a proven interface that serves a wide variety of use cases
75 * in the real world via the Zig ecosystem. It's shown to work.
76 *
77 * 2. Our core implementation itself is Zig, and this lets us very
78 * cheaply and easily convert between C and Zig allocators.
79 *
80 * NOTE(mitchellh): In the future, we can have default implementations of
81 * resize/remap and allow those to be null.
82 */
83typedef struct {
84 /**
85 * Return a pointer to `len` bytes with specified `alignment`, or return
86 * `NULL` indicating the allocation failed.
87 *
88 * @param ctx The allocator context
89 * @param len Number of bytes to allocate
90 * @param alignment Required alignment for the allocation. Guaranteed to
91 * be a power of two between 1 and 16 inclusive.
92 * @param ret_addr First return address of the allocation call stack (0 if not provided)
93 * @return Pointer to allocated memory, or NULL if allocation failed
94 */
95 void* (*alloc)(void *ctx, size_t len, uint8_t alignment, uintptr_t ret_addr);
96
97 /**
98 * Attempt to expand or shrink memory in place.
99 *
100 * `memory_len` must equal the length requested from the most recent
101 * successful call to `alloc`, `resize`, or `remap`. `alignment` must
102 * equal the same value that was passed as the `alignment` parameter to
103 * the original `alloc` call.
104 *
105 * `new_len` must be greater than zero.
106 *
107 * @param ctx The allocator context
108 * @param memory Pointer to the memory block to resize
109 * @param memory_len Current size of the memory block
110 * @param alignment Alignment (must match original allocation)
111 * @param new_len New requested size
112 * @param ret_addr First return address of the allocation call stack (0 if not provided)
113 * @return true if resize was successful in-place, false if relocation would be required
114 */
115 bool (*resize)(void *ctx, void *memory, size_t memory_len, uint8_t alignment, size_t new_len, uintptr_t ret_addr);
116
117 /**
118 * Attempt to expand or shrink memory, allowing relocation.
119 *
120 * `memory_len` must equal the length requested from the most recent
121 * successful call to `alloc`, `resize`, or `remap`. `alignment` must
122 * equal the same value that was passed as the `alignment` parameter to
123 * the original `alloc` call.
124 *
125 * A non-`NULL` return value indicates the resize was successful. The
126 * allocation may have same address, or may have been relocated. In either
127 * case, the allocation now has size of `new_len`. A `NULL` return value
128 * indicates that the resize would be equivalent to allocating new memory,
129 * copying the bytes from the old memory, and then freeing the old memory.
130 * In such case, it is more efficient for the caller to perform the copy.
131 *
132 * `new_len` must be greater than zero.
133 *
134 * @param ctx The allocator context
135 * @param memory Pointer to the memory block to remap
136 * @param memory_len Current size of the memory block
137 * @param alignment Alignment (must match original allocation)
138 * @param new_len New requested size
139 * @param ret_addr First return address of the allocation call stack (0 if not provided)
140 * @return Pointer to resized memory (may be relocated), or NULL if manual copy is needed
141 */
142 void* (*remap)(void *ctx, void *memory, size_t memory_len, uint8_t alignment, size_t new_len, uintptr_t ret_addr);
143
144 /**
145 * Free and invalidate a region of memory.
146 *
147 * `memory_len` must equal the length requested from the most recent
148 * successful call to `alloc`, `resize`, or `remap`. `alignment` must
149 * equal the same value that was passed as the `alignment` parameter to
150 * the original `alloc` call.
151 *
152 * @param ctx The allocator context
153 * @param memory Pointer to the memory block to free
154 * @param memory_len Size of the memory block
155 * @param alignment Alignment (must match original allocation)
156 * @param ret_addr First return address of the allocation call stack (0 if not provided)
157 */
158 void (*free)(void *ctx, void *memory, size_t memory_len, uint8_t alignment, uintptr_t ret_addr);
159} GhosttyAllocatorVtable;
160
161/**
162 * Custom memory allocator.
163 *
164 * For functions that take an allocator pointer, a NULL pointer indicates
165 * that the default allocator should be used. The default allocator will
166 * be libc malloc/free if we're linking to libc. If libc isn't linked,
167 * a custom allocator is used (currently Zig's SMP allocator).
168 *
169 * @ingroup allocator
170 *
171 * Usage example:
172 * @code
173 * GhosttyAllocator allocator = {
174 * .vtable = &my_allocator_vtable,
175 * .ctx = my_allocator_state
176 * };
177 * @endcode
178 */
179typedef struct GhosttyAllocator {
180 /**
181 * Opaque context pointer passed to all vtable functions.
182 * This allows the allocator implementation to maintain state
183 * or reference external resources needed for memory management.
184 */
185 void *ctx;
186
187 /**
188 * Pointer to the allocator's vtable containing function pointers
189 * for memory operations (alloc, resize, remap, free).
190 */
191 const GhosttyAllocatorVtable *vtable;
192} GhosttyAllocator;
193
194/** @} */
195
196#endif /* GHOSTTY_VT_ALLOCATOR_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/color.h+96−0
@@ -0,0 +1,96 @@
1/**
2 * @file color.h
3 *
4 * Color types and utilities.
5 */
6
7#ifndef GHOSTTY_VT_COLOR_H
8#define GHOSTTY_VT_COLOR_H
9
10#include <stdint.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/**
17 * RGB color value.
18 *
19 * @ingroup sgr
20 */
21typedef struct {
22 uint8_t r; /**< Red component (0-255) */
23 uint8_t g; /**< Green component (0-255) */
24 uint8_t b; /**< Blue component (0-255) */
25} GhosttyColorRgb;
26
27/**
28 * Palette color index (0-255).
29 *
30 * @ingroup sgr
31 */
32typedef uint8_t GhosttyColorPaletteIndex;
33
34/** @addtogroup sgr
35 * @{
36 */
37
38/** Black color (0) @ingroup sgr */
39#define GHOSTTY_COLOR_NAMED_BLACK 0
40/** Red color (1) @ingroup sgr */
41#define GHOSTTY_COLOR_NAMED_RED 1
42/** Green color (2) @ingroup sgr */
43#define GHOSTTY_COLOR_NAMED_GREEN 2
44/** Yellow color (3) @ingroup sgr */
45#define GHOSTTY_COLOR_NAMED_YELLOW 3
46/** Blue color (4) @ingroup sgr */
47#define GHOSTTY_COLOR_NAMED_BLUE 4
48/** Magenta color (5) @ingroup sgr */
49#define GHOSTTY_COLOR_NAMED_MAGENTA 5
50/** Cyan color (6) @ingroup sgr */
51#define GHOSTTY_COLOR_NAMED_CYAN 6
52/** White color (7) @ingroup sgr */
53#define GHOSTTY_COLOR_NAMED_WHITE 7
54/** Bright black color (8) @ingroup sgr */
55#define GHOSTTY_COLOR_NAMED_BRIGHT_BLACK 8
56/** Bright red color (9) @ingroup sgr */
57#define GHOSTTY_COLOR_NAMED_BRIGHT_RED 9
58/** Bright green color (10) @ingroup sgr */
59#define GHOSTTY_COLOR_NAMED_BRIGHT_GREEN 10
60/** Bright yellow color (11) @ingroup sgr */
61#define GHOSTTY_COLOR_NAMED_BRIGHT_YELLOW 11
62/** Bright blue color (12) @ingroup sgr */
63#define GHOSTTY_COLOR_NAMED_BRIGHT_BLUE 12
64/** Bright magenta color (13) @ingroup sgr */
65#define GHOSTTY_COLOR_NAMED_BRIGHT_MAGENTA 13
66/** Bright cyan color (14) @ingroup sgr */
67#define GHOSTTY_COLOR_NAMED_BRIGHT_CYAN 14
68/** Bright white color (15) @ingroup sgr */
69#define GHOSTTY_COLOR_NAMED_BRIGHT_WHITE 15
70
71/** @} */
72
73/**
74 * Get the RGB color components.
75 *
76 * This function extracts the individual red, green, and blue components
77 * from a GhosttyColorRgb value. Primarily useful in WebAssembly environments
78 * where accessing struct fields directly is difficult.
79 *
80 * @param color The RGB color value
81 * @param r Pointer to store the red component (0-255)
82 * @param g Pointer to store the green component (0-255)
83 * @param b Pointer to store the blue component (0-255)
84 *
85 * @ingroup sgr
86 */
87void ghostty_color_rgb_get(GhosttyColorRgb color,
88 uint8_t* r,
89 uint8_t* g,
90 uint8_t* b);
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif /* GHOSTTY_VT_COLOR_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/key.h+80−0
@@ -0,0 +1,80 @@
1/**
2 * @file key.h
3 *
4 * Key encoding module - encode key events into terminal escape sequences.
5 */
6
7#ifndef GHOSTTY_VT_KEY_H
8#define GHOSTTY_VT_KEY_H
9
10/** @defgroup key Key Encoding
11 *
12 * Utilities for encoding key events into terminal escape sequences,
13 * supporting both legacy encoding as well as Kitty Keyboard Protocol.
14 *
15 * ## Basic Usage
16 *
17 * 1. Create an encoder instance with ghostty_key_encoder_new()
18 * 2. Configure encoder options with ghostty_key_encoder_setopt().
19 * 3. For each key event:
20 * - Create a key event with ghostty_key_event_new()
21 * - Set event properties (action, key, modifiers, etc.)
22 * - Encode with ghostty_key_encoder_encode()
23 * - Free the event with ghostty_key_event_free()
24 * - Note: You can also reuse the same key event multiple times by
25 * changing its properties.
26 * 4. Free the encoder with ghostty_key_encoder_free() when done
27 *
28 * ## Example
29 *
30 * @code{.c}
31 * #include <assert.h>
32 * #include <stdio.h>
33 * #include <ghostty/vt.h>
34 *
35 * int main() {
36 * // Create encoder
37 * GhosttyKeyEncoder encoder;
38 * GhosttyResult result = ghostty_key_encoder_new(NULL, &encoder);
39 * assert(result == GHOSTTY_SUCCESS);
40 *
41 * // Enable Kitty keyboard protocol with all features
42 * ghostty_key_encoder_setopt(encoder, GHOSTTY_KEY_ENCODER_OPT_KITTY_FLAGS,
43 * &(uint8_t){GHOSTTY_KITTY_KEY_ALL});
44 *
45 * // Create and configure key event for Ctrl+C press
46 * GhosttyKeyEvent event;
47 * result = ghostty_key_event_new(NULL, &event);
48 * assert(result == GHOSTTY_SUCCESS);
49 * ghostty_key_event_set_action(event, GHOSTTY_KEY_ACTION_PRESS);
50 * ghostty_key_event_set_key(event, GHOSTTY_KEY_C);
51 * ghostty_key_event_set_mods(event, GHOSTTY_MODS_CTRL);
52 *
53 * // Encode the key event
54 * char buf[128];
55 * size_t written = 0;
56 * result = ghostty_key_encoder_encode(encoder, event, buf, sizeof(buf), &written);
57 * assert(result == GHOSTTY_SUCCESS);
58 *
59 * // Use the encoded sequence (e.g., write to terminal)
60 * fwrite(buf, 1, written, stdout);
61 *
62 * // Cleanup
63 * ghostty_key_event_free(event);
64 * ghostty_key_encoder_free(encoder);
65 * return 0;
66 * }
67 * @endcode
68 *
69 * For a complete working example, see example/c-vt-key-encode in the
70 * repository.
71 *
72 * @{
73 */
74
75#include <ghostty/vt/key/event.h>
76#include <ghostty/vt/key/encoder.h>
77
78/** @} */
79
80#endif /* GHOSTTY_VT_KEY_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/key/encoder.h+221−0
@@ -0,0 +1,221 @@
1/**
2 * @file encoder.h
3 *
4 * Key event encoding to terminal escape sequences.
5 */
6
7#ifndef GHOSTTY_VT_KEY_ENCODER_H
8#define GHOSTTY_VT_KEY_ENCODER_H
9
10#include <stddef.h>
11#include <stdint.h>
12#include <ghostty/vt/result.h>
13#include <ghostty/vt/allocator.h>
14#include <ghostty/vt/key/event.h>
15
16/**
17 * Opaque handle to a key encoder instance.
18 *
19 * This handle represents a key encoder that converts key events into terminal
20 * escape sequences.
21 *
22 * @ingroup key
23 */
24typedef struct GhosttyKeyEncoder *GhosttyKeyEncoder;
25
26/**
27 * Kitty keyboard protocol flags.
28 *
29 * Bitflags representing the various modes of the Kitty keyboard protocol.
30 * These can be combined using bitwise OR operations. Valid values all
31 * start with `GHOSTTY_KITTY_KEY_`.
32 *
33 * @ingroup key
34 */
35typedef uint8_t GhosttyKittyKeyFlags;
36
37/** Kitty keyboard protocol disabled (all flags off) */
38#define GHOSTTY_KITTY_KEY_DISABLED 0
39
40/** Disambiguate escape codes */
41#define GHOSTTY_KITTY_KEY_DISAMBIGUATE (1 << 0)
42
43/** Report key press and release events */
44#define GHOSTTY_KITTY_KEY_REPORT_EVENTS (1 << 1)
45
46/** Report alternate key codes */
47#define GHOSTTY_KITTY_KEY_REPORT_ALTERNATES (1 << 2)
48
49/** Report all key events including those normally handled by the terminal */
50#define GHOSTTY_KITTY_KEY_REPORT_ALL (1 << 3)
51
52/** Report associated text with key events */
53#define GHOSTTY_KITTY_KEY_REPORT_ASSOCIATED (1 << 4)
54
55/** All Kitty keyboard protocol flags enabled */
56#define GHOSTTY_KITTY_KEY_ALL (GHOSTTY_KITTY_KEY_DISAMBIGUATE | GHOSTTY_KITTY_KEY_REPORT_EVENTS | GHOSTTY_KITTY_KEY_REPORT_ALTERNATES | GHOSTTY_KITTY_KEY_REPORT_ALL | GHOSTTY_KITTY_KEY_REPORT_ASSOCIATED)
57
58/**
59 * macOS option key behavior.
60 *
61 * Determines whether the "option" key on macOS is treated as "alt" or not.
62 * See the Ghostty `macos-option-as-alt` configuration option for more details.
63 *
64 * @ingroup key
65 */
66typedef enum {
67 /** Option key is not treated as alt */
68 GHOSTTY_OPTION_AS_ALT_FALSE = 0,
69 /** Option key is treated as alt */
70 GHOSTTY_OPTION_AS_ALT_TRUE = 1,
71 /** Only left option key is treated as alt */
72 GHOSTTY_OPTION_AS_ALT_LEFT = 2,
73 /** Only right option key is treated as alt */
74 GHOSTTY_OPTION_AS_ALT_RIGHT = 3,
75} GhosttyOptionAsAlt;
76
77/**
78 * Key encoder option identifiers.
79 *
80 * These values are used with ghostty_key_encoder_setopt() to configure
81 * the behavior of the key encoder.
82 *
83 * @ingroup key
84 */
85typedef enum {
86 /** Terminal DEC mode 1: cursor key application mode (value: bool) */
87 GHOSTTY_KEY_ENCODER_OPT_CURSOR_KEY_APPLICATION = 0,
88
89 /** Terminal DEC mode 66: keypad key application mode (value: bool) */
90 GHOSTTY_KEY_ENCODER_OPT_KEYPAD_KEY_APPLICATION = 1,
91
92 /** Terminal DEC mode 1035: ignore keypad with numlock (value: bool) */
93 GHOSTTY_KEY_ENCODER_OPT_IGNORE_KEYPAD_WITH_NUMLOCK = 2,
94
95 /** Terminal DEC mode 1036: alt sends escape prefix (value: bool) */
96 GHOSTTY_KEY_ENCODER_OPT_ALT_ESC_PREFIX = 3,
97
98 /** xterm modifyOtherKeys mode 2 (value: bool) */
99 GHOSTTY_KEY_ENCODER_OPT_MODIFY_OTHER_KEYS_STATE_2 = 4,
100
101 /** Kitty keyboard protocol flags (value: GhosttyKittyKeyFlags bitmask) */
102 GHOSTTY_KEY_ENCODER_OPT_KITTY_FLAGS = 5,
103
104 /** macOS option-as-alt setting (value: GhosttyOptionAsAlt) */
105 GHOSTTY_KEY_ENCODER_OPT_MACOS_OPTION_AS_ALT = 6,
106} GhosttyKeyEncoderOption;
107
108/**
109 * Create a new key encoder instance.
110 *
111 * Creates a new key encoder with default options. The encoder can be configured
112 * using ghostty_key_encoder_setopt() and must be freed using
113 * ghostty_key_encoder_free() when no longer needed.
114 *
115 * @param allocator Pointer to the allocator to use for memory management, or NULL to use the default allocator
116 * @param encoder Pointer to store the created encoder handle
117 * @return GHOSTTY_SUCCESS on success, or an error code on failure
118 *
119 * @ingroup key
120 */
121GhosttyResult ghostty_key_encoder_new(const GhosttyAllocator *allocator, GhosttyKeyEncoder *encoder);
122
123/**
124 * Free a key encoder instance.
125 *
126 * Releases all resources associated with the key encoder. After this call,
127 * the encoder handle becomes invalid and must not be used.
128 *
129 * @param encoder The encoder handle to free (may be NULL)
130 *
131 * @ingroup key
132 */
133void ghostty_key_encoder_free(GhosttyKeyEncoder encoder);
134
135/**
136 * Set an option on the key encoder.
137 *
138 * Configures the behavior of the key encoder. Options control various aspects
139 * of encoding such as terminal modes (cursor key application mode, keypad mode),
140 * protocol selection (Kitty keyboard protocol flags), and platform-specific
141 * behaviors (macOS option-as-alt).
142 *
143 * A null pointer value does nothing. It does not reset the value to the
144 * default. The setopt call will do nothing.
145 *
146 * @param encoder The encoder handle, must not be NULL
147 * @param option The option to set
148 * @param value Pointer to the value to set (type depends on the option)
149 *
150 * @ingroup key
151 */
152void ghostty_key_encoder_setopt(GhosttyKeyEncoder encoder, GhosttyKeyEncoderOption option, const void *value);
153
154/**
155 * Encode a key event into a terminal escape sequence.
156 *
157 * Converts a key event into the appropriate terminal escape sequence based on
158 * the encoder's current options. The sequence is written to the provided buffer.
159 *
160 * Not all key events produce output. For example, unmodified modifier keys
161 * typically don't generate escape sequences. Check the out_len parameter to
162 * determine if any data was written.
163 *
164 * If the output buffer is too small, this function returns GHOSTTY_OUT_OF_MEMORY
165 * and out_len will contain the required buffer size. The caller can then
166 * allocate a larger buffer and call the function again.
167 *
168 * @param encoder The encoder handle, must not be NULL
169 * @param event The key event to encode, must not be NULL
170 * @param out_buf Buffer to write the encoded sequence to
171 * @param out_buf_size Size of the output buffer in bytes
172 * @param out_len Pointer to store the number of bytes written (may be NULL)
173 * @return GHOSTTY_SUCCESS on success, GHOSTTY_OUT_OF_MEMORY if buffer too small, or other error code
174 *
175 * ## Example: Calculate required buffer size
176 *
177 * @code{.c}
178 * // Query the required size with a NULL buffer (always returns OUT_OF_MEMORY)
179 * size_t required = 0;
180 * GhosttyResult result = ghostty_key_encoder_encode(encoder, event, NULL, 0, &required);
181 * assert(result == GHOSTTY_OUT_OF_MEMORY);
182 *
183 * // Allocate buffer of required size
184 * char *buf = malloc(required);
185 *
186 * // Encode with properly sized buffer
187 * size_t written = 0;
188 * result = ghostty_key_encoder_encode(encoder, event, buf, required, &written);
189 * assert(result == GHOSTTY_SUCCESS);
190 *
191 * // Use the encoded sequence...
192 *
193 * free(buf);
194 * @endcode
195 *
196 * ## Example: Direct encoding with static buffer
197 *
198 * @code{.c}
199 * // Most escape sequences are short, so a static buffer often suffices
200 * char buf[128];
201 * size_t written = 0;
202 * GhosttyResult result = ghostty_key_encoder_encode(encoder, event, buf, sizeof(buf), &written);
203 *
204 * if (result == GHOSTTY_SUCCESS) {
205 * // Write the encoded sequence to the terminal
206 * write(pty_fd, buf, written);
207 * } else if (result == GHOSTTY_OUT_OF_MEMORY) {
208 * // Buffer too small, written contains required size
209 * char *dynamic_buf = malloc(written);
210 * result = ghostty_key_encoder_encode(encoder, event, dynamic_buf, written, &written);
211 * assert(result == GHOSTTY_SUCCESS);
212 * write(pty_fd, dynamic_buf, written);
213 * free(dynamic_buf);
214 * }
215 * @endcode
216 *
217 * @ingroup key
218 */
219GhosttyResult ghostty_key_encoder_encode(GhosttyKeyEncoder encoder, GhosttyKeyEvent event, char *out_buf, size_t out_buf_size, size_t *out_len);
220
221#endif /* GHOSTTY_VT_KEY_ENCODER_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/key/event.h+474−0
@@ -0,0 +1,474 @@
1/**
2 * @file event.h
3 *
4 * Key event representation and manipulation.
5 */
6
7#ifndef GHOSTTY_VT_KEY_EVENT_H
8#define GHOSTTY_VT_KEY_EVENT_H
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <ghostty/vt/result.h>
14#include <ghostty/vt/allocator.h>
15
16/**
17 * Opaque handle to a key event.
18 *
19 * This handle represents a keyboard input event containing information about
20 * the physical key pressed, modifiers, and generated text.
21 *
22 * @ingroup key
23 */
24typedef struct GhosttyKeyEvent *GhosttyKeyEvent;
25
26/**
27 * Keyboard input event types.
28 *
29 * @ingroup key
30 */
31typedef enum {
32 /** Key was released */
33 GHOSTTY_KEY_ACTION_RELEASE = 0,
34 /** Key was pressed */
35 GHOSTTY_KEY_ACTION_PRESS = 1,
36 /** Key is being repeated (held down) */
37 GHOSTTY_KEY_ACTION_REPEAT = 2,
38} GhosttyKeyAction;
39
40/**
41 * Keyboard modifier keys bitmask.
42 *
43 * A bitmask representing all keyboard modifiers. This tracks which modifier keys
44 * are pressed and, where supported by the platform, which side (left or right)
45 * of each modifier is active.
46 *
47 * Use the GHOSTTY_MODS_* constants to test and set individual modifiers.
48 *
49 * Modifier side bits are only meaningful when the corresponding modifier bit is set.
50 * Not all platforms support distinguishing between left and right modifier
51 * keys and Ghostty is built to expect that some platforms may not provide this
52 * information.
53 *
54 * @ingroup key
55 */
56typedef uint16_t GhosttyMods;
57
58/** Shift key is pressed */
59#define GHOSTTY_MODS_SHIFT (1 << 0)
60/** Control key is pressed */
61#define GHOSTTY_MODS_CTRL (1 << 1)
62/** Alt/Option key is pressed */
63#define GHOSTTY_MODS_ALT (1 << 2)
64/** Super/Command/Windows key is pressed */
65#define GHOSTTY_MODS_SUPER (1 << 3)
66/** Caps Lock is active */
67#define GHOSTTY_MODS_CAPS_LOCK (1 << 4)
68/** Num Lock is active */
69#define GHOSTTY_MODS_NUM_LOCK (1 << 5)
70
71/**
72 * Right shift is pressed (0 = left, 1 = right).
73 * Only meaningful when GHOSTTY_MODS_SHIFT is set.
74 */
75#define GHOSTTY_MODS_SHIFT_SIDE (1 << 6)
76/**
77 * Right ctrl is pressed (0 = left, 1 = right).
78 * Only meaningful when GHOSTTY_MODS_CTRL is set.
79 */
80#define GHOSTTY_MODS_CTRL_SIDE (1 << 7)
81/**
82 * Right alt is pressed (0 = left, 1 = right).
83 * Only meaningful when GHOSTTY_MODS_ALT is set.
84 */
85#define GHOSTTY_MODS_ALT_SIDE (1 << 8)
86/**
87 * Right super is pressed (0 = left, 1 = right).
88 * Only meaningful when GHOSTTY_MODS_SUPER is set.
89 */
90#define GHOSTTY_MODS_SUPER_SIDE (1 << 9)
91
92/**
93 * Physical key codes.
94 *
95 * The set of key codes that Ghostty is aware of. These represent physical keys
96 * on the keyboard and are layout-independent. For example, the "a" key on a US
97 * keyboard is the same as the "ф" key on a Russian keyboard, but both will
98 * report the same key_a value.
99 *
100 * Layout-dependent strings are provided separately as UTF-8 text and are produced
101 * by the platform. These values are based on the W3C UI Events KeyboardEvent code
102 * standard. See: https://www.w3.org/TR/uievents-code
103 *
104 * @ingroup key
105 */
106typedef enum {
107 GHOSTTY_KEY_UNIDENTIFIED = 0,
108
109 // Writing System Keys (W3C § 3.1.1)
110 GHOSTTY_KEY_BACKQUOTE,
111 GHOSTTY_KEY_BACKSLASH,
112 GHOSTTY_KEY_BRACKET_LEFT,
113 GHOSTTY_KEY_BRACKET_RIGHT,
114 GHOSTTY_KEY_COMMA,
115 GHOSTTY_KEY_DIGIT_0,
116 GHOSTTY_KEY_DIGIT_1,
117 GHOSTTY_KEY_DIGIT_2,
118 GHOSTTY_KEY_DIGIT_3,
119 GHOSTTY_KEY_DIGIT_4,
120 GHOSTTY_KEY_DIGIT_5,
121 GHOSTTY_KEY_DIGIT_6,
122 GHOSTTY_KEY_DIGIT_7,
123 GHOSTTY_KEY_DIGIT_8,
124 GHOSTTY_KEY_DIGIT_9,
125 GHOSTTY_KEY_EQUAL,
126 GHOSTTY_KEY_INTL_BACKSLASH,
127 GHOSTTY_KEY_INTL_RO,
128 GHOSTTY_KEY_INTL_YEN,
129 GHOSTTY_KEY_A,
130 GHOSTTY_KEY_B,
131 GHOSTTY_KEY_C,
132 GHOSTTY_KEY_D,
133 GHOSTTY_KEY_E,
134 GHOSTTY_KEY_F,
135 GHOSTTY_KEY_G,
136 GHOSTTY_KEY_H,
137 GHOSTTY_KEY_I,
138 GHOSTTY_KEY_J,
139 GHOSTTY_KEY_K,
140 GHOSTTY_KEY_L,
141 GHOSTTY_KEY_M,
142 GHOSTTY_KEY_N,
143 GHOSTTY_KEY_O,
144 GHOSTTY_KEY_P,
145 GHOSTTY_KEY_Q,
146 GHOSTTY_KEY_R,
147 GHOSTTY_KEY_S,
148 GHOSTTY_KEY_T,
149 GHOSTTY_KEY_U,
150 GHOSTTY_KEY_V,
151 GHOSTTY_KEY_W,
152 GHOSTTY_KEY_X,
153 GHOSTTY_KEY_Y,
154 GHOSTTY_KEY_Z,
155 GHOSTTY_KEY_MINUS,
156 GHOSTTY_KEY_PERIOD,
157 GHOSTTY_KEY_QUOTE,
158 GHOSTTY_KEY_SEMICOLON,
159 GHOSTTY_KEY_SLASH,
160
161 // Functional Keys (W3C § 3.1.2)
162 GHOSTTY_KEY_ALT_LEFT,
163 GHOSTTY_KEY_ALT_RIGHT,
164 GHOSTTY_KEY_BACKSPACE,
165 GHOSTTY_KEY_CAPS_LOCK,
166 GHOSTTY_KEY_CONTEXT_MENU,
167 GHOSTTY_KEY_CONTROL_LEFT,
168 GHOSTTY_KEY_CONTROL_RIGHT,
169 GHOSTTY_KEY_ENTER,
170 GHOSTTY_KEY_META_LEFT,
171 GHOSTTY_KEY_META_RIGHT,
172 GHOSTTY_KEY_SHIFT_LEFT,
173 GHOSTTY_KEY_SHIFT_RIGHT,
174 GHOSTTY_KEY_SPACE,
175 GHOSTTY_KEY_TAB,
176 GHOSTTY_KEY_CONVERT,
177 GHOSTTY_KEY_KANA_MODE,
178 GHOSTTY_KEY_NON_CONVERT,
179
180 // Control Pad Section (W3C § 3.2)
181 GHOSTTY_KEY_DELETE,
182 GHOSTTY_KEY_END,
183 GHOSTTY_KEY_HELP,
184 GHOSTTY_KEY_HOME,
185 GHOSTTY_KEY_INSERT,
186 GHOSTTY_KEY_PAGE_DOWN,
187 GHOSTTY_KEY_PAGE_UP,
188
189 // Arrow Pad Section (W3C § 3.3)
190 GHOSTTY_KEY_ARROW_DOWN,
191 GHOSTTY_KEY_ARROW_LEFT,
192 GHOSTTY_KEY_ARROW_RIGHT,
193 GHOSTTY_KEY_ARROW_UP,
194
195 // Numpad Section (W3C § 3.4)
196 GHOSTTY_KEY_NUM_LOCK,
197 GHOSTTY_KEY_NUMPAD_0,
198 GHOSTTY_KEY_NUMPAD_1,
199 GHOSTTY_KEY_NUMPAD_2,
200 GHOSTTY_KEY_NUMPAD_3,
201 GHOSTTY_KEY_NUMPAD_4,
202 GHOSTTY_KEY_NUMPAD_5,
203 GHOSTTY_KEY_NUMPAD_6,
204 GHOSTTY_KEY_NUMPAD_7,
205 GHOSTTY_KEY_NUMPAD_8,
206 GHOSTTY_KEY_NUMPAD_9,
207 GHOSTTY_KEY_NUMPAD_ADD,
208 GHOSTTY_KEY_NUMPAD_BACKSPACE,
209 GHOSTTY_KEY_NUMPAD_CLEAR,
210 GHOSTTY_KEY_NUMPAD_CLEAR_ENTRY,
211 GHOSTTY_KEY_NUMPAD_COMMA,
212 GHOSTTY_KEY_NUMPAD_DECIMAL,
213 GHOSTTY_KEY_NUMPAD_DIVIDE,
214 GHOSTTY_KEY_NUMPAD_ENTER,
215 GHOSTTY_KEY_NUMPAD_EQUAL,
216 GHOSTTY_KEY_NUMPAD_MEMORY_ADD,
217 GHOSTTY_KEY_NUMPAD_MEMORY_CLEAR,
218 GHOSTTY_KEY_NUMPAD_MEMORY_RECALL,
219 GHOSTTY_KEY_NUMPAD_MEMORY_STORE,
220 GHOSTTY_KEY_NUMPAD_MEMORY_SUBTRACT,
221 GHOSTTY_KEY_NUMPAD_MULTIPLY,
222 GHOSTTY_KEY_NUMPAD_PAREN_LEFT,
223 GHOSTTY_KEY_NUMPAD_PAREN_RIGHT,
224 GHOSTTY_KEY_NUMPAD_SUBTRACT,
225 GHOSTTY_KEY_NUMPAD_SEPARATOR,
226 GHOSTTY_KEY_NUMPAD_UP,
227 GHOSTTY_KEY_NUMPAD_DOWN,
228 GHOSTTY_KEY_NUMPAD_RIGHT,
229 GHOSTTY_KEY_NUMPAD_LEFT,
230 GHOSTTY_KEY_NUMPAD_BEGIN,
231 GHOSTTY_KEY_NUMPAD_HOME,
232 GHOSTTY_KEY_NUMPAD_END,
233 GHOSTTY_KEY_NUMPAD_INSERT,
234 GHOSTTY_KEY_NUMPAD_DELETE,
235 GHOSTTY_KEY_NUMPAD_PAGE_UP,
236 GHOSTTY_KEY_NUMPAD_PAGE_DOWN,
237
238 // Function Section (W3C § 3.5)
239 GHOSTTY_KEY_ESCAPE,
240 GHOSTTY_KEY_F1,
241 GHOSTTY_KEY_F2,
242 GHOSTTY_KEY_F3,
243 GHOSTTY_KEY_F4,
244 GHOSTTY_KEY_F5,
245 GHOSTTY_KEY_F6,
246 GHOSTTY_KEY_F7,
247 GHOSTTY_KEY_F8,
248 GHOSTTY_KEY_F9,
249 GHOSTTY_KEY_F10,
250 GHOSTTY_KEY_F11,
251 GHOSTTY_KEY_F12,
252 GHOSTTY_KEY_F13,
253 GHOSTTY_KEY_F14,
254 GHOSTTY_KEY_F15,
255 GHOSTTY_KEY_F16,
256 GHOSTTY_KEY_F17,
257 GHOSTTY_KEY_F18,
258 GHOSTTY_KEY_F19,
259 GHOSTTY_KEY_F20,
260 GHOSTTY_KEY_F21,
261 GHOSTTY_KEY_F22,
262 GHOSTTY_KEY_F23,
263 GHOSTTY_KEY_F24,
264 GHOSTTY_KEY_F25,
265 GHOSTTY_KEY_FN,
266 GHOSTTY_KEY_FN_LOCK,
267 GHOSTTY_KEY_PRINT_SCREEN,
268 GHOSTTY_KEY_SCROLL_LOCK,
269 GHOSTTY_KEY_PAUSE,
270
271 // Media Keys (W3C § 3.6)
272 GHOSTTY_KEY_BROWSER_BACK,
273 GHOSTTY_KEY_BROWSER_FAVORITES,
274 GHOSTTY_KEY_BROWSER_FORWARD,
275 GHOSTTY_KEY_BROWSER_HOME,
276 GHOSTTY_KEY_BROWSER_REFRESH,
277 GHOSTTY_KEY_BROWSER_SEARCH,
278 GHOSTTY_KEY_BROWSER_STOP,
279 GHOSTTY_KEY_EJECT,
280 GHOSTTY_KEY_LAUNCH_APP_1,
281 GHOSTTY_KEY_LAUNCH_APP_2,
282 GHOSTTY_KEY_LAUNCH_MAIL,
283 GHOSTTY_KEY_MEDIA_PLAY_PAUSE,
284 GHOSTTY_KEY_MEDIA_SELECT,
285 GHOSTTY_KEY_MEDIA_STOP,
286 GHOSTTY_KEY_MEDIA_TRACK_NEXT,
287 GHOSTTY_KEY_MEDIA_TRACK_PREVIOUS,
288 GHOSTTY_KEY_POWER,
289 GHOSTTY_KEY_SLEEP,
290 GHOSTTY_KEY_AUDIO_VOLUME_DOWN,
291 GHOSTTY_KEY_AUDIO_VOLUME_MUTE,
292 GHOSTTY_KEY_AUDIO_VOLUME_UP,
293 GHOSTTY_KEY_WAKE_UP,
294
295 // Legacy, Non-standard, and Special Keys (W3C § 3.7)
296 GHOSTTY_KEY_COPY,
297 GHOSTTY_KEY_CUT,
298 GHOSTTY_KEY_PASTE,
299} GhosttyKey;
300
301/**
302 * Create a new key event instance.
303 *
304 * Creates a new key event with default values. The event must be freed using
305 * ghostty_key_event_free() when no longer needed.
306 *
307 * @param allocator Pointer to the allocator to use for memory management, or NULL to use the default allocator
308 * @param event Pointer to store the created key event handle
309 * @return GHOSTTY_SUCCESS on success, or an error code on failure
310 *
311 * @ingroup key
312 */
313GhosttyResult ghostty_key_event_new(const GhosttyAllocator *allocator, GhosttyKeyEvent *event);
314
315/**
316 * Free a key event instance.
317 *
318 * Releases all resources associated with the key event. After this call,
319 * the event handle becomes invalid and must not be used.
320 *
321 * @param event The key event handle to free (may be NULL)
322 *
323 * @ingroup key
324 */
325void ghostty_key_event_free(GhosttyKeyEvent event);
326
327/**
328 * Set the key action (press, release, repeat).
329 *
330 * @param event The key event handle, must not be NULL
331 * @param action The action to set
332 *
333 * @ingroup key
334 */
335void ghostty_key_event_set_action(GhosttyKeyEvent event, GhosttyKeyAction action);
336
337/**
338 * Get the key action (press, release, repeat).
339 *
340 * @param event The key event handle, must not be NULL
341 * @return The key action
342 *
343 * @ingroup key
344 */
345GhosttyKeyAction ghostty_key_event_get_action(GhosttyKeyEvent event);
346
347/**
348 * Set the physical key code.
349 *
350 * @param event The key event handle, must not be NULL
351 * @param key The physical key code to set
352 *
353 * @ingroup key
354 */
355void ghostty_key_event_set_key(GhosttyKeyEvent event, GhosttyKey key);
356
357/**
358 * Get the physical key code.
359 *
360 * @param event The key event handle, must not be NULL
361 * @return The physical key code
362 *
363 * @ingroup key
364 */
365GhosttyKey ghostty_key_event_get_key(GhosttyKeyEvent event);
366
367/**
368 * Set the modifier keys bitmask.
369 *
370 * @param event The key event handle, must not be NULL
371 * @param mods The modifier keys bitmask to set
372 *
373 * @ingroup key
374 */
375void ghostty_key_event_set_mods(GhosttyKeyEvent event, GhosttyMods mods);
376
377/**
378 * Get the modifier keys bitmask.
379 *
380 * @param event The key event handle, must not be NULL
381 * @return The modifier keys bitmask
382 *
383 * @ingroup key
384 */
385GhosttyMods ghostty_key_event_get_mods(GhosttyKeyEvent event);
386
387/**
388 * Set the consumed modifiers bitmask.
389 *
390 * @param event The key event handle, must not be NULL
391 * @param consumed_mods The consumed modifiers bitmask to set
392 *
393 * @ingroup key
394 */
395void ghostty_key_event_set_consumed_mods(GhosttyKeyEvent event, GhosttyMods consumed_mods);
396
397/**
398 * Get the consumed modifiers bitmask.
399 *
400 * @param event The key event handle, must not be NULL
401 * @return The consumed modifiers bitmask
402 *
403 * @ingroup key
404 */
405GhosttyMods ghostty_key_event_get_consumed_mods(GhosttyKeyEvent event);
406
407/**
408 * Set whether the key event is part of a composition sequence.
409 *
410 * @param event The key event handle, must not be NULL
411 * @param composing Whether the key event is part of a composition sequence
412 *
413 * @ingroup key
414 */
415void ghostty_key_event_set_composing(GhosttyKeyEvent event, bool composing);
416
417/**
418 * Get whether the key event is part of a composition sequence.
419 *
420 * @param event The key event handle, must not be NULL
421 * @return Whether the key event is part of a composition sequence
422 *
423 * @ingroup key
424 */
425bool ghostty_key_event_get_composing(GhosttyKeyEvent event);
426
427/**
428 * Set the UTF-8 text generated by the key event.
429 *
430 * The key event does NOT take ownership of the text pointer. The caller
431 * must ensure the string remains valid for the lifetime needed by the event.
432 *
433 * @param event The key event handle, must not be NULL
434 * @param utf8 The UTF-8 text to set (or NULL for empty)
435 * @param len Length of the UTF-8 text in bytes
436 *
437 * @ingroup key
438 */
439void ghostty_key_event_set_utf8(GhosttyKeyEvent event, const char *utf8, size_t len);
440
441/**
442 * Get the UTF-8 text generated by the key event.
443 *
444 * The returned pointer is valid until the event is freed or the UTF-8 text is modified.
445 *
446 * @param event The key event handle, must not be NULL
447 * @param len Pointer to store the length of the UTF-8 text in bytes (may be NULL)
448 * @return The UTF-8 text (or NULL for empty)
449 *
450 * @ingroup key
451 */
452const char *ghostty_key_event_get_utf8(GhosttyKeyEvent event, size_t *len);
453
454/**
455 * Set the unshifted Unicode codepoint.
456 *
457 * @param event The key event handle, must not be NULL
458 * @param codepoint The unshifted Unicode codepoint to set
459 *
460 * @ingroup key
461 */
462void ghostty_key_event_set_unshifted_codepoint(GhosttyKeyEvent event, uint32_t codepoint);
463
464/**
465 * Get the unshifted Unicode codepoint.
466 *
467 * @param event The key event handle, must not be NULL
468 * @return The unshifted Unicode codepoint
469 *
470 * @ingroup key
471 */
472uint32_t ghostty_key_event_get_unshifted_codepoint(GhosttyKeyEvent event);
473
474#endif /* GHOSTTY_VT_KEY_EVENT_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/osc.h+233−0
@@ -0,0 +1,233 @@
1/**
2 * @file osc.h
3 *
4 * OSC (Operating System Command) sequence parser and command handling.
5 */
6
7#ifndef GHOSTTY_VT_OSC_H
8#define GHOSTTY_VT_OSC_H
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <ghostty/vt/result.h>
14#include <ghostty/vt/allocator.h>
15
16/**
17 * Opaque handle to an OSC parser instance.
18 *
19 * This handle represents an OSC (Operating System Command) parser that can
20 * be used to parse the contents of OSC sequences.
21 *
22 * @ingroup osc
23 */
24typedef struct GhosttyOscParser *GhosttyOscParser;
25
26/**
27 * Opaque handle to a single OSC command.
28 *
29 * This handle represents a parsed OSC (Operating System Command) command.
30 * The command can be queried for its type and associated data.
31 *
32 * @ingroup osc
33 */
34typedef struct GhosttyOscCommand *GhosttyOscCommand;
35
36/** @defgroup osc OSC Parser
37 *
38 * OSC (Operating System Command) sequence parser and command handling.
39 *
40 * The parser operates in a streaming fashion, processing input byte-by-byte
41 * to handle OSC sequences that may arrive in fragments across multiple reads.
42 * This interface makes it easy to integrate into most environments and avoids
43 * over-allocating buffers.
44 *
45 * ## Basic Usage
46 *
47 * 1. Create a parser instance with ghostty_osc_new()
48 * 2. Feed bytes to the parser using ghostty_osc_next()
49 * 3. Finalize parsing with ghostty_osc_end() to get the command
50 * 4. Query command type and extract data using ghostty_osc_command_type()
51 * and ghostty_osc_command_data()
52 * 5. Free the parser with ghostty_osc_free() when done
53 *
54 * @{
55 */
56
57/**
58 * OSC command types.
59 *
60 * @ingroup osc
61 */
62typedef enum {
63 GHOSTTY_OSC_COMMAND_INVALID = 0,
64 GHOSTTY_OSC_COMMAND_CHANGE_WINDOW_TITLE = 1,
65 GHOSTTY_OSC_COMMAND_CHANGE_WINDOW_ICON = 2,
66 GHOSTTY_OSC_COMMAND_SEMANTIC_PROMPT = 3,
67 GHOSTTY_OSC_COMMAND_CLIPBOARD_CONTENTS = 4,
68 GHOSTTY_OSC_COMMAND_REPORT_PWD = 5,
69 GHOSTTY_OSC_COMMAND_MOUSE_SHAPE = 6,
70 GHOSTTY_OSC_COMMAND_COLOR_OPERATION = 7,
71 GHOSTTY_OSC_COMMAND_KITTY_COLOR_PROTOCOL = 8,
72 GHOSTTY_OSC_COMMAND_SHOW_DESKTOP_NOTIFICATION = 9,
73 GHOSTTY_OSC_COMMAND_HYPERLINK_START = 10,
74 GHOSTTY_OSC_COMMAND_HYPERLINK_END = 11,
75 GHOSTTY_OSC_COMMAND_CONEMU_SLEEP = 12,
76 GHOSTTY_OSC_COMMAND_CONEMU_SHOW_MESSAGE_BOX = 13,
77 GHOSTTY_OSC_COMMAND_CONEMU_CHANGE_TAB_TITLE = 14,
78 GHOSTTY_OSC_COMMAND_CONEMU_PROGRESS_REPORT = 15,
79 GHOSTTY_OSC_COMMAND_CONEMU_WAIT_INPUT = 16,
80 GHOSTTY_OSC_COMMAND_CONEMU_GUIMACRO = 17,
81 GHOSTTY_OSC_COMMAND_CONEMU_RUN_PROCESS = 18,
82 GHOSTTY_OSC_COMMAND_CONEMU_OUTPUT_ENVIRONMENT_VARIABLE = 19,
83 GHOSTTY_OSC_COMMAND_CONEMU_XTERM_EMULATION = 20,
84 GHOSTTY_OSC_COMMAND_CONEMU_COMMENT = 21,
85 GHOSTTY_OSC_COMMAND_KITTY_TEXT_SIZING = 22,
86} GhosttyOscCommandType;
87
88/**
89 * OSC command data types.
90 *
91 * These values specify what type of data to extract from an OSC command
92 * using `ghostty_osc_command_data`.
93 *
94 * @ingroup osc
95 */
96typedef enum {
97 /** Invalid data type. Never results in any data extraction. */
98 GHOSTTY_OSC_DATA_INVALID = 0,
99
100 /**
101 * Window title string data.
102 *
103 * Valid for: GHOSTTY_OSC_COMMAND_CHANGE_WINDOW_TITLE
104 *
105 * Output type: const char ** (pointer to null-terminated string)
106 *
107 * Lifetime: Valid until the next call to any ghostty_osc_* function with
108 * the same parser instance. Memory is owned by the parser.
109 */
110 GHOSTTY_OSC_DATA_CHANGE_WINDOW_TITLE_STR = 1,
111} GhosttyOscCommandData;
112
113/**
114 * Create a new OSC parser instance.
115 *
116 * Creates a new OSC (Operating System Command) parser using the provided
117 * allocator. The parser must be freed using ghostty_vt_osc_free() when
118 * no longer needed.
119 *
120 * @param allocator Pointer to the allocator to use for memory management, or NULL to use the default allocator
121 * @param parser Pointer to store the created parser handle
122 * @return GHOSTTY_SUCCESS on success, or an error code on failure
123 *
124 * @ingroup osc
125 */
126GhosttyResult ghostty_osc_new(const GhosttyAllocator *allocator, GhosttyOscParser *parser);
127
128/**
129 * Free an OSC parser instance.
130 *
131 * Releases all resources associated with the OSC parser. After this call,
132 * the parser handle becomes invalid and must not be used.
133 *
134 * @param parser The parser handle to free (may be NULL)
135 *
136 * @ingroup osc
137 */
138void ghostty_osc_free(GhosttyOscParser parser);
139
140/**
141 * Reset an OSC parser instance to its initial state.
142 *
143 * Resets the parser state, clearing any partially parsed OSC sequences
144 * and returning the parser to its initial state. This is useful for
145 * reusing a parser instance or recovering from parse errors.
146 *
147 * @param parser The parser handle to reset, must not be null.
148 *
149 * @ingroup osc
150 */
151void ghostty_osc_reset(GhosttyOscParser parser);
152
153/**
154 * Parse the next byte in an OSC sequence.
155 *
156 * Processes a single byte as part of an OSC sequence. The parser maintains
157 * internal state to track the progress through the sequence. Call this
158 * function for each byte in the sequence data.
159 *
160 * When finished pumping the parser with bytes, call ghostty_osc_end
161 * to get the final result.
162 *
163 * @param parser The parser handle, must not be null.
164 * @param byte The next byte to parse
165 *
166 * @ingroup osc
167 */
168void ghostty_osc_next(GhosttyOscParser parser, uint8_t byte);
169
170/**
171 * Finalize OSC parsing and retrieve the parsed command.
172 *
173 * Call this function after feeding all bytes of an OSC sequence to the parser
174 * using ghostty_osc_next() with the exception of the terminating character
175 * (ESC or ST). This function finalizes the parsing process and returns the
176 * parsed OSC command.
177 *
178 * The return value is never NULL. Invalid commands will return a command
179 * with type GHOSTTY_OSC_COMMAND_INVALID.
180 *
181 * The terminator parameter specifies the byte that terminated the OSC sequence
182 * (typically 0x07 for BEL or 0x5C for ST after ESC). This information is
183 * preserved in the parsed command so that responses can use the same terminator
184 * format for better compatibility with the calling program. For commands that
185 * do not require a response, this parameter is ignored and the resulting
186 * command will not retain the terminator information.
187 *
188 * The returned command handle is valid until the next call to any
189 * `ghostty_osc_*` function with the same parser instance with the exception
190 * of command introspection functions such as `ghostty_osc_command_type`.
191 *
192 * @param parser The parser handle, must not be null.
193 * @param terminator The terminating byte of the OSC sequence (0x07 for BEL, 0x5C for ST)
194 * @return Handle to the parsed OSC command
195 *
196 * @ingroup osc
197 */
198GhosttyOscCommand ghostty_osc_end(GhosttyOscParser parser, uint8_t terminator);
199
200/**
201 * Get the type of an OSC command.
202 *
203 * Returns the type identifier for the given OSC command. This can be used
204 * to determine what kind of command was parsed and what data might be
205 * available from it.
206 *
207 * @param command The OSC command handle to query (may be NULL)
208 * @return The command type, or GHOSTTY_OSC_COMMAND_INVALID if command is NULL
209 *
210 * @ingroup osc
211 */
212GhosttyOscCommandType ghostty_osc_command_type(GhosttyOscCommand command);
213
214/**
215 * Extract data from an OSC command.
216 *
217 * Extracts typed data from the given OSC command based on the specified
218 * data type. The output pointer must be of the appropriate type for the
219 * requested data kind. Valid command types, output types, and memory
220 * safety information are documented in the `GhosttyOscCommandData` enum.
221 *
222 * @param command The OSC command handle to query (may be NULL)
223 * @param data The type of data to extract
224 * @param out Pointer to store the extracted data (type depends on data parameter)
225 * @return true if data extraction was successful, false otherwise
226 *
227 * @ingroup osc
228 */
229bool ghostty_osc_command_data(GhosttyOscCommand command, GhosttyOscCommandData data, void *out);
230
231/** @} */
232
233#endif /* GHOSTTY_VT_OSC_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/paste.h+75−0
@@ -0,0 +1,75 @@
1/**
2 * @file paste.h
3 *
4 * Paste utilities - validate and encode paste data for terminal input.
5 */
6
7#ifndef GHOSTTY_VT_PASTE_H
8#define GHOSTTY_VT_PASTE_H
9
10/** @defgroup paste Paste Utilities
11 *
12 * Utilities for validating paste data safety.
13 *
14 * ## Basic Usage
15 *
16 * Use ghostty_paste_is_safe() to check if paste data contains potentially
17 * dangerous sequences before sending it to the terminal.
18 *
19 * ## Example
20 *
21 * @code{.c}
22 * #include <stdio.h>
23 * #include <string.h>
24 * #include <ghostty/vt.h>
25 *
26 * int main() {
27 * const char* safe_data = "hello world";
28 * const char* unsafe_data = "rm -rf /\n";
29 *
30 * if (ghostty_paste_is_safe(safe_data, strlen(safe_data))) {
31 * printf("Safe to paste\n");
32 * }
33 *
34 * if (!ghostty_paste_is_safe(unsafe_data, strlen(unsafe_data))) {
35 * printf("Unsafe! Contains newline\n");
36 * }
37 *
38 * return 0;
39 * }
40 * @endcode
41 *
42 * @{
43 */
44
45#include <stdbool.h>
46#include <stddef.h>
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/**
53 * Check if paste data is safe to paste into the terminal.
54 *
55 * Data is considered unsafe if it contains:
56 * - Newlines (`\n`) which can inject commands
57 * - The bracketed paste end sequence (`\x1b[201~`) which can be used
58 * to exit bracketed paste mode and inject commands
59 *
60 * This check is conservative and considers data unsafe regardless of
61 * current terminal state.
62 *
63 * @param data The paste data to check (must not be NULL)
64 * @param len The length of the data in bytes
65 * @return true if the data is safe to paste, false otherwise
66 */
67bool ghostty_paste_is_safe(const char* data, size_t len);
68
69#ifdef __cplusplus
70}
71#endif
72
73/** @} */
74
75#endif /* GHOSTTY_VT_PASTE_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/result.h+22−0
@@ -0,0 +1,22 @@
1/**
2 * @file result.h
3 *
4 * Result codes for libghostty-vt operations.
5 */
6
7#ifndef GHOSTTY_VT_RESULT_H
8#define GHOSTTY_VT_RESULT_H
9
10/**
11 * Result codes for libghostty-vt operations.
12 */
13typedef enum {
14 /** Operation completed successfully */
15 GHOSTTY_SUCCESS = 0,
16 /** Operation failed due to failed allocation */
17 GHOSTTY_OUT_OF_MEMORY = -1,
18 /** Operation failed due to invalid value */
19 GHOSTTY_INVALID_VALUE = -2,
20} GhosttyResult;
21
22#endif /* GHOSTTY_VT_RESULT_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/sgr.h+394−0
@@ -0,0 +1,394 @@
1/**
2 * @file sgr.h
3 *
4 * SGR (Select Graphic Rendition) attribute parsing and handling.
5 */
6
7#ifndef GHOSTTY_VT_SGR_H
8#define GHOSTTY_VT_SGR_H
9
10/** @defgroup sgr SGR Parser
11 *
12 * SGR (Select Graphic Rendition) attribute parser.
13 *
14 * SGR sequences are the syntax used to set styling attributes such as
15 * bold, italic, underline, and colors for text in terminal emulators.
16 * For example, you may be familiar with sequences like `ESC[1;31m`. The
17 * `1;31` is the SGR attribute list.
18 *
19 * The parser processes SGR parameters from CSI sequences (e.g., `ESC[1;31m`)
20 * and returns individual text attributes like bold, italic, colors, etc.
21 * It supports both semicolon (`;`) and colon (`:`) separators, possibly mixed,
22 * and handles various color formats including 8-color, 16-color, 256-color,
23 * X11 named colors, and RGB in multiple formats.
24 *
25 * ## Basic Usage
26 *
27 * 1. Create a parser instance with ghostty_sgr_new()
28 * 2. Set SGR parameters with ghostty_sgr_set_params()
29 * 3. Iterate through attributes using ghostty_sgr_next()
30 * 4. Free the parser with ghostty_sgr_free() when done
31 *
32 * ## Example
33 *
34 * @code{.c}
35 * #include <assert.h>
36 * #include <stdio.h>
37 * #include <ghostty/vt.h>
38 *
39 * int main() {
40 * // Create parser
41 * GhosttySgrParser parser;
42 * GhosttyResult result = ghostty_sgr_new(NULL, &parser);
43 * assert(result == GHOSTTY_SUCCESS);
44 *
45 * // Parse "bold, red foreground" sequence: ESC[1;31m
46 * uint16_t params[] = {1, 31};
47 * result = ghostty_sgr_set_params(parser, params, NULL, 2);
48 * assert(result == GHOSTTY_SUCCESS);
49 *
50 * // Iterate through attributes
51 * GhosttySgrAttribute attr;
52 * while (ghostty_sgr_next(parser, &attr)) {
53 * switch (attr.tag) {
54 * case GHOSTTY_SGR_ATTR_BOLD:
55 * printf("Bold enabled\n");
56 * break;
57 * case GHOSTTY_SGR_ATTR_FG_8:
58 * printf("Foreground color: %d\n", attr.value.fg_8);
59 * break;
60 * default:
61 * break;
62 * }
63 * }
64 *
65 * // Cleanup
66 * ghostty_sgr_free(parser);
67 * return 0;
68 * }
69 * @endcode
70 *
71 * @{
72 */
73
74#include <ghostty/vt/allocator.h>
75#include <ghostty/vt/color.h>
76#include <ghostty/vt/result.h>
77#include <stdbool.h>
78#include <stddef.h>
79#include <stdint.h>
80
81#ifdef __cplusplus
82extern "C" {
83#endif
84
85/**
86 * Opaque handle to an SGR parser instance.
87 *
88 * This handle represents an SGR (Select Graphic Rendition) parser that can
89 * be used to parse SGR sequences and extract individual text attributes.
90 *
91 * @ingroup sgr
92 */
93typedef struct GhosttySgrParser* GhosttySgrParser;
94
95/**
96 * SGR attribute tags.
97 *
98 * These values identify the type of an SGR attribute in a tagged union.
99 * Use the tag to determine which field in the attribute value union to access.
100 *
101 * @ingroup sgr
102 */
103typedef enum {
104 GHOSTTY_SGR_ATTR_UNSET = 0,
105 GHOSTTY_SGR_ATTR_UNKNOWN = 1,
106 GHOSTTY_SGR_ATTR_BOLD = 2,
107 GHOSTTY_SGR_ATTR_RESET_BOLD = 3,
108 GHOSTTY_SGR_ATTR_ITALIC = 4,
109 GHOSTTY_SGR_ATTR_RESET_ITALIC = 5,
110 GHOSTTY_SGR_ATTR_FAINT = 6,
111 GHOSTTY_SGR_ATTR_UNDERLINE = 7,
112 GHOSTTY_SGR_ATTR_RESET_UNDERLINE = 8,
113 GHOSTTY_SGR_ATTR_UNDERLINE_COLOR = 9,
114 GHOSTTY_SGR_ATTR_UNDERLINE_COLOR_256 = 10,
115 GHOSTTY_SGR_ATTR_RESET_UNDERLINE_COLOR = 11,
116 GHOSTTY_SGR_ATTR_OVERLINE = 12,
117 GHOSTTY_SGR_ATTR_RESET_OVERLINE = 13,
118 GHOSTTY_SGR_ATTR_BLINK = 14,
119 GHOSTTY_SGR_ATTR_RESET_BLINK = 15,
120 GHOSTTY_SGR_ATTR_INVERSE = 16,
121 GHOSTTY_SGR_ATTR_RESET_INVERSE = 17,
122 GHOSTTY_SGR_ATTR_INVISIBLE = 18,
123 GHOSTTY_SGR_ATTR_RESET_INVISIBLE = 19,
124 GHOSTTY_SGR_ATTR_STRIKETHROUGH = 20,
125 GHOSTTY_SGR_ATTR_RESET_STRIKETHROUGH = 21,
126 GHOSTTY_SGR_ATTR_DIRECT_COLOR_FG = 22,
127 GHOSTTY_SGR_ATTR_DIRECT_COLOR_BG = 23,
128 GHOSTTY_SGR_ATTR_BG_8 = 24,
129 GHOSTTY_SGR_ATTR_FG_8 = 25,
130 GHOSTTY_SGR_ATTR_RESET_FG = 26,
131 GHOSTTY_SGR_ATTR_RESET_BG = 27,
132 GHOSTTY_SGR_ATTR_BRIGHT_BG_8 = 28,
133 GHOSTTY_SGR_ATTR_BRIGHT_FG_8 = 29,
134 GHOSTTY_SGR_ATTR_BG_256 = 30,
135 GHOSTTY_SGR_ATTR_FG_256 = 31,
136} GhosttySgrAttributeTag;
137
138/**
139 * Underline style types.
140 *
141 * @ingroup sgr
142 */
143typedef enum {
144 GHOSTTY_SGR_UNDERLINE_NONE = 0,
145 GHOSTTY_SGR_UNDERLINE_SINGLE = 1,
146 GHOSTTY_SGR_UNDERLINE_DOUBLE = 2,
147 GHOSTTY_SGR_UNDERLINE_CURLY = 3,
148 GHOSTTY_SGR_UNDERLINE_DOTTED = 4,
149 GHOSTTY_SGR_UNDERLINE_DASHED = 5,
150} GhosttySgrUnderline;
151
152/**
153 * Unknown SGR attribute data.
154 *
155 * Contains the full parameter list and the partial list where parsing
156 * encountered an unknown or invalid sequence.
157 *
158 * @ingroup sgr
159 */
160typedef struct {
161 const uint16_t* full_ptr;
162 size_t full_len;
163 const uint16_t* partial_ptr;
164 size_t partial_len;
165} GhosttySgrUnknown;
166
167/**
168 * SGR attribute value union.
169 *
170 * This union contains all possible attribute values. Use the tag field
171 * to determine which union member is active. Attributes without associated
172 * data (like bold, italic) don't use the union value.
173 *
174 * @ingroup sgr
175 */
176typedef union {
177 GhosttySgrUnknown unknown;
178 GhosttySgrUnderline underline;
179 GhosttyColorRgb underline_color;
180 GhosttyColorPaletteIndex underline_color_256;
181 GhosttyColorRgb direct_color_fg;
182 GhosttyColorRgb direct_color_bg;
183 GhosttyColorPaletteIndex bg_8;
184 GhosttyColorPaletteIndex fg_8;
185 GhosttyColorPaletteIndex bright_bg_8;
186 GhosttyColorPaletteIndex bright_fg_8;
187 GhosttyColorPaletteIndex bg_256;
188 GhosttyColorPaletteIndex fg_256;
189 uint64_t _padding[8];
190} GhosttySgrAttributeValue;
191
192/**
193 * SGR attribute (tagged union).
194 *
195 * A complete SGR attribute with both its type tag and associated value.
196 * Always check the tag field to determine which value union member is valid.
197 *
198 * Attributes without associated data (e.g., GHOSTTY_SGR_ATTR_BOLD) can be
199 * identified by tag alone; the value union is not used for these and
200 * the memory in the value field is undefined.
201 *
202 * @ingroup sgr
203 */
204typedef struct {
205 GhosttySgrAttributeTag tag;
206 GhosttySgrAttributeValue value;
207} GhosttySgrAttribute;
208
209/**
210 * Create a new SGR parser instance.
211 *
212 * Creates a new SGR (Select Graphic Rendition) parser using the provided
213 * allocator. The parser must be freed using ghostty_sgr_free() when
214 * no longer needed.
215 *
216 * @param allocator Pointer to the allocator to use for memory management, or
217 * NULL to use the default allocator
218 * @param parser Pointer to store the created parser handle
219 * @return GHOSTTY_SUCCESS on success, or an error code on failure
220 *
221 * @ingroup sgr
222 */
223GhosttyResult ghostty_sgr_new(const GhosttyAllocator* allocator,
224 GhosttySgrParser* parser);
225
226/**
227 * Free an SGR parser instance.
228 *
229 * Releases all resources associated with the SGR parser. After this call,
230 * the parser handle becomes invalid and must not be used. This includes
231 * any attributes previously returned by ghostty_sgr_next().
232 *
233 * @param parser The parser handle to free (may be NULL)
234 *
235 * @ingroup sgr
236 */
237void ghostty_sgr_free(GhosttySgrParser parser);
238
239/**
240 * Reset an SGR parser instance to the beginning of the parameter list.
241 *
242 * Resets the parser's iteration state without clearing the parameters.
243 * After calling this, ghostty_sgr_next() will start from the beginning
244 * of the parameter list again.
245 *
246 * @param parser The parser handle to reset, must not be NULL
247 *
248 * @ingroup sgr
249 */
250void ghostty_sgr_reset(GhosttySgrParser parser);
251
252/**
253 * Set SGR parameters for parsing.
254 *
255 * Sets the SGR parameter list to parse. Parameters are the numeric values
256 * from a CSI SGR sequence (e.g., for `ESC[1;31m`, params would be {1, 31}).
257 *
258 * The separators array optionally specifies the separator type for each
259 * parameter position. Each byte should be either ';' for semicolon or ':'
260 * for colon. This is needed for certain color formats that use colon
261 * separators (e.g., `ESC[4:3m` for curly underline). Any invalid separator
262 * values are treated as semicolons. The separators array must have the same
263 * length as the params array, if it is not NULL.
264 *
265 * If separators is NULL, all parameters are assumed to be semicolon-separated.
266 *
267 * This function makes an internal copy of the parameter and separator data,
268 * so the caller can safely free or modify the input arrays after this call.
269 *
270 * After calling this function, the parser is automatically reset and ready
271 * to iterate from the beginning.
272 *
273 * @param parser The parser handle, must not be NULL
274 * @param params Array of SGR parameter values
275 * @param separators Optional array of separator characters (';' or ':'), or
276 * NULL
277 * @param len Number of parameters (and separators if provided)
278 * @return GHOSTTY_SUCCESS on success, or an error code on failure
279 *
280 * @ingroup sgr
281 */
282GhosttyResult ghostty_sgr_set_params(GhosttySgrParser parser,
283 const uint16_t* params,
284 const char* separators,
285 size_t len);
286
287/**
288 * Get the next SGR attribute.
289 *
290 * Parses and returns the next attribute from the parameter list.
291 * Call this function repeatedly until it returns false to process
292 * all attributes in the sequence.
293 *
294 * @param parser The parser handle, must not be NULL
295 * @param attr Pointer to store the next attribute
296 * @return true if an attribute was returned, false if no more attributes
297 *
298 * @ingroup sgr
299 */
300bool ghostty_sgr_next(GhosttySgrParser parser, GhosttySgrAttribute* attr);
301
302/**
303 * Get the full parameter list from an unknown SGR attribute.
304 *
305 * This function retrieves the full parameter list that was provided to the
306 * parser when an unknown attribute was encountered. Primarily useful in
307 * WebAssembly environments where accessing struct fields directly is difficult.
308 *
309 * @param unknown The unknown attribute data
310 * @param ptr Pointer to store the pointer to the parameter array (may be NULL)
311 * @return The length of the full parameter array
312 *
313 * @ingroup sgr
314 */
315size_t ghostty_sgr_unknown_full(GhosttySgrUnknown unknown,
316 const uint16_t** ptr);
317
318/**
319 * Get the partial parameter list from an unknown SGR attribute.
320 *
321 * This function retrieves the partial parameter list where parsing stopped
322 * when an unknown attribute was encountered. Primarily useful in WebAssembly
323 * environments where accessing struct fields directly is difficult.
324 *
325 * @param unknown The unknown attribute data
326 * @param ptr Pointer to store the pointer to the parameter array (may be NULL)
327 * @return The length of the partial parameter array
328 *
329 * @ingroup sgr
330 */
331size_t ghostty_sgr_unknown_partial(GhosttySgrUnknown unknown,
332 const uint16_t** ptr);
333
334/**
335 * Get the tag from an SGR attribute.
336 *
337 * This function extracts the tag that identifies which type of attribute
338 * this is. Primarily useful in WebAssembly environments where accessing
339 * struct fields directly is difficult.
340 *
341 * @param attr The SGR attribute
342 * @return The attribute tag
343 *
344 * @ingroup sgr
345 */
346GhosttySgrAttributeTag ghostty_sgr_attribute_tag(GhosttySgrAttribute attr);
347
348/**
349 * Get the value from an SGR attribute.
350 *
351 * This function returns a pointer to the value union from an SGR attribute. Use
352 * the tag to determine which field of the union is valid. Primarily useful in
353 * WebAssembly environments where accessing struct fields directly is difficult.
354 *
355 * @param attr Pointer to the SGR attribute
356 * @return Pointer to the attribute value union
357 *
358 * @ingroup sgr
359 */
360GhosttySgrAttributeValue* ghostty_sgr_attribute_value(
361 GhosttySgrAttribute* attr);
362
363#ifdef __wasm__
364/**
365 * Allocate memory for an SGR attribute (WebAssembly only).
366 *
367 * This is a convenience function for WebAssembly environments to allocate
368 * memory for an SGR attribute structure that can be passed to ghostty_sgr_next.
369 *
370 * @return Pointer to the allocated attribute structure
371 *
372 * @ingroup wasm
373 */
374GhosttySgrAttribute* ghostty_wasm_alloc_sgr_attribute(void);
375
376/**
377 * Free memory for an SGR attribute (WebAssembly only).
378 *
379 * Frees memory allocated by ghostty_wasm_alloc_sgr_attribute.
380 *
381 * @param attr Pointer to the attribute structure to free
382 *
383 * @ingroup wasm
384 */
385void ghostty_wasm_free_sgr_attribute(GhosttySgrAttribute* attr);
386#endif
387
388#ifdef __cplusplus
389}
390#endif
391
392/** @} */
393
394#endif /* GHOSTTY_VT_SGR_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/ghostty/vt/wasm.h+159−0
@@ -0,0 +1,159 @@
1/**
2 * @file wasm.h
3 *
4 * WebAssembly utility functions for libghostty-vt.
5 */
6
7#ifndef GHOSTTY_VT_WASM_H
8#define GHOSTTY_VT_WASM_H
9
10#ifdef __wasm__
11
12#include <stddef.h>
13#include <stdint.h>
14
15/** @defgroup wasm WebAssembly Utilities
16 *
17 * Convenience functions for allocating various types in WebAssembly builds.
18 * **These are only available the libghostty-vt wasm module.**
19 *
20 * Ghostty relies on pointers to various types for ABI compatibility, and
21 * creating those pointers in Wasm can be tedious. These functions provide
22 * a purely additive set of utilities that simplify memory management in
23 * Wasm environments without changing the core C library API.
24 *
25 * @note These functions always use the default allocator. If you need
26 * custom allocation strategies, you should allocate types manually using
27 * your custom allocator. This is a very rare use case in the WebAssembly
28 * world so these are optimized for simplicity.
29 *
30 * ## Example Usage
31 *
32 * Here's a simple example of using the Wasm utilities with the key encoder:
33 *
34 * @code
35 * const { exports } = wasmInstance;
36 * const view = new DataView(wasmMemory.buffer);
37 *
38 * // Create key encoder
39 * const encoderPtr = exports.ghostty_wasm_alloc_opaque();
40 * exports.ghostty_key_encoder_new(null, encoderPtr);
41 * const encoder = view.getUint32(encoder, true);
42 *
43 * // Configure encoder with Kitty protocol flags
44 * const flagsPtr = exports.ghostty_wasm_alloc_u8();
45 * view.setUint8(flagsPtr, 0x1F);
46 * exports.ghostty_key_encoder_setopt(encoder, 5, flagsPtr);
47 *
48 * // Allocate output buffer and size pointer
49 * const bufferSize = 32;
50 * const bufPtr = exports.ghostty_wasm_alloc_u8_array(bufferSize);
51 * const writtenPtr = exports.ghostty_wasm_alloc_usize();
52 *
53 * // Encode the key event
54 * exports.ghostty_key_encoder_encode(
55 * encoder, eventPtr, bufPtr, bufferSize, writtenPtr
56 * );
57 *
58 * // Read encoded output
59 * const bytesWritten = view.getUint32(writtenPtr, true);
60 * const encoded = new Uint8Array(wasmMemory.buffer, bufPtr, bytesWritten);
61 * @endcode
62 *
63 * @remark The code above is pretty ugly! This is the lowest level interface
64 * to the libghostty-vt Wasm module. In practice, this should be wrapped
65 * in a higher-level API that abstracts away all this.
66 *
67 * @{
68 */
69
70/**
71 * Allocate an opaque pointer. This can be used for any opaque pointer
72 * types such as GhosttyKeyEncoder, GhosttyKeyEvent, etc.
73 *
74 * @return Pointer to allocated opaque pointer, or NULL if allocation failed
75 * @ingroup wasm
76 */
77void** ghostty_wasm_alloc_opaque(void);
78
79/**
80 * Free an opaque pointer allocated by ghostty_wasm_alloc_opaque().
81 *
82 * @param ptr Pointer to free, or NULL (NULL is safely ignored)
83 * @ingroup wasm
84 */
85void ghostty_wasm_free_opaque(void **ptr);
86
87/**
88 * Allocate an array of uint8_t values.
89 *
90 * @param len Number of uint8_t elements to allocate
91 * @return Pointer to allocated array, or NULL if allocation failed
92 * @ingroup wasm
93 */
94uint8_t* ghostty_wasm_alloc_u8_array(size_t len);
95
96/**
97 * Free an array allocated by ghostty_wasm_alloc_u8_array().
98 *
99 * @param ptr Pointer to the array to free, or NULL (NULL is safely ignored)
100 * @param len Length of the array (must match the length passed to alloc)
101 * @ingroup wasm
102 */
103void ghostty_wasm_free_u8_array(uint8_t *ptr, size_t len);
104
105/**
106 * Allocate an array of uint16_t values.
107 *
108 * @param len Number of uint16_t elements to allocate
109 * @return Pointer to allocated array, or NULL if allocation failed
110 * @ingroup wasm
111 */
112uint16_t* ghostty_wasm_alloc_u16_array(size_t len);
113
114/**
115 * Free an array allocated by ghostty_wasm_alloc_u16_array().
116 *
117 * @param ptr Pointer to the array to free, or NULL (NULL is safely ignored)
118 * @param len Length of the array (must match the length passed to alloc)
119 * @ingroup wasm
120 */
121void ghostty_wasm_free_u16_array(uint16_t *ptr, size_t len);
122
123/**
124 * Allocate a single uint8_t value.
125 *
126 * @return Pointer to allocated uint8_t, or NULL if allocation failed
127 * @ingroup wasm
128 */
129uint8_t* ghostty_wasm_alloc_u8(void);
130
131/**
132 * Free a uint8_t allocated by ghostty_wasm_alloc_u8().
133 *
134 * @param ptr Pointer to free, or NULL (NULL is safely ignored)
135 * @ingroup wasm
136 */
137void ghostty_wasm_free_u8(uint8_t *ptr);
138
139/**
140 * Allocate a single size_t value.
141 *
142 * @return Pointer to allocated size_t, or NULL if allocation failed
143 * @ingroup wasm
144 */
145size_t* ghostty_wasm_alloc_usize(void);
146
147/**
148 * Free a size_t allocated by ghostty_wasm_alloc_usize().
149 *
150 * @param ptr Pointer to free, or NULL (NULL is safely ignored)
151 * @ingroup wasm
152 */
153void ghostty_wasm_free_usize(size_t *ptr);
154
155/** @} */
156
157#endif /* __wasm__ */
158
159#endif /* GHOSTTY_VT_WASM_H */
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/Headers/module.modulemap+7−0
@@ -0,0 +1,7 @@
1// This makes Ghostty available to the XCode build for the macOS app.
2// We append "Kit" to it not to be cute, but because targets have to have
3// unique names and we use Ghostty for other things.
4module GhosttyKit {
5 umbrella header "ghostty.h"
6 export *
7}
apps/mobile/modules/t3-terminal/Vendor/libghostty/GhosttyKit.xcframework/macos-arm64_x86_64/libghostty.a+0−0

Binary file not shown.

apps/mobile/modules/t3-terminal/Vendor/libghostty/VERSION+1−0
@@ -0,0 +1 @@
1268a0a9d761fb19673f05d28042488e2002300f2
apps/mobile/modules/t3-terminal/android/build.gradle+19−0
@@ -0,0 +1,19 @@
1apply plugin: 'com.android.library'
2apply plugin: 'org.jetbrains.kotlin.android'
3
4group = 'com.t3tools.terminal'
5version = '0.0.0'
6
7android {
8 namespace 'expo.modules.t3terminal'
9 compileSdk rootProject.ext.compileSdkVersion
10
11 defaultConfig {
12 minSdkVersion rootProject.ext.minSdkVersion
13 targetSdkVersion rootProject.ext.targetSdkVersion
14 }
15}
16
17dependencies {
18 implementation project(':expo-modules-core')
19}
apps/mobile/modules/t3-terminal/android/src/main/AndroidManifest.xml+1−0
@@ -0,0 +1 @@
1<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalModule.kt+26−0
@@ -0,0 +1,26 @@
1package expo.modules.t3terminal
2
3import expo.modules.kotlin.modules.Module
4import expo.modules.kotlin.modules.ModuleDefinition
5
6class T3TerminalModule : Module() {
7 override fun definition() = ModuleDefinition {
8 Name("T3TerminalSurface")
9
10 View(T3TerminalView::class) {
11 Prop("terminalKey") { view: T3TerminalView, terminalKey: String ->
12 view.terminalKey = terminalKey
13 }
14
15 Prop("initialBuffer") { view: T3TerminalView, initialBuffer: String ->
16 view.initialBuffer = initialBuffer
17 }
18
19 Prop("fontSize") { view: T3TerminalView, fontSize: Double ->
20 view.fontSize = fontSize.toFloat()
21 }
22
23 Events("onInput", "onResize")
24 }
25 }
26}
apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalView.kt+120−0
@@ -0,0 +1,120 @@
1package expo.modules.t3terminal
2
3import android.content.Context
4import android.graphics.Color
5import android.graphics.Typeface
6import android.view.View
7import android.view.ViewGroup
8import android.view.inputmethod.EditorInfo
9import android.widget.EditText
10import android.widget.LinearLayout
11import android.widget.ScrollView
12import android.widget.TextView
13import expo.modules.kotlin.AppContext
14import expo.modules.kotlin.views.ExpoView
15import expo.modules.kotlin.viewevent.EventDispatcher
16import kotlin.math.max
17import kotlin.math.min
18
19class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
20 private val container = LinearLayout(context)
21 private val scrollView = ScrollView(context)
22 private val textView = TextView(context)
23 private val inputView = EditText(context)
24 private val onInput by EventDispatcher()
25 private val onResize by EventDispatcher()
26 private var lastWidth = 0
27 private var lastHeight = 0
28
29 var terminalKey: String = ""
30 set(value) {
31 field = value
32 contentDescription = "t3-terminal-$value"
33 }
34
35 var initialBuffer: String = ""
36 set(value) {
37 field = value
38 textView.text = value.ifEmpty { "$ " }
39 scrollView.post {
40 scrollView.fullScroll(View.FOCUS_DOWN)
41 }
42 }
43
44 var fontSize: Float = 12f
45 set(value) {
46 field = value
47 textView.textSize = value
48 emitResize()
49 }
50
51 init {
52 setBackgroundColor(Color.BLACK)
53 container.orientation = LinearLayout.VERTICAL
54 container.setBackgroundColor(Color.BLACK)
55
56 textView.setTextColor(Color.rgb(245, 245, 245))
57 textView.typeface = Typeface.MONOSPACE
58 textView.textSize = fontSize
59 textView.setPadding(8, 8, 8, 8)
60 textView.text = "$ "
61
62 inputView.setSingleLine(true)
63 inputView.setTextColor(Color.rgb(245, 245, 245))
64 inputView.setHintTextColor(Color.rgb(115, 115, 115))
65 inputView.setBackgroundColor(Color.BLACK)
66 inputView.typeface = Typeface.MONOSPACE
67 inputView.textSize = max(fontSize, 13f)
68 inputView.hint = "type and press return"
69 inputView.imeOptions = EditorInfo.IME_ACTION_SEND
70 inputView.setPadding(8, 0, 8, 8)
71 inputView.setOnEditorActionListener { view, actionId, _ ->
72 if (actionId != EditorInfo.IME_ACTION_SEND) return@setOnEditorActionListener false
73 val text = view.text?.toString().orEmpty()
74 if (text.isNotEmpty()) {
75 onInput(mapOf("data" to "$text\n"))
76 view.text?.clear()
77 }
78 true
79 }
80
81 scrollView.addView(
82 textView,
83 LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT),
84 )
85 container.addView(
86 scrollView,
87 LinearLayout.LayoutParams(
88 ViewGroup.LayoutParams.MATCH_PARENT,
89 0,
90 1f,
91 ),
92 )
93 container.addView(
94 inputView,
95 LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 48),
96 )
97 addView(
98 container,
99 LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT),
100 )
101 }
102
103 override fun onSizeChanged(width: Int, height: Int, oldWidth: Int, oldHeight: Int) {
104 super.onSizeChanged(width, height, oldWidth, oldHeight)
105 if (width == lastWidth && height == lastHeight) return
106 lastWidth = width
107 lastHeight = height
108 emitResize()
109 }
110
111 private fun emitResize() {
112 if (width <= 0 || height <= 0) return
113 val density = resources.displayMetrics.scaledDensity
114 val fontPx = max(fontSize * density, 1f)
115 val cols = max(20, min(400, (width / (fontPx * 0.62f)).toInt()))
116 val terminalHeight = max(height - inputView.height, 0)
117 val rows = max(5, min(200, (terminalHeight / (fontPx * 1.35f)).toInt()))
118 onResize(mapOf("cols" to cols, "rows" to rows))
119 }
120}
apps/mobile/modules/t3-terminal/expo-module.config.json+10−0
@@ -0,0 +1,10 @@
1{
2 "platforms": ["apple", "android"],
3 "apple": {
4 "modules": ["T3TerminalModule"],
5 "podspecPath": "T3TerminalNative.podspec"
6 },
7 "android": {
8 "modules": ["expo.modules.t3terminal.T3TerminalModule"]
9 }
10}
apps/mobile/modules/t3-terminal/ios/T3TerminalModule.swift+23−0
@@ -0,0 +1,23 @@
1import ExpoModulesCore
2
3public class T3TerminalModule: Module {
4 public func definition() -> ModuleDefinition {
5 Name("T3TerminalSurface")
6
7 View(T3TerminalView.self) {
8 Prop("terminalKey") { (view: T3TerminalView, terminalKey: String) in
9 view.terminalKey = terminalKey
10 }
11
12 Prop("initialBuffer") { (view: T3TerminalView, initialBuffer: String) in
13 view.initialBuffer = initialBuffer
14 }
15
16 Prop("fontSize") { (view: T3TerminalView, fontSize: Double) in
17 view.fontSize = CGFloat(fontSize)
18 }
19
20 Events("onInput", "onResize")
21 }
22 }
23}
apps/mobile/modules/t3-terminal/ios/T3TerminalView.swift+364−0
@@ -0,0 +1,364 @@
1import ExpoModulesCore
2import GhosttyKit
3import QuartzCore
4import UIKit
5
6private enum GhosttyRuntime {
7 private static let lock = NSLock()
8 private static var initialized = false
9
10 static func ensureInitialized() -> Bool {
11 lock.lock()
12 defer { lock.unlock() }
13
14 if initialized {
15 return true
16 }
17
18 let result = ghostty_init(0, nil)
19 initialized = result == GHOSTTY_SUCCESS
20 return initialized
21 }
22}
23
24public final class T3TerminalView: ExpoView, UITextFieldDelegate {
25 private let terminalViewport = UIView()
26 private let inputField = UITextField()
27 private let inputDivider = UIView()
28 private var lastViewportSize: CGSize = .zero
29 private var lastContentScale: CGFloat = 0
30 private var lastReportedGrid: (cols: Int, rows: Int)?
31 private var lastAppliedBuffer = ""
32 private var app: ghostty_app_t?
33 private var surface: ghostty_surface_t?
34 private var isCreatingSurface = false
35 private var surfaceCreationFailed = false
36
37 let onInput = EventDispatcher()
38 let onResize = EventDispatcher()
39
40 var terminalKey: String = "" {
41 didSet {
42 accessibilityIdentifier = "t3-terminal-\(terminalKey)"
43 if oldValue != terminalKey {
44 resetSurface()
45 }
46 }
47 }
48
49 var initialBuffer: String = "" {
50 didSet {
51 applyRemoteBuffer(initialBuffer)
52 }
53 }
54
55 var fontSize: CGFloat = 12 {
56 didSet {
57 inputField.font = UIFont.monospacedSystemFont(ofSize: max(fontSize, 13), weight: .regular)
58 resetSurface()
59 }
60 }
61
62 public required init(appContext: AppContext? = nil) {
63 super.init(appContext: appContext)
64
65 backgroundColor = UIColor.black
66 clipsToBounds = true
67 contentScaleFactor = UIScreen.main.scale
68
69 terminalViewport.backgroundColor = UIColor.black
70 terminalViewport.clipsToBounds = true
71 terminalViewport.contentScaleFactor = contentScaleFactor
72 terminalViewport.translatesAutoresizingMaskIntoConstraints = false
73
74 inputDivider.backgroundColor = UIColor(white: 1, alpha: 0.12)
75 inputDivider.translatesAutoresizingMaskIntoConstraints = false
76
77 inputField.delegate = self
78 inputField.backgroundColor = UIColor.black
79 inputField.textColor = UIColor(white: 0.96, alpha: 1)
80 inputField.tintColor = UIColor(white: 0.96, alpha: 1)
81 inputField.font = UIFont.monospacedSystemFont(ofSize: max(fontSize, 13), weight: .regular)
82 inputField.placeholder = "type and press return"
83 inputField.attributedPlaceholder = NSAttributedString(
84 string: "type and press return",
85 attributes: [.foregroundColor: UIColor(white: 0.45, alpha: 1)]
86 )
87 inputField.autocorrectionType = .no
88 inputField.autocapitalizationType = .none
89 inputField.spellCheckingType = .no
90 inputField.smartDashesType = .no
91 inputField.smartQuotesType = .no
92 inputField.returnKeyType = .send
93 inputField.translatesAutoresizingMaskIntoConstraints = false
94
95 addSubview(terminalViewport)
96 addSubview(inputDivider)
97 addSubview(inputField)
98
99 NSLayoutConstraint.activate([
100 terminalViewport.leadingAnchor.constraint(equalTo: leadingAnchor),
101 terminalViewport.trailingAnchor.constraint(equalTo: trailingAnchor),
102 terminalViewport.topAnchor.constraint(equalTo: topAnchor),
103 terminalViewport.bottomAnchor.constraint(equalTo: inputDivider.topAnchor),
104
105 inputDivider.leadingAnchor.constraint(equalTo: leadingAnchor),
106 inputDivider.trailingAnchor.constraint(equalTo: trailingAnchor),
107 inputDivider.bottomAnchor.constraint(equalTo: inputField.topAnchor),
108 inputDivider.heightAnchor.constraint(equalToConstant: 1),
109
110 inputField.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10),
111 inputField.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -10),
112 inputField.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8),
113 inputField.heightAnchor.constraint(equalToConstant: 32),
114 ])
115 }
116
117 deinit {
118 destroySurface()
119 }
120
121 public override func layoutSubviews() {
122 super.layoutSubviews()
123 updateContentScale()
124
125 let viewportSize = terminalViewport.bounds.size
126 if surface == nil {
127 createSurfaceIfPossible()
128 }
129
130 guard viewportSize != lastViewportSize || contentScaleFactor != lastContentScale else {
131 return
132 }
133
134 lastViewportSize = viewportSize
135 lastContentScale = contentScaleFactor
136 resizeSurface()
137 }
138
139 public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
140 let text = textField.text ?? ""
141 if !text.isEmpty {
142 onInput(["data": "\(text)\n"])
143 textField.text = ""
144 }
145 return false
146 }
147
148 private func createSurfaceIfPossible() {
149 guard surface == nil, app == nil, !isCreatingSurface, !surfaceCreationFailed else { return }
150 guard terminalViewport.bounds.width > 0, terminalViewport.bounds.height > 0 else { return }
151 guard GhosttyRuntime.ensureInitialized() else {
152 surfaceCreationFailed = true
153 return
154 }
155
156 isCreatingSurface = true
157 defer { isCreatingSurface = false }
158
159 var runtimeConfig = ghostty_runtime_config_s(
160 userdata: Unmanaged.passUnretained(self).toOpaque(),
161 supports_selection_clipboard: false,
162 wakeup_cb: { _ in },
163 action_cb: { _, _, _ in false },
164 read_clipboard_cb: { _, _, _ in },
165 confirm_read_clipboard_cb: { _, _, _, _ in },
166 write_clipboard_cb: { _, _, _, _, _ in },
167 close_surface_cb: { _, _ in }
168 )
169
170 guard let config = ghostty_config_new() else {
171 surfaceCreationFailed = true
172 return
173 }
174 ghostty_config_finalize(config)
175 defer { ghostty_config_free(config) }
176
177 guard let createdApp = ghostty_app_new(&runtimeConfig, config) else {
178 surfaceCreationFailed = true
179 return
180 }
181
182 var surfaceConfig = ghostty_surface_config_new()
183 surfaceConfig.platform_tag = GHOSTTY_PLATFORM_IOS
184 surfaceConfig.platform.ios.uiview = Unmanaged.passUnretained(terminalViewport).toOpaque()
185 surfaceConfig.userdata = Unmanaged.passUnretained(self).toOpaque()
186 surfaceConfig.scale_factor = Double(contentScaleFactor)
187 surfaceConfig.font_size = Float(fontSize)
188 surfaceConfig.context = GHOSTTY_SURFACE_CONTEXT_WINDOW
189 surfaceConfig.use_custom_io = true
190
191 guard let createdSurface = ghostty_surface_new(createdApp, &surfaceConfig) else {
192 ghostty_app_free(createdApp)
193 surfaceCreationFailed = true
194 return
195 }
196
197 app = createdApp
198 surface = createdSurface
199 setupWriteCallback()
200 resizeSurface()
201 feedBuffer(initialBuffer)
202 }
203
204 private func resetSurface() {
205 destroySurface()
206 lastAppliedBuffer = ""
207 lastViewportSize = .zero
208 lastContentScale = 0
209 lastReportedGrid = nil
210 surfaceCreationFailed = false
211 setNeedsLayout()
212 }
213
214 private func destroySurface() {
215 if let surface {
216 ghostty_surface_set_write_callback(surface, nil, nil)
217 ghostty_surface_free(surface)
218 }
219 if let app {
220 ghostty_app_free(app)
221 }
222 surface = nil
223 app = nil
224 }
225
226 private func applyRemoteBuffer(_ buffer: String) {
227 guard surface != nil else {
228 createSurfaceIfPossible()
229 return
230 }
231
232 if buffer.hasPrefix(lastAppliedBuffer) {
233 let suffix = String(buffer.dropFirst(lastAppliedBuffer.count))
234 feedData(Data(suffix.utf8))
235 lastAppliedBuffer = buffer
236 return
237 }
238
239 resetSurface()
240 createSurfaceIfPossible()
241 }
242
243 private func feedBuffer(_ buffer: String) {
244 guard !buffer.isEmpty else { return }
245 feedData(Data(buffer.utf8))
246 lastAppliedBuffer = buffer
247 }
248
249 private func feedData(_ data: Data) {
250 guard let surface, !data.isEmpty else { return }
251
252 data.withUnsafeBytes { buffer in
253 guard let pointer = buffer.baseAddress?.assumingMemoryBound(to: UInt8.self) else {
254 return
255 }
256 ghostty_surface_feed_data(surface, pointer, buffer.count)
257 }
258
259 redrawSurface()
260 }
261
262 private func setupWriteCallback() {
263 guard let surface else { return }
264
265 let userdata = Unmanaged.passUnretained(self).toOpaque()
266 ghostty_surface_set_write_callback(surface, { userdata, data, len in
267 guard let userdata, let data, len > 0 else { return }
268 let view = Unmanaged<T3TerminalView>.fromOpaque(userdata).takeUnretainedValue()
269 let bytes = Data(bytes: data, count: len)
270 guard let input = String(data: bytes, encoding: .utf8), !input.isEmpty else { return }
271
272 DispatchQueue.main.async {
273 view.onInput(["data": input])
274 }
275 }, userdata)
276 }
277
278 private func resizeSurface() {
279 guard let surface else {
280 emitEstimatedResize()
281 return
282 }
283
284 let scale = contentScaleFactor
285 let width = UInt32(max(floor(terminalViewport.bounds.width * scale), 1))
286 let height = UInt32(max(floor(terminalViewport.bounds.height * scale), 1))
287
288 terminalViewport.contentScaleFactor = scale
289 ghostty_surface_set_content_scale(surface, Double(scale), Double(scale))
290 ghostty_surface_set_size(surface, width, height)
291 ghostty_surface_set_occlusion(surface, window != nil)
292 configureIOSurfaceLayers()
293 redrawSurface()
294 emitGhosttyResize()
295 }
296
297 private func redrawSurface() {
298 guard let surface else { return }
299 ghostty_surface_refresh(surface)
300 ghostty_surface_draw(surface)
301 markIOSurfaceLayersForDisplay()
302 emitGhosttyResize()
303 }
304
305 private func emitGhosttyResize() {
306 guard let surface else {
307 emitEstimatedResize()
308 return
309 }
310
311 let size = ghostty_surface_size(surface)
312 let cols = max(1, Int(size.columns))
313 let rows = max(1, Int(size.rows))
314 emitResize(cols: cols, rows: rows)
315 }
316
317 private func emitEstimatedResize() {
318 guard bounds.width > 0, bounds.height > 0 else { return }
319
320 let cellWidth = max(fontSize * 0.62, 1)
321 let cellHeight = max(fontSize * 1.35, 1)
322 let cols = max(20, min(400, Int(bounds.width / cellWidth)))
323 let terminalHeight = max(bounds.height - 41, 0)
324 let rows = max(5, min(200, Int(terminalHeight / cellHeight)))
325 emitResize(cols: cols, rows: rows)
326 }
327
328 private func emitResize(cols: Int, rows: Int) {
329 guard lastReportedGrid?.cols != cols || lastReportedGrid?.rows != rows else {
330 return
331 }
332
333 lastReportedGrid = (cols, rows)
334 onResize([
335 "cols": cols,
336 "rows": rows,
337 ])
338 }
339
340 private func updateContentScale() {
341 let scale = window?.screen.scale ?? UIScreen.main.scale
342 if contentScaleFactor != scale {
343 contentScaleFactor = scale
344 }
345 }
346
347 private func configureIOSurfaceLayers() {
348 let targetBounds = CGRect(origin: .zero, size: terminalViewport.bounds.size)
349 CATransaction.begin()
350 CATransaction.setDisableActions(true)
351 terminalViewport.layer.sublayers?.forEach { sublayer in
352 sublayer.frame = targetBounds
353 sublayer.contentsScale = contentScaleFactor
354 }
355 CATransaction.commit()
356 }
357
358 private func markIOSurfaceLayersForDisplay() {
359 terminalViewport.layer.setNeedsDisplay()
360 terminalViewport.layer.sublayers?.forEach { layer in
361 layer.setNeedsDisplay()
362 }
363 }
364}
apps/mobile/modules/t3-terminal/package.json+17−0
@@ -0,0 +1,17 @@
1{
2 "name": "@t3tools/mobile-terminal-native",
3 "version": "0.0.0",
4 "private": true,
5 "expo-module": {
6 "ios": {
7 "modules": [
8 "T3TerminalModule"
9 ]
10 },
11 "android": {
12 "modules": [
13 "expo.modules.t3terminal.T3TerminalModule"
14 ]
15 }
16 }
17}
apps/mobile/package.json+2−0
@@ -41,6 +41,7 @@ · 40 unmodified lines
41 "@react-native-menu/menu": "^2.0.0",41 "@react-native-menu/menu": "^2.0.0",
42 "@t3tools/client-runtime": "workspace:*",42 "@t3tools/client-runtime": "workspace:*",
43 "@t3tools/contracts": "workspace:*",43 "@t3tools/contracts": "workspace:*",
44 "@t3tools/mobile-terminal-native": "file:./modules/t3-terminal",
44 "@t3tools/shared": "workspace:*",45 "@t3tools/shared": "workspace:*",
45 "clsx": "^2.1.1",46 "clsx": "^2.1.1",
46 "effect": "catalog:",47 "effect": "catalog:",
@@ -55,6 +56,7 @@ · 8 unmodified lines
55 "expo-haptics": "^55.0.9",56 "expo-haptics": "^55.0.9",
56 "expo-image-picker": "~55.0.14",57 "expo-image-picker": "~55.0.14",
57 "expo-linking": "~55.0.12",58 "expo-linking": "~55.0.12",
59 "expo-modules-core": "~55.0.22",
58 "expo-paste-input": "^0.1.15",60 "expo-paste-input": "^0.1.15",
59 "expo-router": "~55.0.12",61 "expo-router": "~55.0.12",
60 "expo-secure-store": "~55.0.9",62 "expo-secure-store": "~55.0.9",
apps/mobile/src/features/threads/ThreadDetailScreen.tsx+46−1
@@ -9,8 +9,9 @@ import type { · 8 unmodified lines
9} from "@t3tools/contracts";9} from "@t3tools/contracts";
10import { formatElapsed } from "@t3tools/shared/orchestrationTiming";10import { formatElapsed } from "@t3tools/shared/orchestrationTiming";
11import * as Haptics from "expo-haptics";11import * as Haptics from "expo-haptics";
12import { SymbolView } from "expo-symbols";
12import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";13import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
13import { View, type LayoutChangeEvent } from "react-native";14import { Pressable, View, type LayoutChangeEvent } from "react-native";
14import { Gesture, GestureDetector } from "react-native-gesture-handler";15import { Gesture, GestureDetector } from "react-native-gesture-handler";
15import { KeyboardStickyView } from "react-native-keyboard-controller";16import { KeyboardStickyView } from "react-native-keyboard-controller";
16import { useSafeAreaInsets } from "react-native-safe-area-context";17import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -34,6 +35,7 @@ import { · 17 unmodified lines
34 ThreadComposer,35 ThreadComposer,
35} from "./ThreadComposer";36} from "./ThreadComposer";
36import { ThreadFeed } from "./ThreadFeed";37import { ThreadFeed } from "./ThreadFeed";
38import { ThreadTerminalPanel } from "./ThreadTerminalPanel";
37 39
38export interface ThreadDetailScreenProps {40export interface ThreadDetailScreenProps {
39 readonly selectedThread: OrchestrationThread;41 readonly selectedThread: OrchestrationThread;
@@ -203,6 +205,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread · 163 unmodified lines
203 const estimatedOverlayHeight = composerOverlapHeight + activeWorkIndicatorHeight;205 const estimatedOverlayHeight = composerOverlapHeight + activeWorkIndicatorHeight;
204 const [measuredOverlayHeight, setMeasuredOverlayHeight] = useState(0);206 const [measuredOverlayHeight, setMeasuredOverlayHeight] = useState(0);
205 const [refreshing, setRefreshing] = useState(false);207 const [refreshing, setRefreshing] = useState(false);
208 const [terminalVisible, setTerminalVisible] = useState(false);
206 const showContent = props.showContent ?? true;209 const showContent = props.showContent ?? true;
207 const layoutVariant = props.layoutVariant ?? "compact";210 const layoutVariant = props.layoutVariant ?? "compact";
208 const isSplitLayout = layoutVariant === "split";211 const isSplitLayout = layoutVariant === "split";
@@ -251,6 +254,16 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread · 42 unmodified lines
251 );254 );
252 }, []);255 }, []);
253 256
257 const canOpenTerminal = Boolean(props.projectWorkspaceRoot);
258 const handleToggleTerminal = useCallback(() => {
259 if (!canOpenTerminal) {
260 return;
261 }
262
263 void Haptics.selectionAsync();
264 setTerminalVisible((current) => !current);
265 }, [canOpenTerminal]);
266
254 return (267 return (
255 <GestureDetector gesture={headerDrawerGesture}>268 <GestureDetector gesture={headerDrawerGesture}>
256 <View className="flex-1">269 <View className="flex-1">
@@ -271,6 +284,17 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread · 14 unmodified lines
271 <View style={{ flex: 1 }} />284 <View style={{ flex: 1 }} />
272 )}285 )}
273 286
287 {showContent && props.projectWorkspaceRoot ? (
288 <ThreadTerminalPanel
289 visible={terminalVisible}
290 environmentId={props.environmentId}
291 threadId={props.selectedThread.id}
292 cwd={props.projectWorkspaceRoot}
293 worktreePath={props.selectedThread.worktreePath}
294 onClose={() => setTerminalVisible(false)}
295 />
296 ) : null}
297
274 {/* Floating composer — sticks to keyboard via KeyboardStickyView */}298 {/* Floating composer — sticks to keyboard via KeyboardStickyView */}
275 {showContent ? (299 {showContent ? (
276 <KeyboardStickyView300 <KeyboardStickyView
@@ -305,6 +329,27 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread · 28 unmodified lines
305 </View>329 </View>
306 ) : null}330 ) : null}
307 331
332 <View className="items-end px-4 pb-2">
333 <Pressable
334 disabled={!canOpenTerminal}
335 className="flex-row items-center gap-2 rounded-[8px] border border-neutral-200/80 bg-neutral-50/95 px-3 py-2 dark:border-white/[0.08] dark:bg-white/[0.08]"
336 style={({ pressed }) => ({
337 opacity: !canOpenTerminal ? 0.4 : pressed ? 0.65 : 1,
338 })}
339 onPress={handleToggleTerminal}
340 >
341 <SymbolView
342 name="terminal"
343 size={13}
344 tintColor={terminalVisible ? "#22c55e" : "#a3a3a3"}
345 type="monochrome"
346 />
347 <Text className="font-t3-bold text-[12px] text-neutral-700 dark:text-neutral-200">
348 Terminal
349 </Text>
350 </Pressable>
351 </View>
352
308 <ThreadComposer353 <ThreadComposer
309 draftMessage={props.draftMessage}354 draftMessage={props.draftMessage}
310 draftAttachments={props.draftAttachments}355 draftAttachments={props.draftAttachments}
apps/mobile/src/features/threads/ThreadTerminalPanel.tsx+171−0
@@ -0,0 +1,171 @@
1import { DEFAULT_TERMINAL_ID } from "@t3tools/contracts";
2import { SymbolView } from "expo-symbols";
3import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
4import { Pressable, View } from "react-native";
5
6import { AppText as Text } from "../../components/AppText";
7import { getEnvironmentClient } from "../../state/use-remote-environment-registry";
8import { useTerminalSession, useTerminalSessionTarget } from "../../state/use-terminal-session";
9import {
10 hasNativeTerminalSurface,
11 TerminalSurface,
12} from "../../native/terminal/NativeTerminalSurface";
13
14interface ThreadTerminalPanelProps {
15 readonly environmentId: string;
16 readonly threadId: string;
17 readonly cwd: string;
18 readonly worktreePath: string | null;
19 readonly visible: boolean;
20 readonly onClose: () => void;
21}
22
23const DEFAULT_TERMINAL_COLS = 80;
24const DEFAULT_TERMINAL_ROWS = 24;
25
26export const ThreadTerminalPanel = memo(function ThreadTerminalPanel(
27 props: ThreadTerminalPanelProps,
28) {
29 const terminalId = DEFAULT_TERMINAL_ID;
30 const target = useTerminalSessionTarget({
31 environmentId: props.environmentId,
32 threadId: props.threadId,
33 terminalId,
34 });
35 const terminal = useTerminalSession(target);
36 const [lastGridSize, setLastGridSize] = useState({
37 cols: DEFAULT_TERMINAL_COLS,
38 rows: DEFAULT_TERMINAL_ROWS,
39 });
40 const hasOpenedRef = useRef(false);
41
42 const terminalKey = useMemo(
43 () => `${props.environmentId}:${props.threadId}:${terminalId}`,
44 [props.environmentId, props.threadId, terminalId],
45 );
46 const isRunning = terminal.status === "running" || terminal.status === "starting";
47
48 useEffect(() => {
49 hasOpenedRef.current = false;
50 }, [terminalKey]);
51
52 const openTerminal = useCallback(async () => {
53 const client = getEnvironmentClient(props.environmentId);
54 if (!client) {
55 return;
56 }
57
58 await client.terminal.open({
59 threadId: props.threadId,
60 terminalId,
61 cwd: props.cwd,
62 worktreePath: props.worktreePath,
63 cols: lastGridSize.cols,
64 rows: lastGridSize.rows,
65 });
66 }, [
67 lastGridSize.cols,
68 lastGridSize.rows,
69 props.cwd,
70 props.environmentId,
71 props.threadId,
72 props.worktreePath,
73 terminalId,
74 ]);
75
76 useEffect(() => {
77 if (!props.visible || hasOpenedRef.current || terminal.status !== "closed") {
78 return;
79 }
80
81 hasOpenedRef.current = true;
82 void openTerminal().catch(() => {
83 hasOpenedRef.current = false;
84 });
85 }, [openTerminal, props.visible, terminal.status]);
86
87 const handleInput = useCallback(
88 (data: string) => {
89 const client = getEnvironmentClient(props.environmentId);
90 if (!client || !isRunning) {
91 return;
92 }
93
94 void client.terminal.write({
95 threadId: props.threadId,
96 terminalId,
97 data,
98 });
99 },
100 [isRunning, props.environmentId, props.threadId, terminalId],
101 );
102
103 const handleResize = useCallback(
104 (size: { readonly cols: number; readonly rows: number }) => {
105 if (size.cols === lastGridSize.cols && size.rows === lastGridSize.rows) {
106 return;
107 }
108
109 setLastGridSize(size);
110 const client = getEnvironmentClient(props.environmentId);
111 if (!client || !isRunning) {
112 return;
113 }
114
115 void client.terminal.resize({
116 threadId: props.threadId,
117 terminalId,
118 cols: size.cols,
119 rows: size.rows,
120 });
121 },
122 [
123 isRunning,
124 lastGridSize.cols,
125 lastGridSize.rows,
126 props.environmentId,
127 props.threadId,
128 terminalId,
129 ],
130 );
131
132 if (!props.visible) {
133 return null;
134 }
135
136 return (
137 <View className="absolute inset-x-3 bottom-28 top-28 overflow-hidden rounded-[8px] border border-white/10 bg-neutral-950 shadow-2xl">
138 <View className="flex-row items-center justify-between border-b border-white/10 px-3 py-2">
139 <View className="min-w-0 flex-1">
140 <Text className="font-t3-bold text-[13px] text-neutral-100" numberOfLines={1}>
141 Terminal
142 </Text>
143 <Text className="text-[11px] text-neutral-500" numberOfLines={1}>
144 {hasNativeTerminalSurface ? "Native Ghostty surface" : "Native surface pending link"}
145 </Text>
146 </View>
147 <View className="flex-row items-center gap-2">
148 {terminal.error ? (
149 <Text className="max-w-44 text-right text-[11px] text-red-300" numberOfLines={1}>
150 {terminal.error}
151 </Text>
152 ) : null}
153 <Pressable
154 className="h-8 w-8 items-center justify-center rounded-[8px] bg-white/10"
155 onPress={props.onClose}
156 >
157 <SymbolView name="xmark" size={13} tintColor="#e5e5e5" type="monochrome" />
158 </Pressable>
159 </View>
160 </View>
161 <TerminalSurface
162 terminalKey={terminalKey}
163 buffer={terminal.buffer}
164 isRunning={isRunning}
165 onInput={handleInput}
166 onResize={handleResize}
167 style={{ flex: 1 }}
168 />
169 </View>
170 );
171});
apps/mobile/src/native/terminal/NativeTerminalSurface.tsx+199−0
@@ -0,0 +1,199 @@
1import { memo, useCallback } from "react";
2import { requireNativeViewManager } from "expo-modules-core";
3import {
4 Pressable,
5 ScrollView,
6 TextInput,
7 View,
8 type LayoutChangeEvent,
9 type NativeSyntheticEvent,
10 type ViewProps,
11} from "react-native";
12
13import { AppText as Text } from "../../components/AppText";
14
15interface TerminalInputEvent {
16 readonly data: string;
17}
18
19interface TerminalResizeEvent {
20 readonly cols: number;
21 readonly rows: number;
22}
23
24interface NativeTerminalSurfaceProps extends ViewProps {
25 readonly terminalKey: string;
26 readonly initialBuffer: string;
27 readonly fontSize: number;
28 readonly onInput?: (event: NativeSyntheticEvent<TerminalInputEvent>) => void;
29 readonly onResize?: (event: NativeSyntheticEvent<TerminalResizeEvent>) => void;
30}
31
32interface TerminalSurfaceProps extends ViewProps {
33 readonly terminalKey: string;
34 readonly buffer: string;
35 readonly fontSize?: number;
36 readonly isRunning: boolean;
37 readonly onInput: (data: string) => void;
38 readonly onResize: (size: { readonly cols: number; readonly rows: number }) => void;
39}
40
41const NATIVE_COMPONENT_NAME = "T3TerminalSurface";
42function resolveNativeTerminalSurface() {
43 const expoGlobal = globalThis as typeof globalThis & {
44 expo?: {
45 getViewConfig?: (moduleName: string, viewName?: string) => unknown;
46 };
47 };
48 if (expoGlobal.expo?.getViewConfig?.(NATIVE_COMPONENT_NAME) == null) {
49 return null;
50 }
51
52 return requireNativeViewManager<NativeTerminalSurfaceProps>(NATIVE_COMPONENT_NAME);
53}
54
55const NativeTerminalSurfaceView = resolveNativeTerminalSurface();
56
57export const hasNativeTerminalSurface = NativeTerminalSurfaceView !== null;
58
59function estimateGridSize(input: {
60 readonly width: number;
61 readonly height: number;
62 readonly fontSize: number;
63}): { readonly cols: number; readonly rows: number } {
64 const cellWidth = input.fontSize * 0.62;
65 const cellHeight = input.fontSize * 1.35;
66 return {
67 cols: Math.max(20, Math.min(400, Math.floor(input.width / cellWidth))),
68 rows: Math.max(5, Math.min(200, Math.floor(input.height / cellHeight))),
69 };
70}
71
72const FallbackTerminalSurface = memo(function FallbackTerminalSurface(props: TerminalSurfaceProps) {
73 const fontSize = props.fontSize ?? 12;
74 const statusLabel = props.isRunning
75 ? "Native terminal module not linked. Using text fallback."
76 : "Open terminal to start a shell.";
77
78 const handleLayout = (event: LayoutChangeEvent) => {
79 const { width, height } = event.nativeEvent.layout;
80 props.onResize(estimateGridSize({ width, height, fontSize }));
81 };
82
83 return (
84 <View
85 style={[
86 {
87 flex: 1,
88 backgroundColor: "#050505",
89 borderRadius: 8,
90 overflow: "hidden",
91 },
92 props.style,
93 ]}
94 onLayout={handleLayout}
95 >
96 <View style={{ flex: 1, paddingHorizontal: 10, paddingVertical: 8 }}>
97 <Text className="pb-2 text-[11px] text-neutral-500">{statusLabel}</Text>
98 <ScrollView
99 style={{ flex: 1 }}
100 contentContainerStyle={{ paddingBottom: 12 }}
101 showsVerticalScrollIndicator={false}
102 >
103 <Text
104 selectable
105 style={{
106 color: "#f5f5f5",
107 fontFamily: "Menlo",
108 fontSize,
109 lineHeight: Math.round(fontSize * 1.35),
110 }}
111 >
112 {props.buffer || "$ "}
113 </Text>
114 </ScrollView>
115 </View>
116 <View
117 style={{
118 borderTopWidth: 1,
119 borderTopColor: "rgba(255,255,255,0.12)",
120 flexDirection: "row",
121 alignItems: "center",
122 gap: 8,
123 padding: 8,
124 }}
125 >
126 <TextInput
127 autoCapitalize="none"
128 autoCorrect={false}
129 blurOnSubmit={false}
130 editable={props.isRunning}
131 placeholder="type and press return"
132 placeholderTextColor="#737373"
133 returnKeyType="send"
134 style={{
135 color: "#f5f5f5",
136 flex: 1,
137 fontFamily: "Menlo",
138 fontSize: 13,
139 padding: 0,
140 }}
141 onSubmitEditing={(event) => {
142 const text = event.nativeEvent.text;
143 if (text.length > 0) {
144 props.onInput(`${text}\n`);
145 }
146 }}
147 />
148 <Pressable
149 disabled={!props.isRunning}
150 style={({ pressed }) => ({
151 opacity: !props.isRunning ? 0.35 : pressed ? 0.65 : 1,
152 paddingHorizontal: 10,
153 paddingVertical: 6,
154 borderRadius: 8,
155 backgroundColor: "rgba(255,255,255,0.1)",
156 })}
157 onPress={() => props.onInput("\u0003")}
158 >
159 <Text className="font-t3-bold text-[11px] text-neutral-200">Ctrl-C</Text>
160 </Pressable>
161 </View>
162 </View>
163 );
164});
165
166export const TerminalSurface = memo(function TerminalSurface(props: TerminalSurfaceProps) {
167 const fontSize = props.fontSize ?? 12;
168 const { onInput, onResize } = props;
169 const handleNativeInput = useCallback(
170 (event: NativeSyntheticEvent<TerminalInputEvent>) => {
171 onInput(event.nativeEvent.data);
172 },
173 [onInput],
174 );
175 const handleNativeResize = useCallback(
176 (event: NativeSyntheticEvent<TerminalResizeEvent>) => {
177 onResize({
178 cols: event.nativeEvent.cols,
179 rows: event.nativeEvent.rows,
180 });
181 },
182 [onResize],
183 );
184
185 if (NativeTerminalSurfaceView) {
186 return (
187 <NativeTerminalSurfaceView
188 {...props}
189 terminalKey={props.terminalKey}
190 initialBuffer={props.buffer}
191 fontSize={fontSize}
192 onInput={handleNativeInput}
193 onResize={handleNativeResize}
194 />
195 );
196 }
197
198 return <FallbackTerminalSurface {...props} fontSize={fontSize} />;
199});
apps/mobile/src/state/use-remote-environment-registry.ts+6−1
@@ -23,6 +23,7 @@ import { appAtomRegistry } from "./atom-registry"; · 22 unmodified lines
23import { type ConnectedEnvironmentSummary, type EnvironmentSession } from "./remote-runtime-types";23import { type ConnectedEnvironmentSummary, type EnvironmentSession } from "./remote-runtime-types";
24import { environmentRuntimeManager, useEnvironmentRuntimeStates } from "./use-environment-runtime";24import { environmentRuntimeManager, useEnvironmentRuntimeStates } from "./use-environment-runtime";
25import { shellSnapshotManager } from "./use-shell-snapshot";25import { shellSnapshotManager } from "./use-shell-snapshot";
26import { terminalSessionManager } from "./use-terminal-session";
26 27
27const environmentSessions = new Map<string, EnvironmentSession>();28const environmentSessions = new Map<string, EnvironmentSession>();
28const environmentConnectionListeners = new Set<() => void>();29const environmentConnectionListeners = new Set<() => void>();
@@ -154,6 +155,7 @@ export async function disconnectEnvironment( · 125 unmodified lines
154 notifyEnvironmentConnectionListeners();155 notifyEnvironmentConnectionListeners();
155 await session?.connection.dispose();156 await session?.connection.dispose();
156 shellSnapshotManager.invalidate({ environmentId });157 shellSnapshotManager.invalidate({ environmentId });
158 terminalSessionManager.invalidateEnvironment(environmentId);
157 environmentRuntimeManager.invalidate({ environmentId });159 environmentRuntimeManager.invalidate({ environmentId });
158 160
159 if (options?.removeSaved) {161 if (options?.removeSaved) {
@@ -244,7 +246,9 @@ export async function connectSavedEnvironment( · 84 unmodified lines
244 onShellResubscribe: (environmentId) => {246 onShellResubscribe: (environmentId) => {
245 shellSnapshotManager.markPending({ environmentId });247 shellSnapshotManager.markPending({ environmentId });
246 },248 },
247 applyTerminalEvent: () => undefined,249 applyTerminalEvent: (event, environmentId) => {
250 terminalSessionManager.applyEvent({ environmentId }, event);
251 },
248 onConfigSnapshot: (serverConfig) => {252 onConfigSnapshot: (serverConfig) => {
249 environmentRuntimeManager.patch({ environmentId: connection.environmentId }, (runtime) => ({253 environmentRuntimeManager.patch({ environmentId: connection.environmentId }, (runtime) => ({
250 ...runtime,254 ...runtime,
@@ -333,6 +337,7 @@ export function useRemoteEnvironmentBootstrap() { · 82 unmodified lines
333 environmentSessions.clear();337 environmentSessions.clear();
334 environmentRuntimeManager.invalidate();338 environmentRuntimeManager.invalidate();
335 shellSnapshotManager.invalidate();339 shellSnapshotManager.invalidate();
340 terminalSessionManager.invalidate();
336 notifyEnvironmentConnectionListeners();341 notifyEnvironmentConnectionListeners();
337 };342 };
338 }, []);343 }, []);
apps/mobile/src/state/use-terminal-session.ts+43−0
@@ -0,0 +1,43 @@
1import { useAtomValue } from "@effect/atom-react";
2import {
3 createTerminalSessionManager,
4 EMPTY_TERMINAL_SESSION_ATOM,
5 EMPTY_TERMINAL_SESSION_STATE,
6 getTerminalSessionTargetKey,
7 terminalSessionStateAtom,
8 type TerminalSessionState,
9} from "@t3tools/client-runtime";
10import { useMemo } from "react";
11
12import { appAtomRegistry } from "./atom-registry";
13
14export const terminalSessionManager = createTerminalSessionManager({
15 getRegistry: () => appAtomRegistry,
16});
17
18export function useTerminalSession(input: {
19 readonly environmentId: string | null;
20 readonly threadId: string | null;
21 readonly terminalId: string | null;
22}): TerminalSessionState {
23 const targetKey = getTerminalSessionTargetKey(input);
24 const state = useAtomValue(
25 targetKey !== null ? terminalSessionStateAtom(targetKey) : EMPTY_TERMINAL_SESSION_ATOM,
26 );
27 return targetKey === null ? EMPTY_TERMINAL_SESSION_STATE : state;
28}
29
30export function useTerminalSessionTarget(input: {
31 readonly environmentId: string | null;
32 readonly threadId: string | null;
33 readonly terminalId: string | null;
34}) {
35 return useMemo(
36 () => ({
37 environmentId: input.environmentId,
38 threadId: input.threadId,
39 terminalId: input.terminalId,
40 }),
41 [input.environmentId, input.threadId, input.terminalId],
42 );
43}
bun.lock+4−0
@@ -52,6 +52,7 @@ · 51 unmodified lines
52 "@react-native-menu/menu": "^2.0.0",52 "@react-native-menu/menu": "^2.0.0",
53 "@t3tools/client-runtime": "workspace:*",53 "@t3tools/client-runtime": "workspace:*",
54 "@t3tools/contracts": "workspace:*",54 "@t3tools/contracts": "workspace:*",
55 "@t3tools/mobile-terminal-native": "file:./modules/t3-terminal",
55 "@t3tools/shared": "workspace:*",56 "@t3tools/shared": "workspace:*",
56 "clsx": "^2.1.1",57 "clsx": "^2.1.1",
57 "effect": "catalog:",58 "effect": "catalog:",
@@ -66,6 +67,7 @@ · 8 unmodified lines
66 "expo-haptics": "^55.0.9",67 "expo-haptics": "^55.0.9",
67 "expo-image-picker": "~55.0.14",68 "expo-image-picker": "~55.0.14",
68 "expo-linking": "~55.0.12",69 "expo-linking": "~55.0.12",
70 "expo-modules-core": "~55.0.22",
69 "expo-paste-input": "^0.1.15",71 "expo-paste-input": "^0.1.15",
70 "expo-router": "~55.0.12",72 "expo-router": "~55.0.12",
71 "expo-secure-store": "~55.0.9",73 "expo-secure-store": "~55.0.9",
@@ -2921,6 +2923,8 @@ · 2849 unmodified lines
2921 2923
2922 "@shikijs/transformers/@shikijs/core": ["@shikijs/core@3.23.0", "", { "dependencies": { "@shikijs/types": "3.23.0", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4", "hast-util-to-html": "^9.0.5" } }, "sha512-NSWQz0riNb67xthdm5br6lAkvpDJRTgB36fxlo37ZzM2yq0PQFFzbd8psqC2XMPgCzo1fW6cVi18+ArJ44wqgA=="],2924 "@shikijs/transformers/@shikijs/core": ["@shikijs/core@3.23.0", "", { "dependencies": { "@shikijs/types": "3.23.0", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4", "hast-util-to-html": "^9.0.5" } }, "sha512-NSWQz0riNb67xthdm5br6lAkvpDJRTgB36fxlo37ZzM2yq0PQFFzbd8psqC2XMPgCzo1fW6cVi18+ArJ44wqgA=="],
2923 2925
2926 "@t3tools/mobile/@t3tools/mobile-terminal-native": ["@t3tools/mobile-terminal-native@file:apps/mobile/modules/t3-terminal", {}],
2927
2924 "@tailwindcss/node/tailwindcss": ["tailwindcss@4.2.1", "", {}, "sha512-/tBrSQ36vCleJkAOsy9kbNTgaxvGbyOamC30PRePTQe/o1MFwEKHQk4Cn7BNGaPtjp+PuUrByJehM1hgxfq4sw=="],2928 "@tailwindcss/node/tailwindcss": ["tailwindcss@4.2.1", "", {}, "sha512-/tBrSQ36vCleJkAOsy9kbNTgaxvGbyOamC30PRePTQe/o1MFwEKHQk4Cn7BNGaPtjp+PuUrByJehM1hgxfq4sw=="],
2925 2929
2926 "@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/core@1.9.2", "", { "dependencies": { "@emnapi/wasi-threads": "1.2.1", "tslib": "^2.4.0" }, "bundled": true }, "sha512-UC+ZhH3XtczQYfOlu3lNEkdW/p4dsJ1r/bP7H8+rhao3TTTMO1ATq/4DdIi23XuGoFY+Cz0JmCbdVl0hz9jZcA=="],2930 "@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/core@1.9.2", "", { "dependencies": { "@emnapi/wasi-threads": "1.2.1", "tslib": "^2.4.0" }, "bundled": true }, "sha512-UC+ZhH3XtczQYfOlu3lNEkdW/p4dsJ1r/bP7H8+rhao3TTTMO1ATq/4DdIi23XuGoFY+Cz0JmCbdVl0hz9jZcA=="],
packages/client-runtime/src/index.ts+1−0
@@ -11,6 +11,7 @@ export * from "./gitActions"; · 10 unmodified lines
11export * from "./gitActionState";11export * from "./gitActionState";
12export * from "./gitBranchState";12export * from "./gitBranchState";
13export * from "./gitStatusState";13export * from "./gitStatusState";
14export * from "./terminalSessionState";
14export * from "./transportError";15export * from "./transportError";
15export * from "./wsRpcProtocol";16export * from "./wsRpcProtocol";
16export * from "./wsTransport";17export * from "./wsTransport";
packages/client-runtime/src/terminalSessionState.test.ts+110−0
@@ -0,0 +1,110 @@
1import { AtomRegistry } from "effect/unstable/reactivity";
2import { afterEach, describe, expect, it } from "vitest";
3
4import type { TerminalSessionSnapshot } from "@t3tools/contracts";
5
6import { createTerminalSessionManager } from "./terminalSessionState";
7
8let atomRegistry = AtomRegistry.make();
9
10function resetAtomRegistry() {
11 atomRegistry.dispose();
12 atomRegistry = AtomRegistry.make();
13}
14
15const TARGET = {
16 environmentId: "env-local",
17 threadId: "thread-1",
18 terminalId: "default",
19} as const;
20
21const BASE_SNAPSHOT: TerminalSessionSnapshot = {
22 threadId: TARGET.threadId,
23 terminalId: TARGET.terminalId,
24 cwd: "/repo",
25 worktreePath: null,
26 status: "running",
27 pid: 123,
28 history: "hello",
29 exitCode: null,
30 exitSignal: null,
31 updatedAt: "2026-04-01T00:00:00.000Z",
32};
33
34describe("createTerminalSessionManager", () => {
35 afterEach(() => {
36 resetAtomRegistry();
37 });
38
39 it("hydrates from started snapshots and appends output events", () => {
40 const manager = createTerminalSessionManager({
41 getRegistry: () => atomRegistry,
42 });
43
44 manager.applyEvent(TARGET, {
45 type: "started",
46 threadId: TARGET.threadId,
47 terminalId: TARGET.terminalId,
48 createdAt: BASE_SNAPSHOT.updatedAt,
49 snapshot: BASE_SNAPSHOT,
50 });
51 manager.applyEvent(TARGET, {
52 type: "output",
53 threadId: TARGET.threadId,
54 terminalId: TARGET.terminalId,
55 createdAt: "2026-04-01T00:00:01.000Z",
56 data: " world",
57 });
58
59 expect(manager.getSnapshot(TARGET)).toMatchObject({
60 snapshot: BASE_SNAPSHOT,
61 buffer: "hello world",
62 status: "running",
63 error: null,
64 updatedAt: "2026-04-01T00:00:01.000Z",
65 });
66 });
67
68 it("caps retained output", () => {
69 const manager = createTerminalSessionManager({
70 getRegistry: () => atomRegistry,
71 maxBufferBytes: 5,
72 });
73
74 manager.applyEvent(TARGET, {
75 type: "output",
76 threadId: TARGET.threadId,
77 terminalId: TARGET.terminalId,
78 createdAt: "2026-04-01T00:00:01.000Z",
79 data: "abcdef",
80 });
81
82 expect(manager.getSnapshot(TARGET).buffer).toBe("bcdef");
83 });
84
85 it("invalidates one environment without clearing others", () => {
86 const manager = createTerminalSessionManager({
87 getRegistry: () => atomRegistry,
88 });
89 const otherTarget = {
90 environmentId: "env-remote",
91 threadId: "thread-1",
92 terminalId: "default",
93 } as const;
94
95 for (const target of [TARGET, otherTarget]) {
96 manager.applyEvent(target, {
97 type: "output",
98 threadId: target.threadId,
99 terminalId: target.terminalId,
100 createdAt: "2026-04-01T00:00:01.000Z",
101 data: target.environmentId,
102 });
103 }
104
105 manager.invalidateEnvironment(TARGET.environmentId);
106
107 expect(manager.getSnapshot(TARGET).buffer).toBe("");
108 expect(manager.getSnapshot(otherTarget).buffer).toBe("env-remote");
109 });
110});
packages/client-runtime/src/terminalSessionState.ts+209−0
@@ -0,0 +1,209 @@
1import type { TerminalEvent, TerminalSessionSnapshot } from "@t3tools/contracts";
2import { Atom, type AtomRegistry } from "effect/unstable/reactivity";
3
4export interface TerminalSessionState {
5 readonly snapshot: TerminalSessionSnapshot | null;
6 readonly buffer: string;
7 readonly status: TerminalSessionSnapshot["status"] | "closed";
8 readonly error: string | null;
9 readonly hasRunningSubprocess: boolean;
10 readonly updatedAt: string | null;
11 readonly version: number;
12}
13
14export interface TerminalSessionTarget {
15 readonly environmentId: string | null;
16 readonly threadId: string | null;
17 readonly terminalId: string | null;
18}
19
20export interface TerminalSessionManagerConfig {
21 readonly getRegistry: () => AtomRegistry.AtomRegistry;
22 readonly maxBufferBytes?: number;
23}
24
25export const EMPTY_TERMINAL_SESSION_STATE = Object.freeze<TerminalSessionState>({
26 snapshot: null,
27 buffer: "",
28 status: "closed",
29 error: null,
30 hasRunningSubprocess: false,
31 updatedAt: null,
32 version: 0,
33});
34
35const DEFAULT_MAX_BUFFER_BYTES = 512 * 1024;
36const knownTerminalSessionKeys = new Set<string>();
37
38export const terminalSessionStateAtom = Atom.family((key: string) => {
39 knownTerminalSessionKeys.add(key);
40 return Atom.make(EMPTY_TERMINAL_SESSION_STATE).pipe(
41 Atom.keepAlive,
42 Atom.withLabel(`terminal-session:${key}`),
43 );
44});
45
46export const EMPTY_TERMINAL_SESSION_ATOM = Atom.make(EMPTY_TERMINAL_SESSION_STATE).pipe(
47 Atom.keepAlive,
48 Atom.withLabel("terminal-session:null"),
49);
50
51export function getTerminalSessionTargetKey(target: TerminalSessionTarget): string | null {
52 if (target.environmentId === null || target.threadId === null || target.terminalId === null) {
53 return null;
54 }
55
56 return `${target.environmentId}:${target.threadId}:${target.terminalId}`;
57}
58
59function trimBufferToBytes(buffer: string, maxBufferBytes: number): string {
60 if (buffer.length <= maxBufferBytes) {
61 return buffer;
62 }
63
64 return buffer.slice(buffer.length - maxBufferBytes);
65}
66
67function stateFromSnapshot(
68 snapshot: TerminalSessionSnapshot,
69 maxBufferBytes: number,
70): TerminalSessionState {
71 return {
72 snapshot,
73 buffer: trimBufferToBytes(snapshot.history, maxBufferBytes),
74 status: snapshot.status,
75 error: null,
76 hasRunningSubprocess: false,
77 updatedAt: snapshot.updatedAt,
78 version: 1,
79 };
80}
81
82export function createTerminalSessionManager(config: TerminalSessionManagerConfig) {
83 const maxBufferBytes = config.maxBufferBytes ?? DEFAULT_MAX_BUFFER_BYTES;
84
85 function getSnapshot(target: TerminalSessionTarget): TerminalSessionState {
86 const targetKey = getTerminalSessionTargetKey(target);
87 if (targetKey === null) {
88 return EMPTY_TERMINAL_SESSION_STATE;
89 }
90
91 return config.getRegistry().get(terminalSessionStateAtom(targetKey));
92 }
93
94 function setState(targetKey: string, nextState: TerminalSessionState): void {
95 config.getRegistry().set(terminalSessionStateAtom(targetKey), nextState);
96 }
97
98 function applyEvent(
99 target: Pick<TerminalSessionTarget, "environmentId">,
100 event: TerminalEvent,
101 ): void {
102 const targetKey = getTerminalSessionTargetKey({
103 environmentId: target.environmentId,
104 threadId: event.threadId,
105 terminalId: event.terminalId,
106 });
107 if (targetKey === null) {
108 return;
109 }
110
111 const current = config.getRegistry().get(terminalSessionStateAtom(targetKey));
112 switch (event.type) {
113 case "started":
114 case "restarted":
115 setState(targetKey, stateFromSnapshot(event.snapshot, maxBufferBytes));
116 return;
117 case "output":
118 setState(targetKey, {
119 ...current,
120 buffer: trimBufferToBytes(`${current.buffer}${event.data}`, maxBufferBytes),
121 status: current.status === "closed" ? "running" : current.status,
122 error: null,
123 updatedAt: event.createdAt,
124 version: current.version + 1,
125 });
126 return;
127 case "cleared":
128 setState(targetKey, {
129 ...current,
130 buffer: "",
131 error: null,
132 updatedAt: event.createdAt,
133 version: current.version + 1,
134 });
135 return;
136 case "exited":
137 setState(targetKey, {
138 ...current,
139 snapshot: current.snapshot
140 ? {
141 ...current.snapshot,
142 status: "exited",
143 exitCode: event.exitCode,
144 exitSignal: event.exitSignal,
145 updatedAt: event.createdAt,
146 }
147 : null,
148 status: "exited",
149 hasRunningSubprocess: false,
150 updatedAt: event.createdAt,
151 version: current.version + 1,
152 });
153 return;
154 case "error":
155 setState(targetKey, {
156 ...current,
157 status: "error",
158 error: event.message,
159 hasRunningSubprocess: false,
160 updatedAt: event.createdAt,
161 version: current.version + 1,
162 });
163 return;
164 case "activity":
165 setState(targetKey, {
166 ...current,
167 hasRunningSubprocess: event.hasRunningSubprocess,
168 updatedAt: event.createdAt,
169 version: current.version + 1,
170 });
171 return;
172 }
173 }
174
175 function invalidate(target?: TerminalSessionTarget): void {
176 if (target) {
177 const targetKey = getTerminalSessionTargetKey(target);
178 if (targetKey !== null) {
179 setState(targetKey, EMPTY_TERMINAL_SESSION_STATE);
180 }
181 return;
182 }
183
184 for (const key of knownTerminalSessionKeys) {
185 setState(key, EMPTY_TERMINAL_SESSION_STATE);
186 }
187 }
188
189 function invalidateEnvironment(environmentId: string): void {
190 const prefix = `${environmentId}:`;
191 for (const key of knownTerminalSessionKeys) {
192 if (key.startsWith(prefix)) {
193 setState(key, EMPTY_TERMINAL_SESSION_STATE);
194 }
195 }
196 }
197
198 function reset(): void {
199 invalidate();
200 }
201
202 return {
203 applyEvent,
204 getSnapshot,
205 invalidate,
206 invalidateEnvironment,
207 reset,
208 };
209}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t