@fairyhunter13/opentui-core 0.1.90 → 0.1.92

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 (571) hide show
  1. package/3d/SpriteResourceManager.d.ts +74 -0
  2. package/3d/SpriteUtils.d.ts +13 -0
  3. package/3d/TextureUtils.d.ts +24 -0
  4. package/3d/ThreeRenderable.d.ts +40 -0
  5. package/3d/WGPURenderer.d.ts +61 -0
  6. package/3d/animation/ExplodingSpriteEffect.d.ts +71 -0
  7. package/3d/animation/PhysicsExplodingSpriteEffect.d.ts +76 -0
  8. package/3d/animation/SpriteAnimator.d.ts +124 -0
  9. package/3d/animation/SpriteParticleGenerator.d.ts +62 -0
  10. package/3d/canvas.d.ts +44 -0
  11. package/3d/index.d.ts +12 -0
  12. package/3d/physics/PlanckPhysicsAdapter.d.ts +19 -0
  13. package/3d/physics/RapierPhysicsAdapter.d.ts +19 -0
  14. package/3d/physics/physics-interface.d.ts +27 -0
  15. package/3d.d.ts +2 -0
  16. package/3d.js +34042 -0
  17. package/3d.js.map +155 -0
  18. package/LICENSE +21 -0
  19. package/NativeSpanFeed.d.ts +41 -0
  20. package/README.md +2 -2
  21. package/Renderable.d.ts +334 -0
  22. package/animation/Timeline.d.ts +126 -0
  23. package/ansi.d.ts +13 -0
  24. package/buffer.d.ts +107 -0
  25. package/console.d.ts +143 -0
  26. package/edit-buffer.d.ts +98 -0
  27. package/editor-view.d.ts +73 -0
  28. package/index-e6ec7apq.js +18415 -0
  29. package/index-e6ec7apq.js.map +64 -0
  30. package/index-h066zmrb.js +12619 -0
  31. package/index-h066zmrb.js.map +43 -0
  32. package/index-ynzawt3n.js +113 -0
  33. package/index-ynzawt3n.js.map +10 -0
  34. package/index.d.ts +21 -0
  35. package/index.js +430 -0
  36. package/index.js.map +9 -0
  37. package/lib/KeyHandler.d.ts +61 -0
  38. package/lib/RGBA.d.ts +25 -0
  39. package/lib/ascii.font.d.ts +508 -0
  40. package/lib/border.d.ts +49 -0
  41. package/lib/bunfs.d.ts +7 -0
  42. package/lib/clipboard.d.ts +17 -0
  43. package/lib/clock.d.ts +15 -0
  44. package/lib/data-paths.d.ts +26 -0
  45. package/lib/debounce.d.ts +42 -0
  46. package/lib/detect-links.d.ts +6 -0
  47. package/lib/env.d.ts +42 -0
  48. package/lib/extmarks-history.d.ts +17 -0
  49. package/lib/extmarks.d.ts +89 -0
  50. package/lib/hast-styled-text.d.ts +17 -0
  51. package/lib/index.d.ts +21 -0
  52. package/lib/keymapping.d.ts +25 -0
  53. package/lib/objects-in-viewport.d.ts +24 -0
  54. package/lib/output.capture.d.ts +24 -0
  55. package/lib/parse.keypress-kitty.d.ts +2 -0
  56. package/lib/parse.keypress.d.ts +26 -0
  57. package/lib/parse.mouse.d.ts +30 -0
  58. package/lib/paste.d.ts +7 -0
  59. package/lib/queue.d.ts +15 -0
  60. package/lib/renderable.validations.d.ts +12 -0
  61. package/lib/scroll-acceleration.d.ts +43 -0
  62. package/lib/selection.d.ts +63 -0
  63. package/lib/singleton.d.ts +7 -0
  64. package/lib/stdin-parser.d.ts +76 -0
  65. package/lib/styled-text.d.ts +63 -0
  66. package/lib/terminal-capability-detection.d.ts +30 -0
  67. package/lib/terminal-palette.d.ts +50 -0
  68. package/lib/tree-sitter/assets/update.d.ts +11 -0
  69. package/lib/tree-sitter/client.d.ts +47 -0
  70. package/lib/tree-sitter/default-parsers.d.ts +2 -0
  71. package/lib/tree-sitter/download-utils.d.ts +21 -0
  72. package/lib/tree-sitter/index.d.ts +8 -0
  73. package/lib/tree-sitter/parser.worker.d.ts +1 -0
  74. package/lib/tree-sitter/parsers-config.d.ts +38 -0
  75. package/lib/tree-sitter/resolve-ft.d.ts +2 -0
  76. package/lib/tree-sitter/types.d.ts +81 -0
  77. package/lib/tree-sitter-styled-text.d.ts +14 -0
  78. package/lib/validate-dir-name.d.ts +1 -0
  79. package/lib/yoga.options.d.ts +32 -0
  80. package/package.json +51 -63
  81. package/parser.worker.js +869 -0
  82. package/parser.worker.js.map +12 -0
  83. package/plugins/core-slot.d.ts +72 -0
  84. package/plugins/registry.d.ts +38 -0
  85. package/plugins/types.d.ts +34 -0
  86. package/post/filters.d.ts +105 -0
  87. package/renderables/ASCIIFont.d.ts +52 -0
  88. package/renderables/Box.d.ts +72 -0
  89. package/renderables/Code.d.ts +78 -0
  90. package/renderables/Diff.d.ts +142 -0
  91. package/renderables/EditBufferRenderable.d.ts +162 -0
  92. package/renderables/FrameBuffer.d.ts +16 -0
  93. package/renderables/Input.d.ts +67 -0
  94. package/renderables/LineNumberRenderable.d.ts +74 -0
  95. package/renderables/Markdown.d.ts +173 -0
  96. package/renderables/ScrollBar.d.ts +77 -0
  97. package/renderables/ScrollBox.d.ts +124 -0
  98. package/renderables/Select.d.ts +115 -0
  99. package/renderables/Slider.d.ts +44 -0
  100. package/renderables/TabSelect.d.ts +96 -0
  101. package/renderables/Text.d.ts +36 -0
  102. package/renderables/TextBufferRenderable.d.ts +105 -0
  103. package/renderables/TextNode.d.ts +91 -0
  104. package/renderables/TextTable.d.ts +140 -0
  105. package/renderables/Textarea.d.ts +114 -0
  106. package/renderables/TimeToFirstDraw.d.ts +24 -0
  107. package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
  108. package/renderables/composition/VRenderable.d.ts +16 -0
  109. package/renderables/composition/constructs.d.ts +35 -0
  110. package/renderables/composition/vnode.d.ts +46 -0
  111. package/renderables/index.d.ts +22 -0
  112. package/renderables/markdown-parser.d.ts +10 -0
  113. package/renderer.d.ts +388 -0
  114. package/runtime-plugin-support.d.ts +3 -0
  115. package/runtime-plugin-support.js +29 -0
  116. package/runtime-plugin-support.js.map +10 -0
  117. package/runtime-plugin.d.ts +11 -0
  118. package/runtime-plugin.js +16 -0
  119. package/runtime-plugin.js.map +9 -0
  120. package/syntax-style.d.ts +54 -0
  121. package/testing/manual-clock.d.ts +16 -0
  122. package/testing/mock-keys.d.ts +81 -0
  123. package/testing/mock-mouse.d.ts +38 -0
  124. package/testing/mock-tree-sitter-client.d.ts +23 -0
  125. package/testing/spy.d.ts +7 -0
  126. package/testing/test-recorder.d.ts +61 -0
  127. package/testing/test-renderer.d.ts +23 -0
  128. package/testing.d.ts +6 -0
  129. package/testing.js +675 -0
  130. package/testing.js.map +15 -0
  131. package/text-buffer-view.d.ts +42 -0
  132. package/text-buffer.d.ts +67 -0
  133. package/types.d.ts +131 -0
  134. package/utils.d.ts +14 -0
  135. package/zig-structs.d.ts +155 -0
  136. package/zig.d.ts +351 -0
  137. package/dev/keypress-debug-renderer.ts +0 -148
  138. package/dev/keypress-debug.ts +0 -43
  139. package/dev/print-env-vars.ts +0 -32
  140. package/dev/test-tmux-graphics-334.sh +0 -68
  141. package/dev/thai-debug-test.ts +0 -68
  142. package/docs/development.md +0 -141
  143. package/docs/env-vars.md +0 -140
  144. package/docs/getting-started.md +0 -353
  145. package/docs/renderables-vs-constructs.md +0 -159
  146. package/docs/tree-sitter.md +0 -311
  147. package/scripts/build.ts +0 -400
  148. package/scripts/publish.ts +0 -60
  149. package/src/3d/SpriteResourceManager.ts +0 -286
  150. package/src/3d/SpriteUtils.ts +0 -71
  151. package/src/3d/TextureUtils.ts +0 -196
  152. package/src/3d/ThreeRenderable.ts +0 -197
  153. package/src/3d/WGPURenderer.ts +0 -294
  154. package/src/3d/animation/ExplodingSpriteEffect.ts +0 -513
  155. package/src/3d/animation/PhysicsExplodingSpriteEffect.ts +0 -429
  156. package/src/3d/animation/SpriteAnimator.ts +0 -633
  157. package/src/3d/animation/SpriteParticleGenerator.ts +0 -435
  158. package/src/3d/canvas.ts +0 -464
  159. package/src/3d/index.ts +0 -12
  160. package/src/3d/physics/PlanckPhysicsAdapter.ts +0 -72
  161. package/src/3d/physics/RapierPhysicsAdapter.ts +0 -66
  162. package/src/3d/physics/physics-interface.ts +0 -31
  163. package/src/3d/shaders/supersampling.wgsl +0 -201
  164. package/src/3d.ts +0 -3
  165. package/src/NativeSpanFeed.ts +0 -300
  166. package/src/Renderable.ts +0 -1698
  167. package/src/__snapshots__/buffer.test.ts.snap +0 -28
  168. package/src/animation/Timeline.test.ts +0 -2709
  169. package/src/animation/Timeline.ts +0 -598
  170. package/src/ansi.ts +0 -18
  171. package/src/benchmark/latest-all-bench-run.json +0 -707
  172. package/src/benchmark/latest-async-bench-run.json +0 -336
  173. package/src/benchmark/latest-default-bench-run.json +0 -657
  174. package/src/benchmark/latest-large-bench-run.json +0 -707
  175. package/src/benchmark/latest-quick-bench-run.json +0 -207
  176. package/src/benchmark/markdown-benchmark.ts +0 -1804
  177. package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
  178. package/src/benchmark/native-span-feed-benchmark.md +0 -56
  179. package/src/benchmark/native-span-feed-benchmark.ts +0 -596
  180. package/src/benchmark/native-span-feed-compare.ts +0 -280
  181. package/src/benchmark/renderer-benchmark.ts +0 -754
  182. package/src/benchmark/text-table-benchmark.ts +0 -947
  183. package/src/buffer.test.ts +0 -291
  184. package/src/buffer.ts +0 -519
  185. package/src/console.test.ts +0 -612
  186. package/src/console.ts +0 -1255
  187. package/src/edit-buffer.test.ts +0 -1769
  188. package/src/edit-buffer.ts +0 -411
  189. package/src/editor-view.test.ts +0 -1032
  190. package/src/editor-view.ts +0 -284
  191. package/src/examples/ascii-font-selection-demo.ts +0 -245
  192. package/src/examples/assets/Water_2_M_Normal.jpg +0 -0
  193. package/src/examples/assets/concrete.png +0 -0
  194. package/src/examples/assets/crate.png +0 -0
  195. package/src/examples/assets/crate_emissive.png +0 -0
  196. package/src/examples/assets/forrest_background.png +0 -0
  197. package/src/examples/assets/hast-example.json +0 -1018
  198. package/src/examples/assets/heart.png +0 -0
  199. package/src/examples/assets/main_char_heavy_attack.png +0 -0
  200. package/src/examples/assets/main_char_idle.png +0 -0
  201. package/src/examples/assets/main_char_jump_end.png +0 -0
  202. package/src/examples/assets/main_char_jump_landing.png +0 -0
  203. package/src/examples/assets/main_char_jump_start.png +0 -0
  204. package/src/examples/assets/main_char_run_loop.png +0 -0
  205. package/src/examples/assets/roughness_map.jpg +0 -0
  206. package/src/examples/build.ts +0 -115
  207. package/src/examples/code-demo.ts +0 -584
  208. package/src/examples/console-demo.ts +0 -358
  209. package/src/examples/core-plugin-slots-demo.ts +0 -759
  210. package/src/examples/diff-demo.ts +0 -699
  211. package/src/examples/draggable-three-demo.ts +0 -259
  212. package/src/examples/editor-demo.ts +0 -322
  213. package/src/examples/extmarks-demo.ts +0 -204
  214. package/src/examples/focus-restore-demo.ts +0 -310
  215. package/src/examples/fonts.ts +0 -245
  216. package/src/examples/fractal-shader-demo.ts +0 -268
  217. package/src/examples/framebuffer-demo.ts +0 -674
  218. package/src/examples/full-unicode-demo.ts +0 -181
  219. package/src/examples/golden-star-demo.ts +0 -933
  220. package/src/examples/grayscale-buffer-demo.ts +0 -249
  221. package/src/examples/hast-syntax-highlighting-demo.ts +0 -129
  222. package/src/examples/index.ts +0 -925
  223. package/src/examples/input-demo.ts +0 -377
  224. package/src/examples/input-select-layout-demo.ts +0 -425
  225. package/src/examples/install.sh +0 -143
  226. package/src/examples/keypress-debug-demo.ts +0 -452
  227. package/src/examples/lib/HexList.ts +0 -122
  228. package/src/examples/lib/PaletteGrid.ts +0 -125
  229. package/src/examples/lib/standalone-keys.ts +0 -25
  230. package/src/examples/lib/tab-controller.ts +0 -243
  231. package/src/examples/lights-phong-demo.ts +0 -290
  232. package/src/examples/link-demo.ts +0 -220
  233. package/src/examples/live-state-demo.ts +0 -480
  234. package/src/examples/markdown-demo.ts +0 -620
  235. package/src/examples/mouse-interaction-demo.ts +0 -428
  236. package/src/examples/nested-zindex-demo.ts +0 -357
  237. package/src/examples/opacity-example.ts +0 -235
  238. package/src/examples/opentui-demo.ts +0 -1057
  239. package/src/examples/physx-planck-2d-demo.ts +0 -507
  240. package/src/examples/physx-rapier-2d-demo.ts +0 -526
  241. package/src/examples/relative-positioning-demo.ts +0 -323
  242. package/src/examples/scroll-example.ts +0 -214
  243. package/src/examples/scrollbox-mouse-test.ts +0 -112
  244. package/src/examples/scrollbox-overlay-hit-test.ts +0 -206
  245. package/src/examples/select-demo.ts +0 -237
  246. package/src/examples/shader-cube-demo.ts +0 -772
  247. package/src/examples/simple-layout-example.ts +0 -591
  248. package/src/examples/slider-demo.ts +0 -617
  249. package/src/examples/split-mode-demo.ts +0 -445
  250. package/src/examples/sprite-animation-demo.ts +0 -443
  251. package/src/examples/sprite-particle-generator-demo.ts +0 -486
  252. package/src/examples/static-sprite-demo.ts +0 -193
  253. package/src/examples/sticky-scroll-example.ts +0 -308
  254. package/src/examples/styled-text-demo.ts +0 -282
  255. package/src/examples/tab-select-demo.ts +0 -219
  256. package/src/examples/terminal-title.ts +0 -29
  257. package/src/examples/terminal.ts +0 -305
  258. package/src/examples/text-node-demo.ts +0 -416
  259. package/src/examples/text-selection-demo.ts +0 -377
  260. package/src/examples/text-table-demo.ts +0 -503
  261. package/src/examples/text-truncation-demo.ts +0 -481
  262. package/src/examples/text-wrap.ts +0 -757
  263. package/src/examples/texture-loading-demo.ts +0 -259
  264. package/src/examples/timeline-example.ts +0 -670
  265. package/src/examples/transparency-demo.ts +0 -241
  266. package/src/examples/vnode-composition-demo.ts +0 -404
  267. package/src/index.ts +0 -22
  268. package/src/lib/KeyHandler.integration.test.ts +0 -292
  269. package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
  270. package/src/lib/KeyHandler.test.ts +0 -662
  271. package/src/lib/KeyHandler.ts +0 -222
  272. package/src/lib/RGBA.test.ts +0 -984
  273. package/src/lib/RGBA.ts +0 -204
  274. package/src/lib/ascii.font.ts +0 -330
  275. package/src/lib/border.test.ts +0 -83
  276. package/src/lib/border.ts +0 -168
  277. package/src/lib/bunfs.test.ts +0 -27
  278. package/src/lib/bunfs.ts +0 -18
  279. package/src/lib/clipboard.test.ts +0 -41
  280. package/src/lib/clipboard.ts +0 -47
  281. package/src/lib/clock.ts +0 -31
  282. package/src/lib/data-paths.test.ts +0 -133
  283. package/src/lib/data-paths.ts +0 -109
  284. package/src/lib/debounce.ts +0 -106
  285. package/src/lib/detect-links.test.ts +0 -98
  286. package/src/lib/detect-links.ts +0 -56
  287. package/src/lib/env.test.ts +0 -228
  288. package/src/lib/env.ts +0 -209
  289. package/src/lib/extmarks-history.ts +0 -51
  290. package/src/lib/extmarks-multiwidth.test.ts +0 -322
  291. package/src/lib/extmarks.test.ts +0 -3457
  292. package/src/lib/extmarks.ts +0 -843
  293. package/src/lib/fonts/block.json +0 -405
  294. package/src/lib/fonts/grid.json +0 -265
  295. package/src/lib/fonts/huge.json +0 -741
  296. package/src/lib/fonts/pallet.json +0 -314
  297. package/src/lib/fonts/shade.json +0 -591
  298. package/src/lib/fonts/slick.json +0 -321
  299. package/src/lib/fonts/tiny.json +0 -69
  300. package/src/lib/hast-styled-text.ts +0 -59
  301. package/src/lib/index.ts +0 -21
  302. package/src/lib/keymapping.test.ts +0 -280
  303. package/src/lib/keymapping.ts +0 -87
  304. package/src/lib/objects-in-viewport.test.ts +0 -787
  305. package/src/lib/objects-in-viewport.ts +0 -153
  306. package/src/lib/output.capture.ts +0 -58
  307. package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -340
  308. package/src/lib/parse.keypress-kitty.test.ts +0 -663
  309. package/src/lib/parse.keypress-kitty.ts +0 -439
  310. package/src/lib/parse.keypress.test.ts +0 -1849
  311. package/src/lib/parse.keypress.ts +0 -397
  312. package/src/lib/parse.mouse.test.ts +0 -552
  313. package/src/lib/parse.mouse.ts +0 -232
  314. package/src/lib/paste.ts +0 -16
  315. package/src/lib/queue.ts +0 -65
  316. package/src/lib/renderable.validations.test.ts +0 -87
  317. package/src/lib/renderable.validations.ts +0 -83
  318. package/src/lib/scroll-acceleration.ts +0 -98
  319. package/src/lib/selection.ts +0 -240
  320. package/src/lib/singleton.ts +0 -28
  321. package/src/lib/stdin-parser.test.ts +0 -1676
  322. package/src/lib/stdin-parser.ts +0 -1248
  323. package/src/lib/styled-text.ts +0 -178
  324. package/src/lib/terminal-capability-detection.test.ts +0 -202
  325. package/src/lib/terminal-capability-detection.ts +0 -79
  326. package/src/lib/terminal-palette.test.ts +0 -878
  327. package/src/lib/terminal-palette.ts +0 -383
  328. package/src/lib/tree-sitter/assets/README.md +0 -118
  329. package/src/lib/tree-sitter/assets/update.ts +0 -331
  330. package/src/lib/tree-sitter/assets.d.ts +0 -9
  331. package/src/lib/tree-sitter/cache.test.ts +0 -270
  332. package/src/lib/tree-sitter/client.test.ts +0 -1061
  333. package/src/lib/tree-sitter/client.ts +0 -615
  334. package/src/lib/tree-sitter/default-parsers.ts +0 -80
  335. package/src/lib/tree-sitter/download-utils.ts +0 -148
  336. package/src/lib/tree-sitter/index.ts +0 -28
  337. package/src/lib/tree-sitter/parser.worker.ts +0 -1001
  338. package/src/lib/tree-sitter/parsers-config.ts +0 -75
  339. package/src/lib/tree-sitter/resolve-ft.ts +0 -62
  340. package/src/lib/tree-sitter/types.ts +0 -81
  341. package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
  342. package/src/lib/tree-sitter-styled-text.ts +0 -306
  343. package/src/lib/validate-dir-name.ts +0 -55
  344. package/src/lib/yoga.options.test.ts +0 -628
  345. package/src/lib/yoga.options.ts +0 -346
  346. package/src/plugins/core-slot.ts +0 -579
  347. package/src/plugins/registry.ts +0 -377
  348. package/src/plugins/types.ts +0 -46
  349. package/src/post/filters.ts +0 -888
  350. package/src/renderables/ASCIIFont.ts +0 -219
  351. package/src/renderables/Box.test.ts +0 -160
  352. package/src/renderables/Box.ts +0 -295
  353. package/src/renderables/Code.test.ts +0 -2062
  354. package/src/renderables/Code.ts +0 -357
  355. package/src/renderables/Diff.regression.test.ts +0 -226
  356. package/src/renderables/Diff.test.ts +0 -3027
  357. package/src/renderables/Diff.ts +0 -1209
  358. package/src/renderables/EditBufferRenderable.ts +0 -764
  359. package/src/renderables/FrameBuffer.ts +0 -47
  360. package/src/renderables/Input.test.ts +0 -1228
  361. package/src/renderables/Input.ts +0 -245
  362. package/src/renderables/LineNumberRenderable.ts +0 -675
  363. package/src/renderables/Markdown.ts +0 -1106
  364. package/src/renderables/ScrollBar.ts +0 -422
  365. package/src/renderables/ScrollBox.ts +0 -883
  366. package/src/renderables/Select.test.ts +0 -1010
  367. package/src/renderables/Select.ts +0 -523
  368. package/src/renderables/Slider.test.ts +0 -456
  369. package/src/renderables/Slider.ts +0 -347
  370. package/src/renderables/TabSelect.test.ts +0 -197
  371. package/src/renderables/TabSelect.ts +0 -455
  372. package/src/renderables/Text.selection-buffer.test.ts +0 -123
  373. package/src/renderables/Text.test.ts +0 -2660
  374. package/src/renderables/Text.ts +0 -147
  375. package/src/renderables/TextBufferRenderable.ts +0 -518
  376. package/src/renderables/TextNode.test.ts +0 -1058
  377. package/src/renderables/TextNode.ts +0 -325
  378. package/src/renderables/TextTable.test.ts +0 -1421
  379. package/src/renderables/TextTable.ts +0 -1344
  380. package/src/renderables/Textarea.ts +0 -732
  381. package/src/renderables/TimeToFirstDraw.ts +0 -89
  382. package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
  383. package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
  384. package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
  385. package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
  386. package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
  387. package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -816
  388. package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1787
  389. package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
  390. package/src/renderables/__tests__/Markdown.test.ts +0 -2287
  391. package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
  392. package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -682
  393. package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
  394. package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2041
  395. package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
  396. package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
  397. package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
  398. package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3149
  399. package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
  400. package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1864
  401. package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
  402. package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1590
  403. package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
  404. package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
  405. package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
  406. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
  407. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
  408. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
  409. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
  410. package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
  411. package/src/renderables/__tests__/markdown-parser.test.ts +0 -217
  412. package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
  413. package/src/renderables/composition/README.md +0 -8
  414. package/src/renderables/composition/VRenderable.ts +0 -32
  415. package/src/renderables/composition/constructs.ts +0 -127
  416. package/src/renderables/composition/vnode.ts +0 -289
  417. package/src/renderables/index.ts +0 -22
  418. package/src/renderables/markdown-parser.ts +0 -66
  419. package/src/renderer.ts +0 -2363
  420. package/src/runtime-plugin-support.ts +0 -39
  421. package/src/runtime-plugin.ts +0 -144
  422. package/src/syntax-style.test.ts +0 -841
  423. package/src/syntax-style.ts +0 -264
  424. package/src/testing/README.md +0 -210
  425. package/src/testing/capture-spans.test.ts +0 -194
  426. package/src/testing/integration.test.ts +0 -276
  427. package/src/testing/manual-clock.ts +0 -106
  428. package/src/testing/mock-keys.test.ts +0 -1356
  429. package/src/testing/mock-keys.ts +0 -449
  430. package/src/testing/mock-mouse.test.ts +0 -218
  431. package/src/testing/mock-mouse.ts +0 -247
  432. package/src/testing/mock-tree-sitter-client.ts +0 -73
  433. package/src/testing/spy.ts +0 -13
  434. package/src/testing/test-recorder.test.ts +0 -415
  435. package/src/testing/test-recorder.ts +0 -145
  436. package/src/testing/test-renderer.ts +0 -116
  437. package/src/testing.ts +0 -7
  438. package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
  439. package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
  440. package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
  441. package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
  442. package/src/tests/allocator-stats.test.ts +0 -38
  443. package/src/tests/destroy-during-render.test.ts +0 -200
  444. package/src/tests/hover-cursor.test.ts +0 -98
  445. package/src/tests/native-span-feed-async.test.ts +0 -173
  446. package/src/tests/native-span-feed-close.test.ts +0 -120
  447. package/src/tests/native-span-feed-coverage.test.ts +0 -227
  448. package/src/tests/native-span-feed-edge-cases.test.ts +0 -352
  449. package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
  450. package/src/tests/opacity.test.ts +0 -123
  451. package/src/tests/renderable.snapshot.test.ts +0 -524
  452. package/src/tests/renderable.test.ts +0 -1281
  453. package/src/tests/renderer.console-startup.test.ts +0 -65
  454. package/src/tests/renderer.control.test.ts +0 -364
  455. package/src/tests/renderer.core-slot-binding.test.ts +0 -952
  456. package/src/tests/renderer.cursor.test.ts +0 -26
  457. package/src/tests/renderer.destroy-during-render.test.ts +0 -110
  458. package/src/tests/renderer.focus-restore.test.ts +0 -228
  459. package/src/tests/renderer.focus.test.ts +0 -251
  460. package/src/tests/renderer.idle.test.ts +0 -219
  461. package/src/tests/renderer.input.test.ts +0 -2145
  462. package/src/tests/renderer.kitty-flags.test.ts +0 -195
  463. package/src/tests/renderer.mouse.test.ts +0 -1269
  464. package/src/tests/renderer.palette.test.ts +0 -629
  465. package/src/tests/renderer.selection.test.ts +0 -49
  466. package/src/tests/renderer.slot-registry.test.ts +0 -649
  467. package/src/tests/renderer.useMouse.test.ts +0 -50
  468. package/src/tests/runtime-plugin-support.fixture.ts +0 -11
  469. package/src/tests/runtime-plugin-support.test.ts +0 -28
  470. package/src/tests/runtime-plugin.fixture.ts +0 -40
  471. package/src/tests/runtime-plugin.test.ts +0 -190
  472. package/src/tests/scrollbox-culling-bug.test.ts +0 -114
  473. package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
  474. package/src/tests/scrollbox-hitgrid.test.ts +0 -909
  475. package/src/tests/scrollbox.test.ts +0 -1530
  476. package/src/tests/wrap-resize-perf.test.ts +0 -229
  477. package/src/tests/yoga-setters.test.ts +0 -921
  478. package/src/text-buffer-view.test.ts +0 -705
  479. package/src/text-buffer-view.ts +0 -189
  480. package/src/text-buffer.test.ts +0 -347
  481. package/src/text-buffer.ts +0 -250
  482. package/src/types.ts +0 -152
  483. package/src/utils.ts +0 -88
  484. package/src/zig/ansi.zig +0 -268
  485. package/src/zig/bench/README.md +0 -50
  486. package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -887
  487. package/src/zig/bench/edit-buffer_bench.zig +0 -476
  488. package/src/zig/bench/native-span-feed_bench.zig +0 -100
  489. package/src/zig/bench/rope-markers_bench.zig +0 -713
  490. package/src/zig/bench/rope_bench.zig +0 -514
  491. package/src/zig/bench/styled-text_bench.zig +0 -470
  492. package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
  493. package/src/zig/bench/text-buffer-view_bench.zig +0 -459
  494. package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -273
  495. package/src/zig/bench/utf8_bench.zig +0 -799
  496. package/src/zig/bench-utils.zig +0 -431
  497. package/src/zig/bench.zig +0 -217
  498. package/src/zig/buffer.zig +0 -2223
  499. package/src/zig/build.zig +0 -289
  500. package/src/zig/build.zig.zon +0 -16
  501. package/src/zig/edit-buffer.zig +0 -825
  502. package/src/zig/editor-view.zig +0 -802
  503. package/src/zig/event-bus.zig +0 -13
  504. package/src/zig/event-emitter.zig +0 -65
  505. package/src/zig/file-logger.zig +0 -92
  506. package/src/zig/grapheme.zig +0 -599
  507. package/src/zig/lib.zig +0 -1834
  508. package/src/zig/link.zig +0 -333
  509. package/src/zig/logger.zig +0 -43
  510. package/src/zig/mem-registry.zig +0 -125
  511. package/src/zig/native-span-feed-bench-lib.zig +0 -7
  512. package/src/zig/native-span-feed.zig +0 -708
  513. package/src/zig/renderer.zig +0 -1386
  514. package/src/zig/rope.zig +0 -1220
  515. package/src/zig/syntax-style.zig +0 -161
  516. package/src/zig/terminal.zig +0 -975
  517. package/src/zig/test.zig +0 -70
  518. package/src/zig/tests/README.md +0 -18
  519. package/src/zig/tests/buffer_test.zig +0 -2526
  520. package/src/zig/tests/edit-buffer-history_test.zig +0 -271
  521. package/src/zig/tests/edit-buffer_test.zig +0 -1689
  522. package/src/zig/tests/editor-view_test.zig +0 -3299
  523. package/src/zig/tests/event-emitter_test.zig +0 -249
  524. package/src/zig/tests/grapheme_test.zig +0 -1304
  525. package/src/zig/tests/link_test.zig +0 -190
  526. package/src/zig/tests/mem-registry_test.zig +0 -473
  527. package/src/zig/tests/memory_leak_regression_test.zig +0 -159
  528. package/src/zig/tests/native-span-feed_test.zig +0 -1264
  529. package/src/zig/tests/renderer_test.zig +0 -1010
  530. package/src/zig/tests/rope-nested_test.zig +0 -712
  531. package/src/zig/tests/rope_fuzz_test.zig +0 -238
  532. package/src/zig/tests/rope_test.zig +0 -2362
  533. package/src/zig/tests/segment-merge.test.zig +0 -148
  534. package/src/zig/tests/syntax-style_test.zig +0 -557
  535. package/src/zig/tests/terminal_test.zig +0 -719
  536. package/src/zig/tests/text-buffer-drawing_test.zig +0 -3237
  537. package/src/zig/tests/text-buffer-highlights_test.zig +0 -666
  538. package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
  539. package/src/zig/tests/text-buffer-segment_test.zig +0 -320
  540. package/src/zig/tests/text-buffer-selection_test.zig +0 -1035
  541. package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
  542. package/src/zig/tests/text-buffer-view_test.zig +0 -3649
  543. package/src/zig/tests/text-buffer_test.zig +0 -2191
  544. package/src/zig/tests/unicode-width-map.zon +0 -3909
  545. package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
  546. package/src/zig/tests/utf8_test.zig +0 -4057
  547. package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
  548. package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
  549. package/src/zig/tests/word-wrap-editing_test.zig +0 -498
  550. package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
  551. package/src/zig/text-buffer-iterators.zig +0 -499
  552. package/src/zig/text-buffer-segment.zig +0 -404
  553. package/src/zig/text-buffer-view.zig +0 -1371
  554. package/src/zig/text-buffer.zig +0 -1180
  555. package/src/zig/utf8.zig +0 -1948
  556. package/src/zig/utils.zig +0 -9
  557. package/src/zig-structs.ts +0 -261
  558. package/src/zig.ts +0 -3843
  559. package/tsconfig.build.json +0 -22
  560. package/tsconfig.json +0 -28
  561. /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
  562. /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
  563. /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
  564. /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
  565. /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
  566. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
  567. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  568. /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
  569. /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
  570. /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
  571. /package/{src/lib/tree-sitter/assets → assets}/zig/tree-sitter-zig.wasm +0 -0
