@native-sdk/cli 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/build/app.zig +91 -2
  2. package/build.zig +756 -5
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +19 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +416 -9
  9. package/packages/core/sdk/core.ts +706 -5
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +3187 -264
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +42 -4
  17. package/skill-data/ts-core/SKILL.md +13 -3
  18. package/src/app_runner/root.zig +112 -10
  19. package/src/app_runner/ts_core_main.zig +4 -0
  20. package/src/automation/layout_fingerprint.zig +160 -0
  21. package/src/automation/protocol.zig +82 -33
  22. package/src/automation/root.zig +1 -0
  23. package/src/automation/server.zig +1 -1
  24. package/src/automation/snapshot.zig +68 -9
  25. package/src/automation/watcher.zig +1 -1
  26. package/src/embed/host.zig +5 -0
  27. package/src/embed/tests.zig +119 -1
  28. package/src/embed/ui_host.zig +13 -0
  29. package/src/platform/linux/gtk_host.c +639 -16
  30. package/src/platform/linux/gtk_host.h +25 -0
  31. package/src/platform/linux/root.zig +351 -7
  32. package/src/platform/macos/appkit_host.h +152 -8
  33. package/src/platform/macos/appkit_host.m +1816 -100
  34. package/src/platform/macos/cef_host.mm +372 -11
  35. package/src/platform/macos/root.zig +379 -11
  36. package/src/platform/null_platform.zig +696 -9
  37. package/src/platform/null_platform_tests.zig +35 -0
  38. package/src/platform/root.zig +42 -0
  39. package/src/platform/types.zig +524 -18
  40. package/src/platform/windows/root.zig +432 -9
  41. package/src/platform/windows/webview2_host.cpp +482 -45
  42. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  43. package/src/primitives/app_manifest/root.zig +1 -0
  44. package/src/primitives/app_manifest/types.zig +32 -0
  45. package/src/primitives/app_manifest/validation.zig +18 -0
  46. package/src/primitives/canvas/a11y_audit.zig +33 -11
  47. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  48. package/src/primitives/canvas/drawing.zig +25 -0
  49. package/src/primitives/canvas/equality.zig +8 -0
  50. package/src/primitives/canvas/events.zig +103 -16
  51. package/src/primitives/canvas/frame.zig +125 -1
  52. package/src/primitives/canvas/layout_audit.zig +22 -5
  53. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  54. package/src/primitives/canvas/render_tests.zig +13 -10
  55. package/src/primitives/canvas/root.zig +48 -0
  56. package/src/primitives/canvas/terminal_box.zig +471 -0
  57. package/src/primitives/canvas/terminal_grid.zig +978 -0
  58. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  59. package/src/primitives/canvas/test_support.zig +1 -0
  60. package/src/primitives/canvas/tests.zig +2 -0
  61. package/src/primitives/canvas/text_tests.zig +39 -4
  62. package/src/primitives/canvas/tokens.zig +115 -12
  63. package/src/primitives/canvas/ui.zig +535 -12
  64. package/src/primitives/canvas/ui_markup.zig +253 -36
  65. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  66. package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
  67. package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
  68. package/src/primitives/canvas/ui_markup_contract.zig +89 -6
  69. package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
  70. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  71. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  72. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  73. package/src/primitives/canvas/ui_markup_tests.zig +178 -9
  74. package/src/primitives/canvas/ui_markup_view.zig +220 -11
  75. package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
  76. package/src/primitives/canvas/ui_schema.zig +110 -17
  77. package/src/primitives/canvas/ui_schema_tests.zig +18 -10
  78. package/src/primitives/canvas/ui_tests.zig +141 -9
  79. package/src/primitives/canvas/widget_access.zig +28 -2
  80. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  81. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  82. package/src/primitives/canvas/widget_layout.zig +59 -11
  83. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  84. package/src/primitives/canvas/widget_render.zig +272 -18
  85. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  86. package/src/primitives/canvas/widget_routing.zig +59 -7
  87. package/src/primitives/canvas/widget_runtime.zig +23 -0
  88. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  89. package/src/primitives/canvas/widget_semantics.zig +119 -11
  90. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  91. package/src/primitives/canvas/widget_tree.zig +17 -0
  92. package/src/primitives/canvas/widgets.zig +132 -0
  93. package/src/root.zig +23 -0
  94. package/src/runtime/api.zig +76 -5
  95. package/src/runtime/automation_commands.zig +20 -1
  96. package/src/runtime/automation_snapshot.zig +25 -1
  97. package/src/runtime/automation_widget_dispatch.zig +73 -8
  98. package/src/runtime/bridge_payload.zig +8 -0
  99. package/src/runtime/bridge_responses.zig +5 -0
  100. package/src/runtime/builtin_bridge.zig +9 -4
  101. package/src/runtime/canvas_font_tests.zig +439 -2
  102. package/src/runtime/canvas_fonts.zig +61 -6
  103. package/src/runtime/canvas_frame.zig +62 -7
  104. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  105. package/src/runtime/canvas_frame_helpers.zig +190 -1
  106. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  107. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  108. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  109. package/src/runtime/canvas_image_tests.zig +195 -0
  110. package/src/runtime/canvas_images.zig +45 -12
  111. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  112. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  113. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  114. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  115. package/src/runtime/canvas_widget_display.zig +1 -1
  116. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  117. package/src/runtime/canvas_widget_events.zig +240 -24
  118. package/src/runtime/canvas_widget_runtime.zig +213 -29
  119. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  120. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  121. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  122. package/src/runtime/canvas_widget_state.zig +6 -0
  123. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  124. package/src/runtime/core.zig +131 -13
  125. package/src/runtime/effects.zig +8136 -180
  126. package/src/runtime/effects_channel_tests.zig +3519 -0
  127. package/src/runtime/effects_fetch_tests.zig +89 -1
  128. package/src/runtime/effects_file_tests.zig +41 -1
  129. package/src/runtime/effects_image_tests.zig +1304 -0
  130. package/src/runtime/effects_pty_tests.zig +1362 -0
  131. package/src/runtime/effects_tests.zig +167 -9
  132. package/src/runtime/effects_video_tests.zig +3609 -0
  133. package/src/runtime/flow.zig +42 -4
  134. package/src/runtime/gpu_surface_events.zig +473 -13
  135. package/src/runtime/media_surface.zig +116 -11
  136. package/src/runtime/media_surface_tests.zig +61 -0
  137. package/src/runtime/pty.zig +1252 -0
  138. package/src/runtime/pty_windows.zig +1780 -0
  139. package/src/runtime/root.zig +36 -0
  140. package/src/runtime/runtime_event_tests.zig +20 -1
  141. package/src/runtime/session_blobs.zig +689 -0
  142. package/src/runtime/session_journal.zig +432 -62
  143. package/src/runtime/session_record.zig +43 -2
  144. package/src/runtime/session_replay.zig +556 -20
  145. package/src/runtime/session_tests.zig +2087 -1
  146. package/src/runtime/shell_layout.zig +7 -0
  147. package/src/runtime/terminal_session.zig +1569 -0
  148. package/src/runtime/terminal_session_tests.zig +450 -0
  149. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  150. package/src/runtime/terminal_vt_stub.zig +13 -0
  151. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  152. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  153. package/src/runtime/tests.zig +8 -0
  154. package/src/runtime/ts_core_host.zig +1320 -45
  155. package/src/runtime/ts_core_host_tests.zig +1100 -1
  156. package/src/runtime/ts_ui_app.zig +23 -5
  157. package/src/runtime/ui_app.zig +2444 -69
  158. package/src/runtime/ui_app_tests.zig +3171 -744
  159. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  160. package/src/runtime/ui_app_window_tests.zig +736 -0
  161. package/src/runtime/view.zig +190 -2
  162. package/src/runtime/view_widget_scroll.zig +218 -68
  163. package/src/runtime/view_widget_text.zig +11 -2
  164. package/src/runtime/view_widget_tree.zig +111 -3
  165. package/src/runtime/window_command_bridge_tests.zig +117 -0
  166. package/src/runtime/window_storage.zig +77 -2
  167. package/src/runtime/window_view_runtime.zig +34 -2
  168. package/src/runtime/window_views.zig +62 -1
  169. package/src/terminal_session_tests_root.zig +15 -0
  170. package/src/tooling/manifest.zig +75 -0
  171. package/src/tooling/raw_manifest.zig +2 -0
  172. package/src/tooling/templates.zig +244 -8
