@fairyhunter13/opentui-core 0.1.91 → 0.1.94

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 (570) 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/Renderable.d.ts +334 -0
  21. package/animation/Timeline.d.ts +126 -0
  22. package/ansi.d.ts +13 -0
  23. package/buffer.d.ts +107 -0
  24. package/console.d.ts +143 -0
  25. package/edit-buffer.d.ts +98 -0
  26. package/editor-view.d.ts +73 -0
  27. package/index-e6ec7apq.js +18415 -0
  28. package/index-e6ec7apq.js.map +64 -0
  29. package/index-h066zmrb.js +12619 -0
  30. package/index-h066zmrb.js.map +43 -0
  31. package/index-ynzawt3n.js +113 -0
  32. package/index-ynzawt3n.js.map +10 -0
  33. package/index.d.ts +21 -0
  34. package/index.js +430 -0
  35. package/index.js.map +9 -0
  36. package/lib/KeyHandler.d.ts +61 -0
  37. package/lib/RGBA.d.ts +25 -0
  38. package/lib/ascii.font.d.ts +508 -0
  39. package/lib/border.d.ts +49 -0
  40. package/lib/bunfs.d.ts +7 -0
  41. package/lib/clipboard.d.ts +17 -0
  42. package/lib/clock.d.ts +15 -0
  43. package/lib/data-paths.d.ts +26 -0
  44. package/lib/debounce.d.ts +42 -0
  45. package/lib/detect-links.d.ts +6 -0
  46. package/lib/env.d.ts +42 -0
  47. package/lib/extmarks-history.d.ts +17 -0
  48. package/lib/extmarks.d.ts +89 -0
  49. package/lib/hast-styled-text.d.ts +17 -0
  50. package/lib/index.d.ts +21 -0
  51. package/lib/keymapping.d.ts +25 -0
  52. package/lib/objects-in-viewport.d.ts +24 -0
  53. package/lib/output.capture.d.ts +24 -0
  54. package/lib/parse.keypress-kitty.d.ts +2 -0
  55. package/lib/parse.keypress.d.ts +26 -0
  56. package/lib/parse.mouse.d.ts +30 -0
  57. package/lib/paste.d.ts +7 -0
  58. package/lib/queue.d.ts +15 -0
  59. package/lib/renderable.validations.d.ts +12 -0
  60. package/lib/scroll-acceleration.d.ts +43 -0
  61. package/lib/selection.d.ts +63 -0
  62. package/lib/singleton.d.ts +7 -0
  63. package/lib/stdin-parser.d.ts +76 -0
  64. package/lib/styled-text.d.ts +63 -0
  65. package/lib/terminal-capability-detection.d.ts +30 -0
  66. package/lib/terminal-palette.d.ts +50 -0
  67. package/lib/tree-sitter/assets/update.d.ts +11 -0
  68. package/lib/tree-sitter/client.d.ts +47 -0
  69. package/lib/tree-sitter/default-parsers.d.ts +2 -0
  70. package/lib/tree-sitter/download-utils.d.ts +21 -0
  71. package/lib/tree-sitter/index.d.ts +8 -0
  72. package/lib/tree-sitter/parser.worker.d.ts +1 -0
  73. package/lib/tree-sitter/parsers-config.d.ts +38 -0
  74. package/lib/tree-sitter/resolve-ft.d.ts +2 -0
  75. package/lib/tree-sitter/types.d.ts +81 -0
  76. package/lib/tree-sitter-styled-text.d.ts +14 -0
  77. package/lib/validate-dir-name.d.ts +1 -0
  78. package/lib/yoga.options.d.ts +32 -0
  79. package/package.json +51 -63
  80. package/parser.worker.js +869 -0
  81. package/parser.worker.js.map +12 -0
  82. package/plugins/core-slot.d.ts +72 -0
  83. package/plugins/registry.d.ts +38 -0
  84. package/plugins/types.d.ts +34 -0
  85. package/post/filters.d.ts +105 -0
  86. package/renderables/ASCIIFont.d.ts +52 -0
  87. package/renderables/Box.d.ts +72 -0
  88. package/renderables/Code.d.ts +78 -0
  89. package/renderables/Diff.d.ts +142 -0
  90. package/renderables/EditBufferRenderable.d.ts +162 -0
  91. package/renderables/FrameBuffer.d.ts +16 -0
  92. package/renderables/Input.d.ts +67 -0
  93. package/renderables/LineNumberRenderable.d.ts +74 -0
  94. package/renderables/Markdown.d.ts +173 -0
  95. package/renderables/ScrollBar.d.ts +77 -0
  96. package/renderables/ScrollBox.d.ts +124 -0
  97. package/renderables/Select.d.ts +115 -0
  98. package/renderables/Slider.d.ts +44 -0
  99. package/renderables/TabSelect.d.ts +96 -0
  100. package/renderables/Text.d.ts +36 -0
  101. package/renderables/TextBufferRenderable.d.ts +105 -0
  102. package/renderables/TextNode.d.ts +91 -0
  103. package/renderables/TextTable.d.ts +140 -0
  104. package/renderables/Textarea.d.ts +114 -0
  105. package/renderables/TimeToFirstDraw.d.ts +24 -0
  106. package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
  107. package/renderables/composition/VRenderable.d.ts +16 -0
  108. package/renderables/composition/constructs.d.ts +35 -0
  109. package/renderables/composition/vnode.d.ts +46 -0
  110. package/renderables/index.d.ts +22 -0
  111. package/renderables/markdown-parser.d.ts +10 -0
  112. package/renderer.d.ts +388 -0
  113. package/runtime-plugin-support.d.ts +3 -0
  114. package/runtime-plugin-support.js +29 -0
  115. package/runtime-plugin-support.js.map +10 -0
  116. package/runtime-plugin.d.ts +11 -0
  117. package/runtime-plugin.js +16 -0
  118. package/runtime-plugin.js.map +9 -0
  119. package/syntax-style.d.ts +54 -0
  120. package/testing/manual-clock.d.ts +16 -0
  121. package/testing/mock-keys.d.ts +81 -0
  122. package/testing/mock-mouse.d.ts +38 -0
  123. package/testing/mock-tree-sitter-client.d.ts +23 -0
  124. package/testing/spy.d.ts +7 -0
  125. package/testing/test-recorder.d.ts +61 -0
  126. package/testing/test-renderer.d.ts +23 -0
  127. package/testing.d.ts +6 -0
  128. package/testing.js +675 -0
  129. package/testing.js.map +15 -0
  130. package/text-buffer-view.d.ts +42 -0
  131. package/text-buffer.d.ts +67 -0
  132. package/types.d.ts +131 -0
  133. package/utils.d.ts +14 -0
  134. package/zig-structs.d.ts +155 -0
  135. package/zig.d.ts +351 -0
  136. package/dev/keypress-debug-renderer.ts +0 -148
  137. package/dev/keypress-debug.ts +0 -43
  138. package/dev/print-env-vars.ts +0 -32
  139. package/dev/test-tmux-graphics-334.sh +0 -68
  140. package/dev/thai-debug-test.ts +0 -68
  141. package/docs/development.md +0 -141
  142. package/docs/env-vars.md +0 -140
  143. package/docs/getting-started.md +0 -353
  144. package/docs/renderables-vs-constructs.md +0 -159
  145. package/docs/tree-sitter.md +0 -311
  146. package/scripts/build.ts +0 -400
  147. package/scripts/publish.ts +0 -60
  148. package/src/3d/SpriteResourceManager.ts +0 -286
  149. package/src/3d/SpriteUtils.ts +0 -71
  150. package/src/3d/TextureUtils.ts +0 -196
  151. package/src/3d/ThreeRenderable.ts +0 -197
  152. package/src/3d/WGPURenderer.ts +0 -294
  153. package/src/3d/animation/ExplodingSpriteEffect.ts +0 -513
  154. package/src/3d/animation/PhysicsExplodingSpriteEffect.ts +0 -429
  155. package/src/3d/animation/SpriteAnimator.ts +0 -633
  156. package/src/3d/animation/SpriteParticleGenerator.ts +0 -435
  157. package/src/3d/canvas.ts +0 -464
  158. package/src/3d/index.ts +0 -12
  159. package/src/3d/physics/PlanckPhysicsAdapter.ts +0 -72
  160. package/src/3d/physics/RapierPhysicsAdapter.ts +0 -66
  161. package/src/3d/physics/physics-interface.ts +0 -31
  162. package/src/3d/shaders/supersampling.wgsl +0 -201
  163. package/src/3d.ts +0 -3
  164. package/src/NativeSpanFeed.ts +0 -300
  165. package/src/Renderable.ts +0 -1698
  166. package/src/__snapshots__/buffer.test.ts.snap +0 -28
  167. package/src/animation/Timeline.test.ts +0 -2709
  168. package/src/animation/Timeline.ts +0 -598
  169. package/src/ansi.ts +0 -18
  170. package/src/benchmark/latest-all-bench-run.json +0 -707
  171. package/src/benchmark/latest-async-bench-run.json +0 -336
  172. package/src/benchmark/latest-default-bench-run.json +0 -657
  173. package/src/benchmark/latest-large-bench-run.json +0 -707
  174. package/src/benchmark/latest-quick-bench-run.json +0 -207
  175. package/src/benchmark/markdown-benchmark.ts +0 -1804
  176. package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
  177. package/src/benchmark/native-span-feed-benchmark.md +0 -56
  178. package/src/benchmark/native-span-feed-benchmark.ts +0 -596
  179. package/src/benchmark/native-span-feed-compare.ts +0 -280
  180. package/src/benchmark/renderer-benchmark.ts +0 -754
  181. package/src/benchmark/text-table-benchmark.ts +0 -947
  182. package/src/buffer.test.ts +0 -291
  183. package/src/buffer.ts +0 -519
  184. package/src/console.test.ts +0 -612
  185. package/src/console.ts +0 -1255
  186. package/src/edit-buffer.test.ts +0 -1769
  187. package/src/edit-buffer.ts +0 -411
  188. package/src/editor-view.test.ts +0 -1032
  189. package/src/editor-view.ts +0 -284
  190. package/src/examples/ascii-font-selection-demo.ts +0 -245
  191. package/src/examples/assets/Water_2_M_Normal.jpg +0 -0
  192. package/src/examples/assets/concrete.png +0 -0
  193. package/src/examples/assets/crate.png +0 -0
  194. package/src/examples/assets/crate_emissive.png +0 -0
  195. package/src/examples/assets/forrest_background.png +0 -0
  196. package/src/examples/assets/hast-example.json +0 -1018
  197. package/src/examples/assets/heart.png +0 -0
  198. package/src/examples/assets/main_char_heavy_attack.png +0 -0
  199. package/src/examples/assets/main_char_idle.png +0 -0
  200. package/src/examples/assets/main_char_jump_end.png +0 -0
  201. package/src/examples/assets/main_char_jump_landing.png +0 -0
  202. package/src/examples/assets/main_char_jump_start.png +0 -0
  203. package/src/examples/assets/main_char_run_loop.png +0 -0
  204. package/src/examples/assets/roughness_map.jpg +0 -0
  205. package/src/examples/build.ts +0 -115
  206. package/src/examples/code-demo.ts +0 -584
  207. package/src/examples/console-demo.ts +0 -358
  208. package/src/examples/core-plugin-slots-demo.ts +0 -759
  209. package/src/examples/diff-demo.ts +0 -699
  210. package/src/examples/draggable-three-demo.ts +0 -259
  211. package/src/examples/editor-demo.ts +0 -322
  212. package/src/examples/extmarks-demo.ts +0 -204
  213. package/src/examples/focus-restore-demo.ts +0 -310
  214. package/src/examples/fonts.ts +0 -245
  215. package/src/examples/fractal-shader-demo.ts +0 -268
  216. package/src/examples/framebuffer-demo.ts +0 -674
  217. package/src/examples/full-unicode-demo.ts +0 -181
  218. package/src/examples/golden-star-demo.ts +0 -933
  219. package/src/examples/grayscale-buffer-demo.ts +0 -249
  220. package/src/examples/hast-syntax-highlighting-demo.ts +0 -129
  221. package/src/examples/index.ts +0 -925
  222. package/src/examples/input-demo.ts +0 -377
  223. package/src/examples/input-select-layout-demo.ts +0 -425
  224. package/src/examples/install.sh +0 -143
  225. package/src/examples/keypress-debug-demo.ts +0 -452
  226. package/src/examples/lib/HexList.ts +0 -122
  227. package/src/examples/lib/PaletteGrid.ts +0 -125
  228. package/src/examples/lib/standalone-keys.ts +0 -25
  229. package/src/examples/lib/tab-controller.ts +0 -243
  230. package/src/examples/lights-phong-demo.ts +0 -290
  231. package/src/examples/link-demo.ts +0 -220
  232. package/src/examples/live-state-demo.ts +0 -480
  233. package/src/examples/markdown-demo.ts +0 -620
  234. package/src/examples/mouse-interaction-demo.ts +0 -428
  235. package/src/examples/nested-zindex-demo.ts +0 -357
  236. package/src/examples/opacity-example.ts +0 -235
  237. package/src/examples/opentui-demo.ts +0 -1057
  238. package/src/examples/physx-planck-2d-demo.ts +0 -507
  239. package/src/examples/physx-rapier-2d-demo.ts +0 -526
  240. package/src/examples/relative-positioning-demo.ts +0 -323
  241. package/src/examples/scroll-example.ts +0 -214
  242. package/src/examples/scrollbox-mouse-test.ts +0 -112
  243. package/src/examples/scrollbox-overlay-hit-test.ts +0 -206
  244. package/src/examples/select-demo.ts +0 -237
  245. package/src/examples/shader-cube-demo.ts +0 -772
  246. package/src/examples/simple-layout-example.ts +0 -591
  247. package/src/examples/slider-demo.ts +0 -617
  248. package/src/examples/split-mode-demo.ts +0 -445
  249. package/src/examples/sprite-animation-demo.ts +0 -443
  250. package/src/examples/sprite-particle-generator-demo.ts +0 -486
  251. package/src/examples/static-sprite-demo.ts +0 -193
  252. package/src/examples/sticky-scroll-example.ts +0 -308
  253. package/src/examples/styled-text-demo.ts +0 -282
  254. package/src/examples/tab-select-demo.ts +0 -219
  255. package/src/examples/terminal-title.ts +0 -29
  256. package/src/examples/terminal.ts +0 -305
  257. package/src/examples/text-node-demo.ts +0 -416
  258. package/src/examples/text-selection-demo.ts +0 -377
  259. package/src/examples/text-table-demo.ts +0 -503
  260. package/src/examples/text-truncation-demo.ts +0 -481
  261. package/src/examples/text-wrap.ts +0 -757
  262. package/src/examples/texture-loading-demo.ts +0 -259
  263. package/src/examples/timeline-example.ts +0 -670
  264. package/src/examples/transparency-demo.ts +0 -241
  265. package/src/examples/vnode-composition-demo.ts +0 -404
  266. package/src/index.ts +0 -22
  267. package/src/lib/KeyHandler.integration.test.ts +0 -292
  268. package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
  269. package/src/lib/KeyHandler.test.ts +0 -662
  270. package/src/lib/KeyHandler.ts +0 -222
  271. package/src/lib/RGBA.test.ts +0 -984
  272. package/src/lib/RGBA.ts +0 -204
  273. package/src/lib/ascii.font.ts +0 -330
  274. package/src/lib/border.test.ts +0 -83
  275. package/src/lib/border.ts +0 -168
  276. package/src/lib/bunfs.test.ts +0 -27
  277. package/src/lib/bunfs.ts +0 -18
  278. package/src/lib/clipboard.test.ts +0 -41
  279. package/src/lib/clipboard.ts +0 -47
  280. package/src/lib/clock.ts +0 -31
  281. package/src/lib/data-paths.test.ts +0 -133
  282. package/src/lib/data-paths.ts +0 -109
  283. package/src/lib/debounce.ts +0 -106
  284. package/src/lib/detect-links.test.ts +0 -98
  285. package/src/lib/detect-links.ts +0 -56
  286. package/src/lib/env.test.ts +0 -228
  287. package/src/lib/env.ts +0 -209
  288. package/src/lib/extmarks-history.ts +0 -51
  289. package/src/lib/extmarks-multiwidth.test.ts +0 -322
  290. package/src/lib/extmarks.test.ts +0 -3457
  291. package/src/lib/extmarks.ts +0 -843
  292. package/src/lib/fonts/block.json +0 -405
  293. package/src/lib/fonts/grid.json +0 -265
  294. package/src/lib/fonts/huge.json +0 -741
  295. package/src/lib/fonts/pallet.json +0 -314
  296. package/src/lib/fonts/shade.json +0 -591
  297. package/src/lib/fonts/slick.json +0 -321
  298. package/src/lib/fonts/tiny.json +0 -69
  299. package/src/lib/hast-styled-text.ts +0 -59
  300. package/src/lib/index.ts +0 -21
  301. package/src/lib/keymapping.test.ts +0 -280
  302. package/src/lib/keymapping.ts +0 -87
  303. package/src/lib/objects-in-viewport.test.ts +0 -787
  304. package/src/lib/objects-in-viewport.ts +0 -153
  305. package/src/lib/output.capture.ts +0 -58
  306. package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -340
  307. package/src/lib/parse.keypress-kitty.test.ts +0 -663
  308. package/src/lib/parse.keypress-kitty.ts +0 -439
  309. package/src/lib/parse.keypress.test.ts +0 -1849
  310. package/src/lib/parse.keypress.ts +0 -397
  311. package/src/lib/parse.mouse.test.ts +0 -552
  312. package/src/lib/parse.mouse.ts +0 -232
  313. package/src/lib/paste.ts +0 -16
  314. package/src/lib/queue.ts +0 -65
  315. package/src/lib/renderable.validations.test.ts +0 -87
  316. package/src/lib/renderable.validations.ts +0 -83
  317. package/src/lib/scroll-acceleration.ts +0 -98
  318. package/src/lib/selection.ts +0 -240
  319. package/src/lib/singleton.ts +0 -28
  320. package/src/lib/stdin-parser.test.ts +0 -1676
  321. package/src/lib/stdin-parser.ts +0 -1248
  322. package/src/lib/styled-text.ts +0 -178
  323. package/src/lib/terminal-capability-detection.test.ts +0 -202
  324. package/src/lib/terminal-capability-detection.ts +0 -79
  325. package/src/lib/terminal-palette.test.ts +0 -878
  326. package/src/lib/terminal-palette.ts +0 -383
  327. package/src/lib/tree-sitter/assets/README.md +0 -118
  328. package/src/lib/tree-sitter/assets/update.ts +0 -331
  329. package/src/lib/tree-sitter/assets.d.ts +0 -9
  330. package/src/lib/tree-sitter/cache.test.ts +0 -270
  331. package/src/lib/tree-sitter/client.test.ts +0 -1061
  332. package/src/lib/tree-sitter/client.ts +0 -615
  333. package/src/lib/tree-sitter/default-parsers.ts +0 -80
  334. package/src/lib/tree-sitter/download-utils.ts +0 -148
  335. package/src/lib/tree-sitter/index.ts +0 -28
  336. package/src/lib/tree-sitter/parser.worker.ts +0 -1001
  337. package/src/lib/tree-sitter/parsers-config.ts +0 -75
  338. package/src/lib/tree-sitter/resolve-ft.ts +0 -62
  339. package/src/lib/tree-sitter/types.ts +0 -81
  340. package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
  341. package/src/lib/tree-sitter-styled-text.ts +0 -306
  342. package/src/lib/validate-dir-name.ts +0 -55
  343. package/src/lib/yoga.options.test.ts +0 -628
  344. package/src/lib/yoga.options.ts +0 -346
  345. package/src/plugins/core-slot.ts +0 -579
  346. package/src/plugins/registry.ts +0 -377
  347. package/src/plugins/types.ts +0 -46
  348. package/src/post/filters.ts +0 -888
  349. package/src/renderables/ASCIIFont.ts +0 -219
  350. package/src/renderables/Box.test.ts +0 -160
  351. package/src/renderables/Box.ts +0 -295
  352. package/src/renderables/Code.test.ts +0 -2062
  353. package/src/renderables/Code.ts +0 -357
  354. package/src/renderables/Diff.regression.test.ts +0 -226
  355. package/src/renderables/Diff.test.ts +0 -3027
  356. package/src/renderables/Diff.ts +0 -1209
  357. package/src/renderables/EditBufferRenderable.ts +0 -764
  358. package/src/renderables/FrameBuffer.ts +0 -47
  359. package/src/renderables/Input.test.ts +0 -1228
  360. package/src/renderables/Input.ts +0 -245
  361. package/src/renderables/LineNumberRenderable.ts +0 -675
  362. package/src/renderables/Markdown.ts +0 -1106
  363. package/src/renderables/ScrollBar.ts +0 -422
  364. package/src/renderables/ScrollBox.ts +0 -883
  365. package/src/renderables/Select.test.ts +0 -1010
  366. package/src/renderables/Select.ts +0 -523
  367. package/src/renderables/Slider.test.ts +0 -456
  368. package/src/renderables/Slider.ts +0 -347
  369. package/src/renderables/TabSelect.test.ts +0 -197
  370. package/src/renderables/TabSelect.ts +0 -455
  371. package/src/renderables/Text.selection-buffer.test.ts +0 -123
  372. package/src/renderables/Text.test.ts +0 -2660
  373. package/src/renderables/Text.ts +0 -147
  374. package/src/renderables/TextBufferRenderable.ts +0 -518
  375. package/src/renderables/TextNode.test.ts +0 -1058
  376. package/src/renderables/TextNode.ts +0 -325
  377. package/src/renderables/TextTable.test.ts +0 -1421
  378. package/src/renderables/TextTable.ts +0 -1344
  379. package/src/renderables/Textarea.ts +0 -732
  380. package/src/renderables/TimeToFirstDraw.ts +0 -89
  381. package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
  382. package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
  383. package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
  384. package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
  385. package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
  386. package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -816
  387. package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1787
  388. package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
  389. package/src/renderables/__tests__/Markdown.test.ts +0 -2287
  390. package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
  391. package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -682
  392. package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
  393. package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2041
  394. package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
  395. package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
  396. package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
  397. package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3149
  398. package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
  399. package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1864
  400. package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
  401. package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1590
  402. package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
  403. package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
  404. package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
  405. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
  406. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
  407. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
  408. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
  409. package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
  410. package/src/renderables/__tests__/markdown-parser.test.ts +0 -217
  411. package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
  412. package/src/renderables/composition/README.md +0 -8
  413. package/src/renderables/composition/VRenderable.ts +0 -32
  414. package/src/renderables/composition/constructs.ts +0 -127
  415. package/src/renderables/composition/vnode.ts +0 -289
  416. package/src/renderables/index.ts +0 -22
  417. package/src/renderables/markdown-parser.ts +0 -66
  418. package/src/renderer.ts +0 -2363
  419. package/src/runtime-plugin-support.ts +0 -39
  420. package/src/runtime-plugin.ts +0 -144
  421. package/src/syntax-style.test.ts +0 -841
  422. package/src/syntax-style.ts +0 -264
  423. package/src/testing/README.md +0 -210
  424. package/src/testing/capture-spans.test.ts +0 -194
  425. package/src/testing/integration.test.ts +0 -276
  426. package/src/testing/manual-clock.ts +0 -106
  427. package/src/testing/mock-keys.test.ts +0 -1356
  428. package/src/testing/mock-keys.ts +0 -449
  429. package/src/testing/mock-mouse.test.ts +0 -218
  430. package/src/testing/mock-mouse.ts +0 -247
  431. package/src/testing/mock-tree-sitter-client.ts +0 -73
  432. package/src/testing/spy.ts +0 -13
  433. package/src/testing/test-recorder.test.ts +0 -415
  434. package/src/testing/test-recorder.ts +0 -145
  435. package/src/testing/test-renderer.ts +0 -116
  436. package/src/testing.ts +0 -7
  437. package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
  438. package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
  439. package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
  440. package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
  441. package/src/tests/allocator-stats.test.ts +0 -38
  442. package/src/tests/destroy-during-render.test.ts +0 -200
  443. package/src/tests/hover-cursor.test.ts +0 -98
  444. package/src/tests/native-span-feed-async.test.ts +0 -173
  445. package/src/tests/native-span-feed-close.test.ts +0 -120
  446. package/src/tests/native-span-feed-coverage.test.ts +0 -227
  447. package/src/tests/native-span-feed-edge-cases.test.ts +0 -352
  448. package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
  449. package/src/tests/opacity.test.ts +0 -123
  450. package/src/tests/renderable.snapshot.test.ts +0 -524
  451. package/src/tests/renderable.test.ts +0 -1281
  452. package/src/tests/renderer.console-startup.test.ts +0 -65
  453. package/src/tests/renderer.control.test.ts +0 -364
  454. package/src/tests/renderer.core-slot-binding.test.ts +0 -952
  455. package/src/tests/renderer.cursor.test.ts +0 -26
  456. package/src/tests/renderer.destroy-during-render.test.ts +0 -110
  457. package/src/tests/renderer.focus-restore.test.ts +0 -228
  458. package/src/tests/renderer.focus.test.ts +0 -251
  459. package/src/tests/renderer.idle.test.ts +0 -219
  460. package/src/tests/renderer.input.test.ts +0 -2145
  461. package/src/tests/renderer.kitty-flags.test.ts +0 -195
  462. package/src/tests/renderer.mouse.test.ts +0 -1269
  463. package/src/tests/renderer.palette.test.ts +0 -629
  464. package/src/tests/renderer.selection.test.ts +0 -49
  465. package/src/tests/renderer.slot-registry.test.ts +0 -649
  466. package/src/tests/renderer.useMouse.test.ts +0 -50
  467. package/src/tests/runtime-plugin-support.fixture.ts +0 -11
  468. package/src/tests/runtime-plugin-support.test.ts +0 -28
  469. package/src/tests/runtime-plugin.fixture.ts +0 -40
  470. package/src/tests/runtime-plugin.test.ts +0 -190
  471. package/src/tests/scrollbox-culling-bug.test.ts +0 -114
  472. package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
  473. package/src/tests/scrollbox-hitgrid.test.ts +0 -909
  474. package/src/tests/scrollbox.test.ts +0 -1530
  475. package/src/tests/wrap-resize-perf.test.ts +0 -229
  476. package/src/tests/yoga-setters.test.ts +0 -921
  477. package/src/text-buffer-view.test.ts +0 -705
  478. package/src/text-buffer-view.ts +0 -189
  479. package/src/text-buffer.test.ts +0 -347
  480. package/src/text-buffer.ts +0 -250
  481. package/src/types.ts +0 -152
  482. package/src/utils.ts +0 -88
  483. package/src/zig/ansi.zig +0 -268
  484. package/src/zig/bench/README.md +0 -50
  485. package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -887
  486. package/src/zig/bench/edit-buffer_bench.zig +0 -476
  487. package/src/zig/bench/native-span-feed_bench.zig +0 -100
  488. package/src/zig/bench/rope-markers_bench.zig +0 -713
  489. package/src/zig/bench/rope_bench.zig +0 -514
  490. package/src/zig/bench/styled-text_bench.zig +0 -470
  491. package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
  492. package/src/zig/bench/text-buffer-view_bench.zig +0 -459
  493. package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -273
  494. package/src/zig/bench/utf8_bench.zig +0 -799
  495. package/src/zig/bench-utils.zig +0 -431
  496. package/src/zig/bench.zig +0 -217
  497. package/src/zig/buffer.zig +0 -2223
  498. package/src/zig/build.zig +0 -289
  499. package/src/zig/build.zig.zon +0 -16
  500. package/src/zig/edit-buffer.zig +0 -825
  501. package/src/zig/editor-view.zig +0 -802
  502. package/src/zig/event-bus.zig +0 -13
  503. package/src/zig/event-emitter.zig +0 -65
  504. package/src/zig/file-logger.zig +0 -92
  505. package/src/zig/grapheme.zig +0 -599
  506. package/src/zig/lib.zig +0 -1834
  507. package/src/zig/link.zig +0 -333
  508. package/src/zig/logger.zig +0 -43
  509. package/src/zig/mem-registry.zig +0 -125
  510. package/src/zig/native-span-feed-bench-lib.zig +0 -7
  511. package/src/zig/native-span-feed.zig +0 -708
  512. package/src/zig/renderer.zig +0 -1386
  513. package/src/zig/rope.zig +0 -1220
  514. package/src/zig/syntax-style.zig +0 -161
  515. package/src/zig/terminal.zig +0 -975
  516. package/src/zig/test.zig +0 -70
  517. package/src/zig/tests/README.md +0 -18
  518. package/src/zig/tests/buffer_test.zig +0 -2526
  519. package/src/zig/tests/edit-buffer-history_test.zig +0 -271
  520. package/src/zig/tests/edit-buffer_test.zig +0 -1689
  521. package/src/zig/tests/editor-view_test.zig +0 -3299
  522. package/src/zig/tests/event-emitter_test.zig +0 -249
  523. package/src/zig/tests/grapheme_test.zig +0 -1304
  524. package/src/zig/tests/link_test.zig +0 -190
  525. package/src/zig/tests/mem-registry_test.zig +0 -473
  526. package/src/zig/tests/memory_leak_regression_test.zig +0 -159
  527. package/src/zig/tests/native-span-feed_test.zig +0 -1264
  528. package/src/zig/tests/renderer_test.zig +0 -1010
  529. package/src/zig/tests/rope-nested_test.zig +0 -712
  530. package/src/zig/tests/rope_fuzz_test.zig +0 -238
  531. package/src/zig/tests/rope_test.zig +0 -2362
  532. package/src/zig/tests/segment-merge.test.zig +0 -148
  533. package/src/zig/tests/syntax-style_test.zig +0 -557
  534. package/src/zig/tests/terminal_test.zig +0 -719
  535. package/src/zig/tests/text-buffer-drawing_test.zig +0 -3237
  536. package/src/zig/tests/text-buffer-highlights_test.zig +0 -666
  537. package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
  538. package/src/zig/tests/text-buffer-segment_test.zig +0 -320
  539. package/src/zig/tests/text-buffer-selection_test.zig +0 -1035
  540. package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
  541. package/src/zig/tests/text-buffer-view_test.zig +0 -3649
  542. package/src/zig/tests/text-buffer_test.zig +0 -2191
  543. package/src/zig/tests/unicode-width-map.zon +0 -3909
  544. package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
  545. package/src/zig/tests/utf8_test.zig +0 -4057
  546. package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
  547. package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
  548. package/src/zig/tests/word-wrap-editing_test.zig +0 -498
  549. package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
  550. package/src/zig/text-buffer-iterators.zig +0 -499
  551. package/src/zig/text-buffer-segment.zig +0 -404
  552. package/src/zig/text-buffer-view.zig +0 -1371
  553. package/src/zig/text-buffer.zig +0 -1180
  554. package/src/zig/utf8.zig +0 -1948
  555. package/src/zig/utils.zig +0 -9
  556. package/src/zig-structs.ts +0 -261
  557. package/src/zig.ts +0 -3843
  558. package/tsconfig.build.json +0 -22
  559. package/tsconfig.json +0 -28
  560. /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
  561. /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
  562. /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
  563. /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
  564. /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
  565. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
  566. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  567. /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
  568. /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
  569. /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
  570. /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
- }