@@ -1,708 +0,0 @@
1
- const std = @import("std");
2
-
3
- pub const CallbackFn = fn (stream_ptr: usize, event_id: u32, arg0: usize, arg1: u64) callconv(.c) void;
4
-
5
- pub const GrowthPolicy = enum(u8) {
6
- grow = 0,
7
- block = 1,
8
- };
9
-
10
- pub const Options = extern struct {
11
- chunk_size: u32,
12
- initial_chunks: u32,
13
- max_bytes: u64,
14
- growth_policy: u8,
15
- auto_commit_on_full: u8,
16
- span_queue_capacity: u32,
17
- };
18
-
19
- pub const Stats = extern struct {
20
- bytes_written: u64,
21
- spans_committed: u64,
22
- chunks: u32,
23
- pending_spans: u32,
24
- };
25
-
26
- const Chunk = struct {
27
- ptr: [*]u8,
28
- len: u32,
29
- };
30
-
31
- pub const SpanInfo = extern struct {
32
- chunk_ptr: usize,
33
- offset: u32,
34
- len: u32,
35
- chunk_index: u32,
36
- reserved: u32,
37
-
38
- pub fn slice(self: SpanInfo) []u8 {
39
- const base: [*]u8 = @ptrFromInt(self.chunk_ptr);
40
- const start: usize = @intCast(self.offset);
41
- const length: usize = @intCast(self.len);
42
- return base[start .. start + length];
43
- }
44
- };
45
-
46
- const SpanRing = struct {
47
- buffer: []SpanInfo,
48
- capacity: u32,
49
- head: u32,
50
- tail: u32,
51
-
52
- pub fn count(self: *SpanRing) u32 {
53
- return self.tail -% self.head;
54
- }
55
-
56
- pub fn push(self: *SpanRing, stream: *Stream, span: SpanInfo, notify: *bool) StreamError!void {
57
- const capacity = self.capacity;
58
- const head = self.head;
59
- var tail = self.tail;
60
- const queued = tail -% head;
61
-
62
- if (queued >= capacity) {
63
- return StreamError.NoSpace;
64
- }
65
-
66
- const index = tail % capacity;
67
- self.buffer[index] = span;
68
- tail +%= 1;
69
- self.tail = tail;
70
- const new_count = queued + 1;
71
-
72
- stream.stats.pending_spans = new_count;
73
- if (stream.attached and stream.callback != null) {
74
- if (queued < notify_threshold_default and new_count >= notify_threshold_default) {
75
- notify.* = true;
76
- }
77
- }
78
- }
79
-
80
- pub fn popMany(self: *SpanRing, out: []SpanInfo) u32 {
81
- const available = self.tail -% self.head;
82
- if (available == 0) return 0;
83
- const to_read: u32 = if (available < out.len) @intCast(available) else @intCast(out.len);
84
-
85
- var i: u32 = 0;
86
- while (i < to_read) : (i += 1) {
87
- const index = (self.head +% i) % self.capacity;
88
- out[i] = self.buffer[index];
89
- }
90
- self.head +%= to_read;
91
- return to_read;
92
- }
93
- };
94
-
95
- pub const ReserveInfo = extern struct {
96
- ptr: usize,
97
- len: u32,
98
- reserved: u32,
99
-
100
- pub fn slice(self: ReserveInfo) []u8 {
101
- const base: [*]u8 = @ptrFromInt(self.ptr);
102
- const length: usize = @intCast(self.len);
103
- return base[0..length];
104
- }
105
- };
106
-
107
- pub const Stream = struct {
108
- allocator: std.mem.Allocator,
109
- options: Options,
110
- chunks: std.ArrayList(Chunk),
111
- current_chunk_index: usize,
112
- write_offset: usize,
113
- pending_chunk_index: usize,
114
- pending_offset: usize,
115
- pending_len: usize,
116
- reserved_active: bool,
117
- reserved_chunk_index: usize,
118
- reserved_offset: usize,
119
- reserved_len: usize,
120
- attached: bool,
121
- callback: ?*const CallbackFn,
122
- closed: bool,
123
- span_ring: SpanRing,
124
- state_buffer: []u8,
125
- state_capacity: u32,
126
- stats: Stats,
127
-
128
- pub fn create(allocator: std.mem.Allocator, options: ?Options) StreamError!*Stream {
129
- const opts = normalizeOptions(options orelse defaultOptions());
130
- const stream = allocator.create(Stream) catch return StreamError.OutOfMemory;
131
- stream.* = .{
132
- .allocator = allocator,
133
- .options = opts,
134
- .chunks = std.ArrayList(Chunk).empty,
135
- .current_chunk_index = 0,
136
- .write_offset = 0,
137
- .pending_chunk_index = 0,
138
- .pending_offset = 0,
139
- .pending_len = 0,
140
- .reserved_active = false,
141
- .reserved_chunk_index = 0,
142
- .reserved_offset = 0,
143
- .reserved_len = 0,
144
- .attached = false,
145
- .callback = null,
146
- .closed = false,
147
- .span_ring = .{
148
- .buffer = &[_]SpanInfo{},
149
- .capacity = 0,
150
- .head = 0,
151
- .tail = 0,
152
- },
153
- .state_buffer = &[_]u8{},
154
- .state_capacity = 0,
155
- .stats = .{
156
- .bytes_written = 0,
157
- .spans_committed = 0,
158
- .chunks = 0,
159
- .pending_spans = 0,
160
- },
161
- };
162
-
163
- errdefer stream.destroy();
164
-
165
- const ring_capacity = opts.span_queue_capacity;
166
- const ring_buffer = allocator.alloc(SpanInfo, ring_capacity) catch return StreamError.OutOfMemory;
167
- stream.span_ring = .{
168
- .buffer = ring_buffer,
169
- .capacity = ring_capacity,
170
- .head = 0,
171
- .tail = 0,
172
- };
173
-
174
- try stream.ensureStateCapacity(@intCast(opts.initial_chunks));
175
-
176
- const initial = @as(usize, opts.initial_chunks);
177
- var i: usize = 0;
178
- while (i < initial) : (i += 1) {
179
- try stream.addChunkLocked();
180
- }
181
- stream.stats.chunks = @intCast(stream.chunks.items.len);
182
- return stream;
183
- }
184
-
185
- pub fn attach(self: *Stream) StreamError!void {
186
- if (self.closed) return StreamError.Invalid;
187
-
188
- var notify = false;
189
- var queued: u32 = 0;
190
- defer self.finish(notify, queued);
191
-
192
- self.attached = true;
193
- if (self.callback == null) return;
194
-
195
- self.emitStateBuffer();
196
-
197
- for (self.chunks.items) |chunk| {
198
- self.emitChunkAdded(chunk);
199
- }
200
-
201
- queued = self.span_ring.count();
202
- if (queued > 0) {
203
- notify = true;
204
- }
205
- }
206
-
207
- pub fn setCallback(self: *Stream, cb: ?*const CallbackFn) void {
208
- self.callback = cb;
209
- if (cb == null or !self.attached) return;
210
-
211
- self.emitStateBuffer();
212
- for (self.chunks.items) |chunk| {
213
- self.emitChunkAdded(chunk);
214
- }
215
- const queued = self.span_ring.count();
216
- if (queued > 0) {
217
- self.emitDataAvailable(queued);
218
- }
219
- }
220
-
221
- pub fn write(self: *Stream, data: []const u8) StreamError!void {
222
- if (self.closed) return StreamError.Invalid;
223
- if (data.len == 0) return;
224
- if (self.reserved_active) return StreamError.Busy;
225
-
226
- var notify = false;
227
- // finish() must run on success and error so committed spans notify.
228
- defer self.finish(notify, 0);
229
-
230
- var remaining = data.len;
231
- var src_index: usize = 0;
232
- const auto_commit = self.options.auto_commit_on_full != 0;
233
- const chunk_len = self.options.chunk_size;
234
-
235
- while (remaining > 0) {
236
- var available = @as(usize, chunk_len) - self.write_offset;
237
- if (available == 0) {
238
- if (self.pending_len > 0) {
239
- try self.commitLocked(&notify);
240
- }
241
- try self.ensureWritableChunkLocked();
242
- available = @as(usize, chunk_len);
243
- }
244
-
245
- if (remaining > available and !auto_commit) {
246
- return StreamError.NoSpace;
247
- }
248
-
249
- const to_write = if (remaining < available) remaining else available;
250
- if (self.pending_len == 0) {
251
- self.pending_chunk_index = self.current_chunk_index;
252
- self.pending_offset = self.write_offset;
253
- }
254
-
255
- const chunk = self.chunks.items[self.current_chunk_index];
256
- @memcpy(chunk.ptr[self.write_offset .. self.write_offset + to_write], data[src_index .. src_index + to_write]);
257
-
258
- self.write_offset += to_write;
259
- self.pending_len += to_write;
260
- self.stats.bytes_written += @as(u64, to_write);
261
- src_index += to_write;
262
- remaining -= to_write;
263
-
264
- if (self.write_offset == @as(usize, chunk_len) and auto_commit) {
265
- try self.commitLocked(&notify);
266
- if (remaining > 0) {
267
- try self.ensureWritableChunkLocked();
268
- }
269
- }
270
- }
271
- }
272
-
273
- pub fn reserve(self: *Stream, min_len: u32) StreamError!ReserveInfo {
274
- if (self.closed) return StreamError.Invalid;
275
- return self.reserveLocked(min_len);
276
- }
277
-
278
- pub fn commitReserved(self: *Stream, len: u32) StreamError!void {
279
- if (self.closed) return StreamError.Invalid;
280
-
281
- var notify = false;
282
- defer self.finish(notify, 0);
283
- try self.commitReservedLocked(len, &notify);
284
- }
285
-
286
- pub fn commit(self: *Stream) StreamError!void {
287
- if (self.closed) return StreamError.Invalid;
288
- var notify = false;
289
- defer self.finish(notify, 0);
290
- if (self.reserved_active) return StreamError.Busy;
291
- try self.commitLocked(&notify);
292
- }
293
-
294
- pub fn getStats(self: *Stream) Stats {
295
- var out: Stats = undefined;
296
- out = self.stats;
297
- return out;
298
- }
299
-
300
- /// Apply only runtime-safe options; creation-time fields are ignored.
301
- pub fn setOptions(self: *Stream, options: Options) StreamError!void {
302
- if (self.closed) return StreamError.Invalid;
303
- self.options.max_bytes = options.max_bytes;
304
- self.options.growth_policy = options.growth_policy;
305
- self.options.auto_commit_on_full = options.auto_commit_on_full;
306
- }
307
-
308
- pub fn close(self: *Stream) StreamError!void {
309
- var notify = false;
310
- if (self.closed) {
311
- return;
312
- }
313
- if (self.reserved_active) {
314
- return StreamError.Busy;
315
- }
316
- if (self.pending_len > 0) {
317
- try self.commitLocked(&notify);
318
- }
319
- self.closed = true;
320
- self.attached = false;
321
- self.finish(notify, 0);
322
- self.emitClosed();
323
- }
324
-
325
- pub fn destroy(self: *Stream) void {
326
- if (!self.closed) {
327
- _ = self.close() catch {};
328
- }
329
- for (self.chunks.items) |chunk| {
330
- self.allocator.free(chunk.ptr[0..@as(usize, chunk.len)]);
331
- }
332
- self.chunks.deinit(self.allocator);
333
- if (self.span_ring.capacity > 0) {
334
- self.allocator.free(self.span_ring.buffer);
335
- }
336
- if (self.state_capacity > 0) {
337
- self.allocator.free(self.state_buffer);
338
- }
339
- self.allocator.destroy(self);
340
- }
341
-
342
- pub fn drainSpans(self: *Stream, out: []SpanInfo) u32 {
343
- if (out.len == 0) return 0;
344
- const count = self.span_ring.popMany(out);
345
- self.stats.pending_spans = self.span_ring.count();
346
- return count;
347
- }
348
-
349
- pub fn hasPendingSpans(self: *Stream) bool {
350
- return self.span_ring.count() > 0;
351
- }
352
-
353
- pub fn stateBuffer(self: *Stream) []u8 {
354
- return self.state_buffer;
355
- }
356
-
357
- pub fn markChunkFree(self: *Stream, chunk_index: u32) void {
358
- if (chunk_index < self.state_capacity) {
359
- self.state_buffer[chunk_index] -|= 1;
360
- }
361
- }
362
-
363
- pub fn markSpanConsumed(self: *Stream, span: SpanInfo) void {
364
- self.markChunkFree(span.chunk_index);
365
- }
366
-
367
- pub fn finish(self: *Stream, notify: bool, queued_override: u32) void {
368
- if (notify and self.callback != null) {
369
- const queued = if (queued_override != 0)
370
- queued_override
371
- else
372
- self.span_ring.count();
373
- if (queued > 0) self.emitDataAvailable(queued);
374
- }
375
- }
376
-
377
- fn ensureStateCapacity(self: *Stream, required: u32) StreamError!void {
378
- if (required <= self.state_capacity) return;
379
- var new_capacity: u32 = if (self.state_capacity == 0) 1 else self.state_capacity;
380
- while (new_capacity < required) : (new_capacity *= 2) {}
381
- const new_buffer = self.allocator.alloc(u8, new_capacity) catch return StreamError.OutOfMemory;
382
- @memset(new_buffer, 0);
383
- if (self.state_capacity > 0) {
384
- std.mem.copyForwards(u8, new_buffer[0..self.state_capacity], self.state_buffer);
385
- self.allocator.free(self.state_buffer);
386
- }
387
- self.state_buffer = new_buffer;
388
- self.state_capacity = new_capacity;
389
- if (self.attached and self.callback != null) {
390
- self.emitStateBuffer();
391
- }
392
- }
393
-
394
- fn isChunkFree(self: *Stream, index: usize) bool {
395
- if (index >= self.state_capacity) return true;
396
- return self.state_buffer[index] == 0;
397
- }
398
-
399
- pub fn commitLocked(self: *Stream, notify: *bool) StreamError!void {
400
- if (self.pending_len == 0) return;
401
- const chunk = self.chunks.items[self.pending_chunk_index];
402
- const info = SpanInfo{
403
- .chunk_ptr = @intFromPtr(chunk.ptr),
404
- .offset = @intCast(self.pending_offset),
405
- .len = @intCast(self.pending_len),
406
- .chunk_index = @intCast(self.pending_chunk_index),
407
- .reserved = 0,
408
- };
409
- try self.span_ring.push(self, info, notify);
410
- if (self.pending_chunk_index < self.state_capacity) {
411
- self.state_buffer[self.pending_chunk_index] +|= 1;
412
- // Avoid refcount saturation, which can corrupt data.
413
- if (self.state_buffer[self.pending_chunk_index] == 255) {
414
- self.write_offset = self.options.chunk_size;
415
- }
416
- }
417
- self.stats.spans_committed += 1;
418
- self.pending_len = 0;
419
- self.pending_offset = self.write_offset;
420
- self.pending_chunk_index = self.current_chunk_index;
421
- }
422
-
423
- pub fn reserveLocked(self: *Stream, min_len: u32) StreamError!ReserveInfo {
424
- if (self.reserved_active) return StreamError.Busy;
425
- if (self.pending_len != 0) return StreamError.Busy;
426
-
427
- try self.ensureWritableChunkLocked();
428
-
429
- const chunk = self.chunks.items[self.current_chunk_index];
430
- const available = @as(usize, chunk.len) - self.write_offset;
431
- if (available < min_len) return StreamError.NoSpace;
432
-
433
- self.reserved_active = true;
434
- self.reserved_chunk_index = self.current_chunk_index;
435
- self.reserved_offset = self.write_offset;
436
- self.reserved_len = available;
437
-
438
- return .{
439
- .ptr = @intFromPtr(chunk.ptr + self.write_offset),
440
- .len = @intCast(available),
441
- .reserved = 0,
442
- };
443
- }
444
-
445
- pub fn commitReservedLocked(self: *Stream, len: u32, notify: *bool) StreamError!void {
446
- if (!self.reserved_active) return StreamError.Invalid;
447
- if (len > self.reserved_len) return StreamError.NoSpace;
448
-
449
- self.pending_chunk_index = self.reserved_chunk_index;
450
- self.pending_offset = self.reserved_offset;
451
- self.pending_len = len;
452
- self.write_offset = self.reserved_offset + len;
453
- self.reserved_active = false;
454
- self.reserved_len = 0;
455
-
456
- self.stats.bytes_written += @as(u64, len);
457
-
458
- try self.commitLocked(notify);
459
- }
460
-
461
- fn addChunkLocked(self: *Stream) StreamError!void {
462
- const chunk_size: u32 = self.options.chunk_size;
463
- const max_bytes = self.options.max_bytes;
464
- const allocated = @as(u64, self.chunks.items.len) * @as(u64, chunk_size);
465
- if (max_bytes != 0 and allocated + @as(u64, chunk_size) > max_bytes) {
466
- return StreamError.MaxBytes;
467
- }
468
-
469
- // Grow state buffer first to keep chunk/refcount in sync on failure.
470
- try self.ensureStateCapacity(@as(u32, @intCast(self.chunks.items.len)) + 1);
471
-
472
- const mem = self.allocator.alloc(u8, chunk_size) catch return StreamError.OutOfMemory;
473
- errdefer self.allocator.free(mem);
474
- const chunk = Chunk{ .ptr = mem.ptr, .len = chunk_size };
475
- self.chunks.append(self.allocator, chunk) catch return StreamError.OutOfMemory;
476
- self.stats.chunks = @intCast(self.chunks.items.len);
477
- if (self.attached and self.callback != null) {
478
- self.emitChunkAdded(chunk);
479
- }
480
- }
481
-
482
- fn ensureWritableChunkLocked(self: *Stream) StreamError!void {
483
- const total = self.chunks.items.len;
484
- if (total == 0) return StreamError.Invalid;
485
-
486
- var attempts: usize = 0;
487
- var index = self.current_chunk_index % total;
488
- while (attempts < total) : (attempts += 1) {
489
- if (self.isChunkFree(index)) {
490
- self.current_chunk_index = index;
491
- self.write_offset = 0;
492
- self.pending_chunk_index = index;
493
- self.pending_offset = 0;
494
- self.pending_len = 0;
495
- return;
496
- }
497
- index = (index + 1) % total;
498
- }
499
-
500
- if (self.options.growth_policy == @intFromEnum(GrowthPolicy.block)) {
501
- return StreamError.NoSpace;
502
- }
503
-
504
- try self.addChunkLocked();
505
- const new_total = self.chunks.items.len;
506
- if (new_total == 0) return StreamError.Invalid;
507
- self.current_chunk_index = new_total - 1;
508
- self.write_offset = 0;
509
- self.pending_chunk_index = self.current_chunk_index;
510
- self.pending_offset = 0;
511
- self.pending_len = 0;
512
- }
513
-
514
- fn emitChunkAdded(self: *Stream, chunk: Chunk) void {
515
- if (self.callback) |cb| {
516
- cb(@intFromPtr(self), Event.ChunkAdded, @intFromPtr(chunk.ptr), chunk.len);
517
- }
518
- }
519
-
520
- fn emitDataAvailable(self: *Stream, count: u32) void {
521
- if (self.callback) |cb| {
522
- cb(@intFromPtr(self), Event.DataAvailable, count, 0);
523
- }
524
- }
525
-
526
- fn emitStateBuffer(self: *Stream) void {
527
- if (self.callback) |cb| {
528
- cb(@intFromPtr(self), Event.StateBuffer, @intFromPtr(self.state_buffer.ptr), self.state_capacity);
529
- }
530
- }
531
-
532
- fn emitClosed(self: *Stream) void {
533
- if (self.callback) |cb| {
534
- cb(@intFromPtr(self), Event.Closed, 0, 0);
535
- }
536
- }
537
- };
538
-
539
- pub const default_pattern = "\x1b[32mnative-span-feed\x1b[0m\n";
540
- const span_queue_capacity_default: u32 = 4096;
541
- const notify_threshold_default: u32 = 1;
542
-
543
- pub const EventId = enum(u32) {
544
- ChunkAdded = 2,
545
- Closed = 5,
546
- Error = 6,
547
- DataAvailable = 7,
548
- StateBuffer = 8,
549
- };
550
-
551
- const Event = struct {
552
- pub const ChunkAdded: u32 = @intFromEnum(EventId.ChunkAdded);
553
- pub const Closed: u32 = @intFromEnum(EventId.Closed);
554
- pub const Error: u32 = @intFromEnum(EventId.Error);
555
- pub const DataAvailable: u32 = @intFromEnum(EventId.DataAvailable);
556
- pub const StateBuffer: u32 = @intFromEnum(EventId.StateBuffer);
557
- };
558
-
559
- pub const Status = struct {
560
- pub const ok: i32 = 0;
561
- pub const err_no_space: i32 = -1;
562
- pub const err_max_bytes: i32 = -2;
563
- pub const err_invalid: i32 = -3;
564
- pub const err_alloc: i32 = -4;
565
- pub const err_busy: i32 = -5;
566
- };
567
-
568
- pub const StreamError = error{
569
- NoSpace,
570
- MaxBytes,
571
- Invalid,
572
- OutOfMemory,
573
- Busy,
574
- };
575
-
576
- pub fn defaultOptions() Options {
577
- return .{
578
- .chunk_size = 64 * 1024,
579
- .initial_chunks = 2,
580
- .max_bytes = 0,
581
- .growth_policy = @intFromEnum(GrowthPolicy.grow),
582
- .auto_commit_on_full = 1,
583
- .span_queue_capacity = 0,
584
- };
585
- }
586
-
587
- pub fn normalizeOptions(opts: Options) Options {
588
- var out = opts;
589
- if (out.chunk_size == 0) out.chunk_size = 64 * 1024;
590
- if (out.initial_chunks == 0) out.initial_chunks = 1;
591
- if (out.span_queue_capacity == 0) out.span_queue_capacity = span_queue_capacity_default;
592
- return out;
593
- }
594
-
595
- fn errorToStatus(err: StreamError) i32 {
596
- return switch (err) {
597
- StreamError.NoSpace => Status.err_no_space,
598
- StreamError.MaxBytes => Status.err_max_bytes,
599
- StreamError.Invalid => Status.err_invalid,
600
- StreamError.OutOfMemory => Status.err_alloc,
601
- StreamError.Busy => Status.err_busy,
602
- };
603
- }
604
-
605
- pub fn createNativeSpanFeedWithAllocator(allocator: std.mem.Allocator, options_ptr: ?*const Options) ?*Stream {
606
- const opts = normalizeOptions(if (options_ptr) |p| p.* else defaultOptions());
607
- return Stream.create(allocator, opts) catch null;
608
- }
609
-
610
- pub export fn streamSetCallback(stream: ?*Stream, callback: ?*const CallbackFn) void {
611
- if (stream == null) return;
612
- stream.?.setCallback(callback);
613
- }
614
-
615
- pub export fn attachNativeSpanFeed(stream: ?*Stream) i32 {
616
- if (stream == null) return Status.err_invalid;
617
- const s = stream.?;
618
- s.attach() catch |err| return errorToStatus(err);
619
- return Status.ok;
620
- }
621
-
622
- pub export fn streamClose(stream: ?*Stream) i32 {
623
- if (stream == null) return Status.err_invalid;
624
- const s = stream.?;
625
- s.close() catch |err| return errorToStatus(err);
626
- return Status.ok;
627
- }
628
-
629
- pub export fn destroyNativeSpanFeed(stream: ?*Stream) void {
630
- if (stream == null) return;
631
- const s = stream.?;
632
- s.destroy();
633
- }
634
-
635
- /// Copy API: copies len bytes from src_ptr into the stream's chunk pool.
636
- /// Handles spanning across multiple chunks automatically. If auto_commit_on_full
637
- /// is enabled, commits and emits DataAvailable each time a chunk fills.
638
- /// Best for producers that already have data in a buffer (formatted output,
639
- /// serialized messages, file contents).
640
- /// When auto_commit_on_full is disabled, writes are all-or-nothing per
641
- /// chunk boundary: a write that fits in the remaining space succeeds,
642
- /// but a write that would exceed it returns err_no_space without writing
643
- /// any bytes. A write that exactly fills the chunk succeeds; the next
644
- /// write will move to a new chunk (committing the full one first).
645
- pub export fn streamWrite(stream: ?*Stream, src_ptr: ?*const u8, len: usize) i32 {
646
- if (stream == null or src_ptr == null) return Status.err_invalid;
647
- const s = stream.?;
648
- if (len == 0) return Status.ok;
649
- const src = @as([*]const u8, @ptrCast(src_ptr.?))[0..len];
650
- s.write(src) catch |err| return errorToStatus(err);
651
- return Status.ok;
652
- }
653
-
654
- /// Commits the pending span accumulated by streamWrite and emits DataAvailable.
655
- /// Only needed when auto_commit_on_full is disabled or to flush a partially
656
- /// filled chunk.
657
- pub export fn streamCommit(stream: ?*Stream) i32 {
658
- if (stream == null) return Status.err_invalid;
659
- const s = stream.?;
660
- s.commit() catch |err| return errorToStatus(err);
661
- return Status.ok;
662
- }
663
-
664
- /// Zero-copy API: returns a pointer and available length for direct writes
665
- /// into the current chunk's memory. The caller writes directly into this
666
- /// region (no memcpy) and then calls streamCommitReserved with the number
667
- /// of bytes actually written.
668
- /// Best for producers that can format output in place (e.g., serializing
669
- /// directly into the chunk buffer). Only one reservation can be active at
670
- /// a time; the stream is locked until streamCommitReserved is called.
671
- /// Returns at most one chunk's worth of available space.
672
- pub export fn streamReserve(stream: ?*Stream, min_len: u32, out_ptr: ?*ReserveInfo) i32 {
673
- if (stream == null or out_ptr == null) return Status.err_invalid;
674
- const s = stream.?;
675
- const info = s.reserve(min_len) catch |err| return errorToStatus(err);
676
- out_ptr.?.* = info;
677
- return Status.ok;
678
- }
679
-
680
- /// Commits len bytes of the previously reserved region and emits DataAvailable.
681
- /// Must be called after streamReserve. len must not exceed the reserved length.
682
- pub export fn streamCommitReserved(stream: ?*Stream, len: u32) i32 {
683
- if (stream == null) return Status.err_invalid;
684
- const s = stream.?;
685
- s.commitReserved(len) catch |err| return errorToStatus(err);
686
- return Status.ok;
687
- }
688
-
689
- pub export fn streamSetOptions(stream: ?*Stream, options_ptr: ?*const Options) i32 {
690
- if (stream == null or options_ptr == null) return Status.err_invalid;
691
- const s = stream.?;
692
- s.setOptions(options_ptr.?.*) catch |err| return errorToStatus(err);
693
- return Status.ok;
694
- }
695
-
696
- pub export fn streamGetStats(stream: ?*Stream, stats_ptr: ?*Stats) i32 {
697
- if (stream == null or stats_ptr == null) return Status.err_invalid;
698
- const s = stream.?;
699
- stats_ptr.?.* = s.getStats();
700
- return Status.ok;
701
- }
702
-
703
- pub export fn streamDrainSpans(stream: ?*Stream, out_ptr: ?*SpanInfo, max_spans: u32) u32 {
704
- if (stream == null or out_ptr == null or max_spans == 0) return 0;
705
- const s = stream.?;
706
- const out = @as([*]SpanInfo, @ptrCast(out_ptr.?))[0..max_spans];
707
- return s.drainSpans(out);
708
- }