@xincli/opentui-core 0.4.6 → 0.4.7
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.
- package/LICENSE +21 -0
- package/NativeSpanFeed.d.ts +52 -0
- package/README.md +0 -0
- package/Renderable.d.ts +346 -0
- package/animation/Timeline.d.ts +126 -0
- package/ansi.d.ts +17 -0
- package/audio.d.ts +89 -0
- package/buffer.d.ts +113 -0
- package/console.d.ts +146 -0
- package/edit-buffer.d.ts +97 -0
- package/editor-view.d.ts +72 -0
- package/index-m1y9e40w.js +10045 -0
- package/index-m1y9e40w.js.map +32 -0
- package/index-sqk4ajdf.js +16121 -0
- package/index-sqk4ajdf.js.map +58 -0
- package/index.d.ts +24 -0
- package/index.js +11709 -0
- package/index.js.map +35 -0
- package/lib/KeyHandler.d.ts +61 -0
- package/lib/RGBA.d.ts +42 -0
- package/lib/ascii.font.d.ts +508 -0
- package/lib/border.d.ts +51 -0
- package/lib/bunfs.d.ts +7 -0
- package/lib/clipboard.d.ts +15 -0
- package/lib/clock.d.ts +15 -0
- package/lib/data-paths.d.ts +26 -0
- package/lib/debounce.d.ts +42 -0
- package/lib/detect-links.d.ts +6 -0
- package/lib/env.d.ts +42 -0
- package/lib/extmarks-history.d.ts +17 -0
- package/lib/extmarks.d.ts +90 -0
- package/lib/hast-styled-text.d.ts +17 -0
- package/lib/index.d.ts +22 -0
- package/lib/keybinding.internal.d.ts +33 -0
- package/lib/objects-in-viewport.d.ts +24 -0
- package/lib/output.capture.d.ts +24 -0
- package/lib/parse.keypress-kitty.d.ts +3 -0
- package/lib/parse.keypress.d.ts +27 -0
- package/lib/parse.mouse.d.ts +30 -0
- package/lib/paste.d.ts +7 -0
- package/lib/queue.d.ts +15 -0
- package/lib/render-geometry.d.ts +8 -0
- package/lib/renderable.validations.d.ts +12 -0
- package/lib/scroll-acceleration.d.ts +43 -0
- package/lib/selection.d.ts +64 -0
- package/lib/singleton.d.ts +8 -0
- package/lib/stdin-parser.d.ts +90 -0
- package/lib/styled-text.d.ts +63 -0
- package/lib/terminal-capability-detection.d.ts +32 -0
- package/lib/terminal-palette.d.ts +65 -0
- package/lib/tree-sitter/assets/update.d.ts +12 -0
- package/lib/tree-sitter/client.d.ts +65 -0
- package/lib/tree-sitter/default-parsers.d.ts +2 -0
- package/lib/tree-sitter/download-utils.d.ts +21 -0
- package/lib/tree-sitter/index.d.ts +7 -0
- package/lib/tree-sitter/parser.worker.d.ts +1 -0
- package/lib/tree-sitter/parsers-config.d.ts +53 -0
- package/lib/tree-sitter/resolve-ft.d.ts +5 -0
- package/lib/tree-sitter/types.d.ts +185 -0
- package/lib/tree-sitter/update-assets.d.ts +3 -0
- package/lib/tree-sitter/update-assets.js +379 -0
- package/lib/tree-sitter/update-assets.js.map +12 -0
- package/lib/tree-sitter-styled-text.d.ts +16 -0
- package/lib/validate-dir-name.d.ts +1 -0
- package/lib/yoga.options.d.ts +32 -0
- package/native-event-worker-repro.worker.d.ts +1 -0
- package/package.json +52 -74
- package/parser.worker.js +1399 -0
- package/parser.worker.js.map +20 -0
- package/platform/ffi.d.ts +129 -0
- package/platform/runtime.d.ts +14 -0
- package/platform/test.d.ts +12 -0
- package/platform/worker.d.ts +26 -0
- package/platform/worker.node-test.d.ts +1 -0
- package/plugins/core-slot.d.ts +72 -0
- package/plugins/registry.d.ts +42 -0
- package/plugins/types.d.ts +34 -0
- package/post/effects.d.ts +147 -0
- package/post/filters.d.ts +65 -0
- package/post/matrices.d.ts +20 -0
- package/renderables/ASCIIFont.d.ts +52 -0
- package/renderables/Box.d.ts +85 -0
- package/renderables/Code.d.ts +97 -0
- package/renderables/Diff.d.ts +147 -0
- package/renderables/EditBufferRenderable.d.ts +238 -0
- package/renderables/FrameBuffer.d.ts +16 -0
- package/renderables/Input.d.ts +72 -0
- package/renderables/LineNumberRenderable.d.ts +78 -0
- package/renderables/Markdown.d.ts +255 -0
- package/renderables/ScrollBar.d.ts +77 -0
- package/renderables/ScrollBox.d.ts +128 -0
- package/renderables/Select.d.ts +122 -0
- package/renderables/Slider.d.ts +47 -0
- package/renderables/TabSelect.d.ts +98 -0
- package/renderables/Text.d.ts +36 -0
- package/renderables/TextBufferRenderable.d.ts +107 -0
- package/renderables/TextNode.d.ts +92 -0
- package/renderables/TextTable.d.ts +154 -0
- package/renderables/Textarea.d.ts +65 -0
- package/renderables/TimeToFirstDraw.d.ts +24 -0
- package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
- package/renderables/composition/VRenderable.d.ts +16 -0
- package/renderables/composition/constructs.d.ts +35 -0
- package/renderables/composition/vnode.d.ts +46 -0
- package/renderables/index.d.ts +23 -0
- package/renderables/markdown-parser.d.ts +11 -0
- package/renderer-theme-mode.d.ts +29 -0
- package/renderer.d.ts +601 -0
- package/runtime-plugin-support-configure.d.ts +4 -0
- package/runtime-plugin-support-configure.js +36 -0
- package/runtime-plugin-support-configure.js.map +1 -0
- package/runtime-plugin-support-configure.node.js +15 -0
- package/runtime-plugin-support.d.ts +3 -0
- package/runtime-plugin-support.js +5 -0
- package/runtime-plugin-support.js.map +1 -0
- package/runtime-plugin-support.node.js +15 -0
- package/runtime-plugin.d.ts +16 -0
- package/runtime-plugin.js +473 -0
- package/runtime-plugin.js.map +1 -0
- package/runtime-plugin.node.js +15 -0
- package/syntax-style.d.ts +61 -0
- package/testing/bun-test-node.d.ts +87 -0
- package/testing/manual-clock.d.ts +17 -0
- package/testing/mock-keys.d.ts +81 -0
- package/testing/mock-mouse.d.ts +38 -0
- package/testing/mock-tree-sitter-client.d.ts +27 -0
- package/testing/spy.d.ts +7 -0
- package/testing/terminal-capabilities.d.ts +7 -0
- package/testing/test-recorder.d.ts +61 -0
- package/testing/test-renderer.d.ts +54 -0
- package/testing/test-streams.d.ts +12 -0
- package/testing.d.ts +8 -0
- package/testing.js +1004 -0
- package/testing.js.map +18 -0
- package/tests/yoga-upstream/tools/MeasureCounter.d.ts +16 -0
- package/tests/yoga-upstream/tools/utils.d.ts +11 -0
- package/text-buffer-view.d.ts +42 -0
- package/text-buffer.d.ts +66 -0
- package/types.d.ts +175 -0
- package/utils.d.ts +14 -0
- package/yoga.d.ts +437 -0
- package/yoga.js +193 -0
- package/yoga.js.map +9 -0
- package/zig-structs.d.ts +256 -0
- package/zig.d.ts +496 -0
- package/dev/keypress-debug-renderer.ts +0 -148
- package/dev/keypress-debug.ts +0 -43
- package/dev/print-env-vars.ts +0 -32
- package/dev/test-tmux-graphics-334.sh +0 -68
- package/dev/test-tmux-theme-queries.sh +0 -151
- package/dev/thai-debug-test.ts +0 -68
- package/dev/theme-mode.ts +0 -290
- package/docs/development.md +0 -144
- package/prebuilt/aarch64-android/libopentui.so +0 -0
- package/scripts/build-android.ts +0 -226
- package/scripts/build-native-termux.sh +0 -525
- package/scripts/build.ts +0 -530
- package/scripts/dist-test.ts +0 -312
- package/scripts/package-prebuilt.ts +0 -110
- package/scripts/publish.ts +0 -60
- package/scripts/test-node-hook.mjs +0 -16
- package/scripts/test-node.ts +0 -241
- package/scripts/vendor-deps.sh +0 -73
- package/src/NativeSpanFeed.ts +0 -375
- package/src/Renderable.ts +0 -1878
- package/src/__snapshots__/buffer.test.ts.snap +0 -28
- package/src/animation/Timeline.test.ts +0 -2709
- package/src/animation/Timeline.ts +0 -598
- package/src/ansi.ts +0 -22
- package/src/audio.ts +0 -479
- package/src/benchmark/attenuation-benchmark.ts +0 -81
- package/src/benchmark/audio-playback-benchmark.ts +0 -344
- package/src/benchmark/box-draw-benchmark.ts +0 -1042
- package/src/benchmark/colormatrix-benchmark.ts +0 -123
- package/src/benchmark/gain-benchmark.ts +0 -80
- package/src/benchmark/latest-all-bench-run.json +0 -707
- package/src/benchmark/latest-async-bench-run.json +0 -336
- package/src/benchmark/latest-default-bench-run.json +0 -657
- package/src/benchmark/latest-large-bench-run.json +0 -707
- package/src/benchmark/latest-quick-bench-run.json +0 -207
- package/src/benchmark/layout-benchmark.ts +0 -2547
- package/src/benchmark/markdown-benchmark.ts +0 -1796
- package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
- package/src/benchmark/native-span-feed-benchmark.md +0 -56
- package/src/benchmark/native-span-feed-benchmark.ts +0 -596
- package/src/benchmark/native-span-feed-compare.ts +0 -280
- package/src/benchmark/render-traversal-benchmark.ts +0 -928
- package/src/benchmark/text-buffer-render-benchmark.ts +0 -874
- package/src/benchmark/text-table-benchmark.ts +0 -948
- package/src/buffer.test.ts +0 -292
- package/src/buffer.ts +0 -564
- package/src/console.test.ts +0 -629
- package/src/console.ts +0 -1253
- package/src/edit-buffer.test.ts +0 -1852
- package/src/edit-buffer.ts +0 -417
- package/src/editor-view.test.ts +0 -1056
- package/src/editor-view.ts +0 -290
- package/src/index.ts +0 -25
- package/src/lib/KeyHandler.integration.test.ts +0 -292
- package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
- package/src/lib/KeyHandler.test.ts +0 -662
- package/src/lib/KeyHandler.ts +0 -222
- package/src/lib/RGBA.test.ts +0 -60
- package/src/lib/RGBA.ts +0 -343
- package/src/lib/ascii.font.ts +0 -330
- package/src/lib/border.test.ts +0 -83
- package/src/lib/border.ts +0 -170
- package/src/lib/bunfs.test.ts +0 -27
- package/src/lib/bunfs.ts +0 -18
- package/src/lib/clipboard.test.ts +0 -63
- package/src/lib/clipboard.ts +0 -41
- package/src/lib/clock.ts +0 -35
- package/src/lib/data-paths.test.ts +0 -133
- package/src/lib/data-paths.ts +0 -109
- package/src/lib/debounce.ts +0 -106
- package/src/lib/detect-links.test.ts +0 -98
- package/src/lib/detect-links.ts +0 -56
- package/src/lib/env.test.ts +0 -228
- package/src/lib/env.ts +0 -209
- package/src/lib/extmarks-history.ts +0 -51
- package/src/lib/extmarks-multiwidth.test.ts +0 -324
- package/src/lib/extmarks.test.ts +0 -3547
- package/src/lib/extmarks.ts +0 -861
- package/src/lib/fonts/block.json +0 -405
- package/src/lib/fonts/grid.json +0 -265
- package/src/lib/fonts/huge.json +0 -741
- package/src/lib/fonts/pallet.json +0 -314
- package/src/lib/fonts/shade.json +0 -591
- package/src/lib/fonts/slick.json +0 -321
- package/src/lib/fonts/tiny.json +0 -69
- package/src/lib/hast-styled-text.ts +0 -59
- package/src/lib/index.ts +0 -22
- package/src/lib/keybinding.internal.test.ts +0 -342
- package/src/lib/keybinding.internal.ts +0 -182
- package/src/lib/objects-in-viewport.test.ts +0 -789
- package/src/lib/objects-in-viewport.ts +0 -153
- package/src/lib/output.capture.ts +0 -58
- package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -347
- package/src/lib/parse.keypress-kitty.test.ts +0 -712
- package/src/lib/parse.keypress-kitty.ts +0 -470
- package/src/lib/parse.keypress.test.ts +0 -2020
- package/src/lib/parse.keypress.ts +0 -480
- package/src/lib/parse.mouse.test.ts +0 -552
- package/src/lib/parse.mouse.ts +0 -232
- package/src/lib/paste.ts +0 -18
- package/src/lib/queue.ts +0 -65
- package/src/lib/render-geometry.ts +0 -36
- package/src/lib/renderable.validations.test.ts +0 -87
- package/src/lib/renderable.validations.ts +0 -83
- package/src/lib/scroll-acceleration.ts +0 -98
- package/src/lib/selection.ts +0 -261
- package/src/lib/singleton.ts +0 -34
- package/src/lib/stdin-parser.test.ts +0 -2439
- package/src/lib/stdin-parser.ts +0 -2007
- package/src/lib/styled-text.ts +0 -178
- package/src/lib/terminal-capability-detection.test.ts +0 -226
- package/src/lib/terminal-capability-detection.ts +0 -98
- package/src/lib/terminal-palette.test.ts +0 -954
- package/src/lib/terminal-palette.ts +0 -441
- package/src/lib/tree-sitter/assets/README.md +0 -119
- package/src/lib/tree-sitter/assets/update.ts +0 -360
- package/src/lib/tree-sitter/assets.d.ts +0 -9
- package/src/lib/tree-sitter/cache.test.ts +0 -291
- package/src/lib/tree-sitter/client.test.ts +0 -1434
- package/src/lib/tree-sitter/client.ts +0 -847
- package/src/lib/tree-sitter/default-parsers.ts +0 -133
- package/src/lib/tree-sitter/download-utils.ts +0 -148
- package/src/lib/tree-sitter/index.ts +0 -75
- package/src/lib/tree-sitter/parser.worker.ts +0 -1098
- package/src/lib/tree-sitter/parsers-config.ts +0 -81
- package/src/lib/tree-sitter/resolve-ft.test.ts +0 -55
- package/src/lib/tree-sitter/resolve-ft.ts +0 -189
- package/src/lib/tree-sitter/types.ts +0 -132
- package/src/lib/tree-sitter/update-assets.ts +0 -10
- package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
- package/src/lib/tree-sitter-styled-text.ts +0 -314
- package/src/lib/validate-dir-name.ts +0 -55
- package/src/lib/yoga.options.test.ts +0 -628
- package/src/lib/yoga.options.ts +0 -346
- package/src/native-event-worker-repro.test.ts +0 -48
- package/src/native-event-worker-repro.worker.ts +0 -9
- package/src/native-handle.test.ts +0 -221
- package/src/platform/ffi.test.ts +0 -516
- package/src/platform/ffi.ts +0 -653
- package/src/platform/runtime.test.ts +0 -52
- package/src/platform/runtime.ts +0 -121
- package/src/platform/test.ts +0 -45
- package/src/platform/worker-handler-cleanup.fixture.ts +0 -12
- package/src/platform/worker-onmessage-startup.fixture.ts +0 -10
- package/src/platform/worker-startup.fixture.ts +0 -9
- package/src/platform/worker.node-test.ts +0 -153
- package/src/platform/worker.ts +0 -425
- package/src/plugins/core-slot.ts +0 -579
- package/src/plugins/registry.ts +0 -402
- package/src/plugins/types.ts +0 -46
- package/src/post/effects.ts +0 -948
- package/src/post/filters.ts +0 -512
- package/src/post/matrices.ts +0 -288
- package/src/renderables/ASCIIFont.ts +0 -219
- package/src/renderables/Box.test.ts +0 -474
- package/src/renderables/Box.ts +0 -353
- package/src/renderables/Code.test.ts +0 -2388
- package/src/renderables/Code.ts +0 -555
- package/src/renderables/Diff.regression.test.ts +0 -381
- package/src/renderables/Diff.test.ts +0 -3212
- package/src/renderables/Diff.ts +0 -1278
- package/src/renderables/EditBufferRenderable.test.ts +0 -288
- package/src/renderables/EditBufferRenderable.ts +0 -1152
- package/src/renderables/FrameBuffer.ts +0 -47
- package/src/renderables/Input.test.ts +0 -1310
- package/src/renderables/Input.ts +0 -273
- package/src/renderables/LineNumberRenderable.ts +0 -725
- package/src/renderables/Markdown.ts +0 -2144
- package/src/renderables/ScrollBar.ts +0 -423
- package/src/renderables/ScrollBox.ts +0 -903
- package/src/renderables/Select.test.ts +0 -1134
- package/src/renderables/Select.ts +0 -535
- package/src/renderables/Slider.test.ts +0 -456
- package/src/renderables/Slider.ts +0 -342
- package/src/renderables/TabSelect.test.ts +0 -238
- package/src/renderables/TabSelect.ts +0 -447
- package/src/renderables/Text.selection-buffer.test.ts +0 -118
- package/src/renderables/Text.test.ts +0 -2662
- package/src/renderables/Text.ts +0 -147
- package/src/renderables/TextBufferRenderable.ts +0 -504
- package/src/renderables/TextNode.test.ts +0 -1137
- package/src/renderables/TextNode.ts +0 -379
- package/src/renderables/TextTable.test.ts +0 -1411
- package/src/renderables/TextTable.ts +0 -1434
- package/src/renderables/Textarea.ts +0 -425
- package/src/renderables/TimeToFirstDraw.ts +0 -89
- package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
- package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
- package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
- package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
- package/src/renderables/__tests__/Code.test.ts +0 -55
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -827
- package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1906
- package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
- package/src/renderables/__tests__/Markdown.code-colors.test.ts +0 -288
- package/src/renderables/__tests__/Markdown.test.ts +0 -4175
- package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
- package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -683
- package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
- package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2120
- package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
- package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
- package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
- package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3275
- package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
- package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1927
- package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
- package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1589
- package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
- package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
- package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
- package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
- package/src/renderables/__tests__/markdown-parser.test.ts +0 -241
- package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
- package/src/renderables/composition/README.md +0 -8
- package/src/renderables/composition/VRenderable.ts +0 -32
- package/src/renderables/composition/constructs.ts +0 -127
- package/src/renderables/composition/vnode.ts +0 -277
- package/src/renderables/index.ts +0 -23
- package/src/renderables/markdown-parser.ts +0 -79
- package/src/renderer-theme-mode.ts +0 -199
- package/src/renderer.ts +0 -4975
- package/src/runtime-plugin-support-configure.ts +0 -63
- package/src/runtime-plugin-support.ts +0 -13
- package/src/runtime-plugin.ts +0 -626
- package/src/specs/terminal-startup.md +0 -64
- package/src/syntax-style.test.ts +0 -841
- package/src/syntax-style.ts +0 -274
- package/src/testing/README.md +0 -219
- package/src/testing/bun-test-node.ts +0 -880
- package/src/testing/capture-spans.test.ts +0 -216
- package/src/testing/integration.test.ts +0 -276
- package/src/testing/manual-clock.ts +0 -117
- package/src/testing/mock-keys.test.ts +0 -1378
- package/src/testing/mock-keys.ts +0 -457
- package/src/testing/mock-mouse.test.ts +0 -218
- package/src/testing/mock-mouse.ts +0 -247
- package/src/testing/mock-tree-sitter-client.ts +0 -81
- package/src/testing/spy.ts +0 -13
- package/src/testing/terminal-capabilities.ts +0 -47
- package/src/testing/test-recorder.test.ts +0 -410
- package/src/testing/test-recorder.ts +0 -133
- package/src/testing/test-renderer.ts +0 -375
- package/src/testing/test-renderer.wait.test.ts +0 -278
- package/src/testing/test-streams.ts +0 -31
- package/src/testing.ts +0 -9
- package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
- package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
- package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
- package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
- package/src/tests/allocator-stats.test.ts +0 -53
- package/src/tests/audio.test.ts +0 -303
- package/src/tests/destroy-during-render.test.ts +0 -200
- package/src/tests/destroy-on-exit.fixture.ts +0 -36
- package/src/tests/destroy-on-exit.test.ts +0 -62
- package/src/tests/ffi-borrowed-pointer-callsites.test.ts +0 -153
- package/src/tests/hover-cursor.test.ts +0 -98
- package/src/tests/native-backed-measurement-lifecycle.test.ts +0 -133
- package/src/tests/native-backed-measurement-parity.test.ts +0 -322
- package/src/tests/native-span-feed-async.test.ts +0 -173
- package/src/tests/native-span-feed-close.test.ts +0 -120
- package/src/tests/native-span-feed-coverage.test.ts +0 -227
- package/src/tests/native-span-feed-edge-cases.test.ts +0 -384
- package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
- package/src/tests/opacity.test.ts +0 -123
- package/src/tests/renderable.snapshot.test.ts +0 -524
- package/src/tests/renderable.test.ts +0 -1851
- package/src/tests/renderer.clock.test.ts +0 -270
- package/src/tests/renderer.console-startup.test.ts +0 -2151
- package/src/tests/renderer.control.test.ts +0 -458
- package/src/tests/renderer.core-slot-binding.test.ts +0 -962
- package/src/tests/renderer.cursor.test.ts +0 -26
- package/src/tests/renderer.custom-stdout.test.ts +0 -1112
- package/src/tests/renderer.destroy-during-render.test.ts +0 -147
- package/src/tests/renderer.focus-restore.test.ts +0 -257
- package/src/tests/renderer.focus.test.ts +0 -329
- package/src/tests/renderer.idle.test.ts +0 -219
- package/src/tests/renderer.input.test.ts +0 -2615
- package/src/tests/renderer.kitty-flags.test.ts +0 -195
- package/src/tests/renderer.lifecycle.test.ts +0 -34
- package/src/tests/renderer.mouse.test.ts +0 -1315
- package/src/tests/renderer.notifications.test.ts +0 -27
- package/src/tests/renderer.palette.test.ts +0 -1199
- package/src/tests/renderer.remote.test.ts +0 -247
- package/src/tests/renderer.render-stats.test.ts +0 -146
- package/src/tests/renderer.scrollback-surface.test.ts +0 -474
- package/src/tests/renderer.selection.test.ts +0 -138
- package/src/tests/renderer.slot-registry.test.ts +0 -684
- package/src/tests/renderer.tracker.test.ts +0 -202
- package/src/tests/renderer.useMouse.test.ts +0 -83
- package/src/tests/runtime-plugin-node-modules-cycle.fixture.ts +0 -76
- package/src/tests/runtime-plugin-node-modules-import-like-string.fixture.ts +0 -48
- package/src/tests/runtime-plugin-node-modules-mjs.fixture.ts +0 -43
- package/src/tests/runtime-plugin-node-modules-no-bare-rewrite.fixture.ts +0 -67
- package/src/tests/runtime-plugin-node-modules-package-type-cache.fixture.ts +0 -72
- package/src/tests/runtime-plugin-node-modules-runtime-specifier.fixture.ts +0 -44
- package/src/tests/runtime-plugin-node-modules-scoped-package-bare-rewrite.fixture.ts +0 -85
- package/src/tests/runtime-plugin-path-alias.fixture.ts +0 -43
- package/src/tests/runtime-plugin-resolve-roots.fixture.ts +0 -65
- package/src/tests/runtime-plugin-support-configure.fixture.ts +0 -31
- package/src/tests/runtime-plugin-support-late-addition.fixture.ts +0 -17
- package/src/tests/runtime-plugin-support.fixture.ts +0 -11
- package/src/tests/runtime-plugin-support.test.ts +0 -54
- package/src/tests/runtime-plugin-windows-file-url.fixture.ts +0 -30
- package/src/tests/runtime-plugin.fixture.ts +0 -40
- package/src/tests/runtime-plugin.test.ts +0 -369
- package/src/tests/scrollbox-culling-bug.test.ts +0 -114
- package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
- package/src/tests/scrollbox-hitgrid.test.ts +0 -909
- package/src/tests/scrollbox.test.ts +0 -1895
- package/src/tests/wrap-resize-perf.test.ts +0 -276
- package/src/tests/yoga-api-coverage.test.ts +0 -409
- package/src/tests/yoga-callback-stress.test.ts +0 -122
- package/src/tests/yoga-ffi.test.ts +0 -117
- package/src/tests/yoga-setters.test.ts +0 -921
- package/src/tests/yoga-upstream/YGAlignBaselineTest.test.ts +0 -124
- package/src/tests/yoga-upstream/YGComputedBorderTest.test.ts +0 -27
- package/src/tests/yoga-upstream/YGComputedMarginTest.test.ts +0 -27
- package/src/tests/yoga-upstream/YGComputedPaddingTest.test.ts +0 -27
- package/src/tests/yoga-upstream/YGDirtiedTest.test.ts +0 -157
- package/src/tests/yoga-upstream/YGErrataTest.test.ts +0 -40
- package/src/tests/yoga-upstream/YGFlexBasisAuto.test.ts +0 -23
- package/src/tests/yoga-upstream/YGHasNewLayout.test.ts +0 -81
- package/src/tests/yoga-upstream/YGMeasureCacheTest.test.ts +0 -31
- package/src/tests/yoga-upstream/YGMeasureTest.test.ts +0 -70
- package/src/tests/yoga-upstream/generated/YGAbsolutePositionTest.test.ts +0 -1864
- package/src/tests/yoga-upstream/generated/YGAlignContentTest.test.ts +0 -5829
- package/src/tests/yoga-upstream/generated/YGAlignItemsTest.test.ts +0 -2444
- package/src/tests/yoga-upstream/generated/YGAlignSelfTest.test.ts +0 -293
- package/src/tests/yoga-upstream/generated/YGAndroidNewsFeed.test.ts +0 -315
- package/src/tests/yoga-upstream/generated/YGAspectRatioTest.test.ts +0 -231
- package/src/tests/yoga-upstream/generated/YGAutoTest.test.ts +0 -347
- package/src/tests/yoga-upstream/generated/YGBorderTest.test.ts +0 -256
- package/src/tests/yoga-upstream/generated/YGBoxSizingTest.test.ts +0 -2747
- package/src/tests/yoga-upstream/generated/YGDimensionTest.test.ts +0 -129
- package/src/tests/yoga-upstream/generated/YGDisplayContentsTest.test.ts +0 -109
- package/src/tests/yoga-upstream/generated/YGDisplayTest.test.ts +0 -1097
- package/src/tests/yoga-upstream/generated/YGFlexDirectionTest.test.ts +0 -4562
- package/src/tests/yoga-upstream/generated/YGFlexTest.test.ts +0 -677
- package/src/tests/yoga-upstream/generated/YGFlexWrapTest.test.ts +0 -2071
- package/src/tests/yoga-upstream/generated/YGGapTest.test.ts +0 -3303
- package/src/tests/yoga-upstream/generated/YGIntrinsicSizeTest.test.ts +0 -582
- package/src/tests/yoga-upstream/generated/YGJustifyContentTest.test.ts +0 -2150
- package/src/tests/yoga-upstream/generated/YGMarginTest.test.ts +0 -1963
- package/src/tests/yoga-upstream/generated/YGMinMaxDimensionTest.test.ts +0 -1446
- package/src/tests/yoga-upstream/generated/YGPaddingTest.test.ts +0 -354
- package/src/tests/yoga-upstream/generated/YGPercentageTest.test.ts +0 -1760
- package/src/tests/yoga-upstream/generated/YGRoundingTest.test.ts +0 -1161
- package/src/tests/yoga-upstream/generated/YGSizeOverflowTest.test.ts +0 -207
- package/src/tests/yoga-upstream/generated/YGStaticPositionTest.test.ts +0 -6338
- package/src/tests/yoga-upstream/tools/MeasureCounter.ts +0 -54
- package/src/tests/yoga-upstream/tools/utils.ts +0 -81
- package/src/text-buffer-view.test.ts +0 -722
- package/src/text-buffer-view.ts +0 -193
- package/src/text-buffer.test.ts +0 -512
- package/src/text-buffer.ts +0 -250
- package/src/types.ts +0 -199
- package/src/utils.ts +0 -88
- package/src/yoga.ts +0 -1146
- package/src/zig/ansi.zig +0 -502
- package/src/zig/audio.zig +0 -1206
- package/src/zig/bench/README.md +0 -50
- package/src/zig/bench/buffer-color-blending_bench.zig +0 -350
- package/src/zig/bench/buffer-draw-box_bench.zig +0 -786
- package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -894
- package/src/zig/bench/edit-buffer_bench.zig +0 -476
- package/src/zig/bench/editor-view_bench.zig +0 -169
- package/src/zig/bench/native-span-feed_bench.zig +0 -107
- package/src/zig/bench/rope-markers_bench.zig +0 -713
- package/src/zig/bench/rope_bench.zig +0 -514
- package/src/zig/bench/styled-text_bench.zig +0 -476
- package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
- package/src/zig/bench/text-buffer-view_bench.zig +0 -459
- package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -272
- package/src/zig/bench/utf8_bench.zig +0 -799
- package/src/zig/bench-utils.zig +0 -431
- package/src/zig/bench.zig +0 -223
- package/src/zig/buffer-methods.zig +0 -215
- package/src/zig/buffer.zig +0 -2515
- package/src/zig/build.zig +0 -700
- package/src/zig/build.zig.zon +0 -19
- package/src/zig/edit-buffer.zig +0 -900
- package/src/zig/editor-view.zig +0 -812
- package/src/zig/event-bus.zig +0 -28
- package/src/zig/event-emitter.zig +0 -65
- package/src/zig/file-logger.zig +0 -92
- package/src/zig/grapheme.zig +0 -838
- package/src/zig/handles.zig +0 -267
- package/src/zig/lib.zig +0 -2813
- package/src/zig/link.zig +0 -349
- package/src/zig/logger.zig +0 -43
- package/src/zig/mem-registry.zig +0 -126
- package/src/zig/miniaudio_shim.c +0 -21
- package/src/zig/native-renderable.zig +0 -112
- package/src/zig/native-span-feed-bench-lib.zig +0 -7
- package/src/zig/native-span-feed.zig +0 -747
- package/src/zig/renderer-output.zig +0 -677
- package/src/zig/renderer.zig +0 -2106
- package/src/zig/rope.zig +0 -1220
- package/src/zig/split-scrollback.zig +0 -88
- package/src/zig/syntax-style.zig +0 -174
- package/src/zig/terminal.zig +0 -1652
- package/src/zig/test.zig +0 -82
- package/src/zig/tests/README.md +0 -18
- package/src/zig/tests/ansi_test.zig +0 -18
- package/src/zig/tests/audio_test.zig +0 -439
- package/src/zig/tests/buffer-methods_test.zig +0 -1111
- package/src/zig/tests/buffer_test.zig +0 -2926
- package/src/zig/tests/edit-buffer-history_test.zig +0 -299
- package/src/zig/tests/edit-buffer_test.zig +0 -1688
- package/src/zig/tests/editor-view_test.zig +0 -3454
- package/src/zig/tests/event-emitter_test.zig +0 -249
- package/src/zig/tests/grapheme_test.zig +0 -1329
- package/src/zig/tests/handles_test.zig +0 -123
- package/src/zig/tests/link_test.zig +0 -220
- package/src/zig/tests/mem-registry_test.zig +0 -473
- package/src/zig/tests/memory_leak_regression_test.zig +0 -234
- package/src/zig/tests/native-renderable_test.zig +0 -16
- package/src/zig/tests/native-span-feed_test.zig +0 -1266
- package/src/zig/tests/renderer_test.zig +0 -2604
- package/src/zig/tests/rope-nested_test.zig +0 -712
- package/src/zig/tests/rope_fuzz_test.zig +0 -238
- package/src/zig/tests/rope_test.zig +0 -2362
- package/src/zig/tests/segment-merge.test.zig +0 -148
- package/src/zig/tests/split-scrollback_test.zig +0 -70
- package/src/zig/tests/syntax-style_test.zig +0 -558
- package/src/zig/tests/terminal_test.zig +0 -1489
- package/src/zig/tests/test-renderer.zig +0 -126
- package/src/zig/tests/text-buffer-drawing_test.zig +0 -3291
- package/src/zig/tests/text-buffer-highlights_test.zig +0 -706
- package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
- package/src/zig/tests/text-buffer-segment_test.zig +0 -320
- package/src/zig/tests/text-buffer-selection_test.zig +0 -1056
- package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
- package/src/zig/tests/text-buffer-view_test.zig +0 -3672
- package/src/zig/tests/text-buffer_test.zig +0 -2191
- package/src/zig/tests/unicode-width-map.zon +0 -3909
- package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
- package/src/zig/tests/utf8_test.zig +0 -4060
- package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
- package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
- package/src/zig/tests/word-wrap-editing_test.zig +0 -498
- package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
- package/src/zig/tests/yoga_test.zig +0 -65
- package/src/zig/text-buffer-iterators.zig +0 -496
- package/src/zig/text-buffer-segment.zig +0 -403
- package/src/zig/text-buffer-view.zig +0 -1428
- package/src/zig/text-buffer.zig +0 -1272
- package/src/zig/utf8.zig +0 -1954
- package/src/zig/utils.zig +0 -12
- package/src/zig/uucode-stub.zig +0 -76
- package/src/zig/vendor/miniaudio/miniaudio.h +0 -93468
- package/src/zig/yoga.zig +0 -658
- package/src/zig-structs.ts +0 -381
- package/src/zig.ts +0 -5260
- package/tsconfig.build.json +0 -17
- package/tsconfig.json +0 -27
- package/tsconfig.node-test.json +0 -138
- /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/zig/tree-sitter-zig.wasm +0 -0
|
@@ -1,747 +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
|
-
fn grow(self: *SpanRing, stream: *Stream) StreamError!void {
|
|
57
|
-
if (stream.options.growth_policy == @intFromEnum(GrowthPolicy.block)) {
|
|
58
|
-
return StreamError.NoSpace;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const old_capacity = self.capacity;
|
|
62
|
-
const old_count = self.count();
|
|
63
|
-
const new_capacity = if (old_capacity == 0) 1 else old_capacity * 2;
|
|
64
|
-
const new_buffer = stream.allocator.alloc(SpanInfo, new_capacity) catch return StreamError.OutOfMemory;
|
|
65
|
-
|
|
66
|
-
var i: u32 = 0;
|
|
67
|
-
while (i < old_count) : (i += 1) {
|
|
68
|
-
const old_index = (self.head +% i) % old_capacity;
|
|
69
|
-
new_buffer[i] = self.buffer[old_index];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (old_capacity > 0) {
|
|
73
|
-
stream.allocator.free(self.buffer);
|
|
74
|
-
}
|
|
75
|
-
self.buffer = new_buffer;
|
|
76
|
-
self.capacity = new_capacity;
|
|
77
|
-
self.head = 0;
|
|
78
|
-
self.tail = old_count;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
pub fn push(self: *SpanRing, stream: *Stream, span: SpanInfo, notify: *bool) StreamError!void {
|
|
82
|
-
var capacity = self.capacity;
|
|
83
|
-
var head = self.head;
|
|
84
|
-
var tail = self.tail;
|
|
85
|
-
var queued = tail -% head;
|
|
86
|
-
|
|
87
|
-
if (queued >= capacity) {
|
|
88
|
-
try self.grow(stream);
|
|
89
|
-
capacity = self.capacity;
|
|
90
|
-
head = self.head;
|
|
91
|
-
tail = self.tail;
|
|
92
|
-
queued = tail -% head;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const index = tail % capacity;
|
|
96
|
-
self.buffer[index] = span;
|
|
97
|
-
tail +%= 1;
|
|
98
|
-
self.tail = tail;
|
|
99
|
-
const new_count = queued + 1;
|
|
100
|
-
|
|
101
|
-
stream.stats.pending_spans = new_count;
|
|
102
|
-
if (stream.attached and stream.callback != null) {
|
|
103
|
-
if (queued < notify_threshold_default and new_count >= notify_threshold_default) {
|
|
104
|
-
notify.* = true;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
pub fn popMany(self: *SpanRing, out: []SpanInfo) u32 {
|
|
110
|
-
const available = self.tail -% self.head;
|
|
111
|
-
if (available == 0) return 0;
|
|
112
|
-
const to_read: u32 = if (available < out.len) @intCast(available) else @intCast(out.len);
|
|
113
|
-
|
|
114
|
-
var i: u32 = 0;
|
|
115
|
-
while (i < to_read) : (i += 1) {
|
|
116
|
-
const index = (self.head +% i) % self.capacity;
|
|
117
|
-
out[i] = self.buffer[index];
|
|
118
|
-
}
|
|
119
|
-
self.head +%= to_read;
|
|
120
|
-
return to_read;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
pub const ReserveInfo = extern struct {
|
|
125
|
-
ptr: usize,
|
|
126
|
-
len: u32,
|
|
127
|
-
reserved: u32,
|
|
128
|
-
|
|
129
|
-
pub fn slice(self: ReserveInfo) []u8 {
|
|
130
|
-
const base: [*]u8 = @ptrFromInt(self.ptr);
|
|
131
|
-
const length: usize = @intCast(self.len);
|
|
132
|
-
return base[0..length];
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
pub const Stream = struct {
|
|
137
|
-
allocator: std.mem.Allocator,
|
|
138
|
-
options: Options,
|
|
139
|
-
chunks: std.ArrayList(Chunk),
|
|
140
|
-
current_chunk_index: usize,
|
|
141
|
-
write_offset: usize,
|
|
142
|
-
pending_chunk_index: usize,
|
|
143
|
-
pending_offset: usize,
|
|
144
|
-
pending_len: usize,
|
|
145
|
-
reserved_active: bool,
|
|
146
|
-
reserved_chunk_index: usize,
|
|
147
|
-
reserved_offset: usize,
|
|
148
|
-
reserved_len: usize,
|
|
149
|
-
attached: bool,
|
|
150
|
-
callback: ?*const CallbackFn,
|
|
151
|
-
closed: bool,
|
|
152
|
-
span_ring: SpanRing,
|
|
153
|
-
state_buffer: []u8,
|
|
154
|
-
state_capacity: u32,
|
|
155
|
-
stats: Stats,
|
|
156
|
-
|
|
157
|
-
pub fn create(allocator: std.mem.Allocator, options: ?Options) StreamError!*Stream {
|
|
158
|
-
const opts = normalizeOptions(options orelse defaultOptions());
|
|
159
|
-
const stream = allocator.create(Stream) catch return StreamError.OutOfMemory;
|
|
160
|
-
stream.* = .{
|
|
161
|
-
.allocator = allocator,
|
|
162
|
-
.options = opts,
|
|
163
|
-
.chunks = std.ArrayList(Chunk).empty,
|
|
164
|
-
.current_chunk_index = 0,
|
|
165
|
-
.write_offset = 0,
|
|
166
|
-
.pending_chunk_index = 0,
|
|
167
|
-
.pending_offset = 0,
|
|
168
|
-
.pending_len = 0,
|
|
169
|
-
.reserved_active = false,
|
|
170
|
-
.reserved_chunk_index = 0,
|
|
171
|
-
.reserved_offset = 0,
|
|
172
|
-
.reserved_len = 0,
|
|
173
|
-
.attached = false,
|
|
174
|
-
.callback = null,
|
|
175
|
-
.closed = false,
|
|
176
|
-
.span_ring = .{
|
|
177
|
-
.buffer = &[_]SpanInfo{},
|
|
178
|
-
.capacity = 0,
|
|
179
|
-
.head = 0,
|
|
180
|
-
.tail = 0,
|
|
181
|
-
},
|
|
182
|
-
.state_buffer = &[_]u8{},
|
|
183
|
-
.state_capacity = 0,
|
|
184
|
-
.stats = .{
|
|
185
|
-
.bytes_written = 0,
|
|
186
|
-
.spans_committed = 0,
|
|
187
|
-
.chunks = 0,
|
|
188
|
-
.pending_spans = 0,
|
|
189
|
-
},
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
errdefer stream.destroy();
|
|
193
|
-
|
|
194
|
-
const ring_capacity = opts.span_queue_capacity;
|
|
195
|
-
const ring_buffer = allocator.alloc(SpanInfo, ring_capacity) catch return StreamError.OutOfMemory;
|
|
196
|
-
stream.span_ring = .{
|
|
197
|
-
.buffer = ring_buffer,
|
|
198
|
-
.capacity = ring_capacity,
|
|
199
|
-
.head = 0,
|
|
200
|
-
.tail = 0,
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
try stream.ensureStateCapacity(@intCast(opts.initial_chunks));
|
|
204
|
-
|
|
205
|
-
const initial = @as(usize, opts.initial_chunks);
|
|
206
|
-
var i: usize = 0;
|
|
207
|
-
while (i < initial) : (i += 1) {
|
|
208
|
-
try stream.addChunkLocked();
|
|
209
|
-
}
|
|
210
|
-
stream.stats.chunks = @intCast(stream.chunks.items.len);
|
|
211
|
-
return stream;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
pub fn attach(self: *Stream) StreamError!void {
|
|
215
|
-
if (self.closed) return StreamError.Invalid;
|
|
216
|
-
|
|
217
|
-
var notify = false;
|
|
218
|
-
var queued: u32 = 0;
|
|
219
|
-
defer self.finish(notify, queued);
|
|
220
|
-
|
|
221
|
-
self.attached = true;
|
|
222
|
-
if (self.callback == null) return;
|
|
223
|
-
|
|
224
|
-
self.emitStateBuffer();
|
|
225
|
-
|
|
226
|
-
for (self.chunks.items) |chunk| {
|
|
227
|
-
self.emitChunkAdded(chunk);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
queued = self.span_ring.count();
|
|
231
|
-
if (queued > 0) {
|
|
232
|
-
notify = true;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
pub fn setCallback(self: *Stream, cb: ?*const CallbackFn) void {
|
|
237
|
-
self.callback = cb;
|
|
238
|
-
if (cb == null or !self.attached) return;
|
|
239
|
-
|
|
240
|
-
self.emitStateBuffer();
|
|
241
|
-
for (self.chunks.items) |chunk| {
|
|
242
|
-
self.emitChunkAdded(chunk);
|
|
243
|
-
}
|
|
244
|
-
const queued = self.span_ring.count();
|
|
245
|
-
if (queued > 0) {
|
|
246
|
-
self.emitDataAvailable(queued);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
pub fn write(self: *Stream, data: []const u8) StreamError!void {
|
|
251
|
-
if (self.closed) return StreamError.Invalid;
|
|
252
|
-
if (data.len == 0) return;
|
|
253
|
-
if (self.reserved_active) return StreamError.Busy;
|
|
254
|
-
|
|
255
|
-
var notify = false;
|
|
256
|
-
// finish() must run on success and error so committed spans notify.
|
|
257
|
-
defer self.finish(notify, 0);
|
|
258
|
-
|
|
259
|
-
var remaining = data.len;
|
|
260
|
-
var src_index: usize = 0;
|
|
261
|
-
const auto_commit = self.options.auto_commit_on_full != 0;
|
|
262
|
-
const chunk_len = self.options.chunk_size;
|
|
263
|
-
|
|
264
|
-
while (remaining > 0) {
|
|
265
|
-
var available = @as(usize, chunk_len) - self.write_offset;
|
|
266
|
-
if (available == 0) {
|
|
267
|
-
if (self.pending_len > 0) {
|
|
268
|
-
try self.commitLocked(¬ify);
|
|
269
|
-
}
|
|
270
|
-
try self.ensureWritableChunkLocked();
|
|
271
|
-
available = @as(usize, chunk_len);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (remaining > available and !auto_commit) {
|
|
275
|
-
return StreamError.NoSpace;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const to_write = if (remaining < available) remaining else available;
|
|
279
|
-
if (self.pending_len == 0) {
|
|
280
|
-
self.pending_chunk_index = self.current_chunk_index;
|
|
281
|
-
self.pending_offset = self.write_offset;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const chunk = self.chunks.items[self.current_chunk_index];
|
|
285
|
-
@memcpy(chunk.ptr[self.write_offset .. self.write_offset + to_write], data[src_index .. src_index + to_write]);
|
|
286
|
-
|
|
287
|
-
self.write_offset += to_write;
|
|
288
|
-
self.pending_len += to_write;
|
|
289
|
-
self.stats.bytes_written += @as(u64, to_write);
|
|
290
|
-
src_index += to_write;
|
|
291
|
-
remaining -= to_write;
|
|
292
|
-
|
|
293
|
-
if (self.write_offset == @as(usize, chunk_len) and auto_commit) {
|
|
294
|
-
try self.commitLocked(¬ify);
|
|
295
|
-
if (remaining > 0) {
|
|
296
|
-
try self.ensureWritableChunkLocked();
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
pub fn reserve(self: *Stream, min_len: u32) StreamError!ReserveInfo {
|
|
303
|
-
if (self.closed) return StreamError.Invalid;
|
|
304
|
-
return self.reserveLocked(min_len);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
pub fn commitReserved(self: *Stream, len: u32) StreamError!void {
|
|
308
|
-
if (self.closed) return StreamError.Invalid;
|
|
309
|
-
|
|
310
|
-
var notify = false;
|
|
311
|
-
defer self.finish(notify, 0);
|
|
312
|
-
try self.commitReservedLocked(len, ¬ify);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
pub fn commit(self: *Stream) StreamError!void {
|
|
316
|
-
if (self.closed) return StreamError.Invalid;
|
|
317
|
-
var notify = false;
|
|
318
|
-
defer self.finish(notify, 0);
|
|
319
|
-
if (self.reserved_active) return StreamError.Busy;
|
|
320
|
-
try self.commitLocked(¬ify);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
pub fn getStats(self: *Stream) Stats {
|
|
324
|
-
var out: Stats = undefined;
|
|
325
|
-
out = self.stats;
|
|
326
|
-
return out;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
pub fn hasPendingBytes(self: *Stream) bool {
|
|
330
|
-
return self.pending_len > 0;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/// Apply only runtime-safe options; creation-time fields are ignored.
|
|
334
|
-
pub fn setOptions(self: *Stream, options: Options) StreamError!void {
|
|
335
|
-
if (self.closed) return StreamError.Invalid;
|
|
336
|
-
self.options.max_bytes = options.max_bytes;
|
|
337
|
-
self.options.growth_policy = options.growth_policy;
|
|
338
|
-
self.options.auto_commit_on_full = options.auto_commit_on_full;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
pub fn close(self: *Stream) StreamError!void {
|
|
342
|
-
var notify = false;
|
|
343
|
-
if (self.closed) {
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
if (self.reserved_active) {
|
|
347
|
-
return StreamError.Busy;
|
|
348
|
-
}
|
|
349
|
-
if (self.pending_len > 0) {
|
|
350
|
-
try self.commitLocked(¬ify);
|
|
351
|
-
}
|
|
352
|
-
self.closed = true;
|
|
353
|
-
self.attached = false;
|
|
354
|
-
self.finish(notify, 0);
|
|
355
|
-
self.emitClosed();
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
pub fn destroy(self: *Stream) void {
|
|
359
|
-
if (!self.closed) {
|
|
360
|
-
_ = self.close() catch {};
|
|
361
|
-
}
|
|
362
|
-
for (self.chunks.items) |chunk| {
|
|
363
|
-
self.allocator.free(chunk.ptr[0..@as(usize, chunk.len)]);
|
|
364
|
-
}
|
|
365
|
-
self.chunks.deinit(self.allocator);
|
|
366
|
-
if (self.span_ring.capacity > 0) {
|
|
367
|
-
self.allocator.free(self.span_ring.buffer);
|
|
368
|
-
}
|
|
369
|
-
if (self.state_capacity > 0) {
|
|
370
|
-
self.allocator.free(self.state_buffer);
|
|
371
|
-
}
|
|
372
|
-
self.allocator.destroy(self);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
pub fn drainSpans(self: *Stream, out: []SpanInfo) u32 {
|
|
376
|
-
if (out.len == 0) return 0;
|
|
377
|
-
const count = self.span_ring.popMany(out);
|
|
378
|
-
self.stats.pending_spans = self.span_ring.count();
|
|
379
|
-
return count;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
pub fn hasPendingSpans(self: *Stream) bool {
|
|
383
|
-
return self.span_ring.count() > 0;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
pub fn stateBuffer(self: *Stream) []u8 {
|
|
387
|
-
return self.state_buffer;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
pub fn markChunkFree(self: *Stream, chunk_index: u32) void {
|
|
391
|
-
if (chunk_index < self.state_capacity) {
|
|
392
|
-
self.state_buffer[chunk_index] -|= 1;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
pub fn markSpanConsumed(self: *Stream, span: SpanInfo) void {
|
|
397
|
-
self.markChunkFree(span.chunk_index);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
pub fn finish(self: *Stream, notify: bool, queued_override: u32) void {
|
|
401
|
-
if (notify and self.callback != null) {
|
|
402
|
-
const queued = if (queued_override != 0)
|
|
403
|
-
queued_override
|
|
404
|
-
else
|
|
405
|
-
self.span_ring.count();
|
|
406
|
-
if (queued > 0) self.emitDataAvailable(queued);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
fn ensureStateCapacity(self: *Stream, required: u32) StreamError!void {
|
|
411
|
-
if (required <= self.state_capacity) return;
|
|
412
|
-
var new_capacity: u32 = if (self.state_capacity == 0) 1 else self.state_capacity;
|
|
413
|
-
while (new_capacity < required) : (new_capacity *= 2) {}
|
|
414
|
-
const new_buffer = self.allocator.alloc(u8, new_capacity) catch return StreamError.OutOfMemory;
|
|
415
|
-
@memset(new_buffer, 0);
|
|
416
|
-
if (self.state_capacity > 0) {
|
|
417
|
-
std.mem.copyForwards(u8, new_buffer[0..self.state_capacity], self.state_buffer);
|
|
418
|
-
self.allocator.free(self.state_buffer);
|
|
419
|
-
}
|
|
420
|
-
self.state_buffer = new_buffer;
|
|
421
|
-
self.state_capacity = new_capacity;
|
|
422
|
-
if (self.attached and self.callback != null) {
|
|
423
|
-
self.emitStateBuffer();
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
fn isChunkFree(self: *Stream, index: usize) bool {
|
|
428
|
-
if (index >= self.state_capacity) return true;
|
|
429
|
-
return self.state_buffer[index] == 0;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
pub fn commitLocked(self: *Stream, notify: *bool) StreamError!void {
|
|
433
|
-
if (self.pending_len == 0) return;
|
|
434
|
-
const chunk = self.chunks.items[self.pending_chunk_index];
|
|
435
|
-
const info: SpanInfo = .{
|
|
436
|
-
.chunk_ptr = @intFromPtr(chunk.ptr),
|
|
437
|
-
.offset = @intCast(self.pending_offset),
|
|
438
|
-
.len = @intCast(self.pending_len),
|
|
439
|
-
.chunk_index = @intCast(self.pending_chunk_index),
|
|
440
|
-
.reserved = 0,
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
try self.span_ring.push(self, info, notify);
|
|
444
|
-
self.markSpanPending(info.chunk_index);
|
|
445
|
-
self.stats.spans_committed += 1;
|
|
446
|
-
self.pending_len = 0;
|
|
447
|
-
self.pending_offset = self.write_offset;
|
|
448
|
-
self.pending_chunk_index = self.current_chunk_index;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
fn markSpanPending(self: *Stream, chunk_index: u32) void {
|
|
452
|
-
if (chunk_index < self.state_capacity) {
|
|
453
|
-
self.state_buffer[chunk_index] +|= 1;
|
|
454
|
-
// Avoid refcount saturation, which can corrupt data.
|
|
455
|
-
if (self.state_buffer[chunk_index] == 255) {
|
|
456
|
-
self.write_offset = self.options.chunk_size;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
pub fn reserveLocked(self: *Stream, min_len: u32) StreamError!ReserveInfo {
|
|
462
|
-
if (self.reserved_active) return StreamError.Busy;
|
|
463
|
-
if (self.pending_len != 0) return StreamError.Busy;
|
|
464
|
-
|
|
465
|
-
try self.ensureWritableChunkLocked();
|
|
466
|
-
|
|
467
|
-
const chunk = self.chunks.items[self.current_chunk_index];
|
|
468
|
-
const available = @as(usize, chunk.len) - self.write_offset;
|
|
469
|
-
if (available < min_len) return StreamError.NoSpace;
|
|
470
|
-
|
|
471
|
-
self.reserved_active = true;
|
|
472
|
-
self.reserved_chunk_index = self.current_chunk_index;
|
|
473
|
-
self.reserved_offset = self.write_offset;
|
|
474
|
-
self.reserved_len = available;
|
|
475
|
-
|
|
476
|
-
return .{
|
|
477
|
-
.ptr = @intFromPtr(chunk.ptr + self.write_offset),
|
|
478
|
-
.len = @intCast(available),
|
|
479
|
-
.reserved = 0,
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
pub fn commitReservedLocked(self: *Stream, len: u32, notify: *bool) StreamError!void {
|
|
484
|
-
if (!self.reserved_active) return StreamError.Invalid;
|
|
485
|
-
if (len > self.reserved_len) return StreamError.NoSpace;
|
|
486
|
-
|
|
487
|
-
self.pending_chunk_index = self.reserved_chunk_index;
|
|
488
|
-
self.pending_offset = self.reserved_offset;
|
|
489
|
-
self.pending_len = len;
|
|
490
|
-
self.write_offset = self.reserved_offset + len;
|
|
491
|
-
self.reserved_active = false;
|
|
492
|
-
self.reserved_len = 0;
|
|
493
|
-
|
|
494
|
-
self.stats.bytes_written += @as(u64, len);
|
|
495
|
-
|
|
496
|
-
try self.commitLocked(notify);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
fn addChunkLocked(self: *Stream) StreamError!void {
|
|
500
|
-
const chunk_size: u32 = self.options.chunk_size;
|
|
501
|
-
const max_bytes = self.options.max_bytes;
|
|
502
|
-
const allocated = @as(u64, self.chunks.items.len) * @as(u64, chunk_size);
|
|
503
|
-
if (max_bytes != 0 and allocated + @as(u64, chunk_size) > max_bytes) {
|
|
504
|
-
return StreamError.MaxBytes;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
// Grow state buffer first to keep chunk/refcount in sync on failure.
|
|
508
|
-
try self.ensureStateCapacity(@as(u32, @intCast(self.chunks.items.len)) + 1);
|
|
509
|
-
|
|
510
|
-
const mem = self.allocator.alloc(u8, chunk_size) catch return StreamError.OutOfMemory;
|
|
511
|
-
errdefer self.allocator.free(mem);
|
|
512
|
-
const chunk: Chunk = .{ .ptr = mem.ptr, .len = chunk_size };
|
|
513
|
-
self.chunks.append(self.allocator, chunk) catch return StreamError.OutOfMemory;
|
|
514
|
-
self.stats.chunks = @intCast(self.chunks.items.len);
|
|
515
|
-
if (self.attached and self.callback != null) {
|
|
516
|
-
self.emitChunkAdded(chunk);
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
fn ensureWritableChunkLocked(self: *Stream) StreamError!void {
|
|
521
|
-
const total = self.chunks.items.len;
|
|
522
|
-
if (total == 0) return StreamError.Invalid;
|
|
523
|
-
|
|
524
|
-
var attempts: usize = 0;
|
|
525
|
-
var index = self.current_chunk_index % total;
|
|
526
|
-
while (attempts < total) : (attempts += 1) {
|
|
527
|
-
if (self.isChunkFree(index)) {
|
|
528
|
-
self.current_chunk_index = index;
|
|
529
|
-
self.write_offset = 0;
|
|
530
|
-
self.pending_chunk_index = index;
|
|
531
|
-
self.pending_offset = 0;
|
|
532
|
-
self.pending_len = 0;
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
index = (index + 1) % total;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
if (self.options.growth_policy == @intFromEnum(GrowthPolicy.block)) {
|
|
539
|
-
return StreamError.NoSpace;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
try self.addChunkLocked();
|
|
543
|
-
const new_total = self.chunks.items.len;
|
|
544
|
-
if (new_total == 0) return StreamError.Invalid;
|
|
545
|
-
self.current_chunk_index = new_total - 1;
|
|
546
|
-
self.write_offset = 0;
|
|
547
|
-
self.pending_chunk_index = self.current_chunk_index;
|
|
548
|
-
self.pending_offset = 0;
|
|
549
|
-
self.pending_len = 0;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
fn emitChunkAdded(self: *Stream, chunk: Chunk) void {
|
|
553
|
-
if (self.callback) |cb| {
|
|
554
|
-
cb(@intFromPtr(self), Event.ChunkAdded, @intFromPtr(chunk.ptr), chunk.len);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
fn emitDataAvailable(self: *Stream, count: u32) void {
|
|
559
|
-
if (self.callback) |cb| {
|
|
560
|
-
cb(@intFromPtr(self), Event.DataAvailable, count, 0);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
fn emitStateBuffer(self: *Stream) void {
|
|
565
|
-
if (self.callback) |cb| {
|
|
566
|
-
cb(@intFromPtr(self), Event.StateBuffer, @intFromPtr(self.state_buffer.ptr), self.state_capacity);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
fn emitClosed(self: *Stream) void {
|
|
571
|
-
if (self.callback) |cb| {
|
|
572
|
-
cb(@intFromPtr(self), Event.Closed, 0, 0);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
};
|
|
576
|
-
|
|
577
|
-
pub const default_pattern = "\x1b[32mnative-span-feed\x1b[0m\n";
|
|
578
|
-
const span_queue_capacity_default: u32 = 4096;
|
|
579
|
-
const notify_threshold_default: u32 = 1;
|
|
580
|
-
|
|
581
|
-
pub const EventId = enum(u32) {
|
|
582
|
-
ChunkAdded = 2,
|
|
583
|
-
Closed = 5,
|
|
584
|
-
Error = 6,
|
|
585
|
-
DataAvailable = 7,
|
|
586
|
-
StateBuffer = 8,
|
|
587
|
-
};
|
|
588
|
-
|
|
589
|
-
const Event = struct {
|
|
590
|
-
pub const ChunkAdded: u32 = @intFromEnum(EventId.ChunkAdded);
|
|
591
|
-
pub const Closed: u32 = @intFromEnum(EventId.Closed);
|
|
592
|
-
pub const Error: u32 = @intFromEnum(EventId.Error);
|
|
593
|
-
pub const DataAvailable: u32 = @intFromEnum(EventId.DataAvailable);
|
|
594
|
-
pub const StateBuffer: u32 = @intFromEnum(EventId.StateBuffer);
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
pub const Status = struct {
|
|
598
|
-
pub const ok: i32 = 0;
|
|
599
|
-
pub const err_no_space: i32 = -1;
|
|
600
|
-
pub const err_max_bytes: i32 = -2;
|
|
601
|
-
pub const err_invalid: i32 = -3;
|
|
602
|
-
pub const err_alloc: i32 = -4;
|
|
603
|
-
pub const err_busy: i32 = -5;
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
pub const StreamError = error{
|
|
607
|
-
NoSpace,
|
|
608
|
-
MaxBytes,
|
|
609
|
-
Invalid,
|
|
610
|
-
OutOfMemory,
|
|
611
|
-
Busy,
|
|
612
|
-
};
|
|
613
|
-
|
|
614
|
-
pub fn defaultOptions() Options {
|
|
615
|
-
return .{
|
|
616
|
-
.chunk_size = 64 * 1024,
|
|
617
|
-
.initial_chunks = 2,
|
|
618
|
-
.max_bytes = 0,
|
|
619
|
-
.growth_policy = @intFromEnum(GrowthPolicy.grow),
|
|
620
|
-
.auto_commit_on_full = 1,
|
|
621
|
-
.span_queue_capacity = 0,
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
pub fn normalizeOptions(opts: Options) Options {
|
|
626
|
-
var out = opts;
|
|
627
|
-
if (out.chunk_size == 0) out.chunk_size = 64 * 1024;
|
|
628
|
-
if (out.initial_chunks == 0) out.initial_chunks = 1;
|
|
629
|
-
if (out.span_queue_capacity == 0) out.span_queue_capacity = span_queue_capacity_default;
|
|
630
|
-
return out;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
fn errorToStatus(err: StreamError) i32 {
|
|
634
|
-
return switch (err) {
|
|
635
|
-
StreamError.NoSpace => Status.err_no_space,
|
|
636
|
-
StreamError.MaxBytes => Status.err_max_bytes,
|
|
637
|
-
StreamError.Invalid => Status.err_invalid,
|
|
638
|
-
StreamError.OutOfMemory => Status.err_alloc,
|
|
639
|
-
StreamError.Busy => Status.err_busy,
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
pub fn createNativeSpanFeedWithAllocator(allocator: std.mem.Allocator, options_ptr: ?*const Options) ?*Stream {
|
|
644
|
-
const opts = normalizeOptions(if (options_ptr) |p| p.* else defaultOptions());
|
|
645
|
-
return Stream.create(allocator, opts) catch null;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
pub export fn streamSetCallback(stream: ?*Stream, callback: ?*const CallbackFn) void {
|
|
649
|
-
if (stream == null) return;
|
|
650
|
-
stream.?.setCallback(callback);
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
pub export fn attachNativeSpanFeed(stream: ?*Stream) i32 {
|
|
654
|
-
if (stream == null) return Status.err_invalid;
|
|
655
|
-
const s = stream.?;
|
|
656
|
-
s.attach() catch |err| return errorToStatus(err);
|
|
657
|
-
return Status.ok;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
pub export fn streamClose(stream: ?*Stream) i32 {
|
|
661
|
-
if (stream == null) return Status.err_invalid;
|
|
662
|
-
const s = stream.?;
|
|
663
|
-
s.close() catch |err| return errorToStatus(err);
|
|
664
|
-
return Status.ok;
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
pub export fn destroyNativeSpanFeed(stream: ?*Stream) void {
|
|
668
|
-
if (stream == null) return;
|
|
669
|
-
const s = stream.?;
|
|
670
|
-
s.destroy();
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
/// Copy API: copies len bytes from src_ptr into the stream's chunk pool.
|
|
674
|
-
/// Handles spanning across multiple chunks automatically. If auto_commit_on_full
|
|
675
|
-
/// is enabled, commits and emits DataAvailable each time a chunk fills.
|
|
676
|
-
/// Best for producers that already have data in a buffer (formatted output,
|
|
677
|
-
/// serialized messages, file contents).
|
|
678
|
-
/// When auto_commit_on_full is disabled, writes are all-or-nothing per
|
|
679
|
-
/// chunk boundary: a write that fits in the remaining space succeeds,
|
|
680
|
-
/// but a write that would exceed it returns err_no_space without writing
|
|
681
|
-
/// any bytes. A write that exactly fills the chunk succeeds; the next
|
|
682
|
-
/// write will move to a new chunk (committing the full one first).
|
|
683
|
-
pub export fn streamWrite(stream: ?*Stream, src_ptr: ?[*]const u8, len: u32) i32 {
|
|
684
|
-
if (stream == null) return Status.err_invalid;
|
|
685
|
-
const s = stream.?;
|
|
686
|
-
if (len == 0) return Status.ok;
|
|
687
|
-
if (src_ptr == null) return Status.err_invalid;
|
|
688
|
-
const src = src_ptr.?[0..@as(usize, len)];
|
|
689
|
-
s.write(src) catch |err| return errorToStatus(err);
|
|
690
|
-
return Status.ok;
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
/// Commits the pending span accumulated by streamWrite and emits DataAvailable.
|
|
694
|
-
/// Only needed when auto_commit_on_full is disabled or to flush a partially
|
|
695
|
-
/// filled chunk.
|
|
696
|
-
pub export fn streamCommit(stream: ?*Stream) i32 {
|
|
697
|
-
if (stream == null) return Status.err_invalid;
|
|
698
|
-
const s = stream.?;
|
|
699
|
-
s.commit() catch |err| return errorToStatus(err);
|
|
700
|
-
return Status.ok;
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
/// Zero-copy API: returns a pointer and available length for direct writes
|
|
704
|
-
/// into the current chunk's memory. The caller writes directly into this
|
|
705
|
-
/// region (no memcpy) and then calls streamCommitReserved with the number
|
|
706
|
-
/// of bytes actually written.
|
|
707
|
-
/// Best for producers that can format output in place (e.g., serializing
|
|
708
|
-
/// directly into the chunk buffer). Only one reservation can be active at
|
|
709
|
-
/// a time; the stream is locked until streamCommitReserved is called.
|
|
710
|
-
/// Returns at most one chunk's worth of available space.
|
|
711
|
-
pub export fn streamReserve(stream: ?*Stream, min_len: u32, out_ptr: ?*ReserveInfo) i32 {
|
|
712
|
-
if (stream == null or out_ptr == null) return Status.err_invalid;
|
|
713
|
-
const s = stream.?;
|
|
714
|
-
const info = s.reserve(min_len) catch |err| return errorToStatus(err);
|
|
715
|
-
out_ptr.?.* = info;
|
|
716
|
-
return Status.ok;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
/// Commits len bytes of the previously reserved region and emits DataAvailable.
|
|
720
|
-
/// Must be called after streamReserve. len must not exceed the reserved length.
|
|
721
|
-
pub export fn streamCommitReserved(stream: ?*Stream, len: u32) i32 {
|
|
722
|
-
if (stream == null) return Status.err_invalid;
|
|
723
|
-
const s = stream.?;
|
|
724
|
-
s.commitReserved(len) catch |err| return errorToStatus(err);
|
|
725
|
-
return Status.ok;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
pub export fn streamSetOptions(stream: ?*Stream, options_ptr: ?*const Options) i32 {
|
|
729
|
-
if (stream == null or options_ptr == null) return Status.err_invalid;
|
|
730
|
-
const s = stream.?;
|
|
731
|
-
s.setOptions(options_ptr.?.*) catch |err| return errorToStatus(err);
|
|
732
|
-
return Status.ok;
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
pub export fn streamGetStats(stream: ?*Stream, stats_ptr: ?*Stats) i32 {
|
|
736
|
-
if (stream == null or stats_ptr == null) return Status.err_invalid;
|
|
737
|
-
const s = stream.?;
|
|
738
|
-
stats_ptr.?.* = s.getStats();
|
|
739
|
-
return Status.ok;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
pub export fn streamDrainSpans(stream: ?*Stream, out_ptr: ?*SpanInfo, max_spans: u32) u32 {
|
|
743
|
-
if (stream == null or out_ptr == null or max_spans == 0) return 0;
|
|
744
|
-
const s = stream.?;
|
|
745
|
-
const out = @as([*]SpanInfo, @ptrCast(out_ptr.?))[0..max_spans];
|
|
746
|
-
return s.drainSpans(out);
|
|
747
|
-
}
|