@@ -0,0 +1,450 @@
1
+ //! Terminal session store tests: the runtime-owned emulator behind a
2
+ //! bound pty key — snapshot publication through the lookup seam, the
3
+ //! journaled write-back path (key encoding, committed text, query
4
+ //! answers), layout-driven resize, the scrollback source-wins echo, and
5
+ //! the respawn reset. Every input arrives the way the runtime delivers
6
+ //! it (tap events, reconcile calls), so these are the element contract's
7
+ //! tests, not emulator internals'. Skipped wholesale when the
8
+ //! `terminal_vt` seam carries the stub.
9
+
10
+ const std = @import("std");
11
+ const builtin = @import("builtin");
12
+ const canvas = @import("canvas");
13
+ const effects = @import("effects.zig");
14
+ const terminal_session = @import("terminal_session.zig");
15
+
16
+ const testing = std.testing;
17
+ const TerminalSessions = terminal_session.TerminalSessions;
18
+
19
+ const TestGateway = struct {
20
+ gpa: std.mem.Allocator,
21
+ written: std.ArrayList(u8) = .empty,
22
+ resized: ?struct { cols: u16, rows: u16 } = null,
23
+ resize_count: usize = 0,
24
+ accept: bool = true,
25
+
26
+ fn deinit(self: *TestGateway) void {
27
+ self.written.deinit(self.gpa);
28
+ }
29
+
30
+ fn writeFn(context: *anyopaque, key: u64, bytes: []const u8) bool {
31
+ const self: *TestGateway = @ptrCast(@alignCast(context));
32
+ _ = key;
33
+ if (!self.accept) return false;
34
+ self.written.appendSlice(self.gpa, bytes) catch return false;
35
+ return true;
36
+ }
37
+
38
+ fn resizeFn(context: *anyopaque, key: u64, cols: u16, rows: u16) void {
39
+ const self: *TestGateway = @ptrCast(@alignCast(context));
40
+ _ = key;
41
+ self.resized = .{ .cols = cols, .rows = rows };
42
+ self.resize_count += 1;
43
+ }
44
+
45
+ fn gateway(self: *TestGateway) terminal_session.PtyGateway {
46
+ return .{ .context = @ptrCast(self), .write = writeFn, .resize = resizeFn };
47
+ }
48
+ };
49
+
50
+ /// Resolve the published grid the way finalize does: through the
51
+ /// installed lookup, creating the session on first sight of the key.
52
+ fn resolveGrid(store: *TerminalSessions, pty: u64) ?*const canvas.TerminalGrid {
53
+ const lookup = store.lookup() orelse return null;
54
+ return lookup.resolve(lookup.context, pty);
55
+ }
56
+
57
+ fn feedOutput(store: *TerminalSessions, pty: u64, bytes: []const u8) void {
58
+ const event: effects.EffectPtyEvent = .{ .key = pty, .kind = .output, .bytes = bytes };
59
+ store.notePtyEvent(&event);
60
+ }
61
+
62
+ fn feedExit(store: *TerminalSessions, pty: u64) void {
63
+ const event: effects.EffectPtyEvent = .{ .key = pty, .kind = .exit, .code = 0 };
64
+ store.notePtyEvent(&event);
65
+ }
66
+
67
+ fn gridText(grid: *const canvas.TerminalGrid) []const u8 {
68
+ return grid.screen_text;
69
+ }
70
+
71
+ test "binding a pty key publishes a live grid that carries fed output as real cells" {
72
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
73
+ var store = TerminalSessions.init(testing.allocator);
74
+ defer store.deinit();
75
+ store.beginBuild(.{});
76
+
77
+ // First resolve creates the session (binding IS the request); the
78
+ // fresh grid is a running, empty surface.
79
+ const grid = resolveGrid(&store, 7) orelse return error.TestExpectedGrid;
80
+ try testing.expect(grid.running);
81
+
82
+ feedOutput(&store, 7, "hello \x1b[1;31mworld\x1b[0m\r\n$ ");
83
+ const refreshed = resolveGrid(&store, 7) orelse return error.TestExpectedGrid;
84
+ try testing.expect(std.mem.indexOf(u8, gridText(refreshed), "hello world") != null);
85
+ try testing.expect(std.mem.indexOf(u8, gridText(refreshed), "$") != null);
86
+ // The snapshot's rows carry resolved cells: find the 'h' at 0,0.
87
+ try testing.expect(refreshed.rows.len > 0);
88
+ try testing.expectEqual(@as(u21, 'h'), refreshed.rows[0].cells[0].cp);
89
+ try testing.expectEqualStrings("h", refreshed.rows[0].cells[0].cluster);
90
+ // A default (untouched) ANSI-31 red resolves through the theme's
91
+ // destructive token, the palette-honesty story.
92
+ const tokens: canvas.DesignTokens = .{};
93
+ const red_cell = refreshed.rows[0].cells[6];
94
+ try testing.expectEqual(@as(u21, 'w'), red_cell.cp);
95
+ try testing.expectApproxEqAbs(tokens.colors.destructive.r, red_cell.fg.r, 0.2);
96
+ }
97
+
98
+ test "pointer gestures select terminal cells words and lines for clipboard copy" {
99
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
100
+ var store = TerminalSessions.init(testing.allocator);
101
+ defer store.deinit();
102
+ var gw = TestGateway{ .gpa = testing.allocator };
103
+ defer gw.deinit();
104
+ store.setGateway(gw.gateway());
105
+ store.beginBuild(.{});
106
+ _ = store.reconcile(8, 0, 20, 4) orelse return error.TestExpectedState;
107
+ feedOutput(&store, 8, "alpha beta\r\ngamma delta");
108
+ _ = resolveGrid(&store, 8) orelse return error.TestExpectedGrid;
109
+
110
+ // Default tokens resolve to 8x18 cells. A primary drag from the
111
+ // first cell through the fifth selects "alpha".
112
+ _ = store.pointerSelection(8, .{
113
+ .phase = .down,
114
+ .x = 2,
115
+ .y = 5,
116
+ .width = 160,
117
+ .height = 72,
118
+ });
119
+ const drag = store.pointerSelection(8, .{
120
+ .phase = .move,
121
+ .x = 39,
122
+ .y = 5,
123
+ .width = 160,
124
+ .height = 72,
125
+ });
126
+ try testing.expect(drag.changed);
127
+ try testing.expect(drag.selection_active);
128
+ const release = store.pointerSelection(8, .{
129
+ .phase = .up,
130
+ .x = 39,
131
+ .y = 5,
132
+ .width = 160,
133
+ .height = 72,
134
+ });
135
+ try testing.expect(release.selection_active);
136
+ var grid = resolveGrid(&store, 8) orelse return error.TestExpectedGrid;
137
+ try testing.expectEqualStrings("alpha", grid.selection_text);
138
+ try testing.expectEqualDeep(@as(?[2]u16, .{ 0, 4 }), grid.rows[0].selection);
139
+
140
+ // The runtime's journaled click count chooses Ghostty's standard
141
+ // word and line behaviors without a second click clock.
142
+ _ = store.pointerSelection(8, .{
143
+ .phase = .down,
144
+ .x = 60,
145
+ .y = 5,
146
+ .width = 160,
147
+ .height = 72,
148
+ .click_count = 2,
149
+ });
150
+ grid = resolveGrid(&store, 8) orelse return error.TestExpectedGrid;
151
+ try testing.expectEqualStrings("beta", grid.selection_text);
152
+
153
+ _ = store.pointerSelection(8, .{
154
+ .phase = .down,
155
+ .x = 18,
156
+ .y = 5,
157
+ .width = 160,
158
+ .height = 72,
159
+ .click_count = 3,
160
+ });
161
+ grid = resolveGrid(&store, 8) orelse return error.TestExpectedGrid;
162
+ try testing.expectEqualStrings("alpha beta", grid.selection_text);
163
+
164
+ // Input sent to the child dismisses the live selection. Cmd/Ctrl+C
165
+ // is intercepted by the app loop before it reaches this path.
166
+ try testing.expect(store.textInput(8, "x"));
167
+ grid = resolveGrid(&store, 8) orelse return error.TestExpectedGrid;
168
+ try testing.expect(!grid.selection_active);
169
+ try testing.expectEqualStrings("", grid.selection_text);
170
+ }
171
+
172
+ test "committed text and encoded keys reach the pty through the gateway in stdin order" {
173
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
174
+ var store = TerminalSessions.init(testing.allocator);
175
+ defer store.deinit();
176
+ var gw = TestGateway{ .gpa = testing.allocator };
177
+ defer gw.deinit();
178
+ store.setGateway(gw.gateway());
179
+ store.beginBuild(.{});
180
+ _ = resolveGrid(&store, 3) orelse return error.TestExpectedGrid;
181
+
182
+ try testing.expect(store.textInput(3, "ls"));
183
+ try testing.expect(store.keyEvent(3, .{ .phase = .key_down, .key = "enter" }));
184
+ try testing.expectEqualStrings("ls\r", gw.written.items);
185
+
186
+ // Ctrl+C encodes the C0 interrupt byte, never a literal 'c'.
187
+ gw.written.clearRetainingCapacity();
188
+ try testing.expect(store.keyEvent(3, .{
189
+ .phase = .key_down,
190
+ .key = "c",
191
+ .modifiers = .{ .control = true },
192
+ }));
193
+ try testing.expectEqualStrings("\x03", gw.written.items);
194
+
195
+ // A plain printable key_down is consumed silently (its press
196
+ // travels the committed-text channel) — nothing doubles.
197
+ gw.written.clearRetainingCapacity();
198
+ try testing.expect(store.keyEvent(3, .{ .phase = .key_down, .key = "a" }));
199
+ try testing.expectEqualStrings("", gw.written.items);
200
+
201
+ if (comptime builtin.os.tag == .macos) {
202
+ // Natural text navigation follows macOS terminal conventions:
203
+ // Option moves by words and Command moves to line boundaries.
204
+ // These bindings intentionally remain legacy bytes after a TUI
205
+ // enables kitty reporting, and their releases stay consumed.
206
+ feedOutput(&store, 3, "\x1b[>11u");
207
+ try testing.expect(store.keyEvent(3, .{
208
+ .phase = .key_down,
209
+ .key = "arrowleft",
210
+ .modifiers = .{ .alt = true },
211
+ }));
212
+ try testing.expect(store.keyEvent(3, .{
213
+ .phase = .key_up,
214
+ .key = "arrowleft",
215
+ }));
216
+ try testing.expect(store.keyEvent(3, .{
217
+ .phase = .key_down,
218
+ .key = "arrowright",
219
+ .modifiers = .{ .alt = true },
220
+ }));
221
+ try testing.expect(store.keyEvent(3, .{
222
+ .phase = .key_up,
223
+ .key = "arrowright",
224
+ }));
225
+ try testing.expect(store.keyEvent(3, .{
226
+ .phase = .key_down,
227
+ .key = "arrowleft",
228
+ .modifiers = .{ .super = true },
229
+ }));
230
+ try testing.expect(store.keyEvent(3, .{
231
+ .phase = .key_up,
232
+ .key = "arrowleft",
233
+ }));
234
+ try testing.expect(store.keyEvent(3, .{
235
+ .phase = .key_down,
236
+ .key = "arrowright",
237
+ .modifiers = .{ .super = true },
238
+ }));
239
+ try testing.expect(store.keyEvent(3, .{
240
+ .phase = .key_up,
241
+ .key = "arrowright",
242
+ }));
243
+ try testing.expect(store.keyEvent(3, .{
244
+ .phase = .key_down,
245
+ .key = "backspace",
246
+ .modifiers = .{ .super = true },
247
+ }));
248
+ try testing.expect(store.keyEvent(3, .{
249
+ .phase = .key_up,
250
+ .key = "backspace",
251
+ }));
252
+ try testing.expectEqualStrings("\x1bb\x1bf\x01\x05\x15", gw.written.items);
253
+ }
254
+ }
255
+
256
+ test "clipboard paste uses terminal paste encoding and ended sessions refuse it" {
257
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
258
+ var store = TerminalSessions.init(testing.allocator);
259
+ defer store.deinit();
260
+ var gw = TestGateway{ .gpa = testing.allocator };
261
+ defer gw.deinit();
262
+ store.setGateway(gw.gateway());
263
+ store.beginBuild(.{});
264
+ _ = resolveGrid(&store, 3) orelse return error.TestExpectedGrid;
265
+
266
+ // Unbracketed paste follows xterm: LF becomes CR and dangerous
267
+ // control bytes are spaces, never injected verbatim.
268
+ try testing.expect(store.pasteInput(3, "echo one\necho two\x03\x1b"));
269
+ try testing.expectEqualStrings("echo one\recho two ", gw.written.items);
270
+
271
+ // The child enables mode 2004. The next paste is framed against
272
+ // that live emulator mode, with its multiline payload preserved.
273
+ gw.written.clearRetainingCapacity();
274
+ feedOutput(&store, 3, "\x1b[?2004h");
275
+ try testing.expect(store.pasteInput(3, "alpha\nbeta"));
276
+ try testing.expectEqualStrings("\x1b[200~alpha\nbeta\x1b[201~", gw.written.items);
277
+
278
+ // A parked session is no longer an input target. In particular,
279
+ // the clipboard payload does not escape through any fallback.
280
+ gw.written.clearRetainingCapacity();
281
+ feedExit(&store, 3);
282
+ try testing.expect(!store.pasteInput(3, "late"));
283
+ try testing.expectEqualStrings("", gw.written.items);
284
+ }
285
+
286
+ test "a refused write is retained in the ring and drains on the frame flush" {
287
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
288
+ var store = TerminalSessions.init(testing.allocator);
289
+ defer store.deinit();
290
+ var gw = TestGateway{ .gpa = testing.allocator };
291
+ defer gw.deinit();
292
+ store.setGateway(gw.gateway());
293
+ store.beginBuild(.{});
294
+ _ = resolveGrid(&store, 3) orelse return error.TestExpectedGrid;
295
+
296
+ // The pty refuses (a child that stopped reading): the bytes stay
297
+ // queued, not dropped.
298
+ gw.accept = false;
299
+ try testing.expect(store.textInput(3, "queued"));
300
+ try testing.expectEqualStrings("", gw.written.items);
301
+
302
+ // The child resumes reading: the frame flush drains the ring.
303
+ gw.accept = true;
304
+ try testing.expect(store.flushPending());
305
+ try testing.expectEqualStrings("queued", gw.written.items);
306
+ // Nothing pending anymore: the flush is a no-op.
307
+ try testing.expect(!store.flushPending());
308
+ }
309
+
310
+ test "reconcile resizes the emulator, pushes ptyResize, and reports the state once" {
311
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
312
+ var store = TerminalSessions.init(testing.allocator);
313
+ defer store.deinit();
314
+ var gw = TestGateway{ .gpa = testing.allocator };
315
+ defer gw.deinit();
316
+ store.setGateway(gw.gateway());
317
+ store.beginBuild(.{});
318
+
319
+ // The reconcile creates the session too (a layout pass can land
320
+ // before the first paint's resolve).
321
+ const state = store.reconcile(9, 0, 100, 30) orelse return error.TestExpectedState;
322
+ try testing.expectEqual(@as(u16, 100), state.cols);
323
+ try testing.expectEqual(@as(u16, 30), state.rows);
324
+ try testing.expectEqual(@as(u16, 100), gw.resized.?.cols);
325
+ try testing.expectEqual(@as(u16, 30), gw.resized.?.rows);
326
+ // The same layout reconciles to the same state: nothing new to
327
+ // report, no second dispatch.
328
+ try testing.expectEqual(@as(?canvas.TerminalState, null), store.reconcile(9, 0, 100, 30));
329
+ try testing.expectEqual(@as(usize, 1), gw.resize_count);
330
+
331
+ // The emulator grid moved with the pty: the published snapshot's
332
+ // rows match.
333
+ const grid = resolveGrid(&store, 9) orelse return error.TestExpectedGrid;
334
+ try testing.expectEqual(@as(usize, 30), grid.rows.len);
335
+ }
336
+
337
+ test "wheel scrollback windows the viewport and the declared echo follows source-wins" {
338
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
339
+ var store = TerminalSessions.init(testing.allocator);
340
+ defer store.deinit();
341
+ var gw = TestGateway{ .gpa = testing.allocator };
342
+ defer gw.deinit();
343
+ store.setGateway(gw.gateway());
344
+ store.beginBuild(.{});
345
+ _ = store.reconcile(5, 0, 20, 4) orelse return error.TestExpectedState;
346
+ var line: [16]u8 = undefined;
347
+ for (0..30) |index| {
348
+ feedOutput(&store, 5, std.fmt.bufPrint(&line, "line {d}\r\n", .{index}) catch unreachable);
349
+ }
350
+
351
+ // Positive delta reveals history (natural direction); one session
352
+ // cell height per row.
353
+ try testing.expect(store.wheel(5, 18 * 3));
354
+ const scrolled = store.currentState(5) orelse return error.TestExpectedState;
355
+ try testing.expectEqual(@as(u32, 3), scrolled.scrollback);
356
+ try testing.expect(scrolled.history >= scrolled.scrollback);
357
+
358
+ // The app echoes the reported value back: an unchanged declaration
359
+ // never moves the runtime-owned position.
360
+ try testing.expectEqual(@as(?canvas.TerminalState, null), store.reconcile(5, scrolled.scrollback, 20, 4));
361
+ const held = store.currentState(5) orelse return error.TestExpectedState;
362
+ try testing.expectEqual(@as(u32, 3), held.scrollback);
363
+
364
+ // A model-driven change (the declaration MOVED between builds)
365
+ // wins: scroll programmatically back to the live screen.
366
+ const pinned = store.reconcile(5, 0, 20, 4) orelse return error.TestExpectedState;
367
+ try testing.expectEqual(@as(u32, 0), pinned.scrollback);
368
+ }
369
+
370
+ test "typing while scrolled back snaps the viewport to the live screen" {
371
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
372
+ var store = TerminalSessions.init(testing.allocator);
373
+ defer store.deinit();
374
+ var gw = TestGateway{ .gpa = testing.allocator };
375
+ defer gw.deinit();
376
+ store.setGateway(gw.gateway());
377
+ store.beginBuild(.{});
378
+ _ = store.reconcile(5, 0, 20, 4) orelse return error.TestExpectedState;
379
+ var line: [16]u8 = undefined;
380
+ for (0..30) |index| {
381
+ feedOutput(&store, 5, std.fmt.bufPrint(&line, "line {d}\r\n", .{index}) catch unreachable);
382
+ }
383
+ try testing.expect(store.wheel(5, 18 * 4));
384
+ try testing.expect((store.currentState(5) orelse return error.TestExpectedState).scrollback > 0);
385
+ try testing.expect(store.textInput(5, "x"));
386
+ try testing.expectEqual(@as(u32, 0), (store.currentState(5) orelse return error.TestExpectedState).scrollback);
387
+ }
388
+
389
+ test "an exit parks the session and output on the reused key resets to a clean terminal" {
390
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
391
+ var store = TerminalSessions.init(testing.allocator);
392
+ defer store.deinit();
393
+ var gw = TestGateway{ .gpa = testing.allocator };
394
+ defer gw.deinit();
395
+ store.setGateway(gw.gateway());
396
+ store.beginBuild(.{});
397
+ _ = resolveGrid(&store, 2) orelse return error.TestExpectedGrid;
398
+
399
+ feedOutput(&store, 2, "old session content\r\n");
400
+ feedExit(&store, 2);
401
+ const ended = resolveGrid(&store, 2) orelse return error.TestExpectedGrid;
402
+ try testing.expect(!ended.running);
403
+ // An ended session refuses input (the key is free; a respawn owns it).
404
+ try testing.expect(!store.textInput(2, "late"));
405
+ try testing.expect(!store.keyEvent(2, .{ .phase = .key_down, .key = "enter" }));
406
+
407
+ // A new spawn reused the key: its first output resets the emulator
408
+ // before feeding, so the old screen and modes never leak in.
409
+ feedOutput(&store, 2, "fresh prompt $ ");
410
+ const fresh = resolveGrid(&store, 2) orelse return error.TestExpectedGrid;
411
+ try testing.expect(fresh.running);
412
+ try testing.expect(std.mem.indexOf(u8, gridText(fresh), "fresh prompt") != null);
413
+ try testing.expect(std.mem.indexOf(u8, gridText(fresh), "old session") == null);
414
+ }
415
+
416
+ test "emulator query answers write back to the pty through the ring" {
417
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
418
+ var store = TerminalSessions.init(testing.allocator);
419
+ defer store.deinit();
420
+ var gw = TestGateway{ .gpa = testing.allocator };
421
+ defer gw.deinit();
422
+ store.setGateway(gw.gateway());
423
+ store.beginBuild(.{});
424
+ _ = resolveGrid(&store, 4) orelse return error.TestExpectedGrid;
425
+
426
+ // A DSR cursor-position report: the emulator answers and the answer
427
+ // reaches the child (a blocked `read` on the reply never hangs).
428
+ feedOutput(&store, 4, "\x1b[6n");
429
+ try testing.expect(std.mem.indexOf(u8, gw.written.items, "\x1b[") != null);
430
+ try testing.expect(std.mem.indexOf(u8, gw.written.items, "R") != null);
431
+ }
432
+
433
+ test "the wide-cell spacer extends its primary's background in the published snapshot" {
434
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
435
+ var store = TerminalSessions.init(testing.allocator);
436
+ defer store.deinit();
437
+ store.beginBuild(.{});
438
+ _ = resolveGrid(&store, 6) orelse return error.TestExpectedGrid;
439
+ // Red background behind a double-width glyph (界): the emulator
440
+ // styles only the primary cell, so the snapshot must pre-resolve
441
+ // the spacer's background per the painter's contract.
442
+ feedOutput(&store, 6, "\x1b[41m\xe7\x95\x8c\x1b[0m\r\n");
443
+ const grid = resolveGrid(&store, 6) orelse return error.TestExpectedGrid;
444
+ const row = grid.rows[0];
445
+ try testing.expectEqual(canvas.TerminalWide.wide, row.cells[0].wide);
446
+ try testing.expectEqual(canvas.TerminalWide.spacer, row.cells[1].wide);
447
+ try testing.expect(row.cells[0].bg != null);
448
+ try testing.expect(row.cells[1].bg != null);
449
+ try testing.expectEqual(row.cells[0].bg.?.r, row.cells[1].bg.?.r);
450
+ }
@@ -0,0 +1,15 @@
1
+ //! The `terminal_vt` seam's ENABLED half: re-exports libghostty-vt
2
+ //! (Ghostty's extracted terminal-state core, the `ghostty-vt` Zig
3
+ //! module) for the runtime's terminal-session store. Only an APP build
4
+ //! wires this wrapper, and only when it asks: pin `ghostty` as a lazy
5
+ //! dependency in the app's own `build.zig.zon` and set
6
+ //! `addAppArtifacts(.{ .terminal_sessions = true })`. This package pins
7
+ //! nothing, because a pin here is materialized into every consumer's
8
+ //! package directory even when lazy and unused.
9
+ //!
10
+ //! Everything else (the framework's own builds, scaffolded apps, the
11
+ //! wasm docs preview) gets `terminal_vt_stub.zig` and never traverses
12
+ //! ghostty's graph.
13
+
14
+ pub const enabled = true;
15
+ pub const vt = @import("ghostty-vt");
@@ -0,0 +1,13 @@
1
+ //! The `terminal_vt` seam's DISABLED half: the framework module imports
2
+ //! `terminal_vt` unconditionally, and the build graph wires either this
3
+ //! stub or `terminal_vt_ghostty.zig` (which re-exports the real
4
+ //! `ghostty-vt` module). With the stub in place `<terminal>` elements
5
+ //! render the honest empty surface — no emulator exists — and nothing
6
+ //! in the build traverses ghostty's dependency graph, which is the
7
+ //! load-bearing property for scaffolded and consumer builds (ghostty's
8
+ //! configure step walks lazy dependencies — wuffs, translate_c — whose
9
+ //! build scripts fail in consumer package stores, and its full build
10
+ //! pulls harfbuzz). Code that needs the emulator gates on `enabled` at
11
+ //! comptime and never references `vt` in the disabled branch.
12
+
13
+ pub const enabled = false;
@@ -0,0 +1,93 @@
1
+ Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -21,13 +21,21 @@ test {
21
21
  _ = @import("effects_file_tests.zig");
22
22
  _ = @import("effects_clipboard_tests.zig");
23
23
  _ = @import("effects_audio_tests.zig");
24
+ _ = @import("effects_video_tests.zig");
25
+ _ = @import("effects_image_tests.zig");
26
+ _ = @import("effects_channel_tests.zig");
24
27
  _ = @import("effects_host_tests.zig");
28
+ _ = @import("effects_pty_tests.zig");
29
+ _ = @import("terminal_session_tests.zig");
30
+ _ = @import("pty.zig");
31
+ _ = @import("pty_windows.zig");
25
32
  _ = @import("ts_core_host_tests.zig");
26
33
  _ = @import("clock.zig");
27
34
  _ = @import("frame_profile.zig");
28
35
  _ = @import("markdown_app_tests.zig");
29
36
  _ = @import("platform_bridge_tests.zig");
30
37
  _ = @import("session_journal.zig");
38
+ _ = @import("session_blobs.zig");
31
39
  _ = @import("session_record.zig");
32
40
  _ = @import("session_tests.zig");
33
41
  }