@dst0/p-tui 0.4.41 → 5.0.2
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/dist/autocomplete.d.ts.map +1 -1
- package/dist/autocomplete.js.map +1 -1
- package/dist/components/box.d.ts +3 -1
- package/dist/components/box.d.ts.map +1 -1
- package/dist/components/box.js +19 -10
- package/dist/components/box.js.map +1 -1
- package/dist/components/cancellable-loader.d.ts.map +1 -1
- package/dist/components/cancellable-loader.js.map +1 -1
- package/dist/components/editor/constants.d.ts +9 -0
- package/dist/components/editor/constants.d.ts.map +1 -0
- package/dist/components/editor/constants.js +12 -0
- package/dist/components/editor/constants.js.map +1 -0
- package/dist/components/editor/editor-methods/autocomplete-matching.d.ts +29 -0
- package/dist/components/editor/editor-methods/autocomplete-matching.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/autocomplete-matching.js +104 -0
- package/dist/components/editor/editor-methods/autocomplete-matching.js.map +1 -0
- package/dist/components/editor/editor-methods/autocomplete-request.d.ts +14 -0
- package/dist/components/editor/editor-methods/autocomplete-request.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/autocomplete-request.js +72 -0
- package/dist/components/editor/editor-methods/autocomplete-request.js.map +1 -0
- package/dist/components/editor/editor-methods/backspace-cursor.d.ts +9 -0
- package/dist/components/editor/editor-methods/backspace-cursor.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/backspace-cursor.js +122 -0
- package/dist/components/editor/editor-methods/backspace-cursor.js.map +1 -0
- package/dist/components/editor/editor-methods/configuration.d.ts +17 -0
- package/dist/components/editor/editor-methods/configuration.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/configuration.js +107 -0
- package/dist/components/editor/editor-methods/configuration.js.map +1 -0
- package/dist/components/editor/editor-methods/cursor-movement.d.ts +7 -0
- package/dist/components/editor/editor-methods/cursor-movement.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/cursor-movement.js +112 -0
- package/dist/components/editor/editor-methods/cursor-movement.js.map +1 -0
- package/dist/components/editor/editor-methods/input-handling.d.ts +3 -0
- package/dist/components/editor/editor-methods/input-handling.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/input-handling.js +257 -0
- package/dist/components/editor/editor-methods/input-handling.js.map +1 -0
- package/dist/components/editor/editor-methods/paste-submit.d.ts +7 -0
- package/dist/components/editor/editor-methods/paste-submit.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/paste-submit.js +105 -0
- package/dist/components/editor/editor-methods/paste-submit.js.map +1 -0
- package/dist/components/editor/editor-methods/render.d.ts +3 -0
- package/dist/components/editor/editor-methods/render.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/render.js +114 -0
- package/dist/components/editor/editor-methods/render.js.map +1 -0
- package/dist/components/editor/editor-methods/text-insertion.d.ts +4 -0
- package/dist/components/editor/editor-methods/text-insertion.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/text-insertion.js +91 -0
- package/dist/components/editor/editor-methods/text-insertion.js.map +1 -0
- package/dist/components/editor/editor-methods/text-layout.d.ts +15 -0
- package/dist/components/editor/editor-methods/text-layout.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/text-layout.js +129 -0
- package/dist/components/editor/editor-methods/text-layout.js.map +1 -0
- package/dist/components/editor/editor-methods/vertical-movement.d.ts +8 -0
- package/dist/components/editor/editor-methods/vertical-movement.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/vertical-movement.js +123 -0
- package/dist/components/editor/editor-methods/vertical-movement.js.map +1 -0
- package/dist/components/editor/editor-methods/word-operations.d.ts +19 -0
- package/dist/components/editor/editor-methods/word-operations.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/word-operations.js +122 -0
- package/dist/components/editor/editor-methods/word-operations.js.map +1 -0
- package/dist/components/editor/editor-methods/yank-undo.d.ts +11 -0
- package/dist/components/editor/editor-methods/yank-undo.d.ts.map +1 -0
- package/dist/components/editor/editor-methods/yank-undo.js +132 -0
- package/dist/components/editor/editor-methods/yank-undo.js.map +1 -0
- package/dist/components/editor/editor.d.ts +67 -0
- package/dist/components/editor/editor.d.ts.map +1 -0
- package/dist/components/editor/editor.js +93 -0
- package/dist/components/editor/editor.js.map +1 -0
- package/dist/components/editor/helpers.d.ts +3 -0
- package/dist/components/editor/helpers.d.ts.map +1 -0
- package/dist/components/editor/helpers.js +3 -0
- package/dist/components/editor/helpers.js.map +1 -0
- package/dist/components/editor/index.d.ts +4 -0
- package/dist/components/editor/index.d.ts.map +1 -0
- package/dist/components/editor/index.js +3 -0
- package/dist/components/editor/index.js.map +1 -0
- package/dist/components/editor/paste-marker.d.ts +5 -0
- package/dist/components/editor/paste-marker.d.ts.map +1 -0
- package/dist/components/editor/paste-marker.js +134 -0
- package/dist/components/editor/paste-marker.js.map +1 -0
- package/dist/components/editor/trigger-patterns.d.ts +4 -0
- package/dist/components/editor/trigger-patterns.d.ts.map +1 -0
- package/dist/components/editor/trigger-patterns.js +11 -0
- package/dist/components/editor/trigger-patterns.js.map +1 -0
- package/dist/components/editor/types.d.ts +25 -0
- package/dist/components/editor/types.d.ts.map +1 -0
- package/dist/components/editor/types.js +2 -0
- package/dist/components/editor/types.js.map +1 -0
- package/dist/components/editor.d.ts +1 -253
- package/dist/components/editor.d.ts.map +1 -1
- package/dist/components/editor.js +1 -1915
- package/dist/components/editor.js.map +1 -1
- package/dist/components/image.d.ts.map +1 -1
- package/dist/components/image.js.map +1 -1
- package/dist/components/input/constants.d.ts +2 -0
- package/dist/components/input/constants.d.ts.map +1 -0
- package/dist/components/input/constants.js +3 -0
- package/dist/components/input/constants.js.map +1 -0
- package/dist/components/input/index.d.ts +2 -0
- package/dist/components/input/index.d.ts.map +1 -0
- package/dist/components/input/index.js +2 -0
- package/dist/components/input/index.js.map +1 -0
- package/dist/components/input/input-methods/input-handling.d.ts +3 -0
- package/dist/components/input/input-methods/input-handling.d.ts.map +1 -0
- package/dist/components/input/input-methods/input-handling.js +145 -0
- package/dist/components/input/input-methods/input-handling.js.map +1 -0
- package/dist/components/input/input-methods/render.d.ts +3 -0
- package/dist/components/input/input-methods/render.d.ts.map +1 -0
- package/dist/components/input/input-methods/render.js +62 -0
- package/dist/components/input/input-methods/render.js.map +1 -0
- package/dist/components/input/input-methods/text-editing.d.ts +17 -0
- package/dist/components/input/input-methods/text-editing.d.ts.map +1 -0
- package/dist/components/input/input-methods/text-editing.js +145 -0
- package/dist/components/input/input-methods/text-editing.js.map +1 -0
- package/dist/components/input/input-methods/value-access.d.ts +4 -0
- package/dist/components/input/input-methods/value-access.d.ts.map +1 -0
- package/dist/components/input/input-methods/value-access.js +20 -0
- package/dist/components/input/input-methods/value-access.js.map +1 -0
- package/dist/components/input/input.d.ts +37 -0
- package/dist/components/input/input.d.ts.map +1 -0
- package/dist/components/input/input.js +77 -0
- package/dist/components/input/input.js.map +1 -0
- package/dist/components/input/types.d.ts +5 -0
- package/dist/components/input/types.d.ts.map +1 -0
- package/dist/components/input/types.js +2 -0
- package/dist/components/input/types.js.map +1 -0
- package/dist/components/input.d.ts +1 -36
- package/dist/components/input.d.ts.map +1 -1
- package/dist/components/input.js +1 -377
- package/dist/components/input.js.map +1 -1
- package/dist/components/loader.d.ts.map +1 -1
- package/dist/components/loader.js.map +1 -1
- package/dist/components/markdown/constants.d.ts +4 -0
- package/dist/components/markdown/constants.d.ts.map +1 -0
- package/dist/components/markdown/constants.js +8 -0
- package/dist/components/markdown/constants.js.map +1 -0
- package/dist/components/markdown/index.d.ts +3 -0
- package/dist/components/markdown/index.d.ts.map +1 -0
- package/dist/components/markdown/index.js +2 -0
- package/dist/components/markdown/index.js.map +1 -0
- package/dist/components/markdown/markdown-methods/inline-rendering.d.ts +7 -0
- package/dist/components/markdown/markdown-methods/inline-rendering.d.ts.map +1 -0
- package/dist/components/markdown/markdown-methods/inline-rendering.js +95 -0
- package/dist/components/markdown/markdown-methods/inline-rendering.js.map +1 -0
- package/dist/components/markdown/markdown-methods/list-table-helpers.d.ts +7 -0
- package/dist/components/markdown/markdown-methods/list-table-helpers.d.ts.map +1 -0
- package/dist/components/markdown/markdown-methods/list-table-helpers.js +61 -0
- package/dist/components/markdown/markdown-methods/list-table-helpers.js.map +1 -0
- package/dist/components/markdown/markdown-methods/table-rendering.d.ts +5 -0
- package/dist/components/markdown/markdown-methods/table-rendering.d.ts.map +1 -0
- package/dist/components/markdown/markdown-methods/table-rendering.js +146 -0
- package/dist/components/markdown/markdown-methods/table-rendering.js.map +1 -0
- package/dist/components/markdown/markdown-methods/text-rendering.d.ts +6 -0
- package/dist/components/markdown/markdown-methods/text-rendering.d.ts.map +1 -0
- package/dist/components/markdown/markdown-methods/text-rendering.js +115 -0
- package/dist/components/markdown/markdown-methods/text-rendering.js.map +1 -0
- package/dist/components/markdown/markdown-methods/theming.d.ts +6 -0
- package/dist/components/markdown/markdown-methods/theming.d.ts.map +1 -0
- package/dist/components/markdown/markdown-methods/theming.js +41 -0
- package/dist/components/markdown/markdown-methods/theming.js.map +1 -0
- package/dist/components/markdown/markdown-methods/token-rendering.d.ts +5 -0
- package/dist/components/markdown/markdown-methods/token-rendering.d.ts.map +1 -0
- package/dist/components/markdown/markdown-methods/token-rendering.js +142 -0
- package/dist/components/markdown/markdown-methods/token-rendering.js.map +1 -0
- package/dist/components/markdown/markdown.d.ts +32 -0
- package/dist/components/markdown/markdown.d.ts.map +1 -0
- package/dist/components/markdown/markdown.js +72 -0
- package/dist/components/markdown/markdown.js.map +1 -0
- package/dist/components/markdown/strictstrikethroughtokenizer.d.ts +6 -0
- package/dist/components/markdown/strictstrikethroughtokenizer.d.ts.map +1 -0
- package/dist/components/markdown/strictstrikethroughtokenizer.js +18 -0
- package/dist/components/markdown/strictstrikethroughtokenizer.js.map +1 -0
- package/dist/components/markdown/types.d.ts +42 -0
- package/dist/components/markdown/types.d.ts.map +1 -0
- package/dist/components/markdown/types.js +2 -0
- package/dist/components/markdown/types.js.map +1 -0
- package/dist/components/markdown.d.ts +1 -96
- package/dist/components/markdown.d.ts.map +1 -1
- package/dist/components/markdown.js +1 -653
- package/dist/components/markdown.js.map +1 -1
- package/dist/components/select-list.d.ts.map +1 -1
- package/dist/components/select-list.js +8 -3
- package/dist/components/select-list.js.map +1 -1
- package/dist/components/settings-list.d.ts.map +1 -1
- package/dist/components/settings-list.js +2 -6
- package/dist/components/settings-list.js.map +1 -1
- package/dist/components/spacer.d.ts.map +1 -1
- package/dist/components/spacer.js.map +1 -1
- package/dist/components/text.d.ts.map +1 -1
- package/dist/components/text.js +2 -2
- package/dist/components/text.js.map +1 -1
- package/dist/components/truncated-text.d.ts.map +1 -1
- package/dist/components/truncated-text.js.map +1 -1
- package/dist/editor-component.d.ts.map +1 -1
- package/dist/editor-component.js.map +1 -1
- package/dist/fuzzy.d.ts.map +1 -1
- package/dist/fuzzy.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/keybindings.d.ts.map +1 -1
- package/dist/keybindings.js.map +1 -1
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +145 -14
- package/dist/keys.js.map +1 -1
- package/dist/kill-ring.d.ts.map +1 -1
- package/dist/kill-ring.js.map +1 -1
- package/dist/native-modifiers.d.ts +9 -0
- package/dist/native-modifiers.d.ts.map +1 -1
- package/dist/native-modifiers.js +5 -0
- package/dist/native-modifiers.js.map +1 -1
- package/dist/stdin-buffer.d.ts +3 -0
- package/dist/stdin-buffer.d.ts.map +1 -1
- package/dist/stdin-buffer.js +24 -21
- package/dist/stdin-buffer.js.map +1 -1
- package/dist/terminal/constants.d.ts +9 -0
- package/dist/terminal/constants.d.ts.map +1 -0
- package/dist/terminal/constants.js +10 -0
- package/dist/terminal/constants.js.map +1 -0
- package/dist/terminal/helpers.d.ts +6 -0
- package/dist/terminal/helpers.d.ts.map +1 -0
- package/dist/terminal/helpers.js +23 -0
- package/dist/terminal/helpers.js.map +1 -0
- package/dist/terminal/index.d.ts +4 -0
- package/dist/terminal/index.d.ts.map +1 -0
- package/dist/terminal/index.js +3 -0
- package/dist/terminal/index.js.map +1 -0
- package/dist/terminal/processterminal-methods/cursor-screen.d.ts +11 -0
- package/dist/terminal/processterminal-methods/cursor-screen.d.ts.map +1 -0
- package/dist/terminal/processterminal-methods/cursor-screen.js +50 -0
- package/dist/terminal/processterminal-methods/cursor-screen.js.map +1 -0
- package/dist/terminal/processterminal-methods/keyboard-protocol.d.ts +14 -0
- package/dist/terminal/processterminal-methods/keyboard-protocol.d.ts.map +1 -0
- package/dist/terminal/processterminal-methods/keyboard-protocol.js +147 -0
- package/dist/terminal/processterminal-methods/keyboard-protocol.js.map +1 -0
- package/dist/terminal/processterminal-methods/terminal-io.d.ts +9 -0
- package/dist/terminal/processterminal-methods/terminal-io.d.ts.map +1 -0
- package/dist/terminal/processterminal-methods/terminal-io.js +153 -0
- package/dist/terminal/processterminal-methods/terminal-io.js.map +1 -0
- package/dist/terminal/processterminal.d.ts +49 -0
- package/dist/terminal/processterminal.d.ts.map +1 -0
- package/dist/terminal/processterminal.js +129 -0
- package/dist/terminal/processterminal.js.map +1 -0
- package/dist/terminal/types.d.ts +31 -0
- package/dist/terminal/types.d.ts.map +1 -0
- package/dist/terminal/types.js +2 -0
- package/dist/terminal/types.js.map +1 -0
- package/dist/terminal-colors.d.ts +2 -0
- package/dist/terminal-colors.d.ts.map +1 -1
- package/dist/terminal-colors.js +17 -5
- package/dist/terminal-colors.js.map +1 -1
- package/dist/terminal-image.d.ts.map +1 -1
- package/dist/terminal-image.js.map +1 -1
- package/dist/terminal.d.ts +1 -109
- package/dist/terminal.d.ts.map +1 -1
- package/dist/terminal.js +1 -432
- package/dist/terminal.js.map +1 -1
- package/dist/tui/constants.d.ts +3 -0
- package/dist/tui/constants.d.ts.map +1 -0
- package/dist/tui/constants.js +3 -0
- package/dist/tui/constants.js.map +1 -0
- package/dist/tui/container.d.ts +10 -0
- package/dist/tui/container.d.ts.map +1 -0
- package/dist/tui/container.js +31 -0
- package/dist/tui/container.js.map +1 -0
- package/dist/tui/helpers.d.ts +8 -0
- package/dist/tui/helpers.d.ts.map +1 -0
- package/dist/tui/helpers.js +53 -0
- package/dist/tui/helpers.js.map +1 -0
- package/dist/tui/index.d.ts +6 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/index.js +5 -0
- package/dist/tui/index.js.map +1 -0
- package/dist/tui/tui-methods/configuration.d.ts +20 -0
- package/dist/tui/tui-methods/configuration.d.ts.map +1 -0
- package/dist/tui/tui-methods/configuration.js +131 -0
- package/dist/tui/tui-methods/configuration.js.map +1 -0
- package/dist/tui/tui-methods/cursor-background.d.ts +10 -0
- package/dist/tui/tui-methods/cursor-background.d.ts.map +1 -0
- package/dist/tui/tui-methods/cursor-background.js +52 -0
- package/dist/tui/tui-methods/cursor-background.js.map +1 -0
- package/dist/tui/tui-methods/incremental-render.d.ts +17 -0
- package/dist/tui/tui-methods/incremental-render.d.ts.map +1 -0
- package/dist/tui/tui-methods/incremental-render.js +259 -0
- package/dist/tui/tui-methods/incremental-render.js.map +1 -0
- package/dist/tui/tui-methods/input-handling.d.ts +5 -0
- package/dist/tui/tui-methods/input-handling.d.ts.map +1 -0
- package/dist/tui/tui-methods/input-handling.js +111 -0
- package/dist/tui/tui-methods/input-handling.js.map +1 -0
- package/dist/tui/tui-methods/line-compositing.d.ts +7 -0
- package/dist/tui/tui-methods/line-compositing.d.ts.map +1 -0
- package/dist/tui/tui-methods/line-compositing.js +61 -0
- package/dist/tui/tui-methods/line-compositing.js.map +1 -0
- package/dist/tui/tui-methods/overlay-compositing.d.ts +12 -0
- package/dist/tui/tui-methods/overlay-compositing.d.ts.map +1 -0
- package/dist/tui/tui-methods/overlay-compositing.js +123 -0
- package/dist/tui/tui-methods/overlay-compositing.js.map +1 -0
- package/dist/tui/tui-methods/overlay-layout.d.ts +11 -0
- package/dist/tui/tui-methods/overlay-layout.d.ts.map +1 -0
- package/dist/tui/tui-methods/overlay-layout.js +124 -0
- package/dist/tui/tui-methods/overlay-layout.js.map +1 -0
- package/dist/tui/tui-methods/overlay-management.d.ts +11 -0
- package/dist/tui/tui-methods/overlay-management.d.ts.map +1 -0
- package/dist/tui/tui-methods/overlay-management.js +152 -0
- package/dist/tui/tui-methods/overlay-management.js.map +1 -0
- package/dist/tui/tui-methods/render-pipeline.d.ts +3 -0
- package/dist/tui/tui-methods/render-pipeline.d.ts.map +1 -0
- package/dist/tui/tui-methods/render-pipeline.js +176 -0
- package/dist/tui/tui-methods/render-pipeline.js.map +1 -0
- package/dist/tui/tui-methods/render-width-error.d.ts +3 -0
- package/dist/tui/tui-methods/render-width-error.d.ts.map +1 -0
- package/dist/tui/tui-methods/render-width-error.js +28 -0
- package/dist/tui/tui-methods/render-width-error.js.map +1 -0
- package/dist/tui/tui-methods/terminal-control.d.ts +8 -0
- package/dist/tui/tui-methods/terminal-control.d.ts.map +1 -0
- package/dist/tui/tui-methods/terminal-control.js +101 -0
- package/dist/tui/tui-methods/terminal-control.js.map +1 -0
- package/dist/tui/tui.d.ts +59 -0
- package/dist/tui/tui.d.ts.map +1 -0
- package/dist/tui/tui.js +78 -0
- package/dist/tui/tui.js.map +1 -0
- package/dist/tui/types.d.ts +124 -0
- package/dist/tui/types.d.ts.map +1 -0
- package/dist/tui/types.js +2 -0
- package/dist/tui/types.js.map +1 -0
- package/dist/tui.d.ts +1 -254
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +1 -1344
- package/dist/tui.js.map +1 -1
- package/dist/undo-stack.d.ts.map +1 -1
- package/dist/undo-stack.js.map +1 -1
- package/dist/utils/ansi-wrapping.d.ts +5 -0
- package/dist/utils/ansi-wrapping.d.ts.map +1 -0
- package/dist/utils/ansi-wrapping.js +52 -0
- package/dist/utils/ansi-wrapping.js.map +1 -0
- package/dist/utils/ansicodetracker.d.ts +27 -0
- package/dist/utils/ansicodetracker.d.ts.map +1 -0
- package/dist/utils/ansicodetracker.js +222 -0
- package/dist/utils/ansicodetracker.js.map +1 -0
- package/dist/utils/column-slicing.d.ts +12 -0
- package/dist/utils/column-slicing.d.ts.map +1 -0
- package/dist/utils/column-slicing.js +111 -0
- package/dist/utils/column-slicing.js.map +1 -0
- package/dist/utils/column-truncation.d.ts +2 -0
- package/dist/utils/column-truncation.d.ts.map +1 -0
- package/dist/utils/column-truncation.js +129 -0
- package/dist/utils/column-truncation.js.map +1 -0
- package/dist/utils/constants.d.ts +12 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +12 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/install-delegated-methods.d.ts +5 -0
- package/dist/utils/install-delegated-methods.d.ts.map +1 -0
- package/dist/utils/install-delegated-methods.js +27 -0
- package/dist/utils/install-delegated-methods.js.map +1 -0
- package/dist/utils/segmentation.d.ts +10 -0
- package/dist/utils/segmentation.d.ts.map +1 -0
- package/dist/utils/segmentation.js +111 -0
- package/dist/utils/segmentation.js.map +1 -0
- package/dist/utils/terminal-output.d.ts +10 -0
- package/dist/utils/terminal-output.d.ts.map +1 -0
- package/dist/utils/terminal-output.js +122 -0
- package/dist/utils/terminal-output.js.map +1 -0
- package/dist/utils/types.d.ts +7 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +2 -0
- package/dist/utils/types.js.map +1 -0
- package/dist/utils/width-truncation.d.ts +6 -0
- package/dist/utils/width-truncation.d.ts.map +1 -0
- package/dist/utils/width-truncation.js +121 -0
- package/dist/utils/width-truncation.js.map +1 -0
- package/dist/utils/word-wrapping.d.ts +4 -0
- package/dist/utils/word-wrapping.d.ts.map +1 -0
- package/dist/utils/word-wrapping.js +139 -0
- package/dist/utils/word-wrapping.js.map +1 -0
- package/dist/utils.d.ts +1 -84
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1059
- package/dist/utils.js.map +1 -1
- package/dist/word-navigation.d.ts.map +1 -1
- package/dist/word-navigation.js.map +1 -1
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdin-buffer.d.ts","sourceRoot":"","sources":["../src/stdin-buffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AA6OtC,MAAM,MAAM,kBAAkB,GAAG;IAChC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;IACf,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,qBAAa,WAAY,SAAQ,YAAY,CAAC,mBAAmB,CAAC;IACjE,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAA8C;IAC7D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,8BAA8B,CAAqB;IAE3D,YAAY,OAAO,GAAE,kBAAuB,EAG3C;IAEM,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoG1C;IAED,OAAO,CAAC,gBAAgB;IAWxB,KAAK,IAAI,MAAM,EAAE,CAchB;IAED,KAAK,IAAI,IAAI,CASZ;IAED,SAAS,IAAI,MAAM,CAElB;IAED,OAAO,IAAI,IAAI,CAEd;CACD","sourcesContent":["/**\n * StdinBuffer buffers input and emits complete sequences.\n *\n * This is necessary because stdin data events can arrive in partial chunks,\n * especially for escape sequences like mouse events. Without buffering,\n * partial sequences can be misinterpreted as regular keypresses.\n *\n * For example, the mouse SGR sequence `\\x1b[<35;20;5m` might arrive as:\n * - Event 1: `\\x1b`\n * - Event 2: `[<35`\n * - Event 3: `;20;5m`\n *\n * The buffer accumulates these until a complete sequence is detected.\n * Call the `process()` method to feed input data.\n *\n * Based on code from OpenTUI (https://github.com/anomalyco/opentui)\n * MIT License - Copyright (c) 2025 opentui\n */\n\nimport { EventEmitter } from \"events\";\n\nconst ESC = \"\\x1b\";\nconst BRACKETED_PASTE_START = \"\\x1b[200~\";\nconst BRACKETED_PASTE_END = \"\\x1b[201~\";\n\n/**\n * Check if a string is a complete escape sequence or needs more data\n */\nfunction isCompleteSequence(data: string): \"complete\" | \"incomplete\" | \"not-escape\" {\n\tif (!data.startsWith(ESC)) {\n\t\treturn \"not-escape\";\n\t}\n\n\tif (data.length === 1) {\n\t\treturn \"incomplete\";\n\t}\n\n\tconst afterEsc = data.slice(1);\n\n\t// CSI sequences: ESC [\n\tif (afterEsc.startsWith(\"[\")) {\n\t\t// Check for old-style mouse sequence: ESC[M + 3 bytes\n\t\tif (afterEsc.startsWith(\"[M\")) {\n\t\t\t// Old-style mouse needs ESC[M + 3 bytes = 6 total\n\t\t\treturn data.length >= 6 ? \"complete\" : \"incomplete\";\n\t\t}\n\t\treturn isCompleteCsiSequence(data);\n\t}\n\n\t// OSC sequences: ESC ]\n\tif (afterEsc.startsWith(\"]\")) {\n\t\treturn isCompleteOscSequence(data);\n\t}\n\n\t// DCS sequences: ESC P ... ESC \\ (includes XTVersion responses)\n\tif (afterEsc.startsWith(\"P\")) {\n\t\treturn isCompleteDcsSequence(data);\n\t}\n\n\t// APC sequences: ESC _ ... ESC \\ (includes Kitty graphics responses)\n\tif (afterEsc.startsWith(\"_\")) {\n\t\treturn isCompleteApcSequence(data);\n\t}\n\n\t// SS3 sequences: ESC O\n\tif (afterEsc.startsWith(\"O\")) {\n\t\t// ESC O followed by a single character\n\t\treturn afterEsc.length >= 2 ? \"complete\" : \"incomplete\";\n\t}\n\n\t// Meta key sequences: ESC followed by a single character\n\tif (afterEsc.length === 1) {\n\t\treturn \"complete\";\n\t}\n\n\t// Unknown escape sequence - treat as complete\n\treturn \"complete\";\n}\n\n/**\n * Check if CSI sequence is complete\n * CSI sequences: ESC [ ... followed by a final byte (0x40-0x7E)\n */\nfunction isCompleteCsiSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}[`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// Need at least ESC [ and one more character\n\tif (data.length < 3) {\n\t\treturn \"incomplete\";\n\t}\n\n\tconst payload = data.slice(2);\n\n\t// CSI sequences end with a byte in the range 0x40-0x7E (@-~)\n\t// This includes all letters and several special characters\n\tconst lastChar = payload[payload.length - 1];\n\tconst lastCharCode = lastChar.charCodeAt(0);\n\n\tif (lastCharCode >= 0x40 && lastCharCode <= 0x7e) {\n\t\t// Special handling for SGR mouse sequences\n\t\t// Format: ESC[<B;X;Ym or ESC[<B;X;YM\n\t\tif (payload.startsWith(\"<\")) {\n\t\t\t// Must have format: <digits;digits;digits[Mm]\n\t\t\tconst mouseMatch = /^<\\d+;\\d+;\\d+[Mm]$/.test(payload);\n\t\t\tif (mouseMatch) {\n\t\t\t\treturn \"complete\";\n\t\t\t}\n\t\t\t// If it ends with M or m but doesn't match the pattern, still incomplete\n\t\t\tif (lastChar === \"M\" || lastChar === \"m\") {\n\t\t\t\t// Check if we have the right structure\n\t\t\t\tconst parts = payload.slice(1, -1).split(\";\");\n\t\t\t\tif (parts.length === 3 && parts.every((p) => /^\\d+$/.test(p))) {\n\t\t\t\t\treturn \"complete\";\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn \"incomplete\";\n\t\t}\n\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Check if OSC sequence is complete\n * OSC sequences: ESC ] ... ST (where ST is ESC \\ or BEL)\n */\nfunction isCompleteOscSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}]`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// OSC sequences end with ST (ESC \\) or BEL (\\x07)\n\tif (data.endsWith(`${ESC}\\\\`) || data.endsWith(\"\\x07\")) {\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Check if DCS (Device Control String) sequence is complete\n * DCS sequences: ESC P ... ST (where ST is ESC \\)\n * Used for XTVersion responses like ESC P >| ... ESC \\\n */\nfunction isCompleteDcsSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}P`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// DCS sequences end with ST (ESC \\)\n\tif (data.endsWith(`${ESC}\\\\`)) {\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Check if APC (Application Program Command) sequence is complete\n * APC sequences: ESC _ ... ST (where ST is ESC \\)\n * Used for Kitty graphics responses like ESC _ G ... ESC \\\n */\nfunction isCompleteApcSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}_`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// APC sequences end with ST (ESC \\)\n\tif (data.endsWith(`${ESC}\\\\`)) {\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Split accumulated buffer into complete sequences\n */\nfunction parseUnmodifiedKittyPrintableCodepoint(sequence: string): number | undefined {\n\tconst match = sequence.match(/^\\x1b\\[(\\d+)(?::\\d*)?(?::\\d+)?u$/);\n\tif (!match) return undefined;\n\n\tconst codepoint = parseInt(match[1]!, 10);\n\treturn codepoint >= 32 ? codepoint : undefined;\n}\n\nfunction extractCompleteSequences(buffer: string): { sequences: string[]; remainder: string } {\n\tconst sequences: string[] = [];\n\tlet pos = 0;\n\n\twhile (pos < buffer.length) {\n\t\tconst remaining = buffer.slice(pos);\n\n\t\t// Try to extract a sequence starting at this position\n\t\tif (remaining.startsWith(ESC)) {\n\t\t\t// Find the end of this escape sequence\n\t\t\tlet seqEnd = 1;\n\t\t\twhile (seqEnd <= remaining.length) {\n\t\t\t\tconst candidate = remaining.slice(0, seqEnd);\n\t\t\t\tconst status = isCompleteSequence(candidate);\n\n\t\t\t\tif (status === \"complete\") {\n\t\t\t\t\t// WezTerm with enable_kitty_keyboard sends the Escape key press as a\n\t\t\t\t\t// raw '\\x1b' byte (simple text path in encode_kitty, ignoring\n\t\t\t\t\t// DISAMBIGUATE_ESCAPE_CODES) and the release as a full Kitty CSI-u\n\t\t\t\t\t// sequence. These arrive concatenated as '\\x1b\\x1b[27;...u'.\n\t\t\t\t\t// The buffer would normally treat '\\x1b\\x1b' as a complete meta-key\n\t\t\t\t\t// sequence (ESC + single char), leaving '[27;...u' to be typed as\n\t\t\t\t\t// plain text. If the character immediately following '\\x1b\\x1b'\n\t\t\t\t\t// would begin a new escape sequence, emit only the first ESC and\n\t\t\t\t\t// restart from the second.\n\t\t\t\t\tif (candidate === \"\\x1b\\x1b\") {\n\t\t\t\t\t\tconst nextChar = remaining[seqEnd];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnextChar === \"[\" || // CSI\n\t\t\t\t\t\t\tnextChar === \"]\" || // OSC\n\t\t\t\t\t\t\tnextChar === \"O\" || // SS3\n\t\t\t\t\t\t\tnextChar === \"P\" || // DCS\n\t\t\t\t\t\t\tnextChar === \"_\" // APC\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tsequences.push(ESC);\n\t\t\t\t\t\t\tpos += 1;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tsequences.push(candidate);\n\t\t\t\t\tpos += seqEnd;\n\t\t\t\t\tbreak;\n\t\t\t\t} else if (status === \"incomplete\") {\n\t\t\t\t\tseqEnd++;\n\t\t\t\t} else {\n\t\t\t\t\t// Should not happen when starting with ESC\n\t\t\t\t\tsequences.push(candidate);\n\t\t\t\t\tpos += seqEnd;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (seqEnd > remaining.length) {\n\t\t\t\treturn { sequences, remainder: remaining };\n\t\t\t}\n\t\t} else {\n\t\t\t// Not an escape sequence - take a single character\n\t\t\tsequences.push(remaining[0]!);\n\t\t\tpos++;\n\t\t}\n\t}\n\n\treturn { sequences, remainder: \"\" };\n}\n\nexport type StdinBufferOptions = {\n\t/**\n\t * Maximum time to wait for sequence completion (default: 10ms)\n\t * After this time, the buffer is flushed even if incomplete\n\t */\n\ttimeout?: number;\n};\n\nexport type StdinBufferEventMap = {\n\tdata: [string];\n\tpaste: [string];\n};\n\n/**\n * Buffers stdin input and emits complete sequences via the 'data' event.\n * Handles partial escape sequences that arrive across multiple chunks.\n */\nexport class StdinBuffer extends EventEmitter<StdinBufferEventMap> {\n\tprivate buffer: string = \"\";\n\tprivate timeout: ReturnType<typeof setTimeout> | null = null;\n\tprivate readonly timeoutMs: number;\n\tprivate pasteMode: boolean = false;\n\tprivate pasteBuffer: string = \"\";\n\tprivate pendingKittyPrintableCodepoint: number | undefined;\n\n\tconstructor(options: StdinBufferOptions = {}) {\n\t\tsuper();\n\t\tthis.timeoutMs = options.timeout ?? 10;\n\t}\n\n\tpublic process(data: string | Buffer): void {\n\t\t// Clear any pending timeout\n\t\tif (this.timeout) {\n\t\t\tclearTimeout(this.timeout);\n\t\t\tthis.timeout = null;\n\t\t}\n\n\t\t// Handle high-byte conversion (for compatibility with parseKeypress)\n\t\t// If buffer has single byte > 127, convert to ESC + (byte - 128)\n\t\tlet str: string;\n\t\tif (Buffer.isBuffer(data)) {\n\t\t\tif (data.length === 1 && data[0]! > 127) {\n\t\t\t\tconst byte = data[0]! - 128;\n\t\t\t\tstr = `\\x1b${String.fromCharCode(byte)}`;\n\t\t\t} else {\n\t\t\t\tstr = data.toString();\n\t\t\t}\n\t\t} else {\n\t\t\tstr = data;\n\t\t}\n\n\t\tif (str.length === 0 && this.buffer.length === 0) {\n\t\t\tthis.emitDataSequence(\"\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.buffer += str;\n\n\t\tif (this.pasteMode) {\n\t\t\tthis.pasteBuffer += this.buffer;\n\t\t\tthis.buffer = \"\";\n\n\t\t\tconst endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);\n\t\t\tif (endIndex !== -1) {\n\t\t\t\tconst pastedContent = this.pasteBuffer.slice(0, endIndex);\n\t\t\t\tconst remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);\n\n\t\t\t\tthis.pasteMode = false;\n\t\t\t\tthis.pasteBuffer = \"\";\n\t\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\n\t\t\t\tthis.emit(\"paste\", pastedContent);\n\n\t\t\t\tif (remaining.length > 0) {\n\t\t\t\t\tthis.process(remaining);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst startIndex = this.buffer.indexOf(BRACKETED_PASTE_START);\n\t\tif (startIndex !== -1) {\n\t\t\tif (startIndex > 0) {\n\t\t\t\tconst beforePaste = this.buffer.slice(0, startIndex);\n\t\t\t\tconst result = extractCompleteSequences(beforePaste);\n\t\t\t\tfor (const sequence of result.sequences) {\n\t\t\t\t\tthis.emitDataSequence(sequence);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t\t\tthis.buffer = this.buffer.slice(startIndex + BRACKETED_PASTE_START.length);\n\t\t\tthis.pasteMode = true;\n\t\t\tthis.pasteBuffer = this.buffer;\n\t\t\tthis.buffer = \"\";\n\n\t\t\tconst endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);\n\t\t\tif (endIndex !== -1) {\n\t\t\t\tconst pastedContent = this.pasteBuffer.slice(0, endIndex);\n\t\t\t\tconst remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);\n\n\t\t\t\tthis.pasteMode = false;\n\t\t\t\tthis.pasteBuffer = \"\";\n\t\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\n\t\t\t\tthis.emit(\"paste\", pastedContent);\n\n\t\t\t\tif (remaining.length > 0) {\n\t\t\t\t\tthis.process(remaining);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst result = extractCompleteSequences(this.buffer);\n\t\tthis.buffer = result.remainder;\n\n\t\tfor (const sequence of result.sequences) {\n\t\t\tthis.emitDataSequence(sequence);\n\t\t}\n\n\t\tif (this.buffer.length > 0) {\n\t\t\tthis.timeout = setTimeout(() => {\n\t\t\t\tconst flushed = this.flush();\n\n\t\t\t\tfor (const sequence of flushed) {\n\t\t\t\t\tthis.emitDataSequence(sequence);\n\t\t\t\t}\n\t\t\t}, this.timeoutMs);\n\t\t}\n\t}\n\n\tprivate emitDataSequence(sequence: string): void {\n\t\tconst rawCodepoint = sequence.length === 1 ? sequence.codePointAt(0) : undefined;\n\t\tif (rawCodepoint !== undefined && rawCodepoint === this.pendingKittyPrintableCodepoint) {\n\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.pendingKittyPrintableCodepoint = parseUnmodifiedKittyPrintableCodepoint(sequence);\n\t\tthis.emit(\"data\", sequence);\n\t}\n\n\tflush(): string[] {\n\t\tif (this.timeout) {\n\t\t\tclearTimeout(this.timeout);\n\t\t\tthis.timeout = null;\n\t\t}\n\n\t\tif (this.buffer.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst sequences = [this.buffer];\n\t\tthis.buffer = \"\";\n\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t\treturn sequences;\n\t}\n\n\tclear(): void {\n\t\tif (this.timeout) {\n\t\t\tclearTimeout(this.timeout);\n\t\t\tthis.timeout = null;\n\t\t}\n\t\tthis.buffer = \"\";\n\t\tthis.pasteMode = false;\n\t\tthis.pasteBuffer = \"\";\n\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t}\n\n\tgetBuffer(): string {\n\t\treturn this.buffer;\n\t}\n\n\tdestroy(): void {\n\t\tthis.clear();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"stdin-buffer.d.ts","sourceRoot":"","sources":["../src/stdin-buffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAoNtC,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;IACf,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,qBAAa,WAAY,SAAQ,YAAY,CAAC,mBAAmB,CAAC;IAChE,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAA8C;IAC7D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,8BAA8B,CAAqB;IAC3D,OAAO,CAAC,YAAY,CAA8C;IAClE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAE/C,YAAY,OAAO,GAAE,kBAAuB,EAG3C;IAEM,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA+G1C;IAED,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,aAAa;IAQrB,KAAK,IAAI,MAAM,EAAE,CAchB;IAED,KAAK,IAAI,IAAI,CAaZ;IAED,SAAS,IAAI,MAAM,CAElB;IAED,OAAO,IAAI,IAAI,CAEd;CACF","sourcesContent":["/**\n * StdinBuffer buffers input and emits complete sequences.\n *\n * This is necessary because stdin data events can arrive in partial chunks,\n * especially for escape sequences like mouse events. Without buffering,\n * partial sequences can be misinterpreted as regular keypresses.\n *\n * For example, the mouse SGR sequence `\\x1b[<35;20;5m` might arrive as:\n * - Event 1: `\\x1b`\n * - Event 2: `[<35`\n * - Event 3: `;20;5m`\n *\n * The buffer accumulates these until a complete sequence is detected.\n * Call the `process()` method to feed input data.\n *\n * Based on code from OpenTUI (https://github.com/anomalyco/opentui)\n * MIT License - Copyright (c) 2025 opentui\n */\n\nimport { EventEmitter } from \"events\";\n\nconst ESC = \"\\x1b\";\nconst BRACKETED_PASTE_START = \"\\x1b[200~\";\nconst BRACKETED_PASTE_END = \"\\x1b[201~\";\n\n/**\n * Check if a string is a complete escape sequence or needs more data\n */\nfunction isCompleteSequence(data: string): \"complete\" | \"incomplete\" {\n if (data.length === 1) {\n return \"incomplete\";\n }\n\n const afterEsc = data.slice(1);\n\n // CSI sequences: ESC [\n if (afterEsc.startsWith(\"[\")) {\n // Check for old-style mouse sequence: ESC[M + 3 bytes\n if (afterEsc.startsWith(\"[M\")) {\n // Old-style mouse needs ESC[M + 3 bytes = 6 total\n return data.length >= 6 ? \"complete\" : \"incomplete\";\n }\n return isCompleteCsiSequence(data);\n }\n\n // OSC sequences: ESC ]\n if (afterEsc.startsWith(\"]\")) {\n return isCompleteOscSequence(data);\n }\n\n // DCS sequences: ESC P ... ESC \\ (includes XTVersion responses)\n if (afterEsc.startsWith(\"P\")) {\n return isCompleteDcsSequence(data);\n }\n\n // APC sequences: ESC _ ... ESC \\ (includes Kitty graphics responses)\n if (afterEsc.startsWith(\"_\")) {\n return isCompleteApcSequence(data);\n }\n\n // SS3 sequences: ESC O\n if (afterEsc.startsWith(\"O\")) {\n // ESC O followed by a single character\n return afterEsc.length >= 2 ? \"complete\" : \"incomplete\";\n }\n\n // Meta key sequences: ESC followed by a single character\n if (afterEsc.length === 1) {\n return \"complete\";\n }\n\n // Unknown escape sequence - treat as complete\n return \"complete\";\n}\n\n/**\n * Check if CSI sequence is complete\n * CSI sequences: ESC [ ... followed by a final byte (0x40-0x7E)\n */\nfunction isCompleteCsiSequence(data: string): \"complete\" | \"incomplete\" {\n // Need at least ESC [ and one more character\n if (data.length < 3) {\n return \"incomplete\";\n }\n\n const payload = data.slice(2);\n\n // CSI sequences end with a byte in the range 0x40-0x7E (@-~)\n // This includes all letters and several special characters\n const lastChar = payload[payload.length - 1];\n const lastCharCode = lastChar.charCodeAt(0);\n\n if (lastCharCode >= 0x40 && lastCharCode <= 0x7e) {\n // Special handling for SGR mouse sequences\n // Format: ESC[<B;X;Ym or ESC[<B;X;YM\n if (payload.startsWith(\"<\")) {\n // Must have format: <digits;digits;digits[Mm]\n const mouseMatch = /^<\\d+;\\d+;\\d+[Mm]$/.test(payload);\n if (mouseMatch) {\n return \"complete\";\n }\n // If it ends with M or m but doesn't match the pattern, still incomplete\n if (lastChar === \"M\" || lastChar === \"m\") {\n // Check if we have the right structure\n const parts = payload.slice(1, -1).split(\";\");\n if (parts.length === 3 && parts.every((p) => /^\\d+$/.test(p))) {\n return \"complete\";\n }\n }\n\n return \"incomplete\";\n }\n\n return \"complete\";\n }\n\n return \"incomplete\";\n}\n\n/**\n * Check if OSC sequence is complete\n * OSC sequences: ESC ] ... ST (where ST is ESC \\ or BEL)\n */\nfunction isCompleteOscSequence(data: string): \"complete\" | \"incomplete\" {\n // OSC sequences end with ST (ESC \\) or BEL (\\x07)\n if (data.endsWith(`${ESC}\\\\`) || data.endsWith(\"\\x07\")) {\n return \"complete\";\n }\n\n return \"incomplete\";\n}\n\n/**\n * Check if DCS (Device Control String) sequence is complete\n * DCS sequences: ESC P ... ST (where ST is ESC \\)\n * Used for XTVersion responses like ESC P >| ... ESC \\\n */\nfunction isCompleteDcsSequence(data: string): \"complete\" | \"incomplete\" {\n // DCS sequences end with ST (ESC \\)\n if (data.endsWith(`${ESC}\\\\`)) {\n return \"complete\";\n }\n\n return \"incomplete\";\n}\n\n/**\n * Check if APC (Application Program Command) sequence is complete\n * APC sequences: ESC _ ... ST (where ST is ESC \\)\n * Used for Kitty graphics responses like ESC _ G ... ESC \\\n */\nfunction isCompleteApcSequence(data: string): \"complete\" | \"incomplete\" {\n // APC sequences end with ST (ESC \\)\n if (data.endsWith(`${ESC}\\\\`)) {\n return \"complete\";\n }\n\n return \"incomplete\";\n}\n\n/**\n * Split accumulated buffer into complete sequences\n */\nfunction parseUnmodifiedKittyPrintableCodepoint(sequence: string): number | undefined {\n const match = sequence.match(/^\\x1b\\[(\\d+)(?::\\d*)?(?::\\d+)?u$/);\n if (!match) return undefined;\n\n const codepoint = parseInt(match[1]!, 10);\n return codepoint >= 32 ? codepoint : undefined;\n}\n\nfunction extractCompleteSequences(buffer: string): { sequences: string[]; remainder: string } {\n const sequences: string[] = [];\n let pos = 0;\n\n while (pos < buffer.length) {\n const remaining = buffer.slice(pos);\n\n // Try to extract a sequence starting at this position\n if (remaining.startsWith(ESC)) {\n // Find the end of this escape sequence\n let seqEnd = 1;\n while (seqEnd <= remaining.length) {\n const candidate = remaining.slice(0, seqEnd);\n const status = isCompleteSequence(candidate);\n\n if (status === \"complete\") {\n // WezTerm with enable_kitty_keyboard sends the Escape key press as a\n // raw '\\x1b' byte (simple text path in encode_kitty, ignoring\n // DISAMBIGUATE_ESCAPE_CODES) and the release as a full Kitty CSI-u\n // sequence. These arrive concatenated as '\\x1b\\x1b[27;...u'.\n // The buffer would normally treat '\\x1b\\x1b' as a complete meta-key\n // sequence (ESC + single char), leaving '[27;...u' to be typed as\n // plain text. If the character immediately following '\\x1b\\x1b'\n // would begin a new escape sequence, emit only the first ESC and\n // restart from the second.\n if (candidate === \"\\x1b\\x1b\") {\n const nextChar = remaining[seqEnd];\n if (\n nextChar === \"[\" || // CSI\n nextChar === \"]\" || // OSC\n nextChar === \"O\" || // SS3\n nextChar === \"P\" || // DCS\n nextChar === \"_\" // APC\n ) {\n sequences.push(ESC);\n pos += 1;\n break;\n }\n }\n sequences.push(candidate);\n pos += seqEnd;\n break;\n } else if (status === \"incomplete\") {\n seqEnd++;\n }\n }\n\n if (seqEnd > remaining.length) {\n return { sequences, remainder: remaining };\n }\n } else {\n // Not an escape sequence - take a single character\n sequences.push(remaining[0]!);\n pos++;\n }\n }\n\n return { sequences, remainder: \"\" };\n}\n\nexport type StdinBufferOptions = {\n /**\n * Maximum time to wait for sequence completion (default: 10ms)\n * After this time, the buffer is flushed even if incomplete\n */\n timeout?: number;\n};\n\nexport type StdinBufferEventMap = {\n data: [string];\n paste: [string];\n};\n\n/**\n * Buffers stdin input and emits complete sequences via the 'data' event.\n * Handles partial escape sequences that arrive across multiple chunks.\n */\nexport class StdinBuffer extends EventEmitter<StdinBufferEventMap> {\n private buffer: string = \"\";\n private timeout: ReturnType<typeof setTimeout> | null = null;\n private readonly timeoutMs: number;\n private pasteMode: boolean = false;\n private pasteBuffer: string = \"\";\n private pendingKittyPrintableCodepoint: number | undefined;\n private pasteTimeout: ReturnType<typeof setTimeout> | null = null;\n private readonly pasteTimeoutMs: number = 5000;\n\n constructor(options: StdinBufferOptions = {}) {\n super();\n this.timeoutMs = options.timeout ?? 10;\n }\n\n public process(data: string | Buffer): void {\n // Clear any pending timeout\n if (this.timeout) {\n clearTimeout(this.timeout);\n this.timeout = null;\n }\n\n // Handle high-byte conversion (for compatibility with parseKeypress)\n // If buffer has single byte > 127, convert to ESC + (byte - 128)\n let str: string;\n if (Buffer.isBuffer(data)) {\n if (data.length === 1 && data[0]! > 127) {\n const byte = data[0]! - 128;\n str = `\\x1b${String.fromCharCode(byte)}`;\n } else {\n str = data.toString();\n }\n } else {\n str = data;\n }\n\n if (str.length === 0 && this.buffer.length === 0) {\n this.emitDataSequence(\"\");\n return;\n }\n\n this.buffer += str;\n\n if (this.pasteMode) {\n this.pasteBuffer += this.buffer;\n this.buffer = \"\";\n\n const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);\n if (endIndex !== -1) {\n const pastedContent = this.pasteBuffer.slice(0, endIndex);\n const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);\n\n this.pasteMode = false;\n if (this.pasteTimeout) {\n clearTimeout(this.pasteTimeout);\n this.pasteTimeout = null;\n }\n this.pasteBuffer = \"\";\n this.pendingKittyPrintableCodepoint = undefined;\n\n this.emit(\"paste\", pastedContent);\n\n if (remaining.length > 0) {\n this.process(remaining);\n }\n }\n return;\n }\n\n const startIndex = this.buffer.indexOf(BRACKETED_PASTE_START);\n if (startIndex !== -1) {\n if (startIndex > 0) {\n const beforePaste = this.buffer.slice(0, startIndex);\n const result = extractCompleteSequences(beforePaste);\n for (const sequence of result.sequences) {\n this.emitDataSequence(sequence);\n }\n }\n\n this.pendingKittyPrintableCodepoint = undefined;\n this.buffer = this.buffer.slice(startIndex + BRACKETED_PASTE_START.length);\n this.pasteMode = true;\n this.pasteTimeout = setTimeout(() => {\n this.forcePasteEnd();\n }, this.pasteTimeoutMs);\n this.pasteBuffer = this.buffer;\n this.buffer = \"\";\n\n const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);\n if (endIndex !== -1) {\n const pastedContent = this.pasteBuffer.slice(0, endIndex);\n const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);\n\n this.pasteMode = false;\n if (this.pasteTimeout) {\n clearTimeout(this.pasteTimeout);\n this.pasteTimeout = null;\n }\n this.pasteBuffer = \"\";\n this.pendingKittyPrintableCodepoint = undefined;\n\n this.emit(\"paste\", pastedContent);\n\n if (remaining.length > 0) {\n this.process(remaining);\n }\n }\n return;\n }\n\n const result = extractCompleteSequences(this.buffer);\n this.buffer = result.remainder;\n\n for (const sequence of result.sequences) {\n this.emitDataSequence(sequence);\n }\n\n if (this.buffer.length > 0) {\n this.timeout = setTimeout(() => {\n const flushed = this.flush();\n\n for (const sequence of flushed) {\n this.emitDataSequence(sequence);\n }\n }, this.timeoutMs);\n }\n }\n\n private emitDataSequence(sequence: string): void {\n const rawCodepoint = sequence.length === 1 ? sequence.codePointAt(0) : undefined;\n if (rawCodepoint !== undefined && rawCodepoint === this.pendingKittyPrintableCodepoint) {\n this.pendingKittyPrintableCodepoint = undefined;\n return;\n }\n\n this.pendingKittyPrintableCodepoint = parseUnmodifiedKittyPrintableCodepoint(sequence);\n this.emit(\"data\", sequence);\n }\n\n private forcePasteEnd(): void {\n this.pasteMode = false;\n this.emit(\"paste\", this.pasteBuffer);\n this.pasteBuffer = \"\";\n this.pendingKittyPrintableCodepoint = undefined;\n this.pasteTimeout = null;\n }\n\n flush(): string[] {\n if (this.timeout) {\n clearTimeout(this.timeout);\n this.timeout = null;\n }\n\n if (this.buffer.length === 0) {\n return [];\n }\n\n const sequences = [this.buffer];\n this.buffer = \"\";\n this.pendingKittyPrintableCodepoint = undefined;\n return sequences;\n }\n\n clear(): void {\n if (this.timeout) {\n clearTimeout(this.timeout);\n this.timeout = null;\n }\n if (this.pasteTimeout) {\n clearTimeout(this.pasteTimeout);\n this.pasteTimeout = null;\n }\n this.buffer = \"\";\n this.pasteMode = false;\n this.pasteBuffer = \"\";\n this.pendingKittyPrintableCodepoint = undefined;\n }\n\n getBuffer(): string {\n return this.buffer;\n }\n\n destroy(): void {\n this.clear();\n }\n}\n"]}
|
package/dist/stdin-buffer.js
CHANGED
|
@@ -24,9 +24,6 @@ const BRACKETED_PASTE_END = "\x1b[201~";
|
|
|
24
24
|
* Check if a string is a complete escape sequence or needs more data
|
|
25
25
|
*/
|
|
26
26
|
function isCompleteSequence(data) {
|
|
27
|
-
if (!data.startsWith(ESC)) {
|
|
28
|
-
return "not-escape";
|
|
29
|
-
}
|
|
30
27
|
if (data.length === 1) {
|
|
31
28
|
return "incomplete";
|
|
32
29
|
}
|
|
@@ -69,9 +66,6 @@ function isCompleteSequence(data) {
|
|
|
69
66
|
* CSI sequences: ESC [ ... followed by a final byte (0x40-0x7E)
|
|
70
67
|
*/
|
|
71
68
|
function isCompleteCsiSequence(data) {
|
|
72
|
-
if (!data.startsWith(`${ESC}[`)) {
|
|
73
|
-
return "complete";
|
|
74
|
-
}
|
|
75
69
|
// Need at least ESC [ and one more character
|
|
76
70
|
if (data.length < 3) {
|
|
77
71
|
return "incomplete";
|
|
@@ -109,9 +103,6 @@ function isCompleteCsiSequence(data) {
|
|
|
109
103
|
* OSC sequences: ESC ] ... ST (where ST is ESC \ or BEL)
|
|
110
104
|
*/
|
|
111
105
|
function isCompleteOscSequence(data) {
|
|
112
|
-
if (!data.startsWith(`${ESC}]`)) {
|
|
113
|
-
return "complete";
|
|
114
|
-
}
|
|
115
106
|
// OSC sequences end with ST (ESC \) or BEL (\x07)
|
|
116
107
|
if (data.endsWith(`${ESC}\\`) || data.endsWith("\x07")) {
|
|
117
108
|
return "complete";
|
|
@@ -124,9 +115,6 @@ function isCompleteOscSequence(data) {
|
|
|
124
115
|
* Used for XTVersion responses like ESC P >| ... ESC \
|
|
125
116
|
*/
|
|
126
117
|
function isCompleteDcsSequence(data) {
|
|
127
|
-
if (!data.startsWith(`${ESC}P`)) {
|
|
128
|
-
return "complete";
|
|
129
|
-
}
|
|
130
118
|
// DCS sequences end with ST (ESC \)
|
|
131
119
|
if (data.endsWith(`${ESC}\\`)) {
|
|
132
120
|
return "complete";
|
|
@@ -139,9 +127,6 @@ function isCompleteDcsSequence(data) {
|
|
|
139
127
|
* Used for Kitty graphics responses like ESC _ G ... ESC \
|
|
140
128
|
*/
|
|
141
129
|
function isCompleteApcSequence(data) {
|
|
142
|
-
if (!data.startsWith(`${ESC}_`)) {
|
|
143
|
-
return "complete";
|
|
144
|
-
}
|
|
145
130
|
// APC sequences end with ST (ESC \)
|
|
146
131
|
if (data.endsWith(`${ESC}\\`)) {
|
|
147
132
|
return "complete";
|
|
@@ -200,12 +185,6 @@ function extractCompleteSequences(buffer) {
|
|
|
200
185
|
else if (status === "incomplete") {
|
|
201
186
|
seqEnd++;
|
|
202
187
|
}
|
|
203
|
-
else {
|
|
204
|
-
// Should not happen when starting with ESC
|
|
205
|
-
sequences.push(candidate);
|
|
206
|
-
pos += seqEnd;
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
188
|
}
|
|
210
189
|
if (seqEnd > remaining.length) {
|
|
211
190
|
return { sequences, remainder: remaining };
|
|
@@ -230,6 +209,8 @@ export class StdinBuffer extends EventEmitter {
|
|
|
230
209
|
pasteMode = false;
|
|
231
210
|
pasteBuffer = "";
|
|
232
211
|
pendingKittyPrintableCodepoint;
|
|
212
|
+
pasteTimeout = null;
|
|
213
|
+
pasteTimeoutMs = 5000;
|
|
233
214
|
constructor(options = {}) {
|
|
234
215
|
super();
|
|
235
216
|
this.timeoutMs = options.timeout ?? 10;
|
|
@@ -268,6 +249,10 @@ export class StdinBuffer extends EventEmitter {
|
|
|
268
249
|
const pastedContent = this.pasteBuffer.slice(0, endIndex);
|
|
269
250
|
const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);
|
|
270
251
|
this.pasteMode = false;
|
|
252
|
+
if (this.pasteTimeout) {
|
|
253
|
+
clearTimeout(this.pasteTimeout);
|
|
254
|
+
this.pasteTimeout = null;
|
|
255
|
+
}
|
|
271
256
|
this.pasteBuffer = "";
|
|
272
257
|
this.pendingKittyPrintableCodepoint = undefined;
|
|
273
258
|
this.emit("paste", pastedContent);
|
|
@@ -289,6 +274,9 @@ export class StdinBuffer extends EventEmitter {
|
|
|
289
274
|
this.pendingKittyPrintableCodepoint = undefined;
|
|
290
275
|
this.buffer = this.buffer.slice(startIndex + BRACKETED_PASTE_START.length);
|
|
291
276
|
this.pasteMode = true;
|
|
277
|
+
this.pasteTimeout = setTimeout(() => {
|
|
278
|
+
this.forcePasteEnd();
|
|
279
|
+
}, this.pasteTimeoutMs);
|
|
292
280
|
this.pasteBuffer = this.buffer;
|
|
293
281
|
this.buffer = "";
|
|
294
282
|
const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);
|
|
@@ -296,6 +284,10 @@ export class StdinBuffer extends EventEmitter {
|
|
|
296
284
|
const pastedContent = this.pasteBuffer.slice(0, endIndex);
|
|
297
285
|
const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);
|
|
298
286
|
this.pasteMode = false;
|
|
287
|
+
if (this.pasteTimeout) {
|
|
288
|
+
clearTimeout(this.pasteTimeout);
|
|
289
|
+
this.pasteTimeout = null;
|
|
290
|
+
}
|
|
299
291
|
this.pasteBuffer = "";
|
|
300
292
|
this.pendingKittyPrintableCodepoint = undefined;
|
|
301
293
|
this.emit("paste", pastedContent);
|
|
@@ -328,6 +320,13 @@ export class StdinBuffer extends EventEmitter {
|
|
|
328
320
|
this.pendingKittyPrintableCodepoint = parseUnmodifiedKittyPrintableCodepoint(sequence);
|
|
329
321
|
this.emit("data", sequence);
|
|
330
322
|
}
|
|
323
|
+
forcePasteEnd() {
|
|
324
|
+
this.pasteMode = false;
|
|
325
|
+
this.emit("paste", this.pasteBuffer);
|
|
326
|
+
this.pasteBuffer = "";
|
|
327
|
+
this.pendingKittyPrintableCodepoint = undefined;
|
|
328
|
+
this.pasteTimeout = null;
|
|
329
|
+
}
|
|
331
330
|
flush() {
|
|
332
331
|
if (this.timeout) {
|
|
333
332
|
clearTimeout(this.timeout);
|
|
@@ -346,6 +345,10 @@ export class StdinBuffer extends EventEmitter {
|
|
|
346
345
|
clearTimeout(this.timeout);
|
|
347
346
|
this.timeout = null;
|
|
348
347
|
}
|
|
348
|
+
if (this.pasteTimeout) {
|
|
349
|
+
clearTimeout(this.pasteTimeout);
|
|
350
|
+
this.pasteTimeout = null;
|
|
351
|
+
}
|
|
349
352
|
this.buffer = "";
|
|
350
353
|
this.pasteMode = false;
|
|
351
354
|
this.pasteBuffer = "";
|
package/dist/stdin-buffer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdin-buffer.js","sourceRoot":"","sources":["../src/stdin-buffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,GAAG,GAAG,MAAM,CAAC;AACnB,MAAM,qBAAqB,GAAG,WAAW,CAAC;AAC1C,MAAM,mBAAmB,GAAG,WAAW,CAAC;AAExC;;GAEG;AACH,SAAS,kBAAkB,CAAC,IAAY,EAA4C;IACnF,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,OAAO,YAAY,CAAC;IACrB,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,C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AAC;QACvB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,8BAA8B,GAAG,SAAS,CAAC;IAAA,CAChD;IAED,SAAS,GAAW;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC;IAAA,CACnB;IAED,OAAO,GAAS;QACf,IAAI,CAAC,KAAK,EAAE,CAAC;IAAA,CACb;CACD","sourcesContent":["/**\n * StdinBuffer buffers input and emits complete sequences.\n *\n * This is necessary because stdin data events can arrive in partial chunks,\n * especially for escape sequences like mouse events. Without buffering,\n * partial sequences can be misinterpreted as regular keypresses.\n *\n * For example, the mouse SGR sequence `\\x1b[<35;20;5m` might arrive as:\n * - Event 1: `\\x1b`\n * - Event 2: `[<35`\n * - Event 3: `;20;5m`\n *\n * The buffer accumulates these until a complete sequence is detected.\n * Call the `process()` method to feed input data.\n *\n * Based on code from OpenTUI (https://github.com/anomalyco/opentui)\n * MIT License - Copyright (c) 2025 opentui\n */\n\nimport { EventEmitter } from \"events\";\n\nconst ESC = \"\\x1b\";\nconst BRACKETED_PASTE_START = \"\\x1b[200~\";\nconst BRACKETED_PASTE_END = \"\\x1b[201~\";\n\n/**\n * Check if a string is a complete escape sequence or needs more data\n */\nfunction isCompleteSequence(data: string): \"complete\" | \"incomplete\" | \"not-escape\" {\n\tif (!data.startsWith(ESC)) {\n\t\treturn \"not-escape\";\n\t}\n\n\tif (data.length === 1) {\n\t\treturn \"incomplete\";\n\t}\n\n\tconst afterEsc = data.slice(1);\n\n\t// CSI sequences: ESC [\n\tif (afterEsc.startsWith(\"[\")) {\n\t\t// Check for old-style mouse sequence: ESC[M + 3 bytes\n\t\tif (afterEsc.startsWith(\"[M\")) {\n\t\t\t// Old-style mouse needs ESC[M + 3 bytes = 6 total\n\t\t\treturn data.length >= 6 ? \"complete\" : \"incomplete\";\n\t\t}\n\t\treturn isCompleteCsiSequence(data);\n\t}\n\n\t// OSC sequences: ESC ]\n\tif (afterEsc.startsWith(\"]\")) {\n\t\treturn isCompleteOscSequence(data);\n\t}\n\n\t// DCS sequences: ESC P ... ESC \\ (includes XTVersion responses)\n\tif (afterEsc.startsWith(\"P\")) {\n\t\treturn isCompleteDcsSequence(data);\n\t}\n\n\t// APC sequences: ESC _ ... ESC \\ (includes Kitty graphics responses)\n\tif (afterEsc.startsWith(\"_\")) {\n\t\treturn isCompleteApcSequence(data);\n\t}\n\n\t// SS3 sequences: ESC O\n\tif (afterEsc.startsWith(\"O\")) {\n\t\t// ESC O followed by a single character\n\t\treturn afterEsc.length >= 2 ? \"complete\" : \"incomplete\";\n\t}\n\n\t// Meta key sequences: ESC followed by a single character\n\tif (afterEsc.length === 1) {\n\t\treturn \"complete\";\n\t}\n\n\t// Unknown escape sequence - treat as complete\n\treturn \"complete\";\n}\n\n/**\n * Check if CSI sequence is complete\n * CSI sequences: ESC [ ... followed by a final byte (0x40-0x7E)\n */\nfunction isCompleteCsiSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}[`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// Need at least ESC [ and one more character\n\tif (data.length < 3) {\n\t\treturn \"incomplete\";\n\t}\n\n\tconst payload = data.slice(2);\n\n\t// CSI sequences end with a byte in the range 0x40-0x7E (@-~)\n\t// This includes all letters and several special characters\n\tconst lastChar = payload[payload.length - 1];\n\tconst lastCharCode = lastChar.charCodeAt(0);\n\n\tif (lastCharCode >= 0x40 && lastCharCode <= 0x7e) {\n\t\t// Special handling for SGR mouse sequences\n\t\t// Format: ESC[<B;X;Ym or ESC[<B;X;YM\n\t\tif (payload.startsWith(\"<\")) {\n\t\t\t// Must have format: <digits;digits;digits[Mm]\n\t\t\tconst mouseMatch = /^<\\d+;\\d+;\\d+[Mm]$/.test(payload);\n\t\t\tif (mouseMatch) {\n\t\t\t\treturn \"complete\";\n\t\t\t}\n\t\t\t// If it ends with M or m but doesn't match the pattern, still incomplete\n\t\t\tif (lastChar === \"M\" || lastChar === \"m\") {\n\t\t\t\t// Check if we have the right structure\n\t\t\t\tconst parts = payload.slice(1, -1).split(\";\");\n\t\t\t\tif (parts.length === 3 && parts.every((p) => /^\\d+$/.test(p))) {\n\t\t\t\t\treturn \"complete\";\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn \"incomplete\";\n\t\t}\n\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Check if OSC sequence is complete\n * OSC sequences: ESC ] ... ST (where ST is ESC \\ or BEL)\n */\nfunction isCompleteOscSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}]`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// OSC sequences end with ST (ESC \\) or BEL (\\x07)\n\tif (data.endsWith(`${ESC}\\\\`) || data.endsWith(\"\\x07\")) {\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Check if DCS (Device Control String) sequence is complete\n * DCS sequences: ESC P ... ST (where ST is ESC \\)\n * Used for XTVersion responses like ESC P >| ... ESC \\\n */\nfunction isCompleteDcsSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}P`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// DCS sequences end with ST (ESC \\)\n\tif (data.endsWith(`${ESC}\\\\`)) {\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Check if APC (Application Program Command) sequence is complete\n * APC sequences: ESC _ ... ST (where ST is ESC \\)\n * Used for Kitty graphics responses like ESC _ G ... ESC \\\n */\nfunction isCompleteApcSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}_`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// APC sequences end with ST (ESC \\)\n\tif (data.endsWith(`${ESC}\\\\`)) {\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Split accumulated buffer into complete sequences\n */\nfunction parseUnmodifiedKittyPrintableCodepoint(sequence: string): number | undefined {\n\tconst match = sequence.match(/^\\x1b\\[(\\d+)(?::\\d*)?(?::\\d+)?u$/);\n\tif (!match) return undefined;\n\n\tconst codepoint = parseInt(match[1]!, 10);\n\treturn codepoint >= 32 ? codepoint : undefined;\n}\n\nfunction extractCompleteSequences(buffer: string): { sequences: string[]; remainder: string } {\n\tconst sequences: string[] = [];\n\tlet pos = 0;\n\n\twhile (pos < buffer.length) {\n\t\tconst remaining = buffer.slice(pos);\n\n\t\t// Try to extract a sequence starting at this position\n\t\tif (remaining.startsWith(ESC)) {\n\t\t\t// Find the end of this escape sequence\n\t\t\tlet seqEnd = 1;\n\t\t\twhile (seqEnd <= remaining.length) {\n\t\t\t\tconst candidate = remaining.slice(0, seqEnd);\n\t\t\t\tconst status = isCompleteSequence(candidate);\n\n\t\t\t\tif (status === \"complete\") {\n\t\t\t\t\t// WezTerm with enable_kitty_keyboard sends the Escape key press as a\n\t\t\t\t\t// raw '\\x1b' byte (simple text path in encode_kitty, ignoring\n\t\t\t\t\t// DISAMBIGUATE_ESCAPE_CODES) and the release as a full Kitty CSI-u\n\t\t\t\t\t// sequence. These arrive concatenated as '\\x1b\\x1b[27;...u'.\n\t\t\t\t\t// The buffer would normally treat '\\x1b\\x1b' as a complete meta-key\n\t\t\t\t\t// sequence (ESC + single char), leaving '[27;...u' to be typed as\n\t\t\t\t\t// plain text. If the character immediately following '\\x1b\\x1b'\n\t\t\t\t\t// would begin a new escape sequence, emit only the first ESC and\n\t\t\t\t\t// restart from the second.\n\t\t\t\t\tif (candidate === \"\\x1b\\x1b\") {\n\t\t\t\t\t\tconst nextChar = remaining[seqEnd];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnextChar === \"[\" || // CSI\n\t\t\t\t\t\t\tnextChar === \"]\" || // OSC\n\t\t\t\t\t\t\tnextChar === \"O\" || // SS3\n\t\t\t\t\t\t\tnextChar === \"P\" || // DCS\n\t\t\t\t\t\t\tnextChar === \"_\" // APC\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tsequences.push(ESC);\n\t\t\t\t\t\t\tpos += 1;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tsequences.push(candidate);\n\t\t\t\t\tpos += seqEnd;\n\t\t\t\t\tbreak;\n\t\t\t\t} else if (status === \"incomplete\") {\n\t\t\t\t\tseqEnd++;\n\t\t\t\t} else {\n\t\t\t\t\t// Should not happen when starting with ESC\n\t\t\t\t\tsequences.push(candidate);\n\t\t\t\t\tpos += seqEnd;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (seqEnd > remaining.length) {\n\t\t\t\treturn { sequences, remainder: remaining };\n\t\t\t}\n\t\t} else {\n\t\t\t// Not an escape sequence - take a single character\n\t\t\tsequences.push(remaining[0]!);\n\t\t\tpos++;\n\t\t}\n\t}\n\n\treturn { sequences, remainder: \"\" };\n}\n\nexport type StdinBufferOptions = {\n\t/**\n\t * Maximum time to wait for sequence completion (default: 10ms)\n\t * After this time, the buffer is flushed even if incomplete\n\t */\n\ttimeout?: number;\n};\n\nexport type StdinBufferEventMap = {\n\tdata: [string];\n\tpaste: [string];\n};\n\n/**\n * Buffers stdin input and emits complete sequences via the 'data' event.\n * Handles partial escape sequences that arrive across multiple chunks.\n */\nexport class StdinBuffer extends EventEmitter<StdinBufferEventMap> {\n\tprivate buffer: string = \"\";\n\tprivate timeout: ReturnType<typeof setTimeout> | null = null;\n\tprivate readonly timeoutMs: number;\n\tprivate pasteMode: boolean = false;\n\tprivate pasteBuffer: string = \"\";\n\tprivate pendingKittyPrintableCodepoint: number | undefined;\n\n\tconstructor(options: StdinBufferOptions = {}) {\n\t\tsuper();\n\t\tthis.timeoutMs = options.timeout ?? 10;\n\t}\n\n\tpublic process(data: string | Buffer): void {\n\t\t// Clear any pending timeout\n\t\tif (this.timeout) {\n\t\t\tclearTimeout(this.timeout);\n\t\t\tthis.timeout = null;\n\t\t}\n\n\t\t// Handle high-byte conversion (for compatibility with parseKeypress)\n\t\t// If buffer has single byte > 127, convert to ESC + (byte - 128)\n\t\tlet str: string;\n\t\tif (Buffer.isBuffer(data)) {\n\t\t\tif (data.length === 1 && data[0]! > 127) {\n\t\t\t\tconst byte = data[0]! - 128;\n\t\t\t\tstr = `\\x1b${String.fromCharCode(byte)}`;\n\t\t\t} else {\n\t\t\t\tstr = data.toString();\n\t\t\t}\n\t\t} else {\n\t\t\tstr = data;\n\t\t}\n\n\t\tif (str.length === 0 && this.buffer.length === 0) {\n\t\t\tthis.emitDataSequence(\"\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.buffer += str;\n\n\t\tif (this.pasteMode) {\n\t\t\tthis.pasteBuffer += this.buffer;\n\t\t\tthis.buffer = \"\";\n\n\t\t\tconst endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);\n\t\t\tif (endIndex !== -1) {\n\t\t\t\tconst pastedContent = this.pasteBuffer.slice(0, endIndex);\n\t\t\t\tconst remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);\n\n\t\t\t\tthis.pasteMode = false;\n\t\t\t\tthis.pasteBuffer = \"\";\n\t\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\n\t\t\t\tthis.emit(\"paste\", pastedContent);\n\n\t\t\t\tif (remaining.length > 0) {\n\t\t\t\t\tthis.process(remaining);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst startIndex = this.buffer.indexOf(BRACKETED_PASTE_START);\n\t\tif (startIndex !== -1) {\n\t\t\tif (startIndex > 0) {\n\t\t\t\tconst beforePaste = this.buffer.slice(0, startIndex);\n\t\t\t\tconst result = extractCompleteSequences(beforePaste);\n\t\t\t\tfor (const sequence of result.sequences) {\n\t\t\t\t\tthis.emitDataSequence(sequence);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t\t\tthis.buffer = this.buffer.slice(startIndex + BRACKETED_PASTE_START.length);\n\t\t\tthis.pasteMode = true;\n\t\t\tthis.pasteBuffer = this.buffer;\n\t\t\tthis.buffer = \"\";\n\n\t\t\tconst endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);\n\t\t\tif (endIndex !== -1) {\n\t\t\t\tconst pastedContent = this.pasteBuffer.slice(0, endIndex);\n\t\t\t\tconst remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);\n\n\t\t\t\tthis.pasteMode = false;\n\t\t\t\tthis.pasteBuffer = \"\";\n\t\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\n\t\t\t\tthis.emit(\"paste\", pastedContent);\n\n\t\t\t\tif (remaining.length > 0) {\n\t\t\t\t\tthis.process(remaining);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst result = extractCompleteSequences(this.buffer);\n\t\tthis.buffer = result.remainder;\n\n\t\tfor (const sequence of result.sequences) {\n\t\t\tthis.emitDataSequence(sequence);\n\t\t}\n\n\t\tif (this.buffer.length > 0) {\n\t\t\tthis.timeout = setTimeout(() => {\n\t\t\t\tconst flushed = this.flush();\n\n\t\t\t\tfor (const sequence of flushed) {\n\t\t\t\t\tthis.emitDataSequence(sequence);\n\t\t\t\t}\n\t\t\t}, this.timeoutMs);\n\t\t}\n\t}\n\n\tprivate emitDataSequence(sequence: string): void {\n\t\tconst rawCodepoint = sequence.length === 1 ? sequence.codePointAt(0) : undefined;\n\t\tif (rawCodepoint !== undefined && rawCodepoint === this.pendingKittyPrintableCodepoint) {\n\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.pendingKittyPrintableCodepoint = parseUnmodifiedKittyPrintableCodepoint(sequence);\n\t\tthis.emit(\"data\", sequence);\n\t}\n\n\tflush(): string[] {\n\t\tif (this.timeout) {\n\t\t\tclearTimeout(this.timeout);\n\t\t\tthis.timeout = null;\n\t\t}\n\n\t\tif (this.buffer.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst sequences = [this.buffer];\n\t\tthis.buffer = \"\";\n\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t\treturn sequences;\n\t}\n\n\tclear(): void {\n\t\tif (this.timeout) {\n\t\t\tclearTimeout(this.timeout);\n\t\t\tthis.timeout = null;\n\t\t}\n\t\tthis.buffer = \"\";\n\t\tthis.pasteMode = false;\n\t\tthis.pasteBuffer = \"\";\n\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t}\n\n\tgetBuffer(): string {\n\t\treturn this.buffer;\n\t}\n\n\tdestroy(): void {\n\t\tthis.clear();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"stdin-buffer.js","sourceRoot":"","sources":["../src/stdin-buffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,GAAG,GAAG,MAAM,CAAC;AACnB,MAAM,qBAAqB,GAAG,WAAW,CAAC;AAC1C,MAAM,mBAAmB,GAAG,WAAW,CAAC;AAExC;;GAEG;AACH,SAAS,kBAAkB,CAAC,IAAY,EAA6B;IACnE,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE/B,uBAAuB;IACvB,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,sDAAsD;QACtD,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,kDAAkD;YAClD,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC;QACtD,CAAC;QACD,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,uBAAuB;IACvB,IAAI,QA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AC,MAAM,CAAC;IAAA,CACpB;IAED,OAAO,GAAS;QACd,IAAI,CAAC,KAAK,EAAE,CAAC;IAAA,CACd;CACF","sourcesContent":["/**\n * StdinBuffer buffers input and emits complete sequences.\n *\n * This is necessary because stdin data events can arrive in partial chunks,\n * especially for escape sequences like mouse events. Without buffering,\n * partial sequences can be misinterpreted as regular keypresses.\n *\n * For example, the mouse SGR sequence `\\x1b[<35;20;5m` might arrive as:\n * - Event 1: `\\x1b`\n * - Event 2: `[<35`\n * - Event 3: `;20;5m`\n *\n * The buffer accumulates these until a complete sequence is detected.\n * Call the `process()` method to feed input data.\n *\n * Based on code from OpenTUI (https://github.com/anomalyco/opentui)\n * MIT License - Copyright (c) 2025 opentui\n */\n\nimport { EventEmitter } from \"events\";\n\nconst ESC = \"\\x1b\";\nconst BRACKETED_PASTE_START = \"\\x1b[200~\";\nconst BRACKETED_PASTE_END = \"\\x1b[201~\";\n\n/**\n * Check if a string is a complete escape sequence or needs more data\n */\nfunction isCompleteSequence(data: string): \"complete\" | \"incomplete\" {\n if (data.length === 1) {\n return \"incomplete\";\n }\n\n const afterEsc = data.slice(1);\n\n // CSI sequences: ESC [\n if (afterEsc.startsWith(\"[\")) {\n // Check for old-style mouse sequence: ESC[M + 3 bytes\n if (afterEsc.startsWith(\"[M\")) {\n // Old-style mouse needs ESC[M + 3 bytes = 6 total\n return data.length >= 6 ? \"complete\" : \"incomplete\";\n }\n return isCompleteCsiSequence(data);\n }\n\n // OSC sequences: ESC ]\n if (afterEsc.startsWith(\"]\")) {\n return isCompleteOscSequence(data);\n }\n\n // DCS sequences: ESC P ... ESC \\ (includes XTVersion responses)\n if (afterEsc.startsWith(\"P\")) {\n return isCompleteDcsSequence(data);\n }\n\n // APC sequences: ESC _ ... ESC \\ (includes Kitty graphics responses)\n if (afterEsc.startsWith(\"_\")) {\n return isCompleteApcSequence(data);\n }\n\n // SS3 sequences: ESC O\n if (afterEsc.startsWith(\"O\")) {\n // ESC O followed by a single character\n return afterEsc.length >= 2 ? \"complete\" : \"incomplete\";\n }\n\n // Meta key sequences: ESC followed by a single character\n if (afterEsc.length === 1) {\n return \"complete\";\n }\n\n // Unknown escape sequence - treat as complete\n return \"complete\";\n}\n\n/**\n * Check if CSI sequence is complete\n * CSI sequences: ESC [ ... followed by a final byte (0x40-0x7E)\n */\nfunction isCompleteCsiSequence(data: string): \"complete\" | \"incomplete\" {\n // Need at least ESC [ and one more character\n if (data.length < 3) {\n return \"incomplete\";\n }\n\n const payload = data.slice(2);\n\n // CSI sequences end with a byte in the range 0x40-0x7E (@-~)\n // This includes all letters and several special characters\n const lastChar = payload[payload.length - 1];\n const lastCharCode = lastChar.charCodeAt(0);\n\n if (lastCharCode >= 0x40 && lastCharCode <= 0x7e) {\n // Special handling for SGR mouse sequences\n // Format: ESC[<B;X;Ym or ESC[<B;X;YM\n if (payload.startsWith(\"<\")) {\n // Must have format: <digits;digits;digits[Mm]\n const mouseMatch = /^<\\d+;\\d+;\\d+[Mm]$/.test(payload);\n if (mouseMatch) {\n return \"complete\";\n }\n // If it ends with M or m but doesn't match the pattern, still incomplete\n if (lastChar === \"M\" || lastChar === \"m\") {\n // Check if we have the right structure\n const parts = payload.slice(1, -1).split(\";\");\n if (parts.length === 3 && parts.every((p) => /^\\d+$/.test(p))) {\n return \"complete\";\n }\n }\n\n return \"incomplete\";\n }\n\n return \"complete\";\n }\n\n return \"incomplete\";\n}\n\n/**\n * Check if OSC sequence is complete\n * OSC sequences: ESC ] ... ST (where ST is ESC \\ or BEL)\n */\nfunction isCompleteOscSequence(data: string): \"complete\" | \"incomplete\" {\n // OSC sequences end with ST (ESC \\) or BEL (\\x07)\n if (data.endsWith(`${ESC}\\\\`) || data.endsWith(\"\\x07\")) {\n return \"complete\";\n }\n\n return \"incomplete\";\n}\n\n/**\n * Check if DCS (Device Control String) sequence is complete\n * DCS sequences: ESC P ... ST (where ST is ESC \\)\n * Used for XTVersion responses like ESC P >| ... ESC \\\n */\nfunction isCompleteDcsSequence(data: string): \"complete\" | \"incomplete\" {\n // DCS sequences end with ST (ESC \\)\n if (data.endsWith(`${ESC}\\\\`)) {\n return \"complete\";\n }\n\n return \"incomplete\";\n}\n\n/**\n * Check if APC (Application Program Command) sequence is complete\n * APC sequences: ESC _ ... ST (where ST is ESC \\)\n * Used for Kitty graphics responses like ESC _ G ... ESC \\\n */\nfunction isCompleteApcSequence(data: string): \"complete\" | \"incomplete\" {\n // APC sequences end with ST (ESC \\)\n if (data.endsWith(`${ESC}\\\\`)) {\n return \"complete\";\n }\n\n return \"incomplete\";\n}\n\n/**\n * Split accumulated buffer into complete sequences\n */\nfunction parseUnmodifiedKittyPrintableCodepoint(sequence: string): number | undefined {\n const match = sequence.match(/^\\x1b\\[(\\d+)(?::\\d*)?(?::\\d+)?u$/);\n if (!match) return undefined;\n\n const codepoint = parseInt(match[1]!, 10);\n return codepoint >= 32 ? codepoint : undefined;\n}\n\nfunction extractCompleteSequences(buffer: string): { sequences: string[]; remainder: string } {\n const sequences: string[] = [];\n let pos = 0;\n\n while (pos < buffer.length) {\n const remaining = buffer.slice(pos);\n\n // Try to extract a sequence starting at this position\n if (remaining.startsWith(ESC)) {\n // Find the end of this escape sequence\n let seqEnd = 1;\n while (seqEnd <= remaining.length) {\n const candidate = remaining.slice(0, seqEnd);\n const status = isCompleteSequence(candidate);\n\n if (status === \"complete\") {\n // WezTerm with enable_kitty_keyboard sends the Escape key press as a\n // raw '\\x1b' byte (simple text path in encode_kitty, ignoring\n // DISAMBIGUATE_ESCAPE_CODES) and the release as a full Kitty CSI-u\n // sequence. These arrive concatenated as '\\x1b\\x1b[27;...u'.\n // The buffer would normally treat '\\x1b\\x1b' as a complete meta-key\n // sequence (ESC + single char), leaving '[27;...u' to be typed as\n // plain text. If the character immediately following '\\x1b\\x1b'\n // would begin a new escape sequence, emit only the first ESC and\n // restart from the second.\n if (candidate === \"\\x1b\\x1b\") {\n const nextChar = remaining[seqEnd];\n if (\n nextChar === \"[\" || // CSI\n nextChar === \"]\" || // OSC\n nextChar === \"O\" || // SS3\n nextChar === \"P\" || // DCS\n nextChar === \"_\" // APC\n ) {\n sequences.push(ESC);\n pos += 1;\n break;\n }\n }\n sequences.push(candidate);\n pos += seqEnd;\n break;\n } else if (status === \"incomplete\") {\n seqEnd++;\n }\n }\n\n if (seqEnd > remaining.length) {\n return { sequences, remainder: remaining };\n }\n } else {\n // Not an escape sequence - take a single character\n sequences.push(remaining[0]!);\n pos++;\n }\n }\n\n return { sequences, remainder: \"\" };\n}\n\nexport type StdinBufferOptions = {\n /**\n * Maximum time to wait for sequence completion (default: 10ms)\n * After this time, the buffer is flushed even if incomplete\n */\n timeout?: number;\n};\n\nexport type StdinBufferEventMap = {\n data: [string];\n paste: [string];\n};\n\n/**\n * Buffers stdin input and emits complete sequences via the 'data' event.\n * Handles partial escape sequences that arrive across multiple chunks.\n */\nexport class StdinBuffer extends EventEmitter<StdinBufferEventMap> {\n private buffer: string = \"\";\n private timeout: ReturnType<typeof setTimeout> | null = null;\n private readonly timeoutMs: number;\n private pasteMode: boolean = false;\n private pasteBuffer: string = \"\";\n private pendingKittyPrintableCodepoint: number | undefined;\n private pasteTimeout: ReturnType<typeof setTimeout> | null = null;\n private readonly pasteTimeoutMs: number = 5000;\n\n constructor(options: StdinBufferOptions = {}) {\n super();\n this.timeoutMs = options.timeout ?? 10;\n }\n\n public process(data: string | Buffer): void {\n // Clear any pending timeout\n if (this.timeout) {\n clearTimeout(this.timeout);\n this.timeout = null;\n }\n\n // Handle high-byte conversion (for compatibility with parseKeypress)\n // If buffer has single byte > 127, convert to ESC + (byte - 128)\n let str: string;\n if (Buffer.isBuffer(data)) {\n if (data.length === 1 && data[0]! > 127) {\n const byte = data[0]! - 128;\n str = `\\x1b${String.fromCharCode(byte)}`;\n } else {\n str = data.toString();\n }\n } else {\n str = data;\n }\n\n if (str.length === 0 && this.buffer.length === 0) {\n this.emitDataSequence(\"\");\n return;\n }\n\n this.buffer += str;\n\n if (this.pasteMode) {\n this.pasteBuffer += this.buffer;\n this.buffer = \"\";\n\n const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);\n if (endIndex !== -1) {\n const pastedContent = this.pasteBuffer.slice(0, endIndex);\n const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);\n\n this.pasteMode = false;\n if (this.pasteTimeout) {\n clearTimeout(this.pasteTimeout);\n this.pasteTimeout = null;\n }\n this.pasteBuffer = \"\";\n this.pendingKittyPrintableCodepoint = undefined;\n\n this.emit(\"paste\", pastedContent);\n\n if (remaining.length > 0) {\n this.process(remaining);\n }\n }\n return;\n }\n\n const startIndex = this.buffer.indexOf(BRACKETED_PASTE_START);\n if (startIndex !== -1) {\n if (startIndex > 0) {\n const beforePaste = this.buffer.slice(0, startIndex);\n const result = extractCompleteSequences(beforePaste);\n for (const sequence of result.sequences) {\n this.emitDataSequence(sequence);\n }\n }\n\n this.pendingKittyPrintableCodepoint = undefined;\n this.buffer = this.buffer.slice(startIndex + BRACKETED_PASTE_START.length);\n this.pasteMode = true;\n this.pasteTimeout = setTimeout(() => {\n this.forcePasteEnd();\n }, this.pasteTimeoutMs);\n this.pasteBuffer = this.buffer;\n this.buffer = \"\";\n\n const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);\n if (endIndex !== -1) {\n const pastedContent = this.pasteBuffer.slice(0, endIndex);\n const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);\n\n this.pasteMode = false;\n if (this.pasteTimeout) {\n clearTimeout(this.pasteTimeout);\n this.pasteTimeout = null;\n }\n this.pasteBuffer = \"\";\n this.pendingKittyPrintableCodepoint = undefined;\n\n this.emit(\"paste\", pastedContent);\n\n if (remaining.length > 0) {\n this.process(remaining);\n }\n }\n return;\n }\n\n const result = extractCompleteSequences(this.buffer);\n this.buffer = result.remainder;\n\n for (const sequence of result.sequences) {\n this.emitDataSequence(sequence);\n }\n\n if (this.buffer.length > 0) {\n this.timeout = setTimeout(() => {\n const flushed = this.flush();\n\n for (const sequence of flushed) {\n this.emitDataSequence(sequence);\n }\n }, this.timeoutMs);\n }\n }\n\n private emitDataSequence(sequence: string): void {\n const rawCodepoint = sequence.length === 1 ? sequence.codePointAt(0) : undefined;\n if (rawCodepoint !== undefined && rawCodepoint === this.pendingKittyPrintableCodepoint) {\n this.pendingKittyPrintableCodepoint = undefined;\n return;\n }\n\n this.pendingKittyPrintableCodepoint = parseUnmodifiedKittyPrintableCodepoint(sequence);\n this.emit(\"data\", sequence);\n }\n\n private forcePasteEnd(): void {\n this.pasteMode = false;\n this.emit(\"paste\", this.pasteBuffer);\n this.pasteBuffer = \"\";\n this.pendingKittyPrintableCodepoint = undefined;\n this.pasteTimeout = null;\n }\n\n flush(): string[] {\n if (this.timeout) {\n clearTimeout(this.timeout);\n this.timeout = null;\n }\n\n if (this.buffer.length === 0) {\n return [];\n }\n\n const sequences = [this.buffer];\n this.buffer = \"\";\n this.pendingKittyPrintableCodepoint = undefined;\n return sequences;\n }\n\n clear(): void {\n if (this.timeout) {\n clearTimeout(this.timeout);\n this.timeout = null;\n }\n if (this.pasteTimeout) {\n clearTimeout(this.pasteTimeout);\n this.pasteTimeout = null;\n }\n this.buffer = \"\";\n this.pasteMode = false;\n this.pasteBuffer = \"\";\n this.pendingKittyPrintableCodepoint = undefined;\n }\n\n getBuffer(): string {\n return this.buffer;\n }\n\n destroy(): void {\n this.clear();\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const cjsRequire: NodeJS.Require;
|
|
2
|
+
export declare const TERMINAL_PROGRESS_KEEPALIVE_MS = 1000;
|
|
3
|
+
export declare const TERMINAL_PROGRESS_ACTIVE_SEQUENCE = "\u001B]9;4;3\u0007";
|
|
4
|
+
export declare const TERMINAL_PROGRESS_CLEAR_SEQUENCE = "\u001B]9;4;0;\u0007";
|
|
5
|
+
export declare const APPLE_TERMINAL_SHIFT_ENTER_SEQUENCE = "\u001B[13;2u";
|
|
6
|
+
export declare const DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS = 7;
|
|
7
|
+
export declare const KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS = 150;
|
|
8
|
+
export declare const KITTY_KEYBOARD_PROTOCOL_QUERY = "\u001B[>7u\u001B[?u\u001B[c";
|
|
9
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/terminal/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,gBAAiC,CAAC;AAEzD,eAAO,MAAM,8BAA8B,OAAO,CAAC;AAEnD,eAAO,MAAM,iCAAiC,uBAAmB,CAAC;AAElE,eAAO,MAAM,gCAAgC,wBAAoB,CAAC;AAElE,eAAO,MAAM,mCAAmC,iBAAe,CAAC;AAEhE,eAAO,MAAM,qCAAqC,IAAI,CAAC;AAEvD,eAAO,MAAM,8CAA8C,MAAM,CAAC;AAElE,eAAO,MAAM,6BAA6B,gCAAiE,CAAC","sourcesContent":["import { createRequire } from \"node:module\";\n\nexport const cjsRequire = createRequire(import.meta.url);\n\nexport const TERMINAL_PROGRESS_KEEPALIVE_MS = 1000;\n\nexport const TERMINAL_PROGRESS_ACTIVE_SEQUENCE = \"\\x1b]9;4;3\\x07\";\n\nexport const TERMINAL_PROGRESS_CLEAR_SEQUENCE = \"\\x1b]9;4;0;\\x07\";\n\nexport const APPLE_TERMINAL_SHIFT_ENTER_SEQUENCE = \"\\x1b[13;2u\";\n\nexport const DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS = 7;\n\nexport const KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS = 150;\n\nexport const KITTY_KEYBOARD_PROTOCOL_QUERY = `\\x1b[>${DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS}u\\x1b[?u\\x1b[c`;\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
export const cjsRequire = createRequire(import.meta.url);
|
|
3
|
+
export const TERMINAL_PROGRESS_KEEPALIVE_MS = 1000;
|
|
4
|
+
export const TERMINAL_PROGRESS_ACTIVE_SEQUENCE = "\x1b]9;4;3\x07";
|
|
5
|
+
export const TERMINAL_PROGRESS_CLEAR_SEQUENCE = "\x1b]9;4;0;\x07";
|
|
6
|
+
export const APPLE_TERMINAL_SHIFT_ENTER_SEQUENCE = "\x1b[13;2u";
|
|
7
|
+
export const DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS = 7;
|
|
8
|
+
export const KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS = 150;
|
|
9
|
+
export const KITTY_KEYBOARD_PROTOCOL_QUERY = `\x1b[>${DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS}u\x1b[?u\x1b[c`;
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/terminal/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAEzD,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAEnD,MAAM,CAAC,MAAM,iCAAiC,GAAG,gBAAgB,CAAC;AAElE,MAAM,CAAC,MAAM,gCAAgC,GAAG,iBAAiB,CAAC;AAElE,MAAM,CAAC,MAAM,mCAAmC,GAAG,YAAY,CAAC;AAEhE,MAAM,CAAC,MAAM,qCAAqC,GAAG,CAAC,CAAC;AAEvD,MAAM,CAAC,MAAM,8CAA8C,GAAG,GAAG,CAAC;AAElE,MAAM,CAAC,MAAM,6BAA6B,GAAG,SAAS,qCAAqC,gBAAgB,CAAC","sourcesContent":["import { createRequire } from \"node:module\";\n\nexport const cjsRequire = createRequire(import.meta.url);\n\nexport const TERMINAL_PROGRESS_KEEPALIVE_MS = 1000;\n\nexport const TERMINAL_PROGRESS_ACTIVE_SEQUENCE = \"\\x1b]9;4;3\\x07\";\n\nexport const TERMINAL_PROGRESS_CLEAR_SEQUENCE = \"\\x1b]9;4;0;\\x07\";\n\nexport const APPLE_TERMINAL_SHIFT_ENTER_SEQUENCE = \"\\x1b[13;2u\";\n\nexport const DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS = 7;\n\nexport const KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS = 150;\n\nexport const KITTY_KEYBOARD_PROTOCOL_QUERY = `\\x1b[>${DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS}u\\x1b[?u\\x1b[c`;\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { KeyboardProtocolNegotiationSequence } from "./types.ts";
|
|
2
|
+
export declare function parseKeyboardProtocolNegotiationSequence(sequence: string): KeyboardProtocolNegotiationSequence | undefined;
|
|
3
|
+
export declare function isKeyboardProtocolNegotiationSequencePrefix(sequence: string): boolean;
|
|
4
|
+
export declare function isAppleTerminalSession(): boolean;
|
|
5
|
+
export declare function normalizeAppleTerminalInput(data: string, isAppleTerminal: boolean, isShiftPressed: boolean): string;
|
|
6
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/terminal/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC;AAEtE,wBAAgB,wCAAwC,CACtD,QAAQ,EAAE,MAAM,GACf,mCAAmC,GAAG,SAAS,CASjD;AAED,wBAAgB,2CAA2C,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAErF;AAED,wBAAgB,sBAAsB,IAAI,OAAO,CAEhD;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,GAAG,MAAM,CAGnH","sourcesContent":["import { APPLE_TERMINAL_SHIFT_ENTER_SEQUENCE } from \"./constants.ts\";\nimport type { KeyboardProtocolNegotiationSequence } from \"./types.ts\";\n\nexport function parseKeyboardProtocolNegotiationSequence(\n sequence: string,\n): KeyboardProtocolNegotiationSequence | undefined {\n const kittyFlags = sequence.match(/^\\x1b\\[\\?(\\d+)u$/);\n if (kittyFlags) {\n return { type: \"kitty-flags\", flags: Number.parseInt(kittyFlags[1]!, 10) };\n }\n if (/^\\x1b\\[\\?[\\d;]*c$/.test(sequence)) {\n return { type: \"device-attributes\" };\n }\n return undefined;\n}\n\nexport function isKeyboardProtocolNegotiationSequencePrefix(sequence: string): boolean {\n return sequence === \"\\x1b[\" || /^\\x1b\\[\\?[\\d;]*$/.test(sequence);\n}\n\nexport function isAppleTerminalSession(): boolean {\n return process.platform === \"darwin\" && process.env.TERM_PROGRAM === \"Apple_Terminal\";\n}\n\nexport function normalizeAppleTerminalInput(data: string, isAppleTerminal: boolean, isShiftPressed: boolean): string {\n if (isAppleTerminal && data === \"\\r\" && isShiftPressed) return APPLE_TERMINAL_SHIFT_ENTER_SEQUENCE;\n return data;\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { APPLE_TERMINAL_SHIFT_ENTER_SEQUENCE } from "./constants.js";
|
|
2
|
+
export function parseKeyboardProtocolNegotiationSequence(sequence) {
|
|
3
|
+
const kittyFlags = sequence.match(/^\x1b\[\?(\d+)u$/);
|
|
4
|
+
if (kittyFlags) {
|
|
5
|
+
return { type: "kitty-flags", flags: Number.parseInt(kittyFlags[1], 10) };
|
|
6
|
+
}
|
|
7
|
+
if (/^\x1b\[\?[\d;]*c$/.test(sequence)) {
|
|
8
|
+
return { type: "device-attributes" };
|
|
9
|
+
}
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
export function isKeyboardProtocolNegotiationSequencePrefix(sequence) {
|
|
13
|
+
return sequence === "\x1b[" || /^\x1b\[\?[\d;]*$/.test(sequence);
|
|
14
|
+
}
|
|
15
|
+
export function isAppleTerminalSession() {
|
|
16
|
+
return process.platform === "darwin" && process.env.TERM_PROGRAM === "Apple_Terminal";
|
|
17
|
+
}
|
|
18
|
+
export function normalizeAppleTerminalInput(data, isAppleTerminal, isShiftPressed) {
|
|
19
|
+
if (isAppleTerminal && data === "\r" && isShiftPressed)
|
|
20
|
+
return APPLE_TERMINAL_SHIFT_ENTER_SEQUENCE;
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/terminal/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,gBAAgB,CAAC;AAGrE,MAAM,UAAU,wCAAwC,CACtD,QAAgB,EACiC;IACjD,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtD,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IAC7E,CAAC;IACD,IAAI,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvC,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC;IACvC,CAAC;IACD,OAAO,SAAS,CAAC;AAAA,CAClB;AAED,MAAM,UAAU,2CAA2C,CAAC,QAAgB,EAAW;IACrF,OAAO,QAAQ,KAAK,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAAA,CAClE;AAED,MAAM,UAAU,sBAAsB,GAAY;IAChD,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,gBAAgB,CAAC;AAAA,CACvF;AAED,MAAM,UAAU,2BAA2B,CAAC,IAAY,EAAE,eAAwB,EAAE,cAAuB,EAAU;IACnH,IAAI,eAAe,IAAI,IAAI,KAAK,IAAI,IAAI,cAAc;QAAE,OAAO,mCAAmC,CAAC;IACnG,OAAO,IAAI,CAAC;AAAA,CACb","sourcesContent":["import { APPLE_TERMINAL_SHIFT_ENTER_SEQUENCE } from \"./constants.ts\";\nimport type { KeyboardProtocolNegotiationSequence } from \"./types.ts\";\n\nexport function parseKeyboardProtocolNegotiationSequence(\n sequence: string,\n): KeyboardProtocolNegotiationSequence | undefined {\n const kittyFlags = sequence.match(/^\\x1b\\[\\?(\\d+)u$/);\n if (kittyFlags) {\n return { type: \"kitty-flags\", flags: Number.parseInt(kittyFlags[1]!, 10) };\n }\n if (/^\\x1b\\[\\?[\\d;]*c$/.test(sequence)) {\n return { type: \"device-attributes\" };\n }\n return undefined;\n}\n\nexport function isKeyboardProtocolNegotiationSequencePrefix(sequence: string): boolean {\n return sequence === \"\\x1b[\" || /^\\x1b\\[\\?[\\d;]*$/.test(sequence);\n}\n\nexport function isAppleTerminalSession(): boolean {\n return process.platform === \"darwin\" && process.env.TERM_PROGRAM === \"Apple_Terminal\";\n}\n\nexport function normalizeAppleTerminalInput(data: string, isAppleTerminal: boolean, isShiftPressed: boolean): string {\n if (isAppleTerminal && data === \"\\r\" && isShiftPressed) return APPLE_TERMINAL_SHIFT_ENTER_SEQUENCE;\n return data;\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { isAppleTerminalSession, normalizeAppleTerminalInput, parseKeyboardProtocolNegotiationSequence, } from "./helpers.ts";
|
|
2
|
+
export { ProcessTerminal } from "./processterminal.ts";
|
|
3
|
+
export type { KeyboardProtocolNegotiationSequence, Terminal } from "./types.ts";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/terminal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC3B,wCAAwC,GACzC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EAAE,mCAAmC,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export {\n isAppleTerminalSession,\n normalizeAppleTerminalInput,\n parseKeyboardProtocolNegotiationSequence,\n} from \"./helpers.ts\";\nexport { ProcessTerminal } from \"./processterminal.ts\";\nexport type { KeyboardProtocolNegotiationSequence, Terminal } from \"./types.ts\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/terminal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC3B,wCAAwC,GACzC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export {\n isAppleTerminalSession,\n normalizeAppleTerminalInput,\n parseKeyboardProtocolNegotiationSequence,\n} from \"./helpers.ts\";\nexport { ProcessTerminal } from \"./processterminal.ts\";\nexport type { KeyboardProtocolNegotiationSequence, Terminal } from \"./types.ts\";\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ProcessTerminal } from "../processterminal.ts";
|
|
2
|
+
export declare function do_hideCursor(_self: ProcessTerminal): void;
|
|
3
|
+
export declare function do_showCursor(_self: ProcessTerminal): void;
|
|
4
|
+
export declare function do_clearLine(_self: ProcessTerminal): void;
|
|
5
|
+
export declare function do_clearFromCursor(_self: ProcessTerminal): void;
|
|
6
|
+
export declare function do_clearScreen(_self: ProcessTerminal): void;
|
|
7
|
+
export declare function do_setTitle(_self: ProcessTerminal, title: string): void;
|
|
8
|
+
export declare function do_setProgress(self: ProcessTerminal, active: boolean): void;
|
|
9
|
+
export declare function do_setMouseTracking(self: ProcessTerminal, active: boolean): void;
|
|
10
|
+
export declare function do_clearProgressInterval(self: ProcessTerminal): boolean;
|
|
11
|
+
//# sourceMappingURL=cursor-screen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cursor-screen.d.ts","sourceRoot":"","sources":["../../../src/terminal/processterminal-methods/cursor-screen.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAE1D;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAE1D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAEzD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAE/D;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAE3D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAGvE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAc3E;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAIhF;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAKvE","sourcesContent":["import {\n TERMINAL_PROGRESS_ACTIVE_SEQUENCE,\n TERMINAL_PROGRESS_CLEAR_SEQUENCE,\n TERMINAL_PROGRESS_KEEPALIVE_MS,\n} from \"../constants.ts\";\nimport type { ProcessTerminal } from \"../processterminal.ts\";\n\nexport function do_hideCursor(_self: ProcessTerminal): void {\n process.stdout.write(\"\\x1b[?25l\");\n}\n\nexport function do_showCursor(_self: ProcessTerminal): void {\n process.stdout.write(\"\\x1b[?25h\");\n}\n\nexport function do_clearLine(_self: ProcessTerminal): void {\n process.stdout.write(\"\\x1b[K\");\n}\n\nexport function do_clearFromCursor(_self: ProcessTerminal): void {\n process.stdout.write(\"\\x1b[J\");\n}\n\nexport function do_clearScreen(_self: ProcessTerminal): void {\n process.stdout.write(\"\\x1b[2J\\x1b[H\"); // Clear screen and move to home (1,1)\n}\n\nexport function do_setTitle(_self: ProcessTerminal, title: string): void {\n // OSC 0;title BEL - set terminal window title\n process.stdout.write(`\\x1b]0;${title}\\x07`);\n}\n\nexport function do_setProgress(self: ProcessTerminal, active: boolean): void {\n if (active) {\n // OSC 9;4;3 - indeterminate progress\n process.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n if (!self.progressInterval) {\n self.progressInterval = setInterval(() => {\n process.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n }, TERMINAL_PROGRESS_KEEPALIVE_MS);\n }\n } else {\n self.clearProgressInterval();\n // OSC 9;4;0 - clear progress\n process.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n }\n}\n\nexport function do_setMouseTracking(self: ProcessTerminal, active: boolean): void {\n if (active === self.mouseTrackingActive) return;\n self.mouseTrackingActive = active;\n process.stdout.write(active ? \"\\x1b[?1002h\\x1b[?1006h\" : \"\\x1b[?1006l\\x1b[?1002l\");\n}\n\nexport function do_clearProgressInterval(self: ProcessTerminal): boolean {\n if (!self.progressInterval) return false;\n clearInterval(self.progressInterval);\n self.progressInterval = undefined;\n return true;\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TERMINAL_PROGRESS_ACTIVE_SEQUENCE, TERMINAL_PROGRESS_CLEAR_SEQUENCE, TERMINAL_PROGRESS_KEEPALIVE_MS, } from "../constants.js";
|
|
2
|
+
export function do_hideCursor(_self) {
|
|
3
|
+
process.stdout.write("\x1b[?25l");
|
|
4
|
+
}
|
|
5
|
+
export function do_showCursor(_self) {
|
|
6
|
+
process.stdout.write("\x1b[?25h");
|
|
7
|
+
}
|
|
8
|
+
export function do_clearLine(_self) {
|
|
9
|
+
process.stdout.write("\x1b[K");
|
|
10
|
+
}
|
|
11
|
+
export function do_clearFromCursor(_self) {
|
|
12
|
+
process.stdout.write("\x1b[J");
|
|
13
|
+
}
|
|
14
|
+
export function do_clearScreen(_self) {
|
|
15
|
+
process.stdout.write("\x1b[2J\x1b[H"); // Clear screen and move to home (1,1)
|
|
16
|
+
}
|
|
17
|
+
export function do_setTitle(_self, title) {
|
|
18
|
+
// OSC 0;title BEL - set terminal window title
|
|
19
|
+
process.stdout.write(`\x1b]0;${title}\x07`);
|
|
20
|
+
}
|
|
21
|
+
export function do_setProgress(self, active) {
|
|
22
|
+
if (active) {
|
|
23
|
+
// OSC 9;4;3 - indeterminate progress
|
|
24
|
+
process.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);
|
|
25
|
+
if (!self.progressInterval) {
|
|
26
|
+
self.progressInterval = setInterval(() => {
|
|
27
|
+
process.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);
|
|
28
|
+
}, TERMINAL_PROGRESS_KEEPALIVE_MS);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
self.clearProgressInterval();
|
|
33
|
+
// OSC 9;4;0 - clear progress
|
|
34
|
+
process.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function do_setMouseTracking(self, active) {
|
|
38
|
+
if (active === self.mouseTrackingActive)
|
|
39
|
+
return;
|
|
40
|
+
self.mouseTrackingActive = active;
|
|
41
|
+
process.stdout.write(active ? "\x1b[?1002h\x1b[?1006h" : "\x1b[?1006l\x1b[?1002l");
|
|
42
|
+
}
|
|
43
|
+
export function do_clearProgressInterval(self) {
|
|
44
|
+
if (!self.progressInterval)
|
|
45
|
+
return false;
|
|
46
|
+
clearInterval(self.progressInterval);
|
|
47
|
+
self.progressInterval = undefined;
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=cursor-screen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cursor-screen.js","sourceRoot":"","sources":["../../../src/terminal/processterminal-methods/cursor-screen.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,gCAAgC,EAChC,8BAA8B,GAC/B,MAAM,iBAAiB,CAAC;AAGzB,MAAM,UAAU,aAAa,CAAC,KAAsB,EAAQ;IAC1D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AAAA,CACnC;AAED,MAAM,UAAU,aAAa,CAAC,KAAsB,EAAQ;IAC1D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AAAA,CACnC;AAED,MAAM,UAAU,YAAY,CAAC,KAAsB,EAAQ;IACzD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAAA,CAChC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAsB,EAAQ;IAC/D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAAA,CAChC;AAED,MAAM,UAAU,cAAc,CAAC,KAAsB,EAAQ;IAC3D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,sCAAsC;AAAvC,CACvC;AAED,MAAM,UAAU,WAAW,CAAC,KAAsB,EAAE,KAAa,EAAQ;IACvE,8CAA8C;IAC9C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,KAAK,MAAM,CAAC,CAAC;AAAA,CAC7C;AAED,MAAM,UAAU,cAAc,CAAC,IAAqB,EAAE,MAAe,EAAQ;IAC3E,IAAI,MAAM,EAAE,CAAC;QACX,qCAAqC;QACrC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC3B,IAAI,CAAC,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;gBACxC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;YAAA,CACzD,EAAE,8BAA8B,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7B,6BAA6B;QAC7B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACzD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAqB,EAAE,MAAe,EAAQ;IAChF,IAAI,MAAM,KAAK,IAAI,CAAC,mBAAmB;QAAE,OAAO;IAChD,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;IAClC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC;AAAA,CACpF;AAED,MAAM,UAAU,wBAAwB,CAAC,IAAqB,EAAW;IACvE,IAAI,CAAC,IAAI,CAAC,gBAAgB;QAAE,OAAO,KAAK,CAAC;IACzC,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACrC,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAClC,OAAO,IAAI,CAAC;AAAA,CACb","sourcesContent":["import {\n TERMINAL_PROGRESS_ACTIVE_SEQUENCE,\n TERMINAL_PROGRESS_CLEAR_SEQUENCE,\n TERMINAL_PROGRESS_KEEPALIVE_MS,\n} from \"../constants.ts\";\nimport type { ProcessTerminal } from \"../processterminal.ts\";\n\nexport function do_hideCursor(_self: ProcessTerminal): void {\n process.stdout.write(\"\\x1b[?25l\");\n}\n\nexport function do_showCursor(_self: ProcessTerminal): void {\n process.stdout.write(\"\\x1b[?25h\");\n}\n\nexport function do_clearLine(_self: ProcessTerminal): void {\n process.stdout.write(\"\\x1b[K\");\n}\n\nexport function do_clearFromCursor(_self: ProcessTerminal): void {\n process.stdout.write(\"\\x1b[J\");\n}\n\nexport function do_clearScreen(_self: ProcessTerminal): void {\n process.stdout.write(\"\\x1b[2J\\x1b[H\"); // Clear screen and move to home (1,1)\n}\n\nexport function do_setTitle(_self: ProcessTerminal, title: string): void {\n // OSC 0;title BEL - set terminal window title\n process.stdout.write(`\\x1b]0;${title}\\x07`);\n}\n\nexport function do_setProgress(self: ProcessTerminal, active: boolean): void {\n if (active) {\n // OSC 9;4;3 - indeterminate progress\n process.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n if (!self.progressInterval) {\n self.progressInterval = setInterval(() => {\n process.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n }, TERMINAL_PROGRESS_KEEPALIVE_MS);\n }\n } else {\n self.clearProgressInterval();\n // OSC 9;4;0 - clear progress\n process.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n }\n}\n\nexport function do_setMouseTracking(self: ProcessTerminal, active: boolean): void {\n if (active === self.mouseTrackingActive) return;\n self.mouseTrackingActive = active;\n process.stdout.write(active ? \"\\x1b[?1002h\\x1b[?1006h\" : \"\\x1b[?1006l\\x1b[?1002l\");\n}\n\nexport function do_clearProgressInterval(self: ProcessTerminal): boolean {\n if (!self.progressInterval) return false;\n clearInterval(self.progressInterval);\n self.progressInterval = undefined;\n return true;\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ProcessTerminal } from "../processterminal.ts";
|
|
2
|
+
import type { KeyboardProtocolNegotiationSequence } from "../types.ts";
|
|
3
|
+
export declare function do_start(self: ProcessTerminal, onInput: (data: string) => void, onResize: () => void): void;
|
|
4
|
+
export declare function do_setupStdinBuffer(self: ProcessTerminal): void;
|
|
5
|
+
export declare function do_queryAndEnableKittyProtocol(self: ProcessTerminal): void;
|
|
6
|
+
export declare function do_handleKeyboardProtocolNegotiationSequence(self: ProcessTerminal, negotiationSequence: KeyboardProtocolNegotiationSequence | undefined): boolean;
|
|
7
|
+
export declare function do_readKeyboardProtocolNegotiationSequence(self: ProcessTerminal, sequence: string): KeyboardProtocolNegotiationSequence | "pending" | undefined;
|
|
8
|
+
export declare function do_setKeyboardProtocolNegotiationBuffer(self: ProcessTerminal, sequence: string): void;
|
|
9
|
+
export declare function do_clearKeyboardProtocolNegotiationBuffer(self: ProcessTerminal): void;
|
|
10
|
+
export declare function do_flushKeyboardProtocolNegotiationBufferAsInput(self: ProcessTerminal): void;
|
|
11
|
+
export declare function do_scheduleKeyboardProtocolNegotiationBufferFlush(self: ProcessTerminal): void;
|
|
12
|
+
export declare function do_clearKeyboardProtocolNegotiationBufferFlushTimer(self: ProcessTerminal): void;
|
|
13
|
+
export declare function do_forwardInputSequence(self: ProcessTerminal, sequence: string): void;
|
|
14
|
+
//# sourceMappingURL=keyboard-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard-protocol.d.ts","sourceRoot":"","sources":["../../../src/terminal/processterminal-methods/keyboard-protocol.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC;AAEvE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAiC3G;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CA4B/D;AAED,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAM1E;AAED,wBAAgB,4CAA4C,CAC1D,IAAI,EAAE,eAAe,EACrB,mBAAmB,EAAE,mCAAmC,GAAG,SAAS,GACnE,OAAO,CAoBT;AAED,wBAAgB,0CAA0C,CACxD,IAAI,EAAE,eAAe,EACrB,QAAQ,EAAE,MAAM,GACf,mCAAmC,GAAG,SAAS,GAAG,SAAS,CAsB7D;AAED,wBAAgB,uCAAuC,CAAC,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAGrG;AAED,wBAAgB,yCAAyC,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAGrF;AAED,wBAAgB,gDAAgD,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAK5F;AAED,wBAAgB,iDAAiD,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAM7F;AAED,wBAAgB,mDAAmD,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAI/F;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CASrF","sourcesContent":["import { setKittyProtocolActive } from \"../../keys.ts\";\nimport { isNativeModifierPressed } from \"../../native-modifiers.ts\";\nimport { StdinBuffer } from \"../../stdin-buffer.ts\";\nimport { KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS, KITTY_KEYBOARD_PROTOCOL_QUERY } from \"../constants.ts\";\nimport {\n isAppleTerminalSession,\n isKeyboardProtocolNegotiationSequencePrefix,\n normalizeAppleTerminalInput,\n parseKeyboardProtocolNegotiationSequence,\n} from \"../helpers.ts\";\nimport type { ProcessTerminal } from \"../processterminal.ts\";\nimport type { KeyboardProtocolNegotiationSequence } from \"../types.ts\";\n\nexport function do_start(self: ProcessTerminal, onInput: (data: string) => void, onResize: () => void): void {\n self.inputHandler = onInput;\n self.resizeHandler = onResize;\n\n // Save previous state and enable raw mode\n self.wasRaw = process.stdin.isRaw || false;\n if (process.stdin.setRawMode) {\n process.stdin.setRawMode(true);\n }\n process.stdin.setEncoding(\"utf8\");\n process.stdin.resume();\n\n // Enable bracketed paste mode - terminal will wrap pastes in \\x1b[200~ ... \\x1b[201~\n process.stdout.write(\"\\x1b[?2004h\");\n\n // Set up resize handler immediately\n process.stdout.on(\"resize\", self.resizeHandler);\n\n // Refresh terminal dimensions - they may be stale after suspend/resume\n // (SIGWINCH is lost while process is stopped). Unix only.\n if (process.platform !== \"win32\") {\n process.kill(process.pid, \"SIGWINCH\");\n }\n\n // On Windows, enable ENABLE_VIRTUAL_TERMINAL_INPUT so the console sends\n // VT escape sequences (e.g. \\x1b[Z for Shift+Tab) instead of raw console\n // events that lose modifier information. Must run AFTER setRawMode(true)\n // since that resets console mode flags.\n self.enableWindowsVTInput();\n\n // Query Kitty keyboard protocol and fall back to modifyOtherKeys when DA confirms no Kitty response.\n // See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/\n self.queryAndEnableKittyProtocol();\n}\n\nexport function do_setupStdinBuffer(self: ProcessTerminal): void {\n self.stdinBuffer = new StdinBuffer({ timeout: 10 });\n\n // Forward individual sequences to the input handler\n self.stdinBuffer.on(\"data\", (sequence) => {\n const negotiationSequence = self.readKeyboardProtocolNegotiationSequence(sequence);\n if (negotiationSequence === \"pending\") {\n self.scheduleKeyboardProtocolNegotiationBufferFlush();\n return; // Wait briefly for the rest of a split Kitty response.\n }\n if (self.handleKeyboardProtocolNegotiationSequence(negotiationSequence)) {\n return;\n }\n\n self.forwardInputSequence(sequence);\n });\n\n // Re-wrap paste content with bracketed paste markers for existing editor handling\n self.stdinBuffer.on(\"paste\", (content) => {\n if (self.inputHandler) {\n self.inputHandler(`\\x1b[200~${content}\\x1b[201~`);\n }\n });\n\n // Handler that pipes stdin data through the buffer\n self.stdinDataHandler = (data: string) => {\n self.stdinBuffer!.process(data);\n };\n}\n\nexport function do_queryAndEnableKittyProtocol(self: ProcessTerminal): void {\n self.setupStdinBuffer();\n process.stdin.on(\"data\", self.stdinDataHandler!);\n self.keyboardProtocolPushed = true;\n self.clearKeyboardProtocolNegotiationBuffer();\n process.stdout.write(KITTY_KEYBOARD_PROTOCOL_QUERY);\n}\n\nexport function do_handleKeyboardProtocolNegotiationSequence(\n self: ProcessTerminal,\n negotiationSequence: KeyboardProtocolNegotiationSequence | undefined,\n): boolean {\n if (!negotiationSequence) return false;\n self.clearKeyboardProtocolNegotiationBuffer();\n if (negotiationSequence.type === \"kitty-flags\") {\n if (negotiationSequence.flags !== 0) {\n self.disableModifyOtherKeys();\n if (!self._kittyProtocolActive) {\n self._kittyProtocolActive = true;\n setKittyProtocolActive(true);\n }\n } else {\n self.enableModifyOtherKeys();\n }\n return true;\n }\n\n if (!self._kittyProtocolActive) {\n self.enableModifyOtherKeys();\n }\n return true;\n}\n\nexport function do_readKeyboardProtocolNegotiationSequence(\n self: ProcessTerminal,\n sequence: string,\n): KeyboardProtocolNegotiationSequence | \"pending\" | undefined {\n if (self.keyboardProtocolNegotiationBuffer) {\n const bufferedSequence = self.keyboardProtocolNegotiationBuffer + sequence;\n const negotiationSequence = parseKeyboardProtocolNegotiationSequence(bufferedSequence);\n if (negotiationSequence) {\n self.clearKeyboardProtocolNegotiationBuffer();\n return negotiationSequence;\n }\n if (isKeyboardProtocolNegotiationSequencePrefix(bufferedSequence)) {\n self.setKeyboardProtocolNegotiationBuffer(bufferedSequence);\n return \"pending\";\n }\n self.flushKeyboardProtocolNegotiationBufferAsInput();\n }\n\n const negotiationSequence = parseKeyboardProtocolNegotiationSequence(sequence);\n if (negotiationSequence) return negotiationSequence;\n if (isKeyboardProtocolNegotiationSequencePrefix(sequence)) {\n self.setKeyboardProtocolNegotiationBuffer(sequence);\n return \"pending\";\n }\n return undefined;\n}\n\nexport function do_setKeyboardProtocolNegotiationBuffer(self: ProcessTerminal, sequence: string): void {\n self.clearKeyboardProtocolNegotiationBufferFlushTimer();\n self.keyboardProtocolNegotiationBuffer = sequence;\n}\n\nexport function do_clearKeyboardProtocolNegotiationBuffer(self: ProcessTerminal): void {\n self.clearKeyboardProtocolNegotiationBufferFlushTimer();\n self.keyboardProtocolNegotiationBuffer = \"\";\n}\n\nexport function do_flushKeyboardProtocolNegotiationBufferAsInput(self: ProcessTerminal): void {\n if (!self.keyboardProtocolNegotiationBuffer) return;\n const sequence = self.keyboardProtocolNegotiationBuffer;\n self.clearKeyboardProtocolNegotiationBuffer();\n self.forwardInputSequence(sequence);\n}\n\nexport function do_scheduleKeyboardProtocolNegotiationBufferFlush(self: ProcessTerminal): void {\n if (!self.keyboardProtocolNegotiationBuffer || self.keyboardProtocolBufferFlushTimer) return;\n self.keyboardProtocolBufferFlushTimer = setTimeout(() => {\n self.keyboardProtocolBufferFlushTimer = undefined;\n self.flushKeyboardProtocolNegotiationBufferAsInput();\n }, KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS);\n}\n\nexport function do_clearKeyboardProtocolNegotiationBufferFlushTimer(self: ProcessTerminal): void {\n if (!self.keyboardProtocolBufferFlushTimer) return;\n clearTimeout(self.keyboardProtocolBufferFlushTimer);\n self.keyboardProtocolBufferFlushTimer = undefined;\n}\n\nexport function do_forwardInputSequence(self: ProcessTerminal, sequence: string): void {\n if (!self.inputHandler) return;\n const isAppleTerminal = sequence === \"\\r\" && isAppleTerminalSession();\n const input = normalizeAppleTerminalInput(\n sequence,\n isAppleTerminal,\n isAppleTerminal && isNativeModifierPressed(\"shift\"),\n );\n self.inputHandler(input);\n}\n"]}
|