@eduardo191labs/opentui-core 0.0.0-stage → 0.9.9

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 (209) hide show
  1. package/LICENSE +21 -0
  2. package/NativeScene.d.ts +189 -0
  3. package/NativeSession.d.ts +157 -0
  4. package/NativeSpanFeed.d.ts +49 -0
  5. package/README.md +73 -2
  6. package/Renderable.d.ts +495 -0
  7. package/animation/Timeline.d.ts +145 -0
  8. package/ansi.d.ts +17 -0
  9. package/assets/javascript/highlights.scm +205 -0
  10. package/assets/javascript/tree-sitter-javascript.wasm +0 -0
  11. package/assets/markdown/highlights.scm +150 -0
  12. package/assets/markdown/injections.scm +27 -0
  13. package/assets/markdown/tree-sitter-markdown.wasm +0 -0
  14. package/assets/markdown_inline/highlights.scm +115 -0
  15. package/assets/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  16. package/assets/typescript/highlights.scm +604 -0
  17. package/assets/typescript/tree-sitter-typescript.wasm +0 -0
  18. package/assets/typescriptreact/highlights.scm +758 -0
  19. package/assets/typescriptreact/tree-sitter-tsx.wasm +0 -0
  20. package/assets/zig/highlights.scm +284 -0
  21. package/assets/zig/tree-sitter-zig.wasm +0 -0
  22. package/audio-stream/demuxer.d.ts +19 -0
  23. package/audio-stream/icy/demuxer.d.ts +21 -0
  24. package/audio-stream/icy/metadata.d.ts +1 -0
  25. package/audio.d.ts +496 -0
  26. package/buffer.d.ts +162 -0
  27. package/chunk-bun-13abd3px.js +10 -0
  28. package/chunk-bun-13abd3px.js.map +10 -0
  29. package/chunk-bun-5taceg7v.js +13941 -0
  30. package/chunk-bun-5taceg7v.js.map +35 -0
  31. package/chunk-bun-g0hj4kwy.js +24498 -0
  32. package/chunk-bun-g0hj4kwy.js.map +68 -0
  33. package/chunk-bun-ptw1pcst.js +10 -0
  34. package/chunk-bun-ptw1pcst.js.map +10 -0
  35. package/chunk-bun-qcaz2x8k.js +9 -0
  36. package/chunk-bun-qcaz2x8k.js.map +9 -0
  37. package/chunk-bun-zpcd3nsg.js +9 -0
  38. package/chunk-bun-zpcd3nsg.js.map +9 -0
  39. package/chunk-node-3bzh3jny.js +24497 -0
  40. package/chunk-node-3bzh3jny.js.map +68 -0
  41. package/chunk-node-wf36symw.js +13913 -0
  42. package/chunk-node-wf36symw.js.map +34 -0
  43. package/console.d.ts +146 -0
  44. package/edit-buffer.d.ts +157 -0
  45. package/editor-view.d.ts +116 -0
  46. package/image.d.ts +142 -0
  47. package/index.bun.js +13215 -0
  48. package/index.bun.js.map +38 -0
  49. package/index.d.ts +34 -0
  50. package/index.node.js +13214 -0
  51. package/index.node.js.map +68 -0
  52. package/lib/KeyHandler.d.ts +61 -0
  53. package/lib/RGBA.d.ts +42 -0
  54. package/lib/ascii.font.d.ts +508 -0
  55. package/lib/border.d.ts +51 -0
  56. package/lib/buffer-access.d.ts +6 -0
  57. package/lib/bunfs.d.ts +7 -0
  58. package/lib/clipboard.d.ts +125 -0
  59. package/lib/clock.d.ts +15 -0
  60. package/lib/data-paths.d.ts +26 -0
  61. package/lib/detect-links.d.ts +13 -0
  62. package/lib/env.d.ts +43 -0
  63. package/lib/extmarks.d.ts +59 -0
  64. package/lib/hast-styled-text.d.ts +17 -0
  65. package/lib/host-clipboard.internal.d.ts +22 -0
  66. package/lib/host-clipboard.native.d.ts +2 -0
  67. package/lib/index.d.ts +21 -0
  68. package/lib/keybinding.internal.d.ts +33 -0
  69. package/lib/kitty-keys.d.ts +2 -0
  70. package/lib/objects-in-viewport.d.ts +24 -0
  71. package/lib/output.capture.d.ts +24 -0
  72. package/lib/parse.keypress.d.ts +32 -0
  73. package/lib/parse.mouse.d.ts +17 -0
  74. package/lib/paste.d.ts +7 -0
  75. package/lib/render-geometry.d.ts +8 -0
  76. package/lib/renderable.validations.d.ts +12 -0
  77. package/lib/scroll-acceleration.d.ts +43 -0
  78. package/lib/scroll-chain.d.ts +16 -0
  79. package/lib/selection.d.ts +66 -0
  80. package/lib/singleton.d.ts +8 -0
  81. package/lib/stdin-parser-native.d.ts +102 -0
  82. package/lib/styled-text.d.ts +63 -0
  83. package/lib/terminal-capability-detection.d.ts +38 -0
  84. package/lib/terminal-palette.d.ts +68 -0
  85. package/lib/tree-sitter/assets/update.d.ts +12 -0
  86. package/lib/tree-sitter/client.d.ts +76 -0
  87. package/lib/tree-sitter/default-parser-assets.bun.d.ts +1 -0
  88. package/lib/tree-sitter/default-parsers.d.ts +3 -0
  89. package/lib/tree-sitter/download-utils.d.ts +21 -0
  90. package/lib/tree-sitter/index.d.ts +7 -0
  91. package/lib/tree-sitter/parser.worker.d.ts +1 -0
  92. package/lib/tree-sitter/parsers-config.d.ts +53 -0
  93. package/lib/tree-sitter/resolve-ft.d.ts +5 -0
  94. package/lib/tree-sitter/types.d.ts +197 -0
  95. package/lib/tree-sitter/update-assets.d.ts +3 -0
  96. package/lib/tree-sitter/update-assets.js +445 -0
  97. package/lib/tree-sitter/update-assets.js.map +12 -0
  98. package/lib/tree-sitter-styled-text.d.ts +22 -0
  99. package/lib/validate-dir-name.d.ts +1 -0
  100. package/lib/yoga.options.d.ts +35 -0
  101. package/libopentui-ng55e17a.so +0 -0
  102. package/libopentui-sck3vypm.so +0 -0
  103. package/native-abi.generated.d.ts +7924 -0
  104. package/native-event-worker-repro.worker.d.ts +1 -0
  105. package/node-asset-target.d.ts +12 -0
  106. package/node-assets.d.ts +7 -0
  107. package/node-assets.js +273 -0
  108. package/node-assets.js.map +16 -0
  109. package/package.json +91 -3
  110. package/parser.worker.js +4656 -0
  111. package/parser.worker.js.map +26 -0
  112. package/platform/assets.d.ts +5 -0
  113. package/platform/ffi.d.ts +131 -0
  114. package/platform/runtime-assets.bun.d.ts +4 -0
  115. package/platform/runtime-assets.node.d.ts +4 -0
  116. package/platform/runtime.d.ts +17 -0
  117. package/platform/test.d.ts +12 -0
  118. package/platform/worker.d.ts +26 -0
  119. package/platform/worker.node-test.d.ts +1 -0
  120. package/plugins/core-slot.d.ts +72 -0
  121. package/plugins/registry.d.ts +42 -0
  122. package/plugins/tree.d.ts +151 -0
  123. package/plugins/types.d.ts +34 -0
  124. package/post/effects.d.ts +149 -0
  125. package/post/filters.d.ts +65 -0
  126. package/post/matrices.d.ts +20 -0
  127. package/renderables/ASCIIFont.d.ts +58 -0
  128. package/renderables/Box.d.ts +86 -0
  129. package/renderables/Code.d.ts +138 -0
  130. package/renderables/Diff.d.ts +168 -0
  131. package/renderables/EditBufferRenderable.d.ts +269 -0
  132. package/renderables/EmbeddedTerminal.d.ts +81 -0
  133. package/renderables/FrameBuffer.d.ts +19 -0
  134. package/renderables/Image.d.ts +60 -0
  135. package/renderables/Input.d.ts +71 -0
  136. package/renderables/LineNumberRenderable.d.ts +95 -0
  137. package/renderables/Markdown.d.ts +363 -0
  138. package/renderables/ScrollBar.d.ts +91 -0
  139. package/renderables/ScrollBox.d.ts +174 -0
  140. package/renderables/ScrollBoxParts.d.ts +164 -0
  141. package/renderables/Select.d.ts +121 -0
  142. package/renderables/Slider.d.ts +49 -0
  143. package/renderables/TabSelect.d.ts +97 -0
  144. package/renderables/Text.d.ts +39 -0
  145. package/renderables/TextBufferRenderable.d.ts +117 -0
  146. package/renderables/TextNode.d.ts +100 -0
  147. package/renderables/TextTable.d.ts +171 -0
  148. package/renderables/Textarea.d.ts +66 -0
  149. package/renderables/TimeToFirstDraw.d.ts +25 -0
  150. package/renderables/Video.d.ts +126 -0
  151. package/renderables/__tests__/code-model-harness.d.ts +40 -0
  152. package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
  153. package/renderables/index.d.ts +24 -0
  154. package/renderables/markdown-document.d.ts +37 -0
  155. package/renderables/props.d.ts +10 -0
  156. package/renderables/text-table-width.d.ts +1 -0
  157. package/renderer-theme-mode.d.ts +28 -0
  158. package/renderer.d.ts +740 -0
  159. package/runtime-plugin-support-configure.d.ts +4 -0
  160. package/runtime-plugin-support-configure.js +47 -0
  161. package/runtime-plugin-support-configure.js.map +1 -0
  162. package/runtime-plugin-support-configure.node.js +15 -0
  163. package/runtime-plugin-support.d.ts +3 -0
  164. package/runtime-plugin-support.js +5 -0
  165. package/runtime-plugin-support.js.map +1 -0
  166. package/runtime-plugin-support.node.js +15 -0
  167. package/runtime-plugin.d.ts +18 -0
  168. package/runtime-plugin.js +474 -0
  169. package/runtime-plugin.js.map +1 -0
  170. package/runtime-plugin.node.js +15 -0
  171. package/session-buffer.d.ts +4 -0
  172. package/syntax-style.d.ts +68 -0
  173. package/testing/bun-test-node.d.ts +88 -0
  174. package/testing/harness.d.ts +33 -0
  175. package/testing/manual-clock.d.ts +19 -0
  176. package/testing/mock-keys.d.ts +81 -0
  177. package/testing/mock-mouse.d.ts +38 -0
  178. package/testing/mock-tree-sitter-client.d.ts +32 -0
  179. package/testing/model.d.ts +16 -0
  180. package/testing/spy.d.ts +7 -0
  181. package/testing/terminal-capabilities.d.ts +7 -0
  182. package/testing/test-recorder.d.ts +61 -0
  183. package/testing/test-renderer.d.ts +61 -0
  184. package/testing/test-streams.d.ts +30 -0
  185. package/testing.bun.js +1003 -0
  186. package/testing.bun.js.map +18 -0
  187. package/testing.d.ts +8 -0
  188. package/testing.js +1002 -0
  189. package/testing.js.map +18 -0
  190. package/tests/image-icc-allocation-child.d.ts +1 -0
  191. package/tests/native-log-worker-child.d.ts +1 -0
  192. package/tests/native-symbol-stubs.d.ts +5 -0
  193. package/tests/shrink-same-check.d.ts +4 -0
  194. package/tests/yoga-callback-boundary-child.d.ts +1 -0
  195. package/tests/yoga-default-config-worker-child.d.ts +1 -0
  196. package/tests/yoga-upstream/tools/MeasureCounter.d.ts +16 -0
  197. package/tests/yoga-upstream/tools/utils.d.ts +18 -0
  198. package/text-buffer-view.d.ts +56 -0
  199. package/text-buffer.d.ts +95 -0
  200. package/types.d.ts +240 -0
  201. package/utils.d.ts +15 -0
  202. package/yoga.bun.js +198 -0
  203. package/yoga.bun.js.map +9 -0
  204. package/yoga.d.ts +472 -0
  205. package/yoga.internal.d.ts +79 -0
  206. package/yoga.js +197 -0
  207. package/yoga.js.map +9 -0
  208. package/zig-structs.d.ts +275 -0
  209. package/zig.d.ts +1745 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 opentui
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,189 @@
1
+ import type { NativeSession } from "./NativeSession.js";
2
+ import type { Renderable, RenderableOptions } from "./Renderable.js";
3
+ import type { ImageFit } from "./renderables/Image.js";
4
+ import type { ExtractOptions, NativeImage } from "./image.js";
5
+ import { OptimizedBuffer } from "./buffer.js";
6
+ import type { ImageRenderProtocol } from "./types.js";
7
+ import { type CliRenderer } from "./renderer.js";
8
+ import type { StyledText } from "./lib/styled-text.js";
9
+ import type { RGBA } from "./lib/RGBA.js";
10
+ import type { LocalSelectionBounds } from "./lib/selection.js";
11
+ import { type Value, type MeasureFunction } from "./yoga.js";
12
+ import { NativeSessionRenderStatus, type NativeSceneFrameOptions, type NativeSceneFrameRequest, type NativeSceneLayout, type NativeScenePaint, type NativeScenePaintUpdate, type NativeSceneBoxDetails, type NativeSceneTextOptions, type NativeSceneSliderOptions, type NativeSceneArrowOptions, type NativeSceneScrollOptions, type NativeSceneScrollState, type NativeSceneEditorOptions, type ContextEditorViewHandle, type ContextTextBufferViewHandle, type SceneNodeHandle, type NativeContextHandle, type RenderLib } from "./zig.js";
13
+ type PaintOptions = () => Pick<NativeSceneFrameOptions, "background" | "useMouse" | "excludedHitNum" | "preserveUnwritten">;
14
+ declare class NativeLifecyclePasses extends Set<Renderable> {
15
+ private order;
16
+ private nextOrder;
17
+ private work?;
18
+ add(renderable: Renderable): this;
19
+ refresh(renderable: Renderable): void;
20
+ delete(renderable: Renderable): boolean;
21
+ clear(): void;
22
+ iteratePending(): IterableIterator<Renderable>;
23
+ }
24
+ /** Retained built-in scene with sparse owner-thread hooks. */
25
+ export declare class NativeScene {
26
+ readonly driver: NativeSession;
27
+ private readonly renderer;
28
+ get resourceContext(): import("./buffer.js").ResourceContext;
29
+ readonly lifecyclePasses: NativeLifecyclePasses;
30
+ /** @internal Renderables whose destroy walk is still running; renderer finalization waits for them. */
31
+ readonly cleanupOwners: Set<Renderable>;
32
+ private readonly nodes;
33
+ private paintedFrame;
34
+ private paintRecording?;
35
+ private destroyed;
36
+ private destroying;
37
+ private layoutRevision;
38
+ private readonly staging;
39
+ private readonly yogaHost;
40
+ constructor(driver: NativeSession, renderer: Pick<CliRenderer, "root" | "isDestroyed" | "controlState" | "unregisterLifecyclePass">);
41
+ /** @internal Buffer wrappers borrow the completed paint ticket. */
42
+ get frame(): NativeSceneFrameRequest | null;
43
+ /** @internal Layout reads return the same values until this changes. Undefined while callbacks run inside
44
+ * native layout, because that layout is still being computed. */
45
+ get observedLayoutRevision(): number | undefined;
46
+ /** The scene does no more hook or frame work once it, its Session, or its renderer is gone or going. */
47
+ private get stopped();
48
+ /** Frames, moves, destroys, and translations are the only changes a layout read can see. Measurement and cancels
49
+ * change none today; they bump so that a native solve or observation outside a frame step stays covered. */
50
+ private changeLayout;
51
+ /** @internal Whether style or paint writes await native acceptance. */
52
+ get hasStagedMutations(): boolean;
53
+ /** @internal Apply staged style/paint writes. Runs before every native scene call
54
+ * except node creation, moves, and hit tests, which observe no style or paint.
55
+ * Failed flushes retain their unaccepted suffix for retry, except a record that native
56
+ * rejects for its node (InvalidArgument, WrongKind, StaleHandle). That record is dropped,
57
+ * including other paint fields the node staged since the last flush, and the error is
58
+ * thrown once by whichever call flushes, which may belong to another node.
59
+ * A closing Session paints no more frames, so like a disposed one it drops staged writes. */
60
+ flushStaged(): void;
61
+ /** @internal Detached settlement visits owned controllers, not the render tree. */
62
+ getRenderables(): IterableIterator<Renderable>;
63
+ /** @internal Reject stale scene operations before accessing their Context. */
64
+ assertAlive(): void;
65
+ /** @internal Scene nodes retain native ownership even when their body is a host hook. */
66
+ createNode(renderable: Renderable, options: RenderableOptions): void;
67
+ /** @internal Native acceptance precedes all wrapper topology changes. */
68
+ moveNode(child: Renderable, parent: Renderable | null, index: number): void;
69
+ setViewport(content: Renderable, viewport: Renderable | null): void;
70
+ setFocus(renderable: Renderable, focused: boolean): void;
71
+ /** @internal The wrapper's existing cleanup walk releases nodes child-first. Staged
72
+ * writes flush first so no entry outlives its handle; a flush failure must not
73
+ * leave the native node alive behind a destroyed wrapper. */
74
+ destroyNode(renderable: Renderable): void;
75
+ /** @internal Hook identities publish only after native acceptance. Geometry remains native-owned. */
76
+ setHooks(renderable: Renderable, flags: number, generation: bigint, initialWidth: number, initialHeight: number): void;
77
+ /** @internal Shared Yoga normalization stages through the checked scene style boundary. */
78
+ setStyle(node: {
79
+ _getSceneHandle(owner: NativeScene): SceneNodeHandle;
80
+ }, group: number, kind: number, edge: number, unit: number, value: number, flags?: number): void;
81
+ /** @internal Accept this scene's staged prefix before reading native style.
82
+ * This boundary does not run layout; geometry remains the completed observation. */
83
+ getStyle(node: {
84
+ _getSceneHandle(owner: NativeScene): SceneNodeHandle;
85
+ }, group: number, kind: number, edge: number): Value;
86
+ setMeasureFunc(node: {
87
+ _getSceneHandle(owner: NativeScene): SceneNodeHandle;
88
+ }, measure: MeasureFunction | null): void;
89
+ hasMeasureFunc(node: {
90
+ _getSceneHandle(owner: NativeScene): SceneNodeHandle;
91
+ }): boolean;
92
+ reachesHooks(node: {
93
+ _getSceneHandle(owner: NativeScene): SceneNodeHandle;
94
+ }): boolean;
95
+ /** Whether the latest paint list held the node (see `ot_scene_painted`). */
96
+ painted(node: {
97
+ _getSceneHandle(owner: NativeScene): SceneNodeHandle;
98
+ }): boolean;
99
+ markDirty(node: {
100
+ _getSceneHandle(owner: NativeScene): SceneNodeHandle;
101
+ }): void;
102
+ /** @internal Masked position edges stage as ordinary Yoga position values.
103
+ * Every masked value is validated before the first edge is staged so a rejected edge
104
+ * leaves no partial position behind. */
105
+ setPositions(node: {
106
+ _getSceneHandle(owner: NativeScene): SceneNodeHandle;
107
+ }, mask: number, units: Uint32Array, values: Float32Array): void;
108
+ /** @internal Partial visual writes stage before requested wrapper state is published.
109
+ * Border appearance and Yoga widths are accepted atomically by native. */
110
+ setPaint(renderable: Renderable, paint: NativeScenePaintUpdate): void;
111
+ setBackground(renderable: Renderable, color: RGBA): void;
112
+ setBoxDetails(renderable: Renderable, details: NativeSceneBoxDetails): void;
113
+ /** Border style clears custom glyphs in the same staged record as border widths. */
114
+ setBoxBorderStyle(renderable: Renderable, style: NativeScenePaint["borderStyle"], sides: number): void;
115
+ /** @internal Native copies bytes and styles before the wrapper publishes caller identity. */
116
+ setText(renderable: Renderable, content: string | StyledText): void;
117
+ /** @internal A Markdown document binds the text node after its staged writes. */
118
+ textNode(renderable: Renderable): SceneNodeHandle;
119
+ /** @internal The byte of the text the latest finished frame drew at a cell, or undefined. */
120
+ textByteAt(renderable: Renderable, x: number, y: number): number | undefined;
121
+ /** @internal Text options commit together without exposing the node-owned buffer or view. */
122
+ setTextOptions(renderable: Renderable, options: NativeSceneTextOptions): void;
123
+ /** @internal Native owns slider drawing and thumb geometry; the host retains input callbacks. */
124
+ setSlider(renderable: Renderable, options: NativeSceneSliderOptions): void;
125
+ /** @internal Input-time query only, never a per-node frame pass. */
126
+ getSliderThumb(renderable: Renderable): {
127
+ size: number;
128
+ start: number;
129
+ };
130
+ /** @internal Standard arrow paint commits before its wrapper projection. */
131
+ setArrow(renderable: Renderable, options: NativeSceneArrowOptions): void;
132
+ setImage(renderable: Renderable, image: NativeImage | null, fit: ImageFit, protocol: ImageRenderProtocol, buffer: OptimizedBuffer | null): void;
133
+ setVideo(renderable: Renderable, fit: ImageFit, buffer: OptimizedBuffer | null): void;
134
+ setCrop(renderable: Renderable, crop: ExtractOptions | undefined): void;
135
+ /** @internal Video control and state calls address the node after staged writes. */
136
+ videoNode(renderable: Renderable): {
137
+ lib: RenderLib;
138
+ context: NativeContextHandle;
139
+ node: SceneNodeHandle;
140
+ };
141
+ /** @internal A scroll write moves the box's children, so it bumps the layout revision like a frame step. */
142
+ setScroll(renderable: Renderable, options: NativeSceneScrollOptions): void;
143
+ setScrollArrow(renderable: Renderable, axis: number, end: number, options: Omit<NativeSceneArrowOptions, "direction">): void;
144
+ scrollTo(renderable: Renderable, x: number, y: number, relativeX: boolean, relativeY: boolean, reapply?: boolean): NativeSceneScrollState;
145
+ scrollRequest(renderable: Renderable, kind: "into-view" | "anchor" | "layout", target: Renderable | null, align?: "nearest" | "start" | "end", inset?: number): NativeSceneScrollState;
146
+ getScroll(renderable: Renderable): NativeSceneScrollState;
147
+ setEditorView(renderable: Renderable, view: ContextEditorViewHandle): void;
148
+ setSurface(renderable: Renderable, buffer: OptimizedBuffer | null): void;
149
+ setTextView(renderable: Renderable, view: ContextTextBufferViewHandle | null): void;
150
+ setTextViewPaint(renderable: Renderable, enabled: boolean): void;
151
+ setEditorOptions(renderable: Renderable, options: NativeSceneEditorOptions): void;
152
+ /** @internal Query native text metrics only when requested, never during JS frame traversal. */
153
+ getText(renderable: Renderable): string;
154
+ /** @internal Inherited Text and Box drawing records or draws the native body at the caller's position. */
155
+ drawBody(renderable: Renderable, buffer: OptimizedBuffer, x: number, y: number): void;
156
+ setTextSelection(renderable: Renderable, operation: "set" | "update" | "reset" | "colors", bounds: LocalSelectionBounds | null, bg?: RGBA, fg?: RGBA): boolean;
157
+ getTextSelection(renderable: Renderable): {
158
+ start: number;
159
+ end: number;
160
+ } | null;
161
+ getSelectedText(renderable: Renderable): string;
162
+ /** @internal Line arrays are copied only for explicit line-info queries. */
163
+ getTextLineInfo(renderable: Renderable, firstLine?: number, lineCount?: number): import("./types.js").LineInfo;
164
+ /** @internal Scalar metrics do not copy the document or its line arrays. */
165
+ getTextMetrics(renderable: Renderable): import("./zig.js").NativeSceneTextMetrics;
166
+ /** @internal Accept staging, then read completed geometry without running layout.
167
+ * Native owns callback-time projections and composes accepted ancestor translations. */
168
+ getLayout(node: {
169
+ _getSceneHandle(owner: NativeScene): SceneNodeHandle;
170
+ }, rawYoga?: boolean | "paint" | "content"): NativeSceneLayout;
171
+ /** @internal Measure a snapshot using its existing scene root, without preparing a frame. */
172
+ measureSnapshot(root: Renderable): number;
173
+ paint(deltaTime: number, getPaintOptions: PaintOptions): void;
174
+ private runLifecyclePasses;
175
+ private advancePaint;
176
+ /** Destruction or Session shutdown may have cancelled the attempt already; keep the caller's failure. */
177
+ private cancelAttempt;
178
+ /** Run every slot's paint hooks in paint order before native code paints the frame. */
179
+ private recordPaint;
180
+ private createPaintRecording;
181
+ commit(force?: boolean): NativeSessionRenderStatus;
182
+ /** @internal Split output uses the same painted ticket and presentation endpoint. */
183
+ commitSplit(commits: Parameters<NativeSession["renderSplit"]>[1], pinnedRenderOffset: number, force: boolean): ReturnType<NativeSession["renderSplit"]>;
184
+ /** @internal Called after active effects and captures unwind, never during synchronous node destruction. */
185
+ cancelFrame(): void;
186
+ hitTest(x: number, y: number, excluded?: number): number;
187
+ destroy(): void;
188
+ }
189
+ export {};
@@ -0,0 +1,157 @@
1
+ import { Writable } from "node:stream";
2
+ import { ResourceContext } from "./buffer.js";
3
+ import { NativeSessionRenderStatus, type NativeContextHandle, type NativeContextOptions, type NativeSceneFrameRequest, type NativeSessionCapabilities, type NativeSessionControl, type NativeSessionKittyImageTransportStatus, type NativeSessionOptions, type NativeSessionRendererOptions, type NativeSessionTerminalOptions, type RenderLib, type SessionHandle, type NativeSplitSnapshot } from "./zig.js";
4
+ import type { ProgramStatus } from "./types.js";
5
+ export interface NativeSessionScheduler {
6
+ /** Monotonic nanoseconds. */
7
+ now(): bigint;
8
+ /** Schedule a later event-loop turn, never an inline callback or microtask. */
9
+ schedule(callback: () => void, delayMs?: number): () => void;
10
+ }
11
+ export interface NativeSessionDriverOptions {
12
+ context?: NativeContextOptions;
13
+ output?: NativeSessionOptions;
14
+ /** Copy-buffer size for custom Writable destinations. Native stdout needs no buffer. */
15
+ outputBufferSize?: number;
16
+ /** Graceful close drops the queued output, restores and rejects as late once this long passes without written
17
+ * bytes and no write in progress, or ten times this long in all; a write in progress finishes first. Another
18
+ * interval without written bytes then cancels it unrestored. */
19
+ closeTimeoutMs?: number;
20
+ scheduler?: NativeSessionScheduler;
21
+ }
22
+ /**
23
+ * Owns one checked Session and optionally its Context. Borrows a Writable without
24
+ * ending or destroying it. If emitClose is false, the owner must call dispose() again
25
+ * after silent asynchronous destruction completes; no notification is available.
26
+ */
27
+ export declare class NativeSession {
28
+ private readonly sink;
29
+ private readonly owner?;
30
+ private readonly lib;
31
+ private attachmentCleanup?;
32
+ readonly resourceContext: ResourceContext;
33
+ private readonly nativeSession;
34
+ private buffer;
35
+ private readonly outputBufferSize;
36
+ private readonly sinkWrite;
37
+ /** @internal Shared later-turn scheduler; frame and output cancellations remain independent. */
38
+ readonly scheduler: NativeSessionScheduler;
39
+ /** Configured output capacity, including reserved control storage; raw admission can fail earlier. */
40
+ readonly maxWriteBytes: bigint;
41
+ /** Maximum raw write in an empty queue, excluding reserved control storage and span slots. */
42
+ readonly maxAtomicWriteBytes: bigint;
43
+ private readonly closeTimeoutNs;
44
+ private readonly closeWait;
45
+ private idleWait;
46
+ private presentationWait;
47
+ /** @internal Image uploads that later frames still send, read when the last waited frame presented. */
48
+ imageUploadsPending: number;
49
+ private transition;
50
+ private scheduled;
51
+ private output;
52
+ /** The stdout writer's copy in flight: when it started, and how many polls found it busy. */
53
+ private stdoutPost;
54
+ /** fd 1 output goes through the native writer thread until it reports unsupported. */
55
+ private stdoutWriter;
56
+ private blocked;
57
+ private sinkErrorSeen;
58
+ private detached;
59
+ private closeDeadlineNs;
60
+ private closeCapNs;
61
+ private closeLate;
62
+ private closeRequested;
63
+ private closeInterruption;
64
+ private stopped;
65
+ private exiting;
66
+ private finishing;
67
+ private _disposed;
68
+ private _error;
69
+ private readonly detachedSessions;
70
+ /** Resolves after graceful native close and owned resource cleanup; failure or cancellation rejects. */
71
+ readonly closed: Promise<void>;
72
+ constructor(sink: Writable, options?: NativeSessionDriverOptions, owner?: NativeSession | undefined);
73
+ get context(): NativeContextHandle;
74
+ get renderLib(): RenderLib;
75
+ get session(): Readonly<SessionHandle>;
76
+ /** Native Session teardown is complete; pending sink I/O can still retain listeners. */
77
+ get disposed(): boolean;
78
+ get contextDisposed(): boolean;
79
+ get error(): Error | null;
80
+ /** The Session takes native work: it has not failed and is not closing or exiting. */
81
+ get open(): boolean;
82
+ usesOutput(sink: Writable): boolean;
83
+ /** The optional attachment cleanup is installed only after checked native acceptance. */
84
+ attachRenderer(options: NativeSessionRendererOptions, beforeDispose?: () => void): void;
85
+ /** @internal Independent scene/frame ownership, sharing only the parent's Context resources. */
86
+ createDetached(options: NativeSessionRendererOptions, beforeDispose: () => void): NativeSession;
87
+ /** Repeated calls share pending setup; the first call supplies its options. */
88
+ setupTerminal(options?: NativeSessionTerminalOptions): Promise<void>;
89
+ suspend(): Promise<void>;
90
+ resume(): Promise<void>;
91
+ /** The painted frame is consumed on every returned status. */
92
+ render(force: boolean, frame: NativeSceneFrameRequest): NativeSessionRenderStatus;
93
+ /** @internal One checked admission for a complete split frame. */
94
+ renderSplit(frame: NativeSceneFrameRequest | null, commits: readonly NativeSplitSnapshot[], pinnedRenderOffset: number, force: boolean): {
95
+ status: NativeSessionRenderStatus;
96
+ };
97
+ /** @internal Screen changes join the same ordered output queue as frames and controls. */
98
+ setScreen(alternate: boolean, width: number, height: number, trailingOutput?: Uint8Array): void;
99
+ /** Waits for the current frame's endpoint, not later output or sink drain. Calls share one pending wait. */
100
+ whenPresented(): Promise<void>;
101
+ resize(width: number, height: number): void;
102
+ control(command: NativeSessionControl): void;
103
+ writeClipboard(target: number, bytes: Uint8Array): boolean;
104
+ triggerNotification(message: string, title?: string): boolean;
105
+ /** Returns false while the terminal is inactive or output is full. Invalid reports throw. */
106
+ setProgramStatus(status: ProgramStatus): boolean;
107
+ setKittyImageTransport(mode: number): void;
108
+ getKittyImageTransport(): NativeSessionKittyImageTransportStatus;
109
+ pollKittyImageTransport(): boolean;
110
+ cancelKittyImageTransport(failed: boolean): void;
111
+ processKittyImageReply(bytes: Uint8Array): number;
112
+ startKittyFileProbe(): void;
113
+ getCapabilities(): NativeSessionCapabilities;
114
+ /** Copies all bytes or returns false under queue pressure. Capacity-exceeding writes throw RangeError;
115
+ * lifecycle errors take precedence while writing is unavailable. */
116
+ write(bytes: Uint8Array): boolean;
117
+ /** Waits for accepted output, terminal work, and sink pressure to settle. Calls share one wait. */
118
+ idle(): Promise<void>;
119
+ /** Release external Context leases first. A busy close rejects; dispose() can retry cleanup after release. */
120
+ close(): Promise<void>;
121
+ /** @internal Bound required snapshot flushing by the same graceful-close deadline. */
122
+ armCloseTimeout(): void;
123
+ /** Identifies this driver's close interruption or late close; a late close on `closed` wrote the restore. */
124
+ isCloseInterruption(error: unknown): boolean;
125
+ /**
126
+ * Cancels immediately without claiming restoration. Release external Context
127
+ * leases first; if disposed remains false, release them and call dispose again.
128
+ */
129
+ dispose(): void;
130
+ /** @internal Restore before exit callbacks can terminate the process. The caller
131
+ * must still dispose after wrapper cleanup; this does not release the Context.
132
+ * Only real stdout supports direct synchronous delivery. In-flight writes cannot
133
+ * be replayed, and arbitrary borrowed sinks cannot finish asynchronously at exit. */
134
+ restoreOnExit(): boolean;
135
+ /** One exit copy through the writer. False: no writer, or it never picked the copy up and
136
+ * gave it back; the synchronous drain takes over. */
137
+ private exitThroughWriter;
138
+ private checkOpen;
139
+ private changeTerminal;
140
+ private onError;
141
+ private onClose;
142
+ private onFinish;
143
+ private onDrain;
144
+ private schedule;
145
+ private turn;
146
+ private writeOutput;
147
+ /** Collects the writer's finished copy and, when `start`, hands over the next. */
148
+ private postStdout;
149
+ /** The next poll of a copy in flight: the next turn (0n) for its first 64 polls within 0.5 ms, then an eighth of
150
+ * its age, from 1 to 50 ms. */
151
+ private pollDeadline;
152
+ private writeSink;
153
+ private completePresentation;
154
+ private detach;
155
+ private canDetach;
156
+ private finish;
157
+ }
@@ -0,0 +1,49 @@
1
+ import { type Pointer } from "./platform/ffi.js";
2
+ import type { NativeSpanFeedOptions } from "./zig-structs.js";
3
+ export type { GrowthPolicy, NativeSpanFeedOptions, NativeSpanFeedStats } from "./zig-structs.js";
4
+ export type DataHandler = (data: Uint8Array) => void | Promise<void>;
5
+ /**
6
+ * Zero-copy wrapper over Zig memory; not a full stream interface.
7
+ * Data views are borrowed until all handlers for a span have completed.
8
+ */
9
+ export declare class NativeSpanFeed {
10
+ static create(options?: NativeSpanFeedOptions): NativeSpanFeed;
11
+ static attach(streamPtr: Pointer, _options?: NativeSpanFeedOptions): NativeSpanFeed;
12
+ readonly streamPtr: Pointer;
13
+ private readonly lib;
14
+ private readonly eventHandler;
15
+ private chunkMap;
16
+ private dataHandlers;
17
+ private errorHandlers;
18
+ private drainBuffer;
19
+ private closed;
20
+ private destroyed;
21
+ private draining;
22
+ private pendingDataAvailable;
23
+ private pendingClose;
24
+ private closing;
25
+ private pendingAsyncHandlers;
26
+ private inCallback;
27
+ private closeQueued;
28
+ private idleResolvers;
29
+ private pendingHandlerError;
30
+ private pendingHandlerErrorQueued;
31
+ private constructor();
32
+ private ensureDrainBuffer;
33
+ onData(handler: DataHandler): () => void;
34
+ onError(handler: (code: number) => void): () => void;
35
+ private hasPinnedChunks;
36
+ isBackpressured(): boolean;
37
+ close(): void;
38
+ private processPendingClose;
39
+ private performClose;
40
+ private finalizeDestroy;
41
+ private isIdle;
42
+ private resolveIdleIfNeeded;
43
+ idle(): Promise<void>;
44
+ private handleEvent;
45
+ private queuePendingHandlerError;
46
+ private throwPendingHandlerError;
47
+ private drainOnce;
48
+ drainAll(): void;
49
+ }
package/README.md CHANGED
@@ -1,3 +1,74 @@
1
- # Temporary Holding Version
1
+ <!-- Keep the project introduction aligned with the repository README and opentui.com. -->
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <p align="center">
4
+ <a href="https://opentui.com">
5
+ <img alt="OpenTUI logo" src="https://opentui.com/opentui-logo-auto.svg" width="270" />
6
+ </a>
7
+ </p>
8
+
9
+ <div align="center">
10
+ <a href="https://www.npmjs.com/package/@opentui/core"><img alt="npm version" src="https://img.shields.io/npm/v/@opentui/core?style=flat-square" /></a>
11
+ <a href="https://github.com/anomalyco/opentui/actions/workflows/build-core.yml"><img alt="Core build status" src="https://img.shields.io/github/actions/workflow/status/anomalyco/opentui/build-core.yml?style=flat-square&branch=main" /></a>
12
+ </div>
13
+
14
+ OpenTUI is a library to build terminal user interfaces.
15
+
16
+ - It is written in Zig, with a C API.
17
+ - You write Rust, TypeScript, React, or Solid.
18
+ - You arrange boxes and text with flexbox.
19
+ - You add selects, inputs, and scroll boxes with keyboard and mouse controls.
20
+ - You can play videos and sounds, show images, and render 3D graphics.
21
+
22
+ OpenCode uses OpenTUI in production for millions of users.
23
+
24
+ [Website](https://opentui.com) | [Documentation](https://opentui.com/docs) | [Packages](https://opentui.com/packages)
25
+
26
+ ## OpenTUI Core
27
+
28
+ `@opentui/core` supplies the renderer and TypeScript API. You use imperative renderables and events directly. The
29
+ TypeScript packages call native Zig through an internal foreign function interface (FFI) boundary.
30
+
31
+ ```typescript
32
+ import { TextRenderable, createCliRenderer } from "@opentui/core"
33
+
34
+ const renderer = await createCliRenderer({ exitOnCtrlC: true })
35
+
36
+ renderer.root.add(new TextRenderable(renderer, { content: "Hello, OpenTUI!" }))
37
+ ```
38
+
39
+ `exitOnCtrlC: true` calls `renderer.destroy()` when the user presses Ctrl+C. The code that creates the renderer must
40
+ call `renderer.destroy()` on every other shutdown path.
41
+
42
+ Install the package:
43
+
44
+ ```bash
45
+ bun add @opentui/core
46
+ ```
47
+
48
+ Then build your first app with the [quickstart](https://opentui.com/docs/getting-started/quickstart).
49
+
50
+ ## Runtime and platform support
51
+
52
+ `@opentui/core` runs on Bun 1.3.14 or later, or on Node.js 26.4.0 or later with ECMAScript modules (ESM) and
53
+ `--experimental-ffi`.
54
+
55
+ Use Bun 1.4.0 or later on native Windows arm64.
56
+
57
+ The native ABI and the generated platform packages, such as `@opentui/core-linux-x64`, are internal distribution
58
+ surfaces, not application APIs.
59
+
60
+ ## AI agent skill
61
+
62
+ Install the OpenTUI documentation as a skill for your AI coding assistant with [`npx skills`](https://skills.sh):
63
+
64
+ ```bash
65
+ npx skills add https://opentui.com --skill opentui
66
+ ```
67
+
68
+ Add `-g` to install the skill globally. The skill matches the latest release, and `npx skills update` moves it to each
69
+ new release. Install from `https://opentui.com/docs/next` to follow the main branch. A skill installed with
70
+ `npx skills add anomalyco/opentui` follows the main branch; run the command above to switch it to releases.
71
+
72
+ ## License
73
+
74
+ OpenTUI is licensed under the [MIT License](https://github.com/anomalyco/opentui/blob/main/LICENSE).