@xincli/opentui-core 0.4.6
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/README.md +63 -0
- package/dev/keypress-debug-renderer.ts +148 -0
- package/dev/keypress-debug.ts +43 -0
- package/dev/print-env-vars.ts +32 -0
- package/dev/test-tmux-graphics-334.sh +68 -0
- package/dev/test-tmux-theme-queries.sh +151 -0
- package/dev/thai-debug-test.ts +68 -0
- package/dev/theme-mode.ts +290 -0
- package/docs/development.md +144 -0
- package/package.json +102 -0
- package/prebuilt/aarch64-android/libopentui.so +0 -0
- package/scripts/build-android.ts +226 -0
- package/scripts/build-native-termux.sh +525 -0
- package/scripts/build.ts +530 -0
- package/scripts/dist-test.ts +312 -0
- package/scripts/package-prebuilt.ts +110 -0
- package/scripts/publish.ts +60 -0
- package/scripts/test-node-hook.mjs +16 -0
- package/scripts/test-node.ts +241 -0
- package/scripts/vendor-deps.sh +73 -0
- package/src/NativeSpanFeed.ts +375 -0
- package/src/Renderable.ts +1878 -0
- package/src/__snapshots__/buffer.test.ts.snap +28 -0
- package/src/animation/Timeline.test.ts +2709 -0
- package/src/animation/Timeline.ts +598 -0
- package/src/ansi.ts +22 -0
- package/src/audio.ts +479 -0
- package/src/benchmark/attenuation-benchmark.ts +81 -0
- package/src/benchmark/audio-playback-benchmark.ts +344 -0
- package/src/benchmark/box-draw-benchmark.ts +1042 -0
- package/src/benchmark/colormatrix-benchmark.ts +123 -0
- package/src/benchmark/gain-benchmark.ts +80 -0
- package/src/benchmark/latest-all-bench-run.json +707 -0
- package/src/benchmark/latest-async-bench-run.json +336 -0
- package/src/benchmark/latest-default-bench-run.json +657 -0
- package/src/benchmark/latest-large-bench-run.json +707 -0
- package/src/benchmark/latest-quick-bench-run.json +207 -0
- package/src/benchmark/layout-benchmark.ts +2547 -0
- package/src/benchmark/markdown-benchmark.ts +1796 -0
- package/src/benchmark/native-span-feed-async-benchmark.ts +355 -0
- package/src/benchmark/native-span-feed-benchmark.md +56 -0
- package/src/benchmark/native-span-feed-benchmark.ts +596 -0
- package/src/benchmark/native-span-feed-compare.ts +280 -0
- package/src/benchmark/render-traversal-benchmark.ts +928 -0
- package/src/benchmark/text-buffer-render-benchmark.ts +874 -0
- package/src/benchmark/text-table-benchmark.ts +948 -0
- package/src/buffer.test.ts +292 -0
- package/src/buffer.ts +564 -0
- package/src/console.test.ts +629 -0
- package/src/console.ts +1253 -0
- package/src/edit-buffer.test.ts +1852 -0
- package/src/edit-buffer.ts +417 -0
- package/src/editor-view.test.ts +1056 -0
- package/src/editor-view.ts +290 -0
- package/src/index.ts +25 -0
- package/src/lib/KeyHandler.integration.test.ts +292 -0
- package/src/lib/KeyHandler.stopPropagation.test.ts +289 -0
- package/src/lib/KeyHandler.test.ts +662 -0
- package/src/lib/KeyHandler.ts +222 -0
- package/src/lib/RGBA.test.ts +60 -0
- package/src/lib/RGBA.ts +343 -0
- package/src/lib/ascii.font.ts +330 -0
- package/src/lib/border.test.ts +83 -0
- package/src/lib/border.ts +170 -0
- package/src/lib/bunfs.test.ts +27 -0
- package/src/lib/bunfs.ts +18 -0
- package/src/lib/clipboard.test.ts +63 -0
- package/src/lib/clipboard.ts +41 -0
- package/src/lib/clock.ts +35 -0
- package/src/lib/data-paths.test.ts +133 -0
- package/src/lib/data-paths.ts +109 -0
- package/src/lib/debounce.ts +106 -0
- package/src/lib/detect-links.test.ts +98 -0
- package/src/lib/detect-links.ts +56 -0
- package/src/lib/env.test.ts +228 -0
- package/src/lib/env.ts +209 -0
- package/src/lib/extmarks-history.ts +51 -0
- package/src/lib/extmarks-multiwidth.test.ts +324 -0
- package/src/lib/extmarks.test.ts +3547 -0
- package/src/lib/extmarks.ts +861 -0
- package/src/lib/fonts/block.json +405 -0
- package/src/lib/fonts/grid.json +265 -0
- package/src/lib/fonts/huge.json +741 -0
- package/src/lib/fonts/pallet.json +314 -0
- package/src/lib/fonts/shade.json +591 -0
- package/src/lib/fonts/slick.json +321 -0
- package/src/lib/fonts/tiny.json +69 -0
- package/src/lib/hast-styled-text.ts +59 -0
- package/src/lib/index.ts +22 -0
- package/src/lib/keybinding.internal.test.ts +342 -0
- package/src/lib/keybinding.internal.ts +182 -0
- package/src/lib/objects-in-viewport.test.ts +789 -0
- package/src/lib/objects-in-viewport.ts +153 -0
- package/src/lib/output.capture.ts +58 -0
- package/src/lib/parse.keypress-kitty.protocol.test.ts +347 -0
- package/src/lib/parse.keypress-kitty.test.ts +712 -0
- package/src/lib/parse.keypress-kitty.ts +470 -0
- package/src/lib/parse.keypress.test.ts +2020 -0
- package/src/lib/parse.keypress.ts +480 -0
- package/src/lib/parse.mouse.test.ts +552 -0
- package/src/lib/parse.mouse.ts +232 -0
- package/src/lib/paste.ts +18 -0
- package/src/lib/queue.ts +65 -0
- package/src/lib/render-geometry.ts +36 -0
- package/src/lib/renderable.validations.test.ts +87 -0
- package/src/lib/renderable.validations.ts +83 -0
- package/src/lib/scroll-acceleration.ts +98 -0
- package/src/lib/selection.ts +261 -0
- package/src/lib/singleton.ts +34 -0
- package/src/lib/stdin-parser.test.ts +2439 -0
- package/src/lib/stdin-parser.ts +2007 -0
- package/src/lib/styled-text.ts +178 -0
- package/src/lib/terminal-capability-detection.test.ts +226 -0
- package/src/lib/terminal-capability-detection.ts +98 -0
- package/src/lib/terminal-palette.test.ts +954 -0
- package/src/lib/terminal-palette.ts +441 -0
- package/src/lib/tree-sitter/assets/README.md +119 -0
- package/src/lib/tree-sitter/assets/javascript/highlights.scm +205 -0
- package/src/lib/tree-sitter/assets/javascript/tree-sitter-javascript.wasm +0 -0
- package/src/lib/tree-sitter/assets/markdown/highlights.scm +150 -0
- package/src/lib/tree-sitter/assets/markdown/injections.scm +27 -0
- package/src/lib/tree-sitter/assets/markdown/tree-sitter-markdown.wasm +0 -0
- package/src/lib/tree-sitter/assets/markdown_inline/highlights.scm +115 -0
- package/src/lib/tree-sitter/assets/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
- package/src/lib/tree-sitter/assets/typescript/highlights.scm +604 -0
- package/src/lib/tree-sitter/assets/typescript/tree-sitter-typescript.wasm +0 -0
- package/src/lib/tree-sitter/assets/update.ts +360 -0
- package/src/lib/tree-sitter/assets/zig/highlights.scm +284 -0
- package/src/lib/tree-sitter/assets/zig/tree-sitter-zig.wasm +0 -0
- package/src/lib/tree-sitter/assets.d.ts +9 -0
- package/src/lib/tree-sitter/cache.test.ts +291 -0
- package/src/lib/tree-sitter/client.test.ts +1434 -0
- package/src/lib/tree-sitter/client.ts +847 -0
- package/src/lib/tree-sitter/default-parsers.ts +133 -0
- package/src/lib/tree-sitter/download-utils.ts +148 -0
- package/src/lib/tree-sitter/index.ts +75 -0
- package/src/lib/tree-sitter/parser.worker.ts +1098 -0
- package/src/lib/tree-sitter/parsers-config.ts +81 -0
- package/src/lib/tree-sitter/resolve-ft.test.ts +55 -0
- package/src/lib/tree-sitter/resolve-ft.ts +189 -0
- package/src/lib/tree-sitter/types.ts +132 -0
- package/src/lib/tree-sitter/update-assets.ts +10 -0
- package/src/lib/tree-sitter-styled-text.test.ts +1253 -0
- package/src/lib/tree-sitter-styled-text.ts +314 -0
- package/src/lib/validate-dir-name.ts +55 -0
- package/src/lib/yoga.options.test.ts +628 -0
- package/src/lib/yoga.options.ts +346 -0
- package/src/native-event-worker-repro.test.ts +48 -0
- package/src/native-event-worker-repro.worker.ts +9 -0
- package/src/native-handle.test.ts +221 -0
- package/src/platform/ffi.test.ts +516 -0
- package/src/platform/ffi.ts +653 -0
- package/src/platform/runtime.test.ts +52 -0
- package/src/platform/runtime.ts +121 -0
- package/src/platform/test.ts +45 -0
- package/src/platform/worker-handler-cleanup.fixture.ts +12 -0
- package/src/platform/worker-onmessage-startup.fixture.ts +10 -0
- package/src/platform/worker-startup.fixture.ts +9 -0
- package/src/platform/worker.node-test.ts +153 -0
- package/src/platform/worker.ts +425 -0
- package/src/plugins/core-slot.ts +579 -0
- package/src/plugins/registry.ts +402 -0
- package/src/plugins/types.ts +46 -0
- package/src/post/effects.ts +948 -0
- package/src/post/filters.ts +512 -0
- package/src/post/matrices.ts +288 -0
- package/src/renderables/ASCIIFont.ts +219 -0
- package/src/renderables/Box.test.ts +474 -0
- package/src/renderables/Box.ts +353 -0
- package/src/renderables/Code.test.ts +2388 -0
- package/src/renderables/Code.ts +555 -0
- package/src/renderables/Diff.regression.test.ts +381 -0
- package/src/renderables/Diff.test.ts +3212 -0
- package/src/renderables/Diff.ts +1278 -0
- package/src/renderables/EditBufferRenderable.test.ts +288 -0
- package/src/renderables/EditBufferRenderable.ts +1152 -0
- package/src/renderables/FrameBuffer.ts +47 -0
- package/src/renderables/Input.test.ts +1310 -0
- package/src/renderables/Input.ts +273 -0
- package/src/renderables/LineNumberRenderable.ts +725 -0
- package/src/renderables/Markdown.ts +2144 -0
- package/src/renderables/ScrollBar.ts +423 -0
- package/src/renderables/ScrollBox.ts +903 -0
- package/src/renderables/Select.test.ts +1134 -0
- package/src/renderables/Select.ts +535 -0
- package/src/renderables/Slider.test.ts +456 -0
- package/src/renderables/Slider.ts +342 -0
- package/src/renderables/TabSelect.test.ts +238 -0
- package/src/renderables/TabSelect.ts +447 -0
- package/src/renderables/Text.selection-buffer.test.ts +118 -0
- package/src/renderables/Text.test.ts +2662 -0
- package/src/renderables/Text.ts +147 -0
- package/src/renderables/TextBufferRenderable.ts +504 -0
- package/src/renderables/TextNode.test.ts +1137 -0
- package/src/renderables/TextNode.ts +379 -0
- package/src/renderables/TextTable.test.ts +1411 -0
- package/src/renderables/TextTable.ts +1434 -0
- package/src/renderables/Textarea.ts +425 -0
- package/src/renderables/TimeToFirstDraw.ts +89 -0
- package/src/renderables/__snapshots__/Code.test.ts.snap +13 -0
- package/src/renderables/__snapshots__/Diff.test.ts.snap +785 -0
- package/src/renderables/__snapshots__/Text.test.ts.snap +421 -0
- package/src/renderables/__snapshots__/TextTable.test.ts.snap +215 -0
- package/src/renderables/__tests__/Code.test.ts +55 -0
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +144 -0
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +827 -0
- package/src/renderables/__tests__/LineNumberRenderable.test.ts +1906 -0
- package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +85 -0
- package/src/renderables/__tests__/Markdown.code-colors.test.ts +288 -0
- package/src/renderables/__tests__/Markdown.test.ts +4175 -0
- package/src/renderables/__tests__/MultiRenderable.selection.test.ts +87 -0
- package/src/renderables/__tests__/Textarea.buffer.test.ts +683 -0
- package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +675 -0
- package/src/renderables/__tests__/Textarea.editing.test.ts +2120 -0
- package/src/renderables/__tests__/Textarea.error-handling.test.ts +35 -0
- package/src/renderables/__tests__/Textarea.events.test.ts +738 -0
- package/src/renderables/__tests__/Textarea.highlights.test.ts +590 -0
- package/src/renderables/__tests__/Textarea.keybinding.test.ts +3275 -0
- package/src/renderables/__tests__/Textarea.paste.test.ts +357 -0
- package/src/renderables/__tests__/Textarea.rendering.test.ts +1927 -0
- package/src/renderables/__tests__/Textarea.scroll.test.ts +733 -0
- package/src/renderables/__tests__/Textarea.selection.test.ts +1589 -0
- package/src/renderables/__tests__/Textarea.stress.test.ts +670 -0
- package/src/renderables/__tests__/Textarea.undo-redo.test.ts +383 -0
- package/src/renderables/__tests__/Textarea.visual-lines.test.ts +310 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +221 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +89 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +457 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +158 -0
- package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +387 -0
- package/src/renderables/__tests__/markdown-parser.test.ts +241 -0
- package/src/renderables/__tests__/renderable-test-utils.ts +60 -0
- package/src/renderables/composition/README.md +8 -0
- package/src/renderables/composition/VRenderable.ts +32 -0
- package/src/renderables/composition/constructs.ts +127 -0
- package/src/renderables/composition/vnode.ts +277 -0
- package/src/renderables/index.ts +23 -0
- package/src/renderables/markdown-parser.ts +79 -0
- package/src/renderer-theme-mode.ts +199 -0
- package/src/renderer.ts +4975 -0
- package/src/runtime-plugin-support-configure.ts +63 -0
- package/src/runtime-plugin-support.ts +13 -0
- package/src/runtime-plugin.ts +626 -0
- package/src/specs/terminal-startup.md +64 -0
- package/src/syntax-style.test.ts +841 -0
- package/src/syntax-style.ts +274 -0
- package/src/testing/README.md +219 -0
- package/src/testing/bun-test-node.ts +880 -0
- package/src/testing/capture-spans.test.ts +216 -0
- package/src/testing/integration.test.ts +276 -0
- package/src/testing/manual-clock.ts +117 -0
- package/src/testing/mock-keys.test.ts +1378 -0
- package/src/testing/mock-keys.ts +457 -0
- package/src/testing/mock-mouse.test.ts +218 -0
- package/src/testing/mock-mouse.ts +247 -0
- package/src/testing/mock-tree-sitter-client.ts +81 -0
- package/src/testing/spy.ts +13 -0
- package/src/testing/terminal-capabilities.ts +47 -0
- package/src/testing/test-recorder.test.ts +410 -0
- package/src/testing/test-recorder.ts +133 -0
- package/src/testing/test-renderer.ts +375 -0
- package/src/testing/test-renderer.wait.test.ts +278 -0
- package/src/testing/test-streams.ts +31 -0
- package/src/testing.ts +9 -0
- package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +481 -0
- package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +19 -0
- package/src/tests/__snapshots__/scrollbox.test.ts.snap +29 -0
- package/src/tests/absolute-positioning.snapshot.test.ts +638 -0
- package/src/tests/allocator-stats.test.ts +53 -0
- package/src/tests/audio.test.ts +303 -0
- package/src/tests/destroy-during-render.test.ts +200 -0
- package/src/tests/destroy-on-exit.fixture.ts +36 -0
- package/src/tests/destroy-on-exit.test.ts +62 -0
- package/src/tests/ffi-borrowed-pointer-callsites.test.ts +153 -0
- package/src/tests/hover-cursor.test.ts +98 -0
- package/src/tests/native-backed-measurement-lifecycle.test.ts +133 -0
- package/src/tests/native-backed-measurement-parity.test.ts +322 -0
- package/src/tests/native-span-feed-async.test.ts +173 -0
- package/src/tests/native-span-feed-close.test.ts +120 -0
- package/src/tests/native-span-feed-coverage.test.ts +227 -0
- package/src/tests/native-span-feed-edge-cases.test.ts +384 -0
- package/src/tests/native-span-feed-use-after-free.test.ts +45 -0
- package/src/tests/opacity.test.ts +123 -0
- package/src/tests/renderable.snapshot.test.ts +524 -0
- package/src/tests/renderable.test.ts +1851 -0
- package/src/tests/renderer.clock.test.ts +270 -0
- package/src/tests/renderer.console-startup.test.ts +2151 -0
- package/src/tests/renderer.control.test.ts +458 -0
- package/src/tests/renderer.core-slot-binding.test.ts +962 -0
- package/src/tests/renderer.cursor.test.ts +26 -0
- package/src/tests/renderer.custom-stdout.test.ts +1112 -0
- package/src/tests/renderer.destroy-during-render.test.ts +147 -0
- package/src/tests/renderer.focus-restore.test.ts +257 -0
- package/src/tests/renderer.focus.test.ts +329 -0
- package/src/tests/renderer.idle.test.ts +219 -0
- package/src/tests/renderer.input.test.ts +2615 -0
- package/src/tests/renderer.kitty-flags.test.ts +195 -0
- package/src/tests/renderer.lifecycle.test.ts +34 -0
- package/src/tests/renderer.mouse.test.ts +1315 -0
- package/src/tests/renderer.notifications.test.ts +27 -0
- package/src/tests/renderer.palette.test.ts +1199 -0
- package/src/tests/renderer.remote.test.ts +247 -0
- package/src/tests/renderer.render-stats.test.ts +146 -0
- package/src/tests/renderer.scrollback-surface.test.ts +474 -0
- package/src/tests/renderer.selection.test.ts +138 -0
- package/src/tests/renderer.slot-registry.test.ts +684 -0
- package/src/tests/renderer.tracker.test.ts +202 -0
- package/src/tests/renderer.useMouse.test.ts +83 -0
- package/src/tests/runtime-plugin-node-modules-cycle.fixture.ts +76 -0
- package/src/tests/runtime-plugin-node-modules-import-like-string.fixture.ts +48 -0
- package/src/tests/runtime-plugin-node-modules-mjs.fixture.ts +43 -0
- package/src/tests/runtime-plugin-node-modules-no-bare-rewrite.fixture.ts +67 -0
- package/src/tests/runtime-plugin-node-modules-package-type-cache.fixture.ts +72 -0
- package/src/tests/runtime-plugin-node-modules-runtime-specifier.fixture.ts +44 -0
- package/src/tests/runtime-plugin-node-modules-scoped-package-bare-rewrite.fixture.ts +85 -0
- package/src/tests/runtime-plugin-path-alias.fixture.ts +43 -0
- package/src/tests/runtime-plugin-resolve-roots.fixture.ts +65 -0
- package/src/tests/runtime-plugin-support-configure.fixture.ts +31 -0
- package/src/tests/runtime-plugin-support-late-addition.fixture.ts +17 -0
- package/src/tests/runtime-plugin-support.fixture.ts +11 -0
- package/src/tests/runtime-plugin-support.test.ts +54 -0
- package/src/tests/runtime-plugin-windows-file-url.fixture.ts +30 -0
- package/src/tests/runtime-plugin.fixture.ts +40 -0
- package/src/tests/runtime-plugin.test.ts +369 -0
- package/src/tests/scrollbox-culling-bug.test.ts +114 -0
- package/src/tests/scrollbox-hitgrid-resize.test.ts +136 -0
- package/src/tests/scrollbox-hitgrid.test.ts +909 -0
- package/src/tests/scrollbox.test.ts +1895 -0
- package/src/tests/wrap-resize-perf.test.ts +276 -0
- package/src/tests/yoga-api-coverage.test.ts +409 -0
- package/src/tests/yoga-callback-stress.test.ts +122 -0
- package/src/tests/yoga-ffi.test.ts +117 -0
- package/src/tests/yoga-setters.test.ts +921 -0
- package/src/tests/yoga-upstream/YGAlignBaselineTest.test.ts +124 -0
- package/src/tests/yoga-upstream/YGComputedBorderTest.test.ts +27 -0
- package/src/tests/yoga-upstream/YGComputedMarginTest.test.ts +27 -0
- package/src/tests/yoga-upstream/YGComputedPaddingTest.test.ts +27 -0
- package/src/tests/yoga-upstream/YGDirtiedTest.test.ts +157 -0
- package/src/tests/yoga-upstream/YGErrataTest.test.ts +40 -0
- package/src/tests/yoga-upstream/YGFlexBasisAuto.test.ts +23 -0
- package/src/tests/yoga-upstream/YGHasNewLayout.test.ts +81 -0
- package/src/tests/yoga-upstream/YGMeasureCacheTest.test.ts +31 -0
- package/src/tests/yoga-upstream/YGMeasureTest.test.ts +70 -0
- package/src/tests/yoga-upstream/generated/YGAbsolutePositionTest.test.ts +1864 -0
- package/src/tests/yoga-upstream/generated/YGAlignContentTest.test.ts +5829 -0
- package/src/tests/yoga-upstream/generated/YGAlignItemsTest.test.ts +2444 -0
- package/src/tests/yoga-upstream/generated/YGAlignSelfTest.test.ts +293 -0
- package/src/tests/yoga-upstream/generated/YGAndroidNewsFeed.test.ts +315 -0
- package/src/tests/yoga-upstream/generated/YGAspectRatioTest.test.ts +231 -0
- package/src/tests/yoga-upstream/generated/YGAutoTest.test.ts +347 -0
- package/src/tests/yoga-upstream/generated/YGBorderTest.test.ts +256 -0
- package/src/tests/yoga-upstream/generated/YGBoxSizingTest.test.ts +2747 -0
- package/src/tests/yoga-upstream/generated/YGDimensionTest.test.ts +129 -0
- package/src/tests/yoga-upstream/generated/YGDisplayContentsTest.test.ts +109 -0
- package/src/tests/yoga-upstream/generated/YGDisplayTest.test.ts +1097 -0
- package/src/tests/yoga-upstream/generated/YGFlexDirectionTest.test.ts +4562 -0
- package/src/tests/yoga-upstream/generated/YGFlexTest.test.ts +677 -0
- package/src/tests/yoga-upstream/generated/YGFlexWrapTest.test.ts +2071 -0
- package/src/tests/yoga-upstream/generated/YGGapTest.test.ts +3303 -0
- package/src/tests/yoga-upstream/generated/YGIntrinsicSizeTest.test.ts +582 -0
- package/src/tests/yoga-upstream/generated/YGJustifyContentTest.test.ts +2150 -0
- package/src/tests/yoga-upstream/generated/YGMarginTest.test.ts +1963 -0
- package/src/tests/yoga-upstream/generated/YGMinMaxDimensionTest.test.ts +1446 -0
- package/src/tests/yoga-upstream/generated/YGPaddingTest.test.ts +354 -0
- package/src/tests/yoga-upstream/generated/YGPercentageTest.test.ts +1760 -0
- package/src/tests/yoga-upstream/generated/YGRoundingTest.test.ts +1161 -0
- package/src/tests/yoga-upstream/generated/YGSizeOverflowTest.test.ts +207 -0
- package/src/tests/yoga-upstream/generated/YGStaticPositionTest.test.ts +6338 -0
- package/src/tests/yoga-upstream/tools/MeasureCounter.ts +54 -0
- package/src/tests/yoga-upstream/tools/utils.ts +81 -0
- package/src/text-buffer-view.test.ts +722 -0
- package/src/text-buffer-view.ts +193 -0
- package/src/text-buffer.test.ts +512 -0
- package/src/text-buffer.ts +250 -0
- package/src/types.ts +199 -0
- package/src/utils.ts +88 -0
- package/src/yoga.ts +1146 -0
- package/src/zig/ansi.zig +502 -0
- package/src/zig/audio.zig +1206 -0
- package/src/zig/bench/README.md +50 -0
- package/src/zig/bench/buffer-color-blending_bench.zig +350 -0
- package/src/zig/bench/buffer-draw-box_bench.zig +786 -0
- package/src/zig/bench/buffer-draw-text-buffer_bench.zig +894 -0
- package/src/zig/bench/edit-buffer_bench.zig +476 -0
- package/src/zig/bench/editor-view_bench.zig +169 -0
- package/src/zig/bench/native-span-feed_bench.zig +107 -0
- package/src/zig/bench/rope-markers_bench.zig +713 -0
- package/src/zig/bench/rope_bench.zig +514 -0
- package/src/zig/bench/styled-text_bench.zig +476 -0
- package/src/zig/bench/text-buffer-coords_bench.zig +362 -0
- package/src/zig/bench/text-buffer-view_bench.zig +459 -0
- package/src/zig/bench/text-chunk-graphemes_bench.zig +272 -0
- package/src/zig/bench/utf8_bench.zig +799 -0
- package/src/zig/bench-utils.zig +431 -0
- package/src/zig/bench.zig +223 -0
- package/src/zig/buffer-methods.zig +215 -0
- package/src/zig/buffer.zig +2515 -0
- package/src/zig/build.zig +700 -0
- package/src/zig/build.zig.zon +19 -0
- package/src/zig/edit-buffer.zig +900 -0
- package/src/zig/editor-view.zig +812 -0
- package/src/zig/event-bus.zig +28 -0
- package/src/zig/event-emitter.zig +65 -0
- package/src/zig/file-logger.zig +92 -0
- package/src/zig/grapheme.zig +838 -0
- package/src/zig/handles.zig +267 -0
- package/src/zig/lib.zig +2813 -0
- package/src/zig/link.zig +349 -0
- package/src/zig/logger.zig +43 -0
- package/src/zig/mem-registry.zig +126 -0
- package/src/zig/miniaudio_shim.c +21 -0
- package/src/zig/native-renderable.zig +112 -0
- package/src/zig/native-span-feed-bench-lib.zig +7 -0
- package/src/zig/native-span-feed.zig +747 -0
- package/src/zig/renderer-output.zig +677 -0
- package/src/zig/renderer.zig +2106 -0
- package/src/zig/rope.zig +1220 -0
- package/src/zig/split-scrollback.zig +88 -0
- package/src/zig/syntax-style.zig +174 -0
- package/src/zig/terminal.zig +1652 -0
- package/src/zig/test.zig +82 -0
- package/src/zig/tests/README.md +18 -0
- package/src/zig/tests/ansi_test.zig +18 -0
- package/src/zig/tests/audio_test.zig +439 -0
- package/src/zig/tests/buffer-methods_test.zig +1111 -0
- package/src/zig/tests/buffer_test.zig +2926 -0
- package/src/zig/tests/edit-buffer-history_test.zig +299 -0
- package/src/zig/tests/edit-buffer_test.zig +1688 -0
- package/src/zig/tests/editor-view_test.zig +3454 -0
- package/src/zig/tests/event-emitter_test.zig +249 -0
- package/src/zig/tests/grapheme_test.zig +1329 -0
- package/src/zig/tests/handles_test.zig +123 -0
- package/src/zig/tests/link_test.zig +220 -0
- package/src/zig/tests/mem-registry_test.zig +473 -0
- package/src/zig/tests/memory_leak_regression_test.zig +234 -0
- package/src/zig/tests/native-renderable_test.zig +16 -0
- package/src/zig/tests/native-span-feed_test.zig +1266 -0
- package/src/zig/tests/renderer_test.zig +2604 -0
- package/src/zig/tests/rope-nested_test.zig +712 -0
- package/src/zig/tests/rope_fuzz_test.zig +238 -0
- package/src/zig/tests/rope_test.zig +2362 -0
- package/src/zig/tests/segment-merge.test.zig +148 -0
- package/src/zig/tests/split-scrollback_test.zig +70 -0
- package/src/zig/tests/syntax-style_test.zig +558 -0
- package/src/zig/tests/terminal_test.zig +1489 -0
- package/src/zig/tests/test-renderer.zig +126 -0
- package/src/zig/tests/text-buffer-drawing_test.zig +3291 -0
- package/src/zig/tests/text-buffer-highlights_test.zig +706 -0
- package/src/zig/tests/text-buffer-iterators_test.zig +776 -0
- package/src/zig/tests/text-buffer-segment_test.zig +320 -0
- package/src/zig/tests/text-buffer-selection_test.zig +1056 -0
- package/src/zig/tests/text-buffer-selection_viewport_test.zig +358 -0
- package/src/zig/tests/text-buffer-view_test.zig +3672 -0
- package/src/zig/tests/text-buffer_test.zig +2191 -0
- package/src/zig/tests/unicode-width-map.zon +3909 -0
- package/src/zig/tests/utf8_no_zwj_test.zig +260 -0
- package/src/zig/tests/utf8_test.zig +4060 -0
- package/src/zig/tests/utf8_wcwidth_cursor_test.zig +267 -0
- package/src/zig/tests/utf8_wcwidth_test.zig +357 -0
- package/src/zig/tests/word-wrap-editing_test.zig +498 -0
- package/src/zig/tests/wrap-cache-perf_test.zig +113 -0
- package/src/zig/tests/yoga_test.zig +65 -0
- package/src/zig/text-buffer-iterators.zig +496 -0
- package/src/zig/text-buffer-segment.zig +403 -0
- package/src/zig/text-buffer-view.zig +1428 -0
- package/src/zig/text-buffer.zig +1272 -0
- package/src/zig/utf8.zig +1954 -0
- package/src/zig/utils.zig +12 -0
- package/src/zig/uucode-stub.zig +76 -0
- package/src/zig/vendor/miniaudio/miniaudio.h +93468 -0
- package/src/zig/yoga.zig +658 -0
- package/src/zig-structs.ts +381 -0
- package/src/zig.ts +5260 -0
- package/tsconfig.build.json +17 -0
- package/tsconfig.json +27 -0
- package/tsconfig.node-test.json +138 -0
|
@@ -0,0 +1,1652 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const builtin = @import("builtin");
|
|
3
|
+
const atomic = std.atomic;
|
|
4
|
+
const assert = std.debug.assert;
|
|
5
|
+
const ansi = @import("ansi.zig");
|
|
6
|
+
const utf8 = @import("utf8.zig");
|
|
7
|
+
const logger = @import("logger.zig");
|
|
8
|
+
|
|
9
|
+
const WidthMethod = utf8.WidthMethod;
|
|
10
|
+
|
|
11
|
+
/// Terminal capability detection and management
|
|
12
|
+
pub const Terminal = @This();
|
|
13
|
+
|
|
14
|
+
pub const Capabilities = struct {
|
|
15
|
+
kitty_keyboard: bool = false,
|
|
16
|
+
kitty_graphics: bool = false,
|
|
17
|
+
rgb: bool = false,
|
|
18
|
+
ansi256: bool = false,
|
|
19
|
+
unicode: WidthMethod = .unicode,
|
|
20
|
+
sgr_pixels: bool = false,
|
|
21
|
+
color_scheme_updates: bool = false,
|
|
22
|
+
explicit_width: bool = false,
|
|
23
|
+
scaled_text: bool = false,
|
|
24
|
+
sixel: bool = false,
|
|
25
|
+
focus_tracking: bool = false,
|
|
26
|
+
sync: bool = false,
|
|
27
|
+
bracketed_paste: bool = false,
|
|
28
|
+
hyperlinks: bool = false,
|
|
29
|
+
osc52: bool = false,
|
|
30
|
+
notifications: bool = false,
|
|
31
|
+
explicit_cursor_positioning: bool = false,
|
|
32
|
+
remote: bool = false,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
pub const NotificationProtocol = enum {
|
|
36
|
+
none,
|
|
37
|
+
osc9,
|
|
38
|
+
osc777,
|
|
39
|
+
osc99,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const NotificationProtocolSource = enum {
|
|
43
|
+
none,
|
|
44
|
+
heuristic,
|
|
45
|
+
xtversion,
|
|
46
|
+
query,
|
|
47
|
+
override,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
pub const RemoteMode = enum(u8) {
|
|
51
|
+
auto,
|
|
52
|
+
local,
|
|
53
|
+
remote,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
pub const Multiplexer = enum(u8) {
|
|
57
|
+
none,
|
|
58
|
+
tmux,
|
|
59
|
+
zellij,
|
|
60
|
+
screen,
|
|
61
|
+
unknown,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
pub const Osc52Support = enum(u8) {
|
|
65
|
+
unknown,
|
|
66
|
+
supported,
|
|
67
|
+
unsupported,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const NOTIFICATION_QUERY_ID = "opentui-notifications";
|
|
71
|
+
pub const SCREEN_PASSTHROUGH_CHUNK_SIZE = 252;
|
|
72
|
+
pub const CLIPBOARD_PAYLOAD_SIZE_MAX = std.math.maxInt(u32);
|
|
73
|
+
const OSC52_FRAMING_SIZE = "\x1b]52;c;".len + "\x1b\\".len;
|
|
74
|
+
const PASSTHROUGH_ESCAPED_OSC52_SIZE = OSC52_FRAMING_SIZE + 2;
|
|
75
|
+
|
|
76
|
+
pub const MouseLevel = enum {
|
|
77
|
+
none,
|
|
78
|
+
basic, // click only
|
|
79
|
+
drag, // click + drag
|
|
80
|
+
motion, // all motion
|
|
81
|
+
pixels, // pixel coordinates
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
pub const CursorStyle = enum {
|
|
85
|
+
block,
|
|
86
|
+
line,
|
|
87
|
+
underline,
|
|
88
|
+
default,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
pub const MousePointerStyle = enum(u8) {
|
|
92
|
+
default = 0,
|
|
93
|
+
pointer = 1,
|
|
94
|
+
text = 2,
|
|
95
|
+
crosshair = 3,
|
|
96
|
+
move = 4,
|
|
97
|
+
not_allowed = 5,
|
|
98
|
+
|
|
99
|
+
pub fn toName(self: MousePointerStyle) []const u8 {
|
|
100
|
+
return if (self == .not_allowed) "not-allowed" else @tagName(self);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
pub const ClipboardTarget = enum(u8) {
|
|
105
|
+
clipboard = 0, // "c"
|
|
106
|
+
primary = 1, // "p"
|
|
107
|
+
select = 2, // "s"
|
|
108
|
+
secondary = 3, // "q"
|
|
109
|
+
|
|
110
|
+
pub fn toChar(self: ClipboardTarget) u8 {
|
|
111
|
+
return switch (self) {
|
|
112
|
+
.clipboard => 'c',
|
|
113
|
+
.primary => 'p',
|
|
114
|
+
.select => 's',
|
|
115
|
+
.secondary => 'q',
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
pub const Options = struct {
|
|
121
|
+
// Kitty keyboard protocol flags (progressive enhancement):
|
|
122
|
+
// See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement
|
|
123
|
+
// Bit 0 (0b1): Disambiguate escape codes (fixes ESC timing, alt+key ambiguity, ctrl+c as event)
|
|
124
|
+
// Bit 1 (0b10): Report event types (press/repeat/release)
|
|
125
|
+
// Bit 2 (0b100): Report alternate keys (e.g., numpad vs regular, shifted, base layout)
|
|
126
|
+
// Bit 3 (0b1000): Report all keys as escape codes
|
|
127
|
+
// Bit 4 (0b10000): Report text associated with key events
|
|
128
|
+
// Default 0b00101 (5) = disambiguate + alternate keys
|
|
129
|
+
// Use 0b00111 (7) to also enable event types for key release detection
|
|
130
|
+
kitty_keyboard_flags: u8 = 0b00101,
|
|
131
|
+
remote_mode: RemoteMode = .local,
|
|
132
|
+
// Optional override for environment lookups. Caller owns the map.
|
|
133
|
+
env_map: ?*const std.process.EnvMap = null,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
pub const TerminalInfo = struct {
|
|
137
|
+
name: [64]u8 = [_]u8{0} ** 64,
|
|
138
|
+
name_len: usize = 0,
|
|
139
|
+
version: [32]u8 = [_]u8{0} ** 32,
|
|
140
|
+
version_len: usize = 0,
|
|
141
|
+
from_xtversion: bool = false,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
caps: Capabilities = .{},
|
|
145
|
+
opts: Options = .{},
|
|
146
|
+
host_env_map: ?std.process.EnvMap = null,
|
|
147
|
+
remote: bool = false,
|
|
148
|
+
multiplexer: Multiplexer = .none,
|
|
149
|
+
osc52_support: Osc52Support = .unknown,
|
|
150
|
+
is_foot: bool = false,
|
|
151
|
+
skip_graphics_query: bool = false,
|
|
152
|
+
skip_explicit_width_query: bool = false,
|
|
153
|
+
graphics_query_pending: bool = false,
|
|
154
|
+
capability_queries_pending: bool = false,
|
|
155
|
+
startup_cursor_query_pending: bool = false,
|
|
156
|
+
startup_cursor_query_captured: bool = false,
|
|
157
|
+
|
|
158
|
+
state: struct {
|
|
159
|
+
alt_screen: bool = false,
|
|
160
|
+
kitty_keyboard: bool = false,
|
|
161
|
+
kitty_keyboard_flags: u8 = 0,
|
|
162
|
+
bracketed_paste: bool = false,
|
|
163
|
+
mouse: bool = false,
|
|
164
|
+
mouse_movement: bool = true,
|
|
165
|
+
mouse_was_enabled: bool = false,
|
|
166
|
+
pixel_mouse: bool = false,
|
|
167
|
+
color_scheme_updates: bool = false,
|
|
168
|
+
theme_queries_sent: bool = false,
|
|
169
|
+
focus_tracking: bool = false,
|
|
170
|
+
modify_other_keys: bool = false,
|
|
171
|
+
mouse_pointer: MousePointerStyle = .default,
|
|
172
|
+
cursor: struct {
|
|
173
|
+
row: u16 = 0,
|
|
174
|
+
col: u16 = 0,
|
|
175
|
+
x: u32 = 1, // 1-based for rendering
|
|
176
|
+
y: u32 = 1, // 1-based for rendering
|
|
177
|
+
visible: bool = true,
|
|
178
|
+
style: CursorStyle = .default,
|
|
179
|
+
blinking: bool = false,
|
|
180
|
+
color: ansi.RGBA = ansi.rgbColor(255, 255, 255, 255),
|
|
181
|
+
} = .{},
|
|
182
|
+
} = .{},
|
|
183
|
+
|
|
184
|
+
term_info: TerminalInfo = .{},
|
|
185
|
+
notification_protocol: NotificationProtocol = .none,
|
|
186
|
+
notification_protocol_authoritative: bool = false,
|
|
187
|
+
notification_protocol_source: NotificationProtocolSource = .none,
|
|
188
|
+
notification_id_counter: u64 = 0,
|
|
189
|
+
|
|
190
|
+
pub fn init(opts: Options) Terminal {
|
|
191
|
+
var term: Terminal = .{
|
|
192
|
+
.opts = opts,
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
term.checkEnvironmentOverrides();
|
|
196
|
+
return term;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
pub fn deinit(self: *Terminal) void {
|
|
200
|
+
if (self.host_env_map) |*env_map| {
|
|
201
|
+
env_map.deinit();
|
|
202
|
+
self.host_env_map = null;
|
|
203
|
+
}
|
|
204
|
+
self.opts.env_map = null;
|
|
205
|
+
self.* = undefined;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
pub fn setHostEnvVar(self: *Terminal, allocator: std.mem.Allocator, key: []const u8, value: []const u8) !void {
|
|
209
|
+
if (self.host_env_map == null) {
|
|
210
|
+
self.host_env_map = std.process.EnvMap.init(allocator);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const env_map = &self.host_env_map.?;
|
|
214
|
+
try env_map.put(key, value);
|
|
215
|
+
self.opts.env_map = env_map;
|
|
216
|
+
self.checkEnvironmentOverrides();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
pub fn resetState(self: *Terminal, tty: anytype) !void {
|
|
220
|
+
try tty.writeAll(ansi.ANSI.showCursor);
|
|
221
|
+
try tty.writeAll(ansi.ANSI.reset);
|
|
222
|
+
try tty.writeAll(ansi.ANSI.resetMousePointer);
|
|
223
|
+
self.state.mouse_pointer = .default;
|
|
224
|
+
|
|
225
|
+
if (self.state.kitty_keyboard) {
|
|
226
|
+
try self.setKittyKeyboard(tty, false, 0);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (self.state.modify_other_keys) {
|
|
230
|
+
try self.setModifyOtherKeys(tty, false);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (self.state.mouse_was_enabled) {
|
|
234
|
+
try self.forceDisableMouseMode(tty);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (self.state.bracketed_paste) {
|
|
238
|
+
try self.setBracketedPaste(tty, false);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (self.state.focus_tracking) {
|
|
242
|
+
try self.setFocusTracking(tty, false);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (self.state.alt_screen) {
|
|
246
|
+
try self.exitAltScreen(tty);
|
|
247
|
+
} else {
|
|
248
|
+
switch (builtin.os.tag) {
|
|
249
|
+
.windows => {
|
|
250
|
+
try tty.writeByte('\r');
|
|
251
|
+
var i: u16 = 0;
|
|
252
|
+
while (i < self.state.cursor.row) : (i += 1) {
|
|
253
|
+
try tty.writeAll(ansi.ANSI.reverseIndex);
|
|
254
|
+
}
|
|
255
|
+
try tty.writeAll(ansi.ANSI.eraseBelowCursor);
|
|
256
|
+
},
|
|
257
|
+
else => {},
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (self.state.color_scheme_updates) {
|
|
262
|
+
try self.setColorSchemeUpdates(tty, false);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
self.setTerminalTitle(tty, "");
|
|
266
|
+
|
|
267
|
+
// OSC 111 is intentionally disabled for now. In Ghostty, sending the
|
|
268
|
+
// reset alone is enough to poison later OSC 11 background reporting for
|
|
269
|
+
// system light/dark theme changes, which breaks theme detection on the
|
|
270
|
+
// next app startup even though the immediate reset appears to work.
|
|
271
|
+
// try tty.writeAll(ansi.ANSI.resetTerminalBgColor);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
pub fn enterAltScreen(self: *Terminal, tty: anytype) !void {
|
|
275
|
+
try tty.writeAll(ansi.ANSI.switchToAlternateScreen);
|
|
276
|
+
self.state.alt_screen = true;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
pub fn exitAltScreen(self: *Terminal, tty: anytype) !void {
|
|
280
|
+
try tty.writeAll(ansi.ANSI.switchToMainScreen);
|
|
281
|
+
self.state.alt_screen = false;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
pub fn queryTerminalSend(self: *Terminal, tty: anytype) !void {
|
|
285
|
+
self.checkEnvironmentOverrides();
|
|
286
|
+
self.graphics_query_pending = !self.skip_graphics_query;
|
|
287
|
+
self.capability_queries_pending = false;
|
|
288
|
+
self.startup_cursor_query_pending = true;
|
|
289
|
+
self.startup_cursor_query_captured = false;
|
|
290
|
+
|
|
291
|
+
// We intentionally do not send CSI ?996n here. Terminals disagree on the
|
|
292
|
+
// meaning and reliability of the ?997 reply, so startup theme detection is
|
|
293
|
+
// derived from fresh OSC 10/11 fg/bg colors instead.
|
|
294
|
+
try self.setColorSchemeUpdates(tty, true);
|
|
295
|
+
|
|
296
|
+
try self.queryThemeColors(tty);
|
|
297
|
+
self.state.theme_queries_sent = true;
|
|
298
|
+
|
|
299
|
+
// Send xtversion first (doesn't need DCS wrapping - used for tmux detection)
|
|
300
|
+
try tty.writeAll(ansi.ANSI.xtversion ++
|
|
301
|
+
ansi.ANSI.hideCursor ++
|
|
302
|
+
ansi.ANSI.saveCursorState);
|
|
303
|
+
|
|
304
|
+
// Capture the current cursor position before temporary home-position queries.
|
|
305
|
+
try tty.writeAll(ansi.ANSI.cursorPositionRequest);
|
|
306
|
+
|
|
307
|
+
if (self.isInTmux()) {
|
|
308
|
+
if (self.is_foot) {
|
|
309
|
+
try tty.writeAll(ansi.ANSI.capabilityQueriesFootIsBrokenTmux);
|
|
310
|
+
} else {
|
|
311
|
+
try tty.writeAll(ansi.ANSI.capabilityQueriesTmux);
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
if (self.is_foot) {
|
|
315
|
+
try tty.writeAll(ansi.ANSI.capabilityQueriesFootIsBroken);
|
|
316
|
+
} else {
|
|
317
|
+
try tty.writeAll(ansi.ANSI.capabilityQueries);
|
|
318
|
+
}
|
|
319
|
+
self.capability_queries_pending = true;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (!self.skip_explicit_width_query) {
|
|
323
|
+
try tty.writeAll(ansi.ANSI.home ++
|
|
324
|
+
ansi.ANSI.explicitWidthQuery ++
|
|
325
|
+
ansi.ANSI.cursorPositionRequest ++
|
|
326
|
+
ansi.ANSI.home ++
|
|
327
|
+
ansi.ANSI.scaledTextQuery ++
|
|
328
|
+
ansi.ANSI.cursorPositionRequest);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
try tty.writeAll(ansi.ANSI.restoreCursorState);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
pub fn sendPendingQueries(self: *Terminal, tty: anytype) !bool {
|
|
335
|
+
var sent = false;
|
|
336
|
+
const is_tmux = self.isInTmux();
|
|
337
|
+
|
|
338
|
+
// Re-send capability queries DCS wrapped if tmux detected via xtversion
|
|
339
|
+
// Only needed if we got xtversion response indicating tmux
|
|
340
|
+
if (self.capability_queries_pending) {
|
|
341
|
+
if (self.term_info.from_xtversion and is_tmux) {
|
|
342
|
+
try tty.writeAll(ansi.ANSI.capabilityQueriesTmux);
|
|
343
|
+
sent = true;
|
|
344
|
+
}
|
|
345
|
+
// Clear pending flag regardless - non-tmux terminals already received unwrapped queries
|
|
346
|
+
self.capability_queries_pending = false;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (self.graphics_query_pending and !self.skip_graphics_query) {
|
|
350
|
+
if (is_tmux) {
|
|
351
|
+
try tty.writeAll(ansi.ANSI.kittyGraphicsQueryTmux);
|
|
352
|
+
} else {
|
|
353
|
+
try tty.writeAll(ansi.ANSI.kittyGraphicsQuery);
|
|
354
|
+
}
|
|
355
|
+
self.graphics_query_pending = false;
|
|
356
|
+
sent = true;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return sent;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
pub fn enableDetectedFeatures(self: *Terminal, tty: anytype, use_kitty_keyboard: bool) !void {
|
|
363
|
+
if (builtin.os.tag == .windows) {
|
|
364
|
+
// Windows-specific defaults for ConPTY
|
|
365
|
+
self.caps.rgb = true;
|
|
366
|
+
self.caps.ansi256 = true;
|
|
367
|
+
self.caps.bracketed_paste = true;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
self.checkEnvironmentOverrides();
|
|
371
|
+
|
|
372
|
+
if (!self.state.modify_other_keys and !self.state.kitty_keyboard) {
|
|
373
|
+
try self.setModifyOtherKeys(tty, true);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (self.caps.kitty_keyboard and use_kitty_keyboard) {
|
|
377
|
+
if (self.state.modify_other_keys) {
|
|
378
|
+
try self.setModifyOtherKeys(tty, false);
|
|
379
|
+
}
|
|
380
|
+
try self.setKittyKeyboard(tty, true, self.opts.kitty_keyboard_flags);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (self.caps.unicode == .unicode and !self.caps.explicit_width) {
|
|
384
|
+
try tty.writeAll(ansi.ANSI.unicodeSet);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (self.caps.bracketed_paste) {
|
|
388
|
+
try self.setBracketedPaste(tty, true);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (self.caps.focus_tracking) {
|
|
392
|
+
try self.setFocusTracking(tty, true);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// queryTerminalSend already enabled mode 2031 during normal startup.
|
|
396
|
+
if (!self.state.color_scheme_updates) {
|
|
397
|
+
try self.setColorSchemeUpdates(tty, true);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (!self.state.theme_queries_sent) {
|
|
401
|
+
try self.queryThemeColors(tty);
|
|
402
|
+
self.state.theme_queries_sent = true;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
pub fn queryThemeColors(_: *Terminal, tty: anytype) !void {
|
|
407
|
+
// We only use the ?997 notification as a refresh trigger. The actual theme
|
|
408
|
+
// mode is derived from the returned OSC 10/11 fg/bg colors, so callers
|
|
409
|
+
// should query those colors directly instead of sending CSI ?996n.
|
|
410
|
+
// tmux handles OSC 10/11 as plain OSC; DCS passthrough replies are not
|
|
411
|
+
// routed back to the pane that asked.
|
|
412
|
+
try tty.writeAll(ansi.ANSI.oscThemeQueries);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
fn clearNotificationProtocol(self: *Terminal) void {
|
|
416
|
+
self.notification_protocol = .none;
|
|
417
|
+
self.notification_protocol_authoritative = false;
|
|
418
|
+
self.notification_protocol_source = .none;
|
|
419
|
+
self.caps.notifications = false;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
fn notificationProtocolSourcePriority(source: NotificationProtocolSource) u8 {
|
|
423
|
+
return switch (source) {
|
|
424
|
+
.none => 0,
|
|
425
|
+
.heuristic => 1,
|
|
426
|
+
.xtversion => 2,
|
|
427
|
+
.query => 3,
|
|
428
|
+
.override => 4,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
fn setNotificationProtocol(self: *Terminal, protocol: NotificationProtocol, source: NotificationProtocolSource) void {
|
|
433
|
+
if (protocol == .none) return;
|
|
434
|
+
|
|
435
|
+
// Zellij only forwards OSC 99 desktop notifications. Ignore inherited
|
|
436
|
+
// host-terminal heuristics such as TERM_PROGRAM=ghostty inside Zellij;
|
|
437
|
+
// enable notifications there only from the OSC 99 protocol query or an
|
|
438
|
+
// explicit user override.
|
|
439
|
+
if (self.isInZellij() and source != .override) {
|
|
440
|
+
if (source != .query or protocol != .osc99) return;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const current_source_priority = notificationProtocolSourcePriority(self.notification_protocol_source);
|
|
444
|
+
const next_source_priority = notificationProtocolSourcePriority(source);
|
|
445
|
+
if (next_source_priority < current_source_priority) return;
|
|
446
|
+
if (next_source_priority == current_source_priority and notificationProtocolPriority(protocol) < notificationProtocolPriority(self.notification_protocol)) return;
|
|
447
|
+
|
|
448
|
+
self.notification_protocol = protocol;
|
|
449
|
+
self.notification_protocol_authoritative = source != .heuristic;
|
|
450
|
+
self.notification_protocol_source = source;
|
|
451
|
+
self.caps.notifications = true;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
fn enforceNotificationProtocolForMultiplexer(self: *Terminal) void {
|
|
455
|
+
if (!self.isInZellij() or self.notification_protocol_source == .override) return;
|
|
456
|
+
if (self.notification_protocol_source == .query and self.notification_protocol == .osc99) return;
|
|
457
|
+
|
|
458
|
+
self.clearNotificationProtocol();
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
fn notificationProtocolPriority(protocol: NotificationProtocol) u8 {
|
|
462
|
+
return switch (protocol) {
|
|
463
|
+
.none => 0,
|
|
464
|
+
.osc9 => 1,
|
|
465
|
+
.osc777 => 2,
|
|
466
|
+
.osc99 => 3,
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
fn applyNotificationHeuristic(self: *Terminal, value: []const u8) void {
|
|
471
|
+
if (self.isInZellij()) return;
|
|
472
|
+
if (detectNotificationProtocol(value)) |protocol| {
|
|
473
|
+
self.setNotificationProtocol(protocol, .heuristic);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
fn applyNotificationProtocolOverride(self: *Terminal, value: []const u8) void {
|
|
478
|
+
if (std.mem.eql(u8, value, "0") or
|
|
479
|
+
std.ascii.eqlIgnoreCase(value, "false") or
|
|
480
|
+
std.ascii.eqlIgnoreCase(value, "off") or
|
|
481
|
+
std.ascii.eqlIgnoreCase(value, "none"))
|
|
482
|
+
{
|
|
483
|
+
self.clearNotificationProtocol();
|
|
484
|
+
self.notification_protocol_authoritative = true;
|
|
485
|
+
self.notification_protocol_source = .override;
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
if (std.mem.eql(u8, value, "1") or std.ascii.eqlIgnoreCase(value, "true") or std.ascii.eqlIgnoreCase(value, "on")) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if (std.ascii.eqlIgnoreCase(value, "osc99")) {
|
|
494
|
+
self.setNotificationProtocol(.osc99, .override);
|
|
495
|
+
} else if (std.ascii.eqlIgnoreCase(value, "osc777")) {
|
|
496
|
+
self.setNotificationProtocol(.osc777, .override);
|
|
497
|
+
} else if (std.ascii.eqlIgnoreCase(value, "osc9")) {
|
|
498
|
+
self.setNotificationProtocol(.osc9, .override);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
fn detectNotificationProtocol(value: []const u8) ?NotificationProtocol {
|
|
503
|
+
// OSC 99 is explicitly documented by kitty and supported by foot. Prefer it
|
|
504
|
+
// where the terminal family is known because it has the only real queryable
|
|
505
|
+
// notification protocol and robust text encoding.
|
|
506
|
+
if (std.ascii.indexOfIgnoreCase(value, "kitty") != null or
|
|
507
|
+
std.ascii.indexOfIgnoreCase(value, "foot") != null)
|
|
508
|
+
{
|
|
509
|
+
return .osc99;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// OSC 777 is documented by WezTerm, Warp, hterm/Blink, and is the
|
|
513
|
+
// rxvt/VTE-style title+body notification sequence. Use it where sources
|
|
514
|
+
// document support, or where the terminal is clearly VTE/rxvt-derived.
|
|
515
|
+
if (std.ascii.indexOfIgnoreCase(value, "ghostty") != null or
|
|
516
|
+
std.ascii.indexOfIgnoreCase(value, "wezterm") != null or
|
|
517
|
+
std.ascii.indexOfIgnoreCase(value, "warp") != null or
|
|
518
|
+
std.ascii.indexOfIgnoreCase(value, "hterm") != null or
|
|
519
|
+
std.ascii.indexOfIgnoreCase(value, "blink") != null or
|
|
520
|
+
std.ascii.indexOfIgnoreCase(value, "contour") != null or
|
|
521
|
+
std.ascii.indexOfIgnoreCase(value, "vte") != null or
|
|
522
|
+
std.ascii.indexOfIgnoreCase(value, "gnome") != null or
|
|
523
|
+
std.ascii.indexOfIgnoreCase(value, "tilix") != null or
|
|
524
|
+
std.ascii.indexOfIgnoreCase(value, "terminator") != null or
|
|
525
|
+
std.ascii.indexOfIgnoreCase(value, "xfce") != null or
|
|
526
|
+
std.ascii.indexOfIgnoreCase(value, "urxvt") != null or
|
|
527
|
+
std.ascii.indexOfIgnoreCase(value, "rxvt") != null or
|
|
528
|
+
std.ascii.indexOfIgnoreCase(value, "windows terminal") != null or
|
|
529
|
+
std.ascii.indexOfIgnoreCase(value, "windows_terminal") != null)
|
|
530
|
+
{
|
|
531
|
+
return .osc777;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// OSC 9 is the iTerm2 notification sequence. ConEmu also uses OSC 9 for
|
|
535
|
+
// multiple extensions, so use it only for terminal families with documented
|
|
536
|
+
// notification support rather than as a generic fallback.
|
|
537
|
+
if (std.ascii.indexOfIgnoreCase(value, "iterm") != null or
|
|
538
|
+
std.ascii.indexOfIgnoreCase(value, "Apple_Terminal") != null or
|
|
539
|
+
std.ascii.indexOfIgnoreCase(value, "Terminal.app") != null or
|
|
540
|
+
std.ascii.indexOfIgnoreCase(value, "conemu") != null)
|
|
541
|
+
{
|
|
542
|
+
return .osc9;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
fn termFeaturesHasCode(features: []const u8, code: []const u8) bool {
|
|
549
|
+
var i: usize = 0;
|
|
550
|
+
while (i < features.len) {
|
|
551
|
+
const c = features[i];
|
|
552
|
+
if (!std.ascii.isAlphanumeric(c)) break;
|
|
553
|
+
if (!std.ascii.isUpper(c)) {
|
|
554
|
+
i += 1;
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
const start = i;
|
|
559
|
+
i += 1;
|
|
560
|
+
while (i < features.len and std.ascii.isLower(features[i])) : (i += 1) {}
|
|
561
|
+
if (std.mem.eql(u8, features[start..i], code)) return true;
|
|
562
|
+
while (i < features.len and std.ascii.isDigit(features[i])) : (i += 1) {}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
fn findOscTerminator(payload: []const u8) usize {
|
|
569
|
+
const bel_end = std.mem.indexOfScalar(u8, payload, '\x07');
|
|
570
|
+
const st_end = std.mem.indexOf(u8, payload, "\x1b\\");
|
|
571
|
+
|
|
572
|
+
if (bel_end) |bel| {
|
|
573
|
+
if (st_end) |st| return @min(bel, st);
|
|
574
|
+
return bel;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (st_end) |st| return st;
|
|
578
|
+
return payload.len;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
fn parseItermCapabilities(self: *Terminal, response: []const u8) void {
|
|
582
|
+
var search_start: usize = 0;
|
|
583
|
+
const prefix = "\x1b]1337;Capabilities=";
|
|
584
|
+
while (std.mem.indexOf(u8, response[search_start..], prefix)) |rel_pos| {
|
|
585
|
+
const start = search_start + rel_pos + prefix.len;
|
|
586
|
+
const end = start + findOscTerminator(response[start..]);
|
|
587
|
+
|
|
588
|
+
if (termFeaturesHasCode(response[start..end], "No")) {
|
|
589
|
+
self.setNotificationProtocol(.osc9, .query);
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
search_start = end;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
fn parseOsc99NotificationQuery(self: *Terminal, response: []const u8) void {
|
|
598
|
+
var search_start: usize = 0;
|
|
599
|
+
const prefix = "\x1b]99;";
|
|
600
|
+
while (std.mem.indexOf(u8, response[search_start..], prefix)) |rel_pos| {
|
|
601
|
+
const start = search_start + rel_pos;
|
|
602
|
+
const payload_start = start + prefix.len;
|
|
603
|
+
const end = payload_start + findOscTerminator(response[payload_start..]);
|
|
604
|
+
const payload = response[payload_start..end];
|
|
605
|
+
|
|
606
|
+
if (std.mem.indexOf(u8, payload, "i=" ++ NOTIFICATION_QUERY_ID) != null and
|
|
607
|
+
std.mem.indexOf(u8, payload, "p=?") != null and
|
|
608
|
+
std.mem.indexOf(u8, payload, "p=") != null and
|
|
609
|
+
std.mem.indexOf(u8, payload, "title") != null)
|
|
610
|
+
{
|
|
611
|
+
self.setNotificationProtocol(.osc99, .query);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
search_start = end;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
fn checkEnvironmentOverrides(self: *Terminal) void {
|
|
620
|
+
if (self.isXtversionTmux()) {
|
|
621
|
+
self.multiplexer = .tmux;
|
|
622
|
+
} else if (self.isXtversionZellij()) {
|
|
623
|
+
self.multiplexer = .zellij;
|
|
624
|
+
} else if (self.term_info.from_xtversion) {
|
|
625
|
+
self.multiplexer = .none;
|
|
626
|
+
} else {
|
|
627
|
+
self.multiplexer = .none;
|
|
628
|
+
}
|
|
629
|
+
self.is_foot = self.term_info.from_xtversion and std.ascii.indexOfIgnoreCase(self.getTerminalName(), "foot") != null;
|
|
630
|
+
self.skip_graphics_query = false;
|
|
631
|
+
self.skip_explicit_width_query = false;
|
|
632
|
+
|
|
633
|
+
// Always just try to enable bracketed paste, even if it was reported as not supported
|
|
634
|
+
self.caps.bracketed_paste = true;
|
|
635
|
+
|
|
636
|
+
if (self.caps.rgb) {
|
|
637
|
+
self.caps.ansi256 = true;
|
|
638
|
+
self.caps.hyperlinks = true;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
if (self.opts.remote_mode == .remote) {
|
|
642
|
+
self.remote = true;
|
|
643
|
+
self.caps.remote = true;
|
|
644
|
+
} else if (self.opts.remote_mode == .local) {
|
|
645
|
+
self.remote = false;
|
|
646
|
+
self.caps.remote = false;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
var env_map_storage: ?std.process.EnvMap = null;
|
|
650
|
+
const maybe_env_map: ?*const std.process.EnvMap = self.opts.env_map orelse blk: {
|
|
651
|
+
if (self.opts.remote_mode == .remote) break :blk null;
|
|
652
|
+
env_map_storage = std.process.getEnvMap(std.heap.page_allocator) catch |err| {
|
|
653
|
+
logger.err("Failed to get environment map: {}", .{err});
|
|
654
|
+
return;
|
|
655
|
+
};
|
|
656
|
+
break :blk &env_map_storage.?;
|
|
657
|
+
};
|
|
658
|
+
defer if (env_map_storage) |*map| map.deinit();
|
|
659
|
+
|
|
660
|
+
if (maybe_env_map == null) {
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
const env_map = maybe_env_map.?;
|
|
665
|
+
|
|
666
|
+
if (self.opts.remote_mode == .auto) {
|
|
667
|
+
self.remote = self.remote or isRemoteSessionEnv(env_map);
|
|
668
|
+
self.caps.remote = self.remote;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (self.remote and self.opts.env_map == null) {
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
if (!self.term_info.from_xtversion) {
|
|
676
|
+
if (env_map.get("TMUX")) |_| {
|
|
677
|
+
self.multiplexer = .tmux;
|
|
678
|
+
self.caps.unicode = .wcwidth;
|
|
679
|
+
self.caps.explicit_cursor_positioning = true;
|
|
680
|
+
} else if (env_map.get("ZELLIJ") != null or env_map.get("ZELLIJ_SESSION_NAME") != null or env_map.get("ZELLIJ_PANE_ID") != null) {
|
|
681
|
+
self.multiplexer = .zellij;
|
|
682
|
+
if (self.term_info.name_len == 0) {
|
|
683
|
+
const name = "Zellij";
|
|
684
|
+
@memcpy(self.term_info.name[0..name.len], name);
|
|
685
|
+
self.term_info.name_len = name.len;
|
|
686
|
+
}
|
|
687
|
+
} else if (env_map.get("STY") != null) {
|
|
688
|
+
self.multiplexer = .screen;
|
|
689
|
+
self.skip_graphics_query = true;
|
|
690
|
+
self.caps.unicode = .wcwidth;
|
|
691
|
+
self.caps.explicit_cursor_positioning = true;
|
|
692
|
+
} else if (env_map.get("TERM")) |term| {
|
|
693
|
+
if (std.mem.startsWith(u8, term, "tmux")) {
|
|
694
|
+
self.multiplexer = .tmux;
|
|
695
|
+
self.caps.unicode = .wcwidth;
|
|
696
|
+
self.caps.explicit_cursor_positioning = true;
|
|
697
|
+
} else if (std.mem.startsWith(u8, term, "screen")) {
|
|
698
|
+
self.multiplexer = .screen;
|
|
699
|
+
self.skip_graphics_query = true;
|
|
700
|
+
self.caps.unicode = .wcwidth;
|
|
701
|
+
self.caps.explicit_cursor_positioning = true;
|
|
702
|
+
}
|
|
703
|
+
if (std.mem.indexOf(u8, term, "alacritty") != null) {
|
|
704
|
+
self.caps.explicit_cursor_positioning = true;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
if (env_map.get("TERM")) |term| {
|
|
710
|
+
if (std.ascii.indexOfIgnoreCase(term, "256color") != null) {
|
|
711
|
+
self.caps.ansi256 = true;
|
|
712
|
+
}
|
|
713
|
+
self.applyNotificationHeuristic(term);
|
|
714
|
+
self.is_foot = self.is_foot or std.ascii.indexOfIgnoreCase(term, "foot") != null;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (env_map.get("TERM_FEATURES")) |features| {
|
|
718
|
+
if (termFeaturesHasCode(features, "No")) {
|
|
719
|
+
self.setNotificationProtocol(.osc9, .heuristic);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (env_map.get("OPENTUI_GRAPHICS")) |val| {
|
|
724
|
+
if (std.mem.eql(u8, val, "false") or std.mem.eql(u8, val, "0")) {
|
|
725
|
+
self.skip_graphics_query = true;
|
|
726
|
+
} else if (std.mem.eql(u8, val, "true") or std.mem.eql(u8, val, "1")) {
|
|
727
|
+
self.skip_graphics_query = false;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
if (!self.term_info.from_xtversion) {
|
|
732
|
+
if (env_map.get("TERM_PROGRAM")) |prog| {
|
|
733
|
+
if (!self.isInZellij()) {
|
|
734
|
+
const copy_len = @min(prog.len, self.term_info.name.len);
|
|
735
|
+
@memcpy(self.term_info.name[0..copy_len], prog[0..copy_len]);
|
|
736
|
+
self.term_info.name_len = copy_len;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
if (!self.isInZellij() and std.mem.eql(u8, prog, "tmux")) {
|
|
740
|
+
self.multiplexer = .tmux;
|
|
741
|
+
self.caps.unicode = .wcwidth;
|
|
742
|
+
self.caps.explicit_cursor_positioning = true;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
self.applyNotificationHeuristic(prog);
|
|
746
|
+
|
|
747
|
+
if (!self.isInZellij()) {
|
|
748
|
+
if (env_map.get("TERM_PROGRAM_VERSION")) |ver| {
|
|
749
|
+
const ver_len = @min(ver.len, self.term_info.version.len);
|
|
750
|
+
@memcpy(self.term_info.version[0..ver_len], ver[0..ver_len]);
|
|
751
|
+
self.term_info.version_len = ver_len;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
if (env_map.get("TERM_PROGRAM")) |prog| {
|
|
757
|
+
if (std.mem.eql(u8, prog, "vscode")) {
|
|
758
|
+
self.caps.kitty_keyboard = false;
|
|
759
|
+
self.caps.kitty_graphics = false;
|
|
760
|
+
self.caps.unicode = .unicode;
|
|
761
|
+
} else if (std.mem.eql(u8, prog, "Apple_Terminal")) {
|
|
762
|
+
self.caps.unicode = .wcwidth;
|
|
763
|
+
} else if (std.mem.eql(u8, prog, "Alacritty")) {
|
|
764
|
+
self.caps.explicit_cursor_positioning = true;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
if (env_map.get("ALACRITTY_SOCKET") != null or env_map.get("ALACRITTY_LOG") != null) {
|
|
769
|
+
self.caps.explicit_cursor_positioning = true;
|
|
770
|
+
if (self.term_info.name_len == 0) {
|
|
771
|
+
const name = "Alacritty";
|
|
772
|
+
@memcpy(self.term_info.name[0..name.len], name);
|
|
773
|
+
self.term_info.name_len = name.len;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (env_map.get("COLORTERM")) |colorterm| {
|
|
779
|
+
if (std.mem.eql(u8, colorterm, "truecolor") or
|
|
780
|
+
std.mem.eql(u8, colorterm, "24bit"))
|
|
781
|
+
{
|
|
782
|
+
self.caps.rgb = true;
|
|
783
|
+
self.caps.ansi256 = true;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
if (env_map.get("WT_SESSION") != null) {
|
|
788
|
+
self.caps.rgb = true;
|
|
789
|
+
self.caps.ansi256 = true;
|
|
790
|
+
self.setNotificationProtocol(.osc777, .heuristic);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
if (env_map.get("OPENTUI_NOTIFICATION_PROTOCOL")) |protocol| {
|
|
794
|
+
self.applyNotificationProtocolOverride(protocol);
|
|
795
|
+
}
|
|
796
|
+
if (env_map.get("OPENTUI_NOTIFICATIONS")) |value| {
|
|
797
|
+
if (std.mem.eql(u8, value, "0") or std.ascii.eqlIgnoreCase(value, "false") or std.ascii.eqlIgnoreCase(value, "off")) {
|
|
798
|
+
self.applyNotificationProtocolOverride("none");
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
self.enforceNotificationProtocolForMultiplexer();
|
|
803
|
+
|
|
804
|
+
if (!self.term_info.from_xtversion) {
|
|
805
|
+
if (env_map.get("TERMUX_VERSION")) |_| {
|
|
806
|
+
self.caps.unicode = .wcwidth;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
if (env_map.get("VHS_RECORD")) |_| {
|
|
810
|
+
self.caps.unicode = .wcwidth;
|
|
811
|
+
self.caps.kitty_keyboard = false;
|
|
812
|
+
self.caps.kitty_graphics = false;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
if (env_map.get("OPENTUI_FORCE_WCWIDTH")) |_| {
|
|
817
|
+
self.caps.unicode = .wcwidth;
|
|
818
|
+
}
|
|
819
|
+
if (env_map.get("OPENTUI_FORCE_UNICODE")) |_| {
|
|
820
|
+
self.caps.unicode = .unicode;
|
|
821
|
+
}
|
|
822
|
+
if (env_map.get("OPENTUI_FORCE_NOZWJ")) |_| {
|
|
823
|
+
self.caps.unicode = .no_zwj;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
if (env_map.get("OPENTUI_FORCE_EXPLICIT_WIDTH")) |val| {
|
|
827
|
+
if (std.mem.eql(u8, val, "true") or std.mem.eql(u8, val, "1")) {
|
|
828
|
+
self.caps.explicit_width = true;
|
|
829
|
+
} else if (std.mem.eql(u8, val, "false") or std.mem.eql(u8, val, "0")) {
|
|
830
|
+
self.caps.explicit_width = false;
|
|
831
|
+
self.skip_explicit_width_query = true;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
if (!self.caps.hyperlinks and self.term_info.from_xtversion) {
|
|
836
|
+
if (isHyperlinkTerm(self.getTerminalName())) {
|
|
837
|
+
self.caps.hyperlinks = true;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
if (!self.caps.hyperlinks and !self.term_info.from_xtversion) {
|
|
842
|
+
if (env_map.get("TERM")) |term| {
|
|
843
|
+
if (isHyperlinkTerm(term)) {
|
|
844
|
+
self.caps.hyperlinks = true;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
if (!self.caps.hyperlinks and !self.term_info.from_xtversion) {
|
|
850
|
+
const is_wsl = env_map.get("WSL_DISTRO_NAME") != null or env_map.get("WSL_INTEROP") != null;
|
|
851
|
+
const has_wt_session = env_map.get("WT_SESSION") != null;
|
|
852
|
+
if (is_wsl and has_wt_session) {
|
|
853
|
+
if (env_map.get("TERM")) |term| {
|
|
854
|
+
if (std.mem.startsWith(u8, term, "xterm")) {
|
|
855
|
+
self.caps.hyperlinks = true;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
if (!self.caps.osc52 and !self.term_info.from_xtversion) {
|
|
862
|
+
if (env_map.get("WT_SESSION") != null) {
|
|
863
|
+
self.caps.osc52 = true;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
if (!self.caps.osc52 and (self.isInTmux() or self.isInScreen() or env_map.get("STY") != null)) {
|
|
867
|
+
self.caps.osc52 = true;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
if (!self.caps.osc52) {
|
|
871
|
+
if (env_map.get("TERM_PROGRAM")) |prog| {
|
|
872
|
+
if (isOsc52Term(prog)) {
|
|
873
|
+
self.caps.osc52 = true;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
if (!self.caps.osc52) {
|
|
879
|
+
if (env_map.get("TERM")) |term| {
|
|
880
|
+
if (isOsc52Term(term) or std.mem.indexOf(u8, term, "256color") != null or std.mem.indexOf(u8, term, "xterm") != null) {
|
|
881
|
+
self.caps.osc52 = true;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
fn isRemoteSessionEnv(env_map: *const std.process.EnvMap) bool {
|
|
889
|
+
return env_map.get("SSH_CONNECTION") != null or
|
|
890
|
+
env_map.get("SSH_CLIENT") != null or
|
|
891
|
+
env_map.get("SSH_TTY") != null or
|
|
892
|
+
env_map.get("MOSH_CONNECTION") != null;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
fn writeMouseDisableSequences(tty: anytype) !void {
|
|
896
|
+
try tty.writeAll(ansi.ANSI.disableAnyEventTracking);
|
|
897
|
+
try tty.writeAll(ansi.ANSI.disableButtonEventTracking);
|
|
898
|
+
try tty.writeAll(ansi.ANSI.disableMouseTracking);
|
|
899
|
+
try tty.writeAll(ansi.ANSI.disableSGRMouseMode);
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
// TODO: Allow pixel mouse mode to be enabled,
|
|
903
|
+
// currently does not make sense and is not supported by higher levels
|
|
904
|
+
pub fn setMouseMode(self: *Terminal, tty: anytype, enable: bool, enable_movement: bool) !void {
|
|
905
|
+
if (enable) {
|
|
906
|
+
if (self.state.mouse and self.state.mouse_movement == enable_movement) return;
|
|
907
|
+
} else if (!self.state.mouse) {
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
if (enable) {
|
|
912
|
+
self.state.mouse = true;
|
|
913
|
+
self.state.mouse_movement = enable_movement;
|
|
914
|
+
// Arms the shutdown cleanup path so resetState() will still emit mouse
|
|
915
|
+
// disable sequences even if a later best-effort disable silently fails.
|
|
916
|
+
self.state.mouse_was_enabled = true;
|
|
917
|
+
if (!enable_movement) {
|
|
918
|
+
// Some terminals treat ?1000/?1002/?1003 as one family and let the
|
|
919
|
+
// last sequence win. Reset any-event tracking first, then enable
|
|
920
|
+
// click/drag modes so they remain active.
|
|
921
|
+
try tty.writeAll(ansi.ANSI.disableAnyEventTracking);
|
|
922
|
+
}
|
|
923
|
+
try tty.writeAll(ansi.ANSI.enableMouseTracking);
|
|
924
|
+
try tty.writeAll(ansi.ANSI.enableButtonEventTracking);
|
|
925
|
+
if (enable_movement) {
|
|
926
|
+
try tty.writeAll(ansi.ANSI.enableAnyEventTracking);
|
|
927
|
+
}
|
|
928
|
+
try tty.writeAll(ansi.ANSI.enableSGRMouseMode);
|
|
929
|
+
} else {
|
|
930
|
+
self.state.mouse = false;
|
|
931
|
+
self.state.pixel_mouse = false;
|
|
932
|
+
try writeMouseDisableSequences(tty);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// Best-effort shutdown path: emit the reset sequences even if tracked state
|
|
937
|
+
// already drifted to false because earlier writes failed.
|
|
938
|
+
pub fn forceDisableMouseMode(self: *Terminal, tty: anytype) !void {
|
|
939
|
+
self.state.mouse = false;
|
|
940
|
+
self.state.pixel_mouse = false;
|
|
941
|
+
try writeMouseDisableSequences(tty);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
pub fn setBracketedPaste(self: *Terminal, tty: anytype, enable: bool) !void {
|
|
945
|
+
const seq = if (enable) ansi.ANSI.bracketedPasteSet else ansi.ANSI.bracketedPasteReset;
|
|
946
|
+
try tty.writeAll(seq);
|
|
947
|
+
self.state.bracketed_paste = enable;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
pub fn setFocusTracking(self: *Terminal, tty: anytype, enable: bool) !void {
|
|
951
|
+
const seq = if (enable) ansi.ANSI.focusSet else ansi.ANSI.focusReset;
|
|
952
|
+
try tty.writeAll(seq);
|
|
953
|
+
self.state.focus_tracking = enable;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
pub fn setKittyKeyboard(self: *Terminal, tty: anytype, enable: bool, flags: u8) !void {
|
|
957
|
+
if (enable) {
|
|
958
|
+
if (!self.state.kitty_keyboard) {
|
|
959
|
+
try tty.print(ansi.ANSI.csiUPush, .{flags});
|
|
960
|
+
self.state.kitty_keyboard = true;
|
|
961
|
+
self.state.kitty_keyboard_flags = flags;
|
|
962
|
+
}
|
|
963
|
+
} else {
|
|
964
|
+
if (self.state.kitty_keyboard) {
|
|
965
|
+
try tty.writeAll(ansi.ANSI.csiUPop);
|
|
966
|
+
self.state.kitty_keyboard = false;
|
|
967
|
+
self.state.kitty_keyboard_flags = 0;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
pub fn setModifyOtherKeys(self: *Terminal, tty: anytype, enable: bool) !void {
|
|
973
|
+
const seq = if (enable) ansi.ANSI.modifyOtherKeysSet else ansi.ANSI.modifyOtherKeysReset;
|
|
974
|
+
try tty.writeAll(seq);
|
|
975
|
+
self.state.modify_other_keys = enable;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
pub fn setColorSchemeUpdates(self: *Terminal, tty: anytype, enable: bool) !void {
|
|
979
|
+
const seq = if (enable) ansi.ANSI.colorSchemeSet else ansi.ANSI.colorSchemeReset;
|
|
980
|
+
try tty.writeAll(seq);
|
|
981
|
+
self.state.color_scheme_updates = enable;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/// Re-send all currently-active terminal mode escape sequences unconditionally.
|
|
985
|
+
///
|
|
986
|
+
/// When the terminal loses and regains focus (e.g. alt-tab, tab switch, minimize),
|
|
987
|
+
/// some terminal emulators (notably Windows Terminal / ConPTY) strip or reset
|
|
988
|
+
/// DEC private modes like mouse tracking (?1000/?1002/?1003/?1006), focus
|
|
989
|
+
/// tracking (?1004), and bracketed paste (?2004). This function re-emits the
|
|
990
|
+
/// enable sequences for every mode that our state tracking says is currently on,
|
|
991
|
+
/// without checking whether the mode "should" already be enabled — because the
|
|
992
|
+
/// terminal may have silently disabled it.
|
|
993
|
+
///
|
|
994
|
+
/// This should be called in response to the focus-in event (\x1b[I).
|
|
995
|
+
///
|
|
996
|
+
/// Per the xterm ctlseqs spec (Patch #401, 2025/06/22) and the Microsoft
|
|
997
|
+
/// Console Virtual Terminal Sequences documentation, the relevant DECSET
|
|
998
|
+
/// private modes are:
|
|
999
|
+
/// ?1000h - Normal mouse tracking (sends button press/release)
|
|
1000
|
+
/// ?1002h - Button-event tracking (adds drag reporting)
|
|
1001
|
+
/// ?1003h - Any-event tracking (adds all motion reporting)
|
|
1002
|
+
/// ?1006h - SGR extended mouse mode (extended coordinate encoding)
|
|
1003
|
+
/// ?1004h - Focus event tracking (sends \x1b[I / \x1b[O)
|
|
1004
|
+
/// ?2004h - Bracketed paste mode (wraps pasted text in markers)
|
|
1005
|
+
/// Kitty keyboard protocol (CSI > flags u) - progressive enhancement
|
|
1006
|
+
/// modifyOtherKeys (CSI > 4 ; 1 m) - xterm key modification
|
|
1007
|
+
pub fn restoreTerminalModes(self: *Terminal, tty: anytype) !void {
|
|
1008
|
+
// Re-enable mouse tracking modes if active
|
|
1009
|
+
if (self.state.mouse) {
|
|
1010
|
+
if (!self.state.mouse_movement) {
|
|
1011
|
+
try tty.writeAll(ansi.ANSI.disableAnyEventTracking);
|
|
1012
|
+
}
|
|
1013
|
+
try tty.writeAll(ansi.ANSI.enableMouseTracking);
|
|
1014
|
+
try tty.writeAll(ansi.ANSI.enableButtonEventTracking);
|
|
1015
|
+
if (self.state.mouse_movement) {
|
|
1016
|
+
try tty.writeAll(ansi.ANSI.enableAnyEventTracking);
|
|
1017
|
+
}
|
|
1018
|
+
try tty.writeAll(ansi.ANSI.enableSGRMouseMode);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
// Re-enable focus tracking if active
|
|
1022
|
+
if (self.state.focus_tracking) {
|
|
1023
|
+
try tty.writeAll(ansi.ANSI.focusSet);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
// Re-enable bracketed paste if active
|
|
1027
|
+
if (self.state.bracketed_paste) {
|
|
1028
|
+
try tty.writeAll(ansi.ANSI.bracketedPasteSet);
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// Pop stale entry then re-push kitty keyboard protocol to avoid stack growth.
|
|
1032
|
+
// Both sequences are in the same write buffer so the terminal processes them atomically.
|
|
1033
|
+
if (self.state.kitty_keyboard) {
|
|
1034
|
+
try tty.writeAll(ansi.ANSI.csiUPop);
|
|
1035
|
+
try tty.print(ansi.ANSI.csiUPush, .{self.state.kitty_keyboard_flags});
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// Re-enable modifyOtherKeys if active
|
|
1039
|
+
if (self.state.modify_other_keys) {
|
|
1040
|
+
try tty.writeAll(ansi.ANSI.modifyOtherKeysSet);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/// The responses look like these:
|
|
1045
|
+
/// kitty - '\x1B[?1016;2$y\x1B[?2027;0$y\x1B[?2031;2$y\x1B[?1004;1$y\x1B[?2026;2$y\x1B[1;2R\x1B[1;3R\x1BP>|kitty(0.40.1)\x1B\\\x1B[?0u\x1B_Gi=1;EINVAL:Zero width/height not allowed\x1B\\\x1B[?62;c'
|
|
1046
|
+
/// ghostty - '\x1B[?1016;1$y\x1B[?2027;1$y\x1B[?2031;2$y\x1B[?1004;1$y\x1B[?2004;2$y\x1B[?2026;2$y\x1B[1;1R\x1B[1;1R\x1BP>|ghostty 1.1.3\x1B\\\x1B[?0u\x1B_Gi=1;OK\x1B\\\x1B[?62;22c'
|
|
1047
|
+
/// tmux - '\x1B[1;1R\x1B[1;1R\x1BP>|tmux 3.5a\x1B\\\x1B[?1;2;4c\x1B[?2;3;0S'
|
|
1048
|
+
/// vscode - '\x1B[?1016;2$y'
|
|
1049
|
+
/// alacritty - '\x1B[?1016;0$y\x1B[?2027;0$y\x1B[?2031;0$y\x1B[?1004;2$y\x1B[?2004;2$y\x1B[?2026;2$y\x1B[1;1R\x1B[1;1R\x1B[?0u\x1B[?6c'
|
|
1050
|
+
///
|
|
1051
|
+
/// Parsing these is not complete yet
|
|
1052
|
+
pub fn processCapabilityResponse(self: *Terminal, response: []const u8) void {
|
|
1053
|
+
self.parseOsc99NotificationQuery(response);
|
|
1054
|
+
self.parseItermCapabilities(response);
|
|
1055
|
+
self.parseXtgettcapMs(response);
|
|
1056
|
+
|
|
1057
|
+
// DECRPM responses
|
|
1058
|
+
if (std.mem.indexOf(u8, response, "1016;2$y")) |_| {
|
|
1059
|
+
self.caps.sgr_pixels = true;
|
|
1060
|
+
}
|
|
1061
|
+
if (std.mem.indexOf(u8, response, "2027;2$y")) |_| {
|
|
1062
|
+
self.caps.unicode = .unicode;
|
|
1063
|
+
}
|
|
1064
|
+
if (std.mem.indexOf(u8, response, "2031;1$y") != null or std.mem.indexOf(u8, response, "2031;2$y") != null) {
|
|
1065
|
+
self.caps.color_scheme_updates = true;
|
|
1066
|
+
}
|
|
1067
|
+
if (std.mem.indexOf(u8, response, "1004;1$y") != null or std.mem.indexOf(u8, response, "1004;2$y") != null) {
|
|
1068
|
+
self.caps.focus_tracking = true;
|
|
1069
|
+
}
|
|
1070
|
+
if (std.mem.indexOf(u8, response, "2026;1$y") != null or std.mem.indexOf(u8, response, "2026;2$y") != null) {
|
|
1071
|
+
self.caps.sync = true;
|
|
1072
|
+
}
|
|
1073
|
+
if (std.mem.indexOf(u8, response, "2004;1$y") != null or std.mem.indexOf(u8, response, "2004;2$y") != null) {
|
|
1074
|
+
self.caps.bracketed_paste = true;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
// Parse cursor position reports: ESC[row;colR
|
|
1078
|
+
// The first report after queryTerminalSend is the pre-home cursor position.
|
|
1079
|
+
var scan_pos: usize = 0;
|
|
1080
|
+
while (scan_pos < response.len) {
|
|
1081
|
+
const esc_rel = std.mem.indexOf(u8, response[scan_pos..], "\x1b[") orelse break;
|
|
1082
|
+
const esc = scan_pos + esc_rel;
|
|
1083
|
+
var pos = esc + 2;
|
|
1084
|
+
|
|
1085
|
+
const row_start = pos;
|
|
1086
|
+
while (pos < response.len and response[pos] >= '0' and response[pos] <= '9') : (pos += 1) {}
|
|
1087
|
+
if (pos == row_start or pos >= response.len or response[pos] != ';') {
|
|
1088
|
+
scan_pos = esc + 2;
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
const row = std.fmt.parseInt(u16, response[row_start..pos], 10) catch {
|
|
1093
|
+
scan_pos = pos + 1;
|
|
1094
|
+
continue;
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
pos += 1;
|
|
1098
|
+
const col_start = pos;
|
|
1099
|
+
while (pos < response.len and response[pos] >= '0' and response[pos] <= '9') : (pos += 1) {}
|
|
1100
|
+
if (pos == col_start or pos >= response.len or response[pos] != 'R') {
|
|
1101
|
+
scan_pos = col_start;
|
|
1102
|
+
continue;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
const col = std.fmt.parseInt(u16, response[col_start..pos], 10) catch {
|
|
1106
|
+
scan_pos = pos + 1;
|
|
1107
|
+
continue;
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
if (self.startup_cursor_query_pending and !self.startup_cursor_query_captured and row >= 1 and col >= 1) {
|
|
1111
|
+
self.setCursorPosition(col, row, self.state.cursor.visible);
|
|
1112
|
+
self.startup_cursor_query_captured = true;
|
|
1113
|
+
self.startup_cursor_query_pending = false;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
if (row == 1) {
|
|
1117
|
+
if (col >= 2) {
|
|
1118
|
+
self.caps.explicit_width = true;
|
|
1119
|
+
}
|
|
1120
|
+
if (col >= 3) {
|
|
1121
|
+
self.caps.scaled_text = true;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
scan_pos = pos + 1;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// Parse xtversion response: ESC P > | name version ESC \
|
|
1129
|
+
// Examples: "\x1BP>|kitty(0.40.1)\x1B\\" or "\x1BP>|ghostty 1.1.3\x1B\\" or "\x1BP>|tmux 3.5a\x1B\\"
|
|
1130
|
+
if (std.mem.indexOf(u8, response, "\x1bP>|")) |pos| {
|
|
1131
|
+
const start = pos + 4; // Skip past "\x1BP>|"
|
|
1132
|
+
if (std.mem.indexOf(u8, response[start..], "\x1b\\")) |end_offset| {
|
|
1133
|
+
const term_str = response[start .. start + end_offset];
|
|
1134
|
+
self.parseXtversion(term_str);
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// Kitty detection
|
|
1139
|
+
if (std.mem.indexOf(u8, response, "kitty")) |_| {
|
|
1140
|
+
self.caps.kitty_keyboard = true;
|
|
1141
|
+
self.caps.kitty_graphics = true;
|
|
1142
|
+
self.caps.unicode = .unicode;
|
|
1143
|
+
self.caps.rgb = true;
|
|
1144
|
+
self.caps.ansi256 = true;
|
|
1145
|
+
self.caps.sixel = true;
|
|
1146
|
+
self.caps.bracketed_paste = true;
|
|
1147
|
+
self.caps.hyperlinks = true;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// Kitty keyboard protocol detection via CSI ? u response
|
|
1151
|
+
// Terminals supporting the protocol respond to CSI ? u with CSI ? <flags> u
|
|
1152
|
+
// Examples: \x1b[?0u (ghostty, alacritty), \x1b[?1u, etc.
|
|
1153
|
+
if (std.mem.indexOf(u8, response, "\x1b[?") != null and std.mem.indexOf(u8, response, "u") != null) {
|
|
1154
|
+
// Look for pattern \x1b[?Nu where N is 0-31
|
|
1155
|
+
var i: usize = 0;
|
|
1156
|
+
while (i + 4 < response.len) : (i += 1) {
|
|
1157
|
+
if (response[i] == '\x1b' and i + 1 < response.len and response[i + 1] == '[' and i + 2 < response.len and response[i + 2] == '?') {
|
|
1158
|
+
var num_end = i + 3;
|
|
1159
|
+
while (num_end < response.len and response[num_end] >= '0' and response[num_end] <= '9') : (num_end += 1) {}
|
|
1160
|
+
if (num_end > i + 3 and num_end < response.len and response[num_end] == 'u') {
|
|
1161
|
+
self.caps.kitty_keyboard = true;
|
|
1162
|
+
break;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
if (std.mem.indexOf(u8, response, "tmux")) |_| {
|
|
1169
|
+
self.caps.unicode = .wcwidth;
|
|
1170
|
+
self.caps.explicit_cursor_positioning = true;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
if (std.mem.indexOf(u8, response, "alacritty")) |_| {
|
|
1174
|
+
self.caps.explicit_cursor_positioning = true;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
// Sixel detection via device attributes (capability 4 in DA1 response ending with 'c')
|
|
1178
|
+
if (std.mem.indexOf(u8, response, ";c")) |pos| {
|
|
1179
|
+
var start: usize = 0;
|
|
1180
|
+
if (pos >= 4) {
|
|
1181
|
+
start = pos;
|
|
1182
|
+
while (start > 0 and response[start] != '\x1b') {
|
|
1183
|
+
start -= 1;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
const da_response = response[start .. pos + 2];
|
|
1187
|
+
|
|
1188
|
+
if (std.mem.indexOf(u8, da_response, "\x1b[?") == 0) {
|
|
1189
|
+
if (std.mem.indexOf(u8, da_response, "4;") != null or std.mem.indexOf(u8, da_response, ";4;") != null or std.mem.indexOf(u8, da_response, ";4c") != null) {
|
|
1190
|
+
self.caps.sixel = true;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
// Kitty graphics response: ESC_Gi=31337;OK ESC\ or ESC_Gi=31337;EERROR... ESC\
|
|
1197
|
+
// We look for our specific query ID (31337) to avoid false positives
|
|
1198
|
+
if (std.mem.indexOf(u8, response, "\x1b_G")) |_| {
|
|
1199
|
+
if (std.mem.indexOf(u8, response, "i=31337")) |_| {
|
|
1200
|
+
// Got a response to our graphics query with our ID
|
|
1201
|
+
// If it contains "OK" or even an error, the protocol is supported
|
|
1202
|
+
// (errors mean the query was understood, just parameters were wrong)
|
|
1203
|
+
self.caps.kitty_graphics = true;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
if (!self.caps.osc52 and isOsc52Term(response)) {
|
|
1208
|
+
self.caps.osc52 = true;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
if (!self.caps.hyperlinks and isHyperlinkTerm(response)) {
|
|
1212
|
+
self.caps.hyperlinks = true;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
fn parseXtgettcapMs(self: *Terminal, response: []const u8) void {
|
|
1217
|
+
const prefix = "\x1bP";
|
|
1218
|
+
var scan_pos: usize = 0;
|
|
1219
|
+
while (std.mem.indexOfPos(u8, response, scan_pos, prefix)) |start| {
|
|
1220
|
+
const body_start = start + prefix.len;
|
|
1221
|
+
const end = std.mem.indexOfPos(u8, response, body_start, "\x1b\\") orelse return;
|
|
1222
|
+
const body = response[body_start..end];
|
|
1223
|
+
scan_pos = end + 2;
|
|
1224
|
+
|
|
1225
|
+
if (body.len < 6 or body[0] != '1') continue;
|
|
1226
|
+
if (!std.mem.eql(u8, body[1..3], "+r")) continue;
|
|
1227
|
+
|
|
1228
|
+
const result = body[3..];
|
|
1229
|
+
const separator = std.mem.indexOfScalar(u8, result, '=') orelse continue;
|
|
1230
|
+
if (!std.ascii.eqlIgnoreCase(result[0..separator], "4d73")) continue;
|
|
1231
|
+
|
|
1232
|
+
const value = result[separator + 1 ..];
|
|
1233
|
+
if (value.len == 0 or value.len % 2 != 0) continue;
|
|
1234
|
+
for (value) |byte| {
|
|
1235
|
+
if (!std.ascii.isHex(byte)) break;
|
|
1236
|
+
} else {
|
|
1237
|
+
self.osc52_support = .supported;
|
|
1238
|
+
self.caps.osc52 = true;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
fn isOsc52Term(value: []const u8) bool {
|
|
1244
|
+
return std.ascii.indexOfIgnoreCase(value, "iterm") != null or
|
|
1245
|
+
std.ascii.indexOfIgnoreCase(value, "kitty") != null or
|
|
1246
|
+
std.ascii.indexOfIgnoreCase(value, "alacritty") != null or
|
|
1247
|
+
std.ascii.indexOfIgnoreCase(value, "wezterm") != null or
|
|
1248
|
+
std.ascii.indexOfIgnoreCase(value, "contour") != null or
|
|
1249
|
+
std.ascii.indexOfIgnoreCase(value, "foot") != null or
|
|
1250
|
+
std.ascii.indexOfIgnoreCase(value, "rio") != null or
|
|
1251
|
+
std.ascii.indexOfIgnoreCase(value, "ghostty") != null or
|
|
1252
|
+
std.ascii.indexOfIgnoreCase(value, "tmux") != null or
|
|
1253
|
+
std.ascii.indexOfIgnoreCase(value, "screen") != null;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
fn isHyperlinkTerm(value: []const u8) bool {
|
|
1257
|
+
return std.ascii.indexOfIgnoreCase(value, "ghostty") != null or
|
|
1258
|
+
std.ascii.indexOfIgnoreCase(value, "kitty") != null or
|
|
1259
|
+
std.ascii.indexOfIgnoreCase(value, "wezterm") != null or
|
|
1260
|
+
std.ascii.indexOfIgnoreCase(value, "alacritty") != null or
|
|
1261
|
+
std.ascii.indexOfIgnoreCase(value, "iterm") != null;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
pub fn getCapabilities(self: *Terminal) Capabilities {
|
|
1265
|
+
return self.caps;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
pub fn setMousePointerStyle(self: *Terminal, style: MousePointerStyle) void {
|
|
1269
|
+
self.state.mouse_pointer = style;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
pub fn getMousePointer(self: *Terminal) MousePointerStyle {
|
|
1273
|
+
return self.state.mouse_pointer;
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
pub fn setCursorPosition(self: *Terminal, x: u32, y: u32, visible: bool) void {
|
|
1277
|
+
self.state.cursor.x = @max(1, x);
|
|
1278
|
+
self.state.cursor.y = @max(1, y);
|
|
1279
|
+
self.state.cursor.visible = visible;
|
|
1280
|
+
|
|
1281
|
+
// Update 0-based coordinates for terminal operations
|
|
1282
|
+
self.state.cursor.col = @intCast(@max(0, x - 1));
|
|
1283
|
+
self.state.cursor.row = @intCast(@max(0, y - 1));
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
pub fn setCursorStyle(self: *Terminal, style: CursorStyle, blinking: bool) void {
|
|
1287
|
+
self.state.cursor.style = style;
|
|
1288
|
+
self.state.cursor.blinking = blinking;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
pub fn setCursorColor(self: *Terminal, color: ansi.RGBA) void {
|
|
1292
|
+
self.state.cursor.color = color;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
pub fn getCursorPosition(self: *Terminal) struct { x: u32, y: u32, visible: bool } {
|
|
1296
|
+
return .{
|
|
1297
|
+
.x = self.state.cursor.x,
|
|
1298
|
+
.y = self.state.cursor.y,
|
|
1299
|
+
.visible = self.state.cursor.visible,
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
pub fn getCursorStyle(self: *Terminal) struct { style: CursorStyle, blinking: bool } {
|
|
1304
|
+
return .{
|
|
1305
|
+
.style = self.state.cursor.style,
|
|
1306
|
+
.blinking = self.state.cursor.blinking,
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
pub fn getCursorColor(self: *Terminal) ansi.RGBA {
|
|
1311
|
+
return self.state.cursor.color;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
pub fn setKittyKeyboardFlags(self: *Terminal, flags: u8) void {
|
|
1315
|
+
self.opts.kitty_keyboard_flags = flags;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
pub fn setTerminalTitle(_: *Terminal, tty: anytype, title: []const u8) void {
|
|
1319
|
+
// For Windows, we might need to use different approach, but ANSI sequences work in Windows Terminal, ConPTY, etc.
|
|
1320
|
+
// For other platforms, ANSI OSC sequences work reliably
|
|
1321
|
+
ansi.ANSI.setTerminalTitleOutput(tty, title) catch {};
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
fn writePassthroughSequence(self: *Terminal, tty: anytype, sequence: []const u8) !void {
|
|
1325
|
+
const is_tmux = self.isInTmux();
|
|
1326
|
+
if (is_tmux) {
|
|
1327
|
+
try tty.writeAll(ansi.ANSI.tmuxDcsStart);
|
|
1328
|
+
for (sequence) |c| {
|
|
1329
|
+
if (c == '\x1b') try tty.writeByte('\x1b');
|
|
1330
|
+
try tty.writeByte(c);
|
|
1331
|
+
}
|
|
1332
|
+
try tty.writeAll(ansi.ANSI.tmuxDcsEnd);
|
|
1333
|
+
return;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
if (!self.remote) {
|
|
1337
|
+
var env_map_storage: ?std.process.EnvMap = null;
|
|
1338
|
+
const env_map: ?*const std.process.EnvMap = self.opts.env_map orelse blk: {
|
|
1339
|
+
env_map_storage = std.process.getEnvMap(std.heap.page_allocator) catch null;
|
|
1340
|
+
break :blk if (env_map_storage) |*map| map else null;
|
|
1341
|
+
};
|
|
1342
|
+
defer if (env_map_storage) |*map| map.deinit();
|
|
1343
|
+
|
|
1344
|
+
if (env_map) |map| {
|
|
1345
|
+
if (map.get("STY") != null) {
|
|
1346
|
+
try tty.writeAll(ansi.ANSI.screenDcsStart);
|
|
1347
|
+
for (sequence) |c| {
|
|
1348
|
+
if (c == '\x1b') try tty.writeByte('\x1b');
|
|
1349
|
+
try tty.writeByte(c);
|
|
1350
|
+
}
|
|
1351
|
+
try tty.writeAll(ansi.ANSI.screenDcsEnd);
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
try tty.writeAll(sequence);
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
fn writeSanitizedNotificationText(writer: anytype, text: []const u8, replace_semicolon: bool) !void {
|
|
1361
|
+
for (text) |c| {
|
|
1362
|
+
if (c < 0x20 or c == 0x7f or c == '\x1b' or (replace_semicolon and c == ';')) {
|
|
1363
|
+
try writer.writeByte(' ');
|
|
1364
|
+
} else {
|
|
1365
|
+
try writer.writeByte(c);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
fn writeOsc99Payload(allocator: std.mem.Allocator, writer: anytype, id: []const u8, payload_type: []const u8, payload: []const u8, done: bool) !void {
|
|
1371
|
+
const encoded_len = std.base64.standard.Encoder.calcSize(payload.len);
|
|
1372
|
+
const encoded_buf = try allocator.alloc(u8, encoded_len);
|
|
1373
|
+
defer allocator.free(encoded_buf);
|
|
1374
|
+
const encoded = std.base64.standard.Encoder.encode(encoded_buf, payload);
|
|
1375
|
+
|
|
1376
|
+
try writer.print("\x1b]99;i={s}:p={s}:e=1:d={d};", .{ id, payload_type, @intFromBool(done) });
|
|
1377
|
+
try writer.writeAll(encoded);
|
|
1378
|
+
try writer.writeAll("\x1b\\");
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
pub fn writeNotification(self: *Terminal, allocator: std.mem.Allocator, tty: anytype, message: []const u8, title: ?[]const u8) !bool {
|
|
1382
|
+
if (!self.caps.notifications or self.notification_protocol == .none) {
|
|
1383
|
+
return false;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
self.notification_id_counter +%= 1;
|
|
1387
|
+
|
|
1388
|
+
var buffer: std.ArrayListUnmanaged(u8) = .{};
|
|
1389
|
+
defer buffer.deinit(allocator);
|
|
1390
|
+
const writer = buffer.writer(allocator);
|
|
1391
|
+
|
|
1392
|
+
switch (self.notification_protocol) {
|
|
1393
|
+
.none => return false,
|
|
1394
|
+
.osc99 => {
|
|
1395
|
+
const id = try std.fmt.allocPrint(allocator, "opentui-{d}", .{self.notification_id_counter});
|
|
1396
|
+
defer allocator.free(id);
|
|
1397
|
+
|
|
1398
|
+
if (title) |notification_title| {
|
|
1399
|
+
if (notification_title.len > 0) {
|
|
1400
|
+
try writeOsc99Payload(allocator, writer, id, "title", notification_title, false);
|
|
1401
|
+
try writeOsc99Payload(allocator, writer, id, "body", message, true);
|
|
1402
|
+
} else {
|
|
1403
|
+
try writeOsc99Payload(allocator, writer, id, "body", message, true);
|
|
1404
|
+
}
|
|
1405
|
+
} else {
|
|
1406
|
+
try writeOsc99Payload(allocator, writer, id, "body", message, true);
|
|
1407
|
+
}
|
|
1408
|
+
},
|
|
1409
|
+
.osc777 => {
|
|
1410
|
+
try writer.writeAll("\x1b]777;notify;");
|
|
1411
|
+
if (title) |notification_title| {
|
|
1412
|
+
try writeSanitizedNotificationText(writer, notification_title, true);
|
|
1413
|
+
try writer.writeByte(';');
|
|
1414
|
+
try writeSanitizedNotificationText(writer, message, true);
|
|
1415
|
+
} else {
|
|
1416
|
+
try writeSanitizedNotificationText(writer, message, true);
|
|
1417
|
+
try writer.writeByte(';');
|
|
1418
|
+
}
|
|
1419
|
+
try writer.writeAll("\x1b\\");
|
|
1420
|
+
},
|
|
1421
|
+
.osc9 => {
|
|
1422
|
+
try writer.writeAll("\x1b]9;");
|
|
1423
|
+
if (title) |notification_title| {
|
|
1424
|
+
if (notification_title.len > 0) {
|
|
1425
|
+
try writeSanitizedNotificationText(writer, notification_title, false);
|
|
1426
|
+
try writer.writeAll(": ");
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
try writeSanitizedNotificationText(writer, message, false);
|
|
1430
|
+
try writer.writeAll("\x1b\\");
|
|
1431
|
+
},
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
try self.writePassthroughSequence(tty, buffer.items);
|
|
1435
|
+
return true;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
/// Return the exact number of bytes emitted by writeClipboard.
|
|
1439
|
+
pub fn clipboardSequenceSize(self: *Terminal, payload_len: usize) !usize {
|
|
1440
|
+
if (payload_len > CLIPBOARD_PAYLOAD_SIZE_MAX) return error.ClipboardPayloadTooLarge;
|
|
1441
|
+
const padded_len = try std.math.add(usize, payload_len, 2);
|
|
1442
|
+
const encoded_len = try std.math.mul(usize, @divFloor(padded_len, 3), 4);
|
|
1443
|
+
const sequence_len = try std.math.add(usize, encoded_len, OSC52_FRAMING_SIZE);
|
|
1444
|
+
|
|
1445
|
+
if (self.isInTmux()) {
|
|
1446
|
+
const wrapped_len = try std.math.add(usize, sequence_len, 2);
|
|
1447
|
+
return std.math.add(usize, wrapped_len, ansi.ANSI.tmuxDcsStart.len + ansi.ANSI.tmuxDcsEnd.len);
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
if (self.isInScreen()) {
|
|
1451
|
+
const escaped_len = try std.math.add(usize, encoded_len, PASSTHROUGH_ESCAPED_OSC52_SIZE);
|
|
1452
|
+
const chunk_count = @divFloor(escaped_len - 1, SCREEN_PASSTHROUGH_CHUNK_SIZE) + 1;
|
|
1453
|
+
const envelopes_len = try std.math.mul(usize, chunk_count, ansi.ANSI.screenDcsStart.len + ansi.ANSI.screenDcsEnd.len);
|
|
1454
|
+
return std.math.add(usize, escaped_len, envelopes_len);
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
return sequence_len;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
/// Write OSC 52 clipboard sequence to the terminal from raw clipboard bytes.
|
|
1461
|
+
/// Supports tmux/screen passthrough, including nested tmux sessions
|
|
1462
|
+
pub fn writeClipboard(self: *Terminal, tty: anytype, target: ClipboardTarget, text_utf8: []const u8) !void {
|
|
1463
|
+
if (!self.canWriteClipboard()) {
|
|
1464
|
+
return error.NotSupported;
|
|
1465
|
+
}
|
|
1466
|
+
_ = try self.clipboardSequenceSize(text_utf8.len);
|
|
1467
|
+
|
|
1468
|
+
if (self.isInTmux()) {
|
|
1469
|
+
try tty.writeAll(ansi.ANSI.tmuxDcsStart);
|
|
1470
|
+
try writeClipboardSequence(tty, target, text_utf8, true);
|
|
1471
|
+
try tty.writeAll(ansi.ANSI.tmuxDcsEnd);
|
|
1472
|
+
return;
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
if (self.isInScreen()) {
|
|
1476
|
+
var screen_writer = ScreenPassthroughWriter(@TypeOf(tty)).init(tty);
|
|
1477
|
+
try writeClipboardSequence(&screen_writer, target, text_utf8, false);
|
|
1478
|
+
try screen_writer.finish();
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
try writeClipboardSequence(tty, target, text_utf8, false);
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
fn ScreenPassthroughWriter(comptime Writer: type) type {
|
|
1486
|
+
return struct {
|
|
1487
|
+
writer: Writer,
|
|
1488
|
+
buffer: [SCREEN_PASSTHROUGH_CHUNK_SIZE]u8 = undefined,
|
|
1489
|
+
length: usize = 0,
|
|
1490
|
+
|
|
1491
|
+
const Self = @This();
|
|
1492
|
+
|
|
1493
|
+
fn init(writer: Writer) Self {
|
|
1494
|
+
return .{ .writer = writer };
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
pub fn writeAll(self: *Self, bytes: []const u8) !void {
|
|
1498
|
+
for (bytes) |byte| try self.writeByte(byte);
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
pub fn writeByte(self: *Self, byte: u8) !void {
|
|
1502
|
+
const encoded_length: usize = if (byte == '\x1b') 2 else 1;
|
|
1503
|
+
if (self.length + encoded_length > self.buffer.len) try self.flush();
|
|
1504
|
+
|
|
1505
|
+
if (byte == '\x1b') {
|
|
1506
|
+
self.buffer[self.length] = '\x1b';
|
|
1507
|
+
self.length += 1;
|
|
1508
|
+
}
|
|
1509
|
+
self.buffer[self.length] = byte;
|
|
1510
|
+
self.length += 1;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
fn finish(self: *Self) !void {
|
|
1514
|
+
try self.flush();
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
fn flush(self: *Self) !void {
|
|
1518
|
+
if (self.length == 0) return;
|
|
1519
|
+
try self.writer.writeAll(ansi.ANSI.screenDcsStart);
|
|
1520
|
+
try self.writer.writeAll(self.buffer[0..self.length]);
|
|
1521
|
+
try self.writer.writeAll(ansi.ANSI.screenDcsEnd);
|
|
1522
|
+
self.length = 0;
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
fn writeClipboardSequence(writer: anytype, target: ClipboardTarget, text_utf8: []const u8, escape: bool) !void {
|
|
1528
|
+
try writeClipboardBytes(writer, "\x1b]52;", escape);
|
|
1529
|
+
try writer.writeByte(target.toChar());
|
|
1530
|
+
try writer.writeByte(';');
|
|
1531
|
+
try writeClipboardBase64(writer, text_utf8);
|
|
1532
|
+
try writeClipboardBytes(writer, "\x1b\\", escape);
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
fn writeClipboardBase64(writer: anytype, source: []const u8) !void {
|
|
1536
|
+
const source_chunk_size = 3 * 1024;
|
|
1537
|
+
var encoded_buffer: [4 * 1024]u8 = undefined;
|
|
1538
|
+
var offset: usize = 0;
|
|
1539
|
+
|
|
1540
|
+
while (offset < source.len) {
|
|
1541
|
+
const chunk_len = @min(source.len - offset, source_chunk_size);
|
|
1542
|
+
const chunk = source[offset .. offset + chunk_len];
|
|
1543
|
+
const encoded = std.base64.standard.Encoder.encode(&encoded_buffer, chunk);
|
|
1544
|
+
try writer.writeAll(encoded);
|
|
1545
|
+
offset += chunk_len;
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
fn writeClipboardBytes(writer: anytype, bytes: []const u8, escape: bool) !void {
|
|
1550
|
+
if (!escape) {
|
|
1551
|
+
try writer.writeAll(bytes);
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
for (bytes) |byte| {
|
|
1556
|
+
if (byte == '\x1b') try writer.writeByte('\x1b');
|
|
1557
|
+
try writer.writeByte(byte);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
/// Check if we can write to the clipboard (TTY and OSC 52 supported)
|
|
1562
|
+
fn canWriteClipboard(self: *Terminal) bool {
|
|
1563
|
+
// In a real TTY environment, we'd check isTTY here
|
|
1564
|
+
// Missing or inconclusive capability responses must not block optimistic emission.
|
|
1565
|
+
return self.osc52_support != .unsupported;
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
/// Parse xtversion response string and extract terminal name and version
|
|
1569
|
+
/// Examples: "kitty(0.40.1)", "ghostty 1.1.3", "tmux 3.5a"
|
|
1570
|
+
fn parseXtversion(self: *Terminal, term_str: []const u8) void {
|
|
1571
|
+
if (term_str.len == 0) return;
|
|
1572
|
+
|
|
1573
|
+
if (std.mem.indexOf(u8, term_str, "(")) |paren_pos| {
|
|
1574
|
+
const name_len = @min(paren_pos, self.term_info.name.len);
|
|
1575
|
+
@memcpy(self.term_info.name[0..name_len], term_str[0..name_len]);
|
|
1576
|
+
self.term_info.name_len = name_len;
|
|
1577
|
+
|
|
1578
|
+
if (std.mem.indexOf(u8, term_str[paren_pos..], ")")) |close_offset| {
|
|
1579
|
+
const ver_start = paren_pos + 1;
|
|
1580
|
+
const ver_end = paren_pos + close_offset;
|
|
1581
|
+
const ver_len = @min(ver_end - ver_start, self.term_info.version.len);
|
|
1582
|
+
@memcpy(self.term_info.version[0..ver_len], term_str[ver_start .. ver_start + ver_len]);
|
|
1583
|
+
self.term_info.version_len = ver_len;
|
|
1584
|
+
}
|
|
1585
|
+
} else {
|
|
1586
|
+
if (std.mem.indexOf(u8, term_str, " ")) |space_pos| {
|
|
1587
|
+
const name_len = @min(space_pos, self.term_info.name.len);
|
|
1588
|
+
@memcpy(self.term_info.name[0..name_len], term_str[0..name_len]);
|
|
1589
|
+
self.term_info.name_len = name_len;
|
|
1590
|
+
|
|
1591
|
+
const ver_start = space_pos + 1;
|
|
1592
|
+
const ver_len = @min(term_str.len - ver_start, self.term_info.version.len);
|
|
1593
|
+
@memcpy(self.term_info.version[0..ver_len], term_str[ver_start .. ver_start + ver_len]);
|
|
1594
|
+
self.term_info.version_len = ver_len;
|
|
1595
|
+
} else {
|
|
1596
|
+
const name_len = @min(term_str.len, self.term_info.name.len);
|
|
1597
|
+
@memcpy(self.term_info.name[0..name_len], term_str[0..name_len]);
|
|
1598
|
+
self.term_info.name_len = name_len;
|
|
1599
|
+
self.term_info.version_len = 0;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
self.term_info.from_xtversion = true;
|
|
1604
|
+
self.is_foot = std.ascii.indexOfIgnoreCase(self.getTerminalName(), "foot") != null;
|
|
1605
|
+
if (std.mem.eql(u8, self.getTerminalName(), "tmux")) {
|
|
1606
|
+
self.multiplexer = .tmux;
|
|
1607
|
+
} else if (std.ascii.eqlIgnoreCase(self.getTerminalName(), "Zellij")) {
|
|
1608
|
+
self.multiplexer = .zellij;
|
|
1609
|
+
} else {
|
|
1610
|
+
self.multiplexer = .none;
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
if (!self.isInZellij()) {
|
|
1614
|
+
if (detectNotificationProtocol(self.getTerminalName())) |protocol| {
|
|
1615
|
+
self.setNotificationProtocol(protocol, .xtversion);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
self.enforceNotificationProtocolForMultiplexer();
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
pub fn isXtversionTmux(self: *Terminal) bool {
|
|
1623
|
+
return self.term_info.from_xtversion and std.mem.eql(u8, self.getTerminalName(), "tmux");
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
pub fn isXtversionZellij(self: *Terminal) bool {
|
|
1627
|
+
return self.term_info.from_xtversion and std.ascii.eqlIgnoreCase(self.getTerminalName(), "Zellij");
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
pub fn isInTmux(self: *Terminal) bool {
|
|
1631
|
+
return self.multiplexer == .tmux;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
pub fn isInZellij(self: *Terminal) bool {
|
|
1635
|
+
return self.multiplexer == .zellij;
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
pub fn isInScreen(self: *Terminal) bool {
|
|
1639
|
+
return self.multiplexer == .screen;
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
pub fn getTerminalInfo(self: *Terminal) TerminalInfo {
|
|
1643
|
+
return self.term_info;
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
pub fn getTerminalName(self: *Terminal) []const u8 {
|
|
1647
|
+
return self.term_info.name[0..self.term_info.name_len];
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
pub fn getTerminalVersion(self: *Terminal) []const u8 {
|
|
1651
|
+
return self.term_info.version[0..self.term_info.version_len];
|
|
1652
|
+
}
|