@visulima/tui 0.0.1 → 1.0.0-alpha.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/CHANGELOG.md +200 -0
- package/LICENSE.md +303 -0
- package/README.md +173 -29
- package/dist/core/app.d.ts +50 -0
- package/dist/core/cell.d.ts +33 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +5 -0
- package/dist/core/inline.d.ts +22 -0
- package/dist/core/input.d.ts +18 -0
- package/dist/core/native-binding.d.ts +22 -0
- package/dist/ink/ansi-to-cell.d.ts +5 -0
- package/dist/ink/ansi-tokenizer.d.ts +38 -0
- package/dist/ink/clipboard.d.ts +29 -0
- package/dist/ink/color-matrix.d.ts +49 -0
- package/dist/ink/color-utils.d.ts +30 -0
- package/dist/ink/colorize.d.ts +4 -0
- package/dist/ink/components/AccessibilityContext.d.ts +4 -0
- package/dist/ink/components/Alert.d.ts +30 -0
- package/dist/ink/components/AnimationContext.d.ts +10 -0
- package/dist/ink/components/App.d.ts +19 -0
- package/dist/ink/components/AppContext.d.ts +38 -0
- package/dist/ink/components/BackgroundContext.d.ts +5 -0
- package/dist/ink/components/Badge.d.ts +27 -0
- package/dist/ink/components/BigText.d.ts +71 -0
- package/dist/ink/components/Box.d.ts +58 -0
- package/dist/ink/components/Code.d.ts +46 -0
- package/dist/ink/components/ConfirmInput.d.ts +40 -0
- package/dist/ink/components/ConsoleOverlay.d.ts +52 -0
- package/dist/ink/components/Cursor.d.ts +43 -0
- package/dist/ink/components/CursorContext.d.ts +12 -0
- package/dist/ink/components/Dialog.d.ts +93 -0
- package/dist/ink/components/DiffView.d.ts +71 -0
- package/dist/ink/components/ErrorBoundary.d.ts +17 -0
- package/dist/ink/components/ErrorOverview.d.ts +6 -0
- package/dist/ink/components/FocusContext.d.ts +17 -0
- package/dist/ink/components/Gradient.d.ts +38 -0
- package/dist/ink/components/Help.d.ts +49 -0
- package/dist/ink/components/Link.d.ts +34 -0
- package/dist/ink/components/Markdown.d.ts +34 -0
- package/dist/ink/components/MultiSelect.d.ts +63 -0
- package/dist/ink/components/Newline.d.ts +12 -0
- package/dist/ink/components/OrderedList.d.ts +30 -0
- package/dist/ink/components/Paginator.d.ts +75 -0
- package/dist/ink/components/ProgressBar.d.ts +51 -0
- package/dist/ink/components/SelectInput.d.ts +96 -0
- package/dist/ink/components/SelectInputIndicator.d.ts +36 -0
- package/dist/ink/components/SelectInputItem.d.ts +43 -0
- package/dist/ink/components/Slider.d.ts +92 -0
- package/dist/ink/components/Spacer.d.ts +7 -0
- package/dist/ink/components/Spinner.d.ts +42 -0
- package/dist/ink/components/Static.d.ts +24 -0
- package/dist/ink/components/StaticRender.d.ts +28 -0
- package/dist/ink/components/StatusMessage.d.ts +26 -0
- package/dist/ink/components/StderrContext.d.ts +16 -0
- package/dist/ink/components/StdinContext.d.ts +29 -0
- package/dist/ink/components/StdoutContext.d.ts +16 -0
- package/dist/ink/components/Stopwatch.d.ts +44 -0
- package/dist/ink/components/Tab.d.ts +25 -0
- package/dist/ink/components/Table.d.ts +80 -0
- package/dist/ink/components/Tabs.d.ts +104 -0
- package/dist/ink/components/Text.d.ts +63 -0
- package/dist/ink/components/TextInput.d.ts +48 -0
- package/dist/ink/components/Textarea.d.ts +62 -0
- package/dist/ink/components/Timer.d.ts +52 -0
- package/dist/ink/components/Transform.d.ts +16 -0
- package/dist/ink/components/UnorderedList.d.ts +35 -0
- package/dist/ink/components/file-picker/FilePicker.d.ts +75 -0
- package/dist/ink/components/file-picker/index.d.ts +3 -0
- package/dist/ink/components/file-picker/types.d.ts +38 -0
- package/dist/ink/components/file-picker/use-file-system.d.ts +16 -0
- package/dist/ink/components/scroll/ControlledScrollView.d.ts +43 -0
- package/dist/ink/components/scroll/ScrollBar.d.ts +20 -0
- package/dist/ink/components/scroll/ScrollBarBox.d.ts +15 -0
- package/dist/ink/components/scroll/ScrollList.d.ts +12 -0
- package/dist/ink/components/scroll/ScrollView.d.ts +98 -0
- package/dist/ink/components/scroll/index.d.ts +10 -0
- package/dist/ink/components/scroll/use-state-ref.d.ts +8 -0
- package/dist/ink/components/tree-view/TreeView.d.ts +89 -0
- package/dist/ink/components/tree-view/TreeViewNode.d.ts +29 -0
- package/dist/ink/components/tree-view/index.d.ts +11 -0
- package/dist/ink/components/tree-view/theme.d.ts +24 -0
- package/dist/ink/components/tree-view/tree-node-map.d.ts +72 -0
- package/dist/ink/components/tree-view/types.d.ts +55 -0
- package/dist/ink/components/tree-view/use-tree-view-state.d.ts +135 -0
- package/dist/ink/components/tree-view/use-tree-view.d.ts +26 -0
- package/dist/ink/components/variant-config.d.ts +10 -0
- package/dist/ink/cursor-helpers.d.ts +38 -0
- package/dist/ink/data-limited-lru-map.d.ts +21 -0
- package/dist/ink/devtools-window-polyfill.d.ts +1 -0
- package/dist/ink/devtools.d.ts +1 -0
- package/dist/ink/dom.d.ts +213 -0
- package/dist/ink/get-max-width.d.ts +3 -0
- package/dist/ink/highlighter.d.ts +28 -0
- package/dist/ink/hooks/use-animation.d.ts +43 -0
- package/dist/ink/hooks/use-app.d.ts +6 -0
- package/dist/ink/hooks/use-box-metrics.d.ts +58 -0
- package/dist/ink/hooks/use-clipboard.d.ts +29 -0
- package/dist/ink/hooks/use-color-blindness.d.ts +33 -0
- package/dist/ink/hooks/use-console-capture.d.ts +43 -0
- package/dist/ink/hooks/use-cursor.d.ts +12 -0
- package/dist/ink/hooks/use-focus-manager.d.ts +42 -0
- package/dist/ink/hooks/use-focus.d.ts +30 -0
- package/dist/ink/hooks/use-input.d.ts +149 -0
- package/dist/ink/hooks/use-is-screen-reader-enabled.d.ts +6 -0
- package/dist/ink/hooks/use-key-bindings.d.ts +61 -0
- package/dist/ink/hooks/use-linked-scroll.d.ts +41 -0
- package/dist/ink/hooks/use-paste.d.ts +44 -0
- package/dist/ink/hooks/use-scroll-acceleration.d.ts +47 -0
- package/dist/ink/hooks/use-scroll-input.d.ts +34 -0
- package/dist/ink/hooks/use-stderr.d.ts +6 -0
- package/dist/ink/hooks/use-stdin.d.ts +7 -0
- package/dist/ink/hooks/use-stdout.d.ts +6 -0
- package/dist/ink/hooks/use-stopwatch.d.ts +40 -0
- package/dist/ink/hooks/use-terminal-palette.d.ts +19 -0
- package/dist/ink/hooks/use-text-buffer.d.ts +42 -0
- package/dist/ink/hooks/use-text-selection.d.ts +45 -0
- package/dist/ink/hooks/use-timer.d.ts +49 -0
- package/dist/ink/hooks/use-window-size.d.ts +18 -0
- package/dist/ink/ime-utils.d.ts +25 -0
- package/dist/ink/index.d.ts +159 -0
- package/dist/ink/index.js +100 -0
- package/dist/ink/ink.d.ts +189 -0
- package/dist/ink/input-parser.d.ts +10 -0
- package/dist/ink/input-utils.d.ts +16 -0
- package/dist/ink/instances.d.ts +3 -0
- package/dist/ink/kitty-keyboard.d.ts +23 -0
- package/dist/ink/layout.d.ts +26 -0
- package/dist/ink/log-update-native.d.ts +14 -0
- package/dist/ink/log-update.d.ts +21 -0
- package/dist/ink/measure-element.d.ts +147 -0
- package/dist/ink/measure-text.d.ts +56 -0
- package/dist/ink/mouse/Fullscreen.d.ts +8 -0
- package/dist/ink/mouse/MouseProvider.d.ts +11 -0
- package/dist/ink/mouse/ansi-parser.d.ts +37 -0
- package/dist/ink/mouse/constants.d.ts +59 -0
- package/dist/ink/mouse/index.d.ts +20 -0
- package/dist/ink/mouse/is-intersecting.d.ts +18 -0
- package/dist/ink/mouse/mouse-context.d.ts +36 -0
- package/dist/ink/mouse/use-element-position.d.ts +29 -0
- package/dist/ink/mouse/use-mouse-action.d.ts +7 -0
- package/dist/ink/mouse/use-mouse-position.d.ts +7 -0
- package/dist/ink/mouse/use-mouse.d.ts +7 -0
- package/dist/ink/mouse/use-on-mouse-click.d.ts +14 -0
- package/dist/ink/mouse/use-on-mouse-hover.d.ts +8 -0
- package/dist/ink/mouse/use-on-mouse-state.d.ts +11 -0
- package/dist/ink/output.d.ts +74 -0
- package/dist/ink/parse-keypress.d.ts +22 -0
- package/dist/ink/reconciler.d.ts +3 -0
- package/dist/ink/region.d.ts +99 -0
- package/dist/ink/render-background.d.ts +4 -0
- package/dist/ink/render-border.d.ts +4 -0
- package/dist/ink/render-node-to-output.d.ts +38 -0
- package/dist/ink/render-scrollbar.d.ts +9 -0
- package/dist/ink/render-sticky.d.ts +44 -0
- package/dist/ink/render-to-string.d.ts +37 -0
- package/dist/ink/render.d.ts +191 -0
- package/dist/ink/renderer.d.ts +17 -0
- package/dist/ink/resize-observer.d.ts +44 -0
- package/dist/ink/sanitize-ansi.d.ts +2 -0
- package/dist/ink/scroll.d.ts +23 -0
- package/dist/ink/selection.d.ts +70 -0
- package/dist/ink/squash-text-nodes.d.ts +18 -0
- package/dist/ink/style-flags.d.ts +17 -0
- package/dist/ink/styled-line-factory.d.ts +25 -0
- package/dist/ink/styled-line-serializer.d.ts +18 -0
- package/dist/ink/styled-line.d.ts +109 -0
- package/dist/ink/styles.d.ts +369 -0
- package/dist/ink/terminal-palette.d.ts +25 -0
- package/dist/ink/text-wrap.d.ts +10 -0
- package/dist/ink/token-to-elements.d.ts +22 -0
- package/dist/ink/utils/format-time.d.ts +4 -0
- package/dist/ink/utils.d.ts +9 -0
- package/dist/ink/wrap-text.d.ts +3 -0
- package/dist/ink/write-synchronized.d.ts +4 -0
- package/dist/packem_chunks/devtools.js +27 -0
- package/dist/packem_shared/AccessibilityContext-BLelHhNU.js +7 -0
- package/dist/packem_shared/Alert-Dr3s_LD9.js +17 -0
- package/dist/packem_shared/AnimationContext-BcJg8Jr6.js +15 -0
- package/dist/packem_shared/AppContext-CP0U6H7O.js +11 -0
- package/dist/packem_shared/BackgroundContext-BAUaxfOb.js +5 -0
- package/dist/packem_shared/Badge-Dk7EGGM6.js +13 -0
- package/dist/packem_shared/BigText-CjMdY63X.js +24 -0
- package/dist/packem_shared/Box-D_pSJ9Jp.js +73 -0
- package/dist/packem_shared/COLOR_BLINDNESS_SIMULATION-BsMy5Ewl.js +81 -0
- package/dist/packem_shared/Cell-DCg1kJY-.js +48 -0
- package/dist/packem_shared/Code-DjQvPBD9.js +53 -0
- package/dist/packem_shared/ConfirmInput-85Y4kRQW.js +44 -0
- package/dist/packem_shared/ConsoleOverlay-DBNa4vtj.js +57 -0
- package/dist/packem_shared/ControlledScrollView-BlOaxcsN.js +286 -0
- package/dist/packem_shared/ControlledScrollView-DfAhcufF.js +5 -0
- package/dist/packem_shared/Cursor-DiW7YoSK.js +18 -0
- package/dist/packem_shared/CursorContext-JxRzlqAx.js +9 -0
- package/dist/packem_shared/DevTools-aMPIsaHx.js +61 -0
- package/dist/packem_shared/Dialog-DsSNAVgC.js +71 -0
- package/dist/packem_shared/DiffView-hqaw-2S6.js +329 -0
- package/dist/packem_shared/FilePicker-DNwFxRhq.js +254 -0
- package/dist/packem_shared/FocusContext-CWkYtgcm.js +26 -0
- package/dist/packem_shared/FocusContext-D5wFxSRz.js +153 -0
- package/dist/packem_shared/Fullscreen-DrElAE1o.js +11 -0
- package/dist/packem_shared/Gradient-Ql5P0GUd.js +136 -0
- package/dist/packem_shared/Help-6wanGG38.js +112 -0
- package/dist/packem_shared/IMECompositionBuffer-Dl3S0KnF.js +55 -0
- package/dist/packem_shared/InputParser-BKHpWfvN.js +156 -0
- package/dist/packem_shared/LayoutNode-Cjnsodiy.js +131 -0
- package/dist/packem_shared/Link-COcKYfGT.js +66 -0
- package/dist/packem_shared/Markdown-y1ISztof.js +212 -0
- package/dist/packem_shared/MouseProvider-Y9TSSEGl.js +136 -0
- package/dist/packem_shared/MultiSelect-ChoLUcDI.js +129 -0
- package/dist/packem_shared/NAMED_COLORS-a4QBvb5r.js +262 -0
- package/dist/packem_shared/Newline-DBtYEg8x.js +7 -0
- package/dist/packem_shared/OrderedList-Cp7pXr6m.js +26 -0
- package/dist/packem_shared/Paginator-D1AuD-kj.js +104 -0
- package/dist/packem_shared/ProgressBar-DOfpVagn.js +22 -0
- package/dist/packem_shared/Renderer-zZ5O3vxc.js +31 -0
- package/dist/packem_shared/ResizeObserverEntry-Br4seLeQ.js +102 -0
- package/dist/packem_shared/ScrollBar-EWAs2Uc7.js +106 -0
- package/dist/packem_shared/ScrollBarBox-DTNNlh7R.js +72 -0
- package/dist/packem_shared/ScrollList-DCeIFL8M.js +227 -0
- package/dist/packem_shared/ScrollView-v3MCNIyX.js +196 -0
- package/dist/packem_shared/SelectInput-BN2TMyxp.js +260 -0
- package/dist/packem_shared/SelectInputIndicator-DkRMoH_b.js +9 -0
- package/dist/packem_shared/SelectInputItem-BF9LQgKu.js +8 -0
- package/dist/packem_shared/Slider-BWD7xZX6.js +116 -0
- package/dist/packem_shared/Spacer-Bs4ER-HK.js +8 -0
- package/dist/packem_shared/Spinner-BuI-kN4p.js +1799 -0
- package/dist/packem_shared/Static-DpTd6Eed.js +22 -0
- package/dist/packem_shared/Static-xmD9giJj.js +18 -0
- package/dist/packem_shared/StaticRender-tYwH6QXl.js +33 -0
- package/dist/packem_shared/StatusMessage-BtSYxzwb.js +14 -0
- package/dist/packem_shared/StderrContext-Bj4Mf7v7.js +17 -0
- package/dist/packem_shared/StdinContext-Bq_GNJ3z.js +38 -0
- package/dist/packem_shared/StdoutContext-CgjWeCdO.js +17 -0
- package/dist/packem_shared/Stopwatch-DjtTCyHn.js +23 -0
- package/dist/packem_shared/Tab-C6r5q4hR.js +7 -0
- package/dist/packem_shared/Table-D-rSVlzb.js +82 -0
- package/dist/packem_shared/Tabs-hki-KRnx.js +153 -0
- package/dist/packem_shared/Text-DvAUdZcK.js +65 -0
- package/dist/packem_shared/TextInput-C79WEQ5U.js +137 -0
- package/dist/packem_shared/Textarea-Dj06R6Zd.js +272 -0
- package/dist/packem_shared/Timer-wi9zuh4n.js +22 -0
- package/dist/packem_shared/Transform-BHxY_dAM.js +14 -0
- package/dist/packem_shared/TreeNodeMap-CtJUvBnd.js +155 -0
- package/dist/packem_shared/TreeView-C2062dtj.js +148 -0
- package/dist/packem_shared/TuiApp-DfxOnXqi.js +120 -0
- package/dist/packem_shared/TuiContext-CqEjMyXd.js +415 -0
- package/dist/packem_shared/UnorderedList-DhnadWjX.js +33 -0
- package/dist/packem_shared/ansi-parser-0BdVTKho.js +41 -0
- package/dist/packem_shared/ansi-tokenizer-LHq2LUWA.js +307 -0
- package/dist/packem_shared/boxes-oi3WUbyR.js +92 -0
- package/dist/packem_shared/colorize-88_Vk8cn.js +48 -0
- package/dist/packem_shared/comparePoints-CGMDnd3_.js +287 -0
- package/dist/packem_shared/createInlineLoop-BxMmcq9D.js +93 -0
- package/dist/packem_shared/createLinkedScrollGroup-Djw4Ceo0.js +44 -0
- package/dist/packem_shared/dom-DvzhsAez.js +225 -0
- package/dist/packem_shared/format-time-BGmnDukX.js +12 -0
- package/dist/packem_shared/getPathToRoot-a1wbwxfL.js +4 -0
- package/dist/packem_shared/getScrollHeight-BubfU_df.js +63 -0
- package/dist/packem_shared/input-utils-ViAEXa0Z.js +19 -0
- package/dist/packem_shared/isIntersecting-fEXHJN5R.js +10 -0
- package/dist/packem_shared/isOsc52Supported-G0k4sXJx.js +36 -0
- package/dist/packem_shared/isTerminalPaletteQuerySupported-EeiwMKbr.js +93 -0
- package/dist/packem_shared/kittyFlags-bNNf_9kX.js +26 -0
- package/dist/packem_shared/measure-element-Reza_yfC.js +396 -0
- package/dist/packem_shared/measure-text-DItZYotK.js +1189 -0
- package/dist/packem_shared/measureElement-CTgFCmKd.js +4 -0
- package/dist/packem_shared/mouse-context-BUHWKEIe.js +6 -0
- package/dist/packem_shared/parseSgrMouse-BHVBPP9G.js +1 -0
- package/dist/packem_shared/processLayout-BQ9kXfd3.js +2 -0
- package/dist/packem_shared/reconciler-BXf6miSS.js +211 -0
- package/dist/packem_shared/reconciler-gfmqURLy.js +680 -0
- package/dist/packem_shared/render-BAwdjfki.js +2806 -0
- package/dist/packem_shared/render-Bpjhf0lD.js +195 -0
- package/dist/packem_shared/renderToString-Cfg55DRD.js +62 -0
- package/dist/packem_shared/renderToString-ClIaXgrC.js +86 -0
- package/dist/packem_shared/renderTreeToBuffer-D3mo7M7m.js +308 -0
- package/dist/packem_shared/renderer-B3wROkeg.js +1431 -0
- package/dist/packem_shared/setEnableStyledLineCache-BpskngSJ.js +2 -0
- package/dist/packem_shared/squashTextNodesWithMap-iqm6OMMT.js +100 -0
- package/dist/packem_shared/text-width-DhuarWcB.js +42 -0
- package/dist/packem_shared/token-to-elements-BRFl_rzw.js +249 -0
- package/dist/packem_shared/treeViewTheme-BpSw9TMf.js +52 -0
- package/dist/packem_shared/useAnimation-kj31sA-T.js +62 -0
- package/dist/packem_shared/useApp-DPQlRzi5.js +6 -0
- package/dist/packem_shared/useBoxMetrics-rBjKc-g4.js +54 -0
- package/dist/packem_shared/useClipboard-B_9-adw1.js +23 -0
- package/dist/packem_shared/useColorBlindness-D_sTIhcb.js +30 -0
- package/dist/packem_shared/useConsoleCapture-Dvt7G1W1.js +61 -0
- package/dist/packem_shared/useCursor-BIJzc8k9.js +19 -0
- package/dist/packem_shared/useElementDimensions-CAoKitVD.js +67 -0
- package/dist/packem_shared/useFocus-CNl5QHHf.js +37 -0
- package/dist/packem_shared/useFocusManager-BPYaUuKQ.js +16 -0
- package/dist/packem_shared/useInput-Cfp5zB2s.js +594 -0
- package/dist/packem_shared/useIsScreenReaderEnabled-CnGKCe0f.js +9 -0
- package/dist/packem_shared/useKeyBindings-B78l1E1n.js +66 -0
- package/dist/packem_shared/useMouseAction-C5gZ2nj7.js +29 -0
- package/dist/packem_shared/useMouseContext-D-rFy60Q.js +12 -0
- package/dist/packem_shared/useMousePosition-BHBJ-kBk.js +25 -0
- package/dist/packem_shared/useOnMouseClick--ZIyBOBO.js +35 -0
- package/dist/packem_shared/useOnMouseHover-26diuXUC.js +32 -0
- package/dist/packem_shared/useOnMouseState-NO_Kda_C.js +13 -0
- package/dist/packem_shared/usePaste-Ct8J4AGR.js +35 -0
- package/dist/packem_shared/useScrollAcceleration-R9LfrPVG.js +73 -0
- package/dist/packem_shared/useScrollInput-D3CpBq_a.js +72 -0
- package/dist/packem_shared/useStderr-CAOVUh4E.js +6 -0
- package/dist/packem_shared/useStdin-X-O0kd-n.js +7 -0
- package/dist/packem_shared/useStdout-DyF6DSH0.js +6 -0
- package/dist/packem_shared/useStopwatch-qC4Beai4.js +33 -0
- package/dist/packem_shared/useTerminalPalette-BaWO2c4Q.js +38 -0
- package/dist/packem_shared/useTextBuffer-C8fEe9Ly.js +398 -0
- package/dist/packem_shared/useTextSelection-mXtxgsPK.js +50 -0
- package/dist/packem_shared/useTimer-CPQ7j827.js +46 -0
- package/dist/packem_shared/useTreeView-BT57P3Kx.js +101 -0
- package/dist/packem_shared/useTreeViewState-BpS_KZ-K.js +502 -0
- package/dist/packem_shared/useWindowSize-ugEmGZJm.js +20 -0
- package/dist/packem_shared/utils-BgdlrbOH.js +140 -0
- package/dist/packem_shared/variant-config-DSZoX5TM.js +8 -0
- package/dist/packem_shared/wrapOrTruncateStyledLine-DN3Nogoc.js +147 -0
- package/dist/react/devtools.d.ts +27 -0
- package/dist/react/focus.d.ts +39 -0
- package/dist/react/hooks.d.ts +238 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.js +9 -0
- package/dist/react/layout.d.ts +35 -0
- package/dist/react/react.d.ts +57 -0
- package/dist/react/reconciler.d.ts +4 -0
- package/dist/react/render-to-string.d.ts +21 -0
- package/dist/react/renderer.d.ts +2 -0
- package/dist/react/scene.d.ts +3 -0
- package/dist/react/static.d.ts +39 -0
- package/dist/react/styles.d.ts +83 -0
- package/dist/react/text-width.d.ts +20 -0
- package/dist/testing/index.d.ts +144 -0
- package/dist/testing/index.js +260 -0
- package/dist/testing/keys.d.ts +89 -0
- package/dist/testing/screen.d.ts +35 -0
- package/dist/testing/wait-for.d.ts +21 -0
- package/index.js +585 -0
- package/package.json +117 -7
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import React, { createContext, useRef, useState, useCallback, useMemo, useContext, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const FocusContext = createContext({
|
|
4
|
+
activate() {
|
|
5
|
+
},
|
|
6
|
+
activeId: void 0,
|
|
7
|
+
add() {
|
|
8
|
+
},
|
|
9
|
+
deactivate() {
|
|
10
|
+
},
|
|
11
|
+
disableFocus() {
|
|
12
|
+
},
|
|
13
|
+
enableFocus() {
|
|
14
|
+
},
|
|
15
|
+
focus() {
|
|
16
|
+
},
|
|
17
|
+
focusNext() {
|
|
18
|
+
},
|
|
19
|
+
focusPrevious() {
|
|
20
|
+
},
|
|
21
|
+
remove() {
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
FocusContext.displayName = "TuiFocusContext";
|
|
25
|
+
const FocusProvider = ({ children }) => {
|
|
26
|
+
const itemsRef = useRef([]);
|
|
27
|
+
const [activeId, setActiveId] = useState(void 0);
|
|
28
|
+
const [isEnabled, setIsEnabled] = useState(true);
|
|
29
|
+
const add = useCallback((id, options) => {
|
|
30
|
+
if (itemsRef.current.some((e) => e.id === id)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const entry = { autoFocus: options.autoFocus, id, isActive: true };
|
|
34
|
+
itemsRef.current = [...itemsRef.current, entry];
|
|
35
|
+
setActiveId((previous) => {
|
|
36
|
+
if (options.autoFocus && previous === void 0) {
|
|
37
|
+
return id;
|
|
38
|
+
}
|
|
39
|
+
if (itemsRef.current.filter((e) => e.isActive).length === 1 && previous === void 0) {
|
|
40
|
+
return id;
|
|
41
|
+
}
|
|
42
|
+
return previous;
|
|
43
|
+
});
|
|
44
|
+
}, []);
|
|
45
|
+
const remove = useCallback((id) => {
|
|
46
|
+
itemsRef.current = itemsRef.current.filter((e) => e.id !== id);
|
|
47
|
+
setActiveId((previous) => previous === id ? void 0 : previous);
|
|
48
|
+
}, []);
|
|
49
|
+
const activate = useCallback((id) => {
|
|
50
|
+
itemsRef.current = itemsRef.current.map((e) => e.id === id ? { ...e, isActive: true } : e);
|
|
51
|
+
}, []);
|
|
52
|
+
const deactivate = useCallback((id) => {
|
|
53
|
+
itemsRef.current = itemsRef.current.map((e) => e.id === id ? { ...e, isActive: false } : e);
|
|
54
|
+
setActiveId((previous) => previous === id ? void 0 : previous);
|
|
55
|
+
}, []);
|
|
56
|
+
const enableFocus = useCallback(() => setIsEnabled(true), []);
|
|
57
|
+
const disableFocus = useCallback(() => {
|
|
58
|
+
setIsEnabled(false);
|
|
59
|
+
setActiveId(void 0);
|
|
60
|
+
}, []);
|
|
61
|
+
const focusNext = useCallback(() => {
|
|
62
|
+
if (!isEnabled) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const active = itemsRef.current.filter((e) => e.isActive);
|
|
66
|
+
if (active.length === 0) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
setActiveId((previous) => {
|
|
70
|
+
if (previous === void 0) {
|
|
71
|
+
return active[0]?.id;
|
|
72
|
+
}
|
|
73
|
+
const index = active.findIndex((e) => e.id === previous);
|
|
74
|
+
return active[(index + 1) % active.length]?.id ?? active[0]?.id;
|
|
75
|
+
});
|
|
76
|
+
}, [isEnabled]);
|
|
77
|
+
const focusPrevious = useCallback(() => {
|
|
78
|
+
if (!isEnabled) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const active = itemsRef.current.filter((e) => e.isActive);
|
|
82
|
+
if (active.length === 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
setActiveId((previous) => {
|
|
86
|
+
if (previous === void 0) {
|
|
87
|
+
return active.at(-1)?.id;
|
|
88
|
+
}
|
|
89
|
+
const index = active.findIndex((e) => e.id === previous);
|
|
90
|
+
return active[(index - 1 + active.length) % active.length]?.id ?? active.at(-1)?.id;
|
|
91
|
+
});
|
|
92
|
+
}, [isEnabled]);
|
|
93
|
+
const focus = useCallback(
|
|
94
|
+
(id) => {
|
|
95
|
+
if (!isEnabled) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (itemsRef.current.some((e) => e.id === id && e.isActive)) {
|
|
99
|
+
setActiveId(id);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
[isEnabled]
|
|
103
|
+
);
|
|
104
|
+
const value = useMemo(() => {
|
|
105
|
+
return {
|
|
106
|
+
activate,
|
|
107
|
+
activeId,
|
|
108
|
+
add,
|
|
109
|
+
deactivate,
|
|
110
|
+
disableFocus,
|
|
111
|
+
enableFocus,
|
|
112
|
+
focus,
|
|
113
|
+
focusNext,
|
|
114
|
+
focusPrevious,
|
|
115
|
+
remove
|
|
116
|
+
};
|
|
117
|
+
}, [activeId, add, remove, activate, deactivate, enableFocus, disableFocus, focusNext, focusPrevious, focus]);
|
|
118
|
+
return React.createElement(FocusContext.Provider, { value }, children);
|
|
119
|
+
};
|
|
120
|
+
const useFocus = ({ autoFocus = false, id: customId, isActive = true } = {}) => {
|
|
121
|
+
const { activate, activeId, add, deactivate, focus, remove } = useContext(FocusContext);
|
|
122
|
+
const id = useMemo(() => customId ?? Math.random().toString(36).slice(2, 7), [customId]);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
add(id, { autoFocus });
|
|
125
|
+
return () => {
|
|
126
|
+
remove(id);
|
|
127
|
+
};
|
|
128
|
+
}, [id, autoFocus]);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (isActive) {
|
|
131
|
+
activate(id);
|
|
132
|
+
} else {
|
|
133
|
+
deactivate(id);
|
|
134
|
+
}
|
|
135
|
+
}, [isActive, id]);
|
|
136
|
+
return {
|
|
137
|
+
focus,
|
|
138
|
+
isFocused: Boolean(id) && activeId === id
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
const useFocusManager = () => {
|
|
142
|
+
const context = useContext(FocusContext);
|
|
143
|
+
return {
|
|
144
|
+
activeId: context.activeId,
|
|
145
|
+
disableFocus: context.disableFocus,
|
|
146
|
+
enableFocus: context.enableFocus,
|
|
147
|
+
focus: context.focus,
|
|
148
|
+
focusNext: context.focusNext,
|
|
149
|
+
focusPrevious: context.focusPrevious
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export { FocusContext, FocusProvider, useFocus, useFocusManager };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import 'react';
|
|
3
|
+
import Box from './Box-D_pSJ9Jp.js';
|
|
4
|
+
import useWindowSize from './useWindowSize-ugEmGZJm.js';
|
|
5
|
+
|
|
6
|
+
const Fullscreen = ({ children }) => {
|
|
7
|
+
const { columns, rows } = useWindowSize();
|
|
8
|
+
return jsx(Box, { flexGrow: 1, height: rows, width: columns, children });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { Fullscreen as default };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { strip } from '@visulima/ansi';
|
|
3
|
+
import { multilineGradient } from '@visulima/colorize/gradient';
|
|
4
|
+
import { useMemo, Children, isValidElement, cloneElement } from 'react';
|
|
5
|
+
import Box from './Box-D_pSJ9Jp.js';
|
|
6
|
+
import Text from './Text-DvAUdZcK.js';
|
|
7
|
+
import Transform from './Transform-BHxY_dAM.js';
|
|
8
|
+
|
|
9
|
+
const presets = {
|
|
10
|
+
atlas: { colors: ["#feac5e", "#c779d0", "#4bc0c8"] },
|
|
11
|
+
cristal: { colors: ["#bdfff3", "#4ac29a"] },
|
|
12
|
+
fruit: { colors: ["#ff4e50", "#f9d423"] },
|
|
13
|
+
instagram: { colors: ["#833ab4", "#fd1d1d", "#fcb045"] },
|
|
14
|
+
mind: { colors: ["#473b7b", "#3584a7", "#30d2be"] },
|
|
15
|
+
morning: { colors: ["#ff5f6d", "#ffc371"], options: { interpolation: "hsv" } },
|
|
16
|
+
passion: { colors: ["#f43b47", "#453a94"] },
|
|
17
|
+
pastel: { colors: ["#74ebd5", "#74ecd5"], options: { hsvSpin: "long", interpolation: "hsv" } },
|
|
18
|
+
rainbow: { colors: ["#ff0000", "#ff0100"], options: { hsvSpin: "long", interpolation: "hsv" } },
|
|
19
|
+
retro: { colors: ["#3f51b1", "#5a55ae", "#7b5fac", "#8f6aae", "#a86aa4", "#cc6b8e", "#f18271", "#f3a469", "#f7c978"] },
|
|
20
|
+
summer: { colors: ["#fdbb2d", "#22c1c3"] },
|
|
21
|
+
teen: { colors: ["#77a1d3", "#79cbca", "#e684ae"] },
|
|
22
|
+
vice: { colors: ["#5ee7df", "#b490ca"], options: { interpolation: "hsv" } }
|
|
23
|
+
};
|
|
24
|
+
const containsBoxDescendant = (nodeChildren) => {
|
|
25
|
+
let hasBox = false;
|
|
26
|
+
const search = (value) => {
|
|
27
|
+
Children.forEach(value, (child) => {
|
|
28
|
+
if (hasBox) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!isValidElement(child)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (child.type === Box) {
|
|
35
|
+
hasBox = true;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const childProps = child.props;
|
|
39
|
+
if (Object.hasOwn(childProps, "children")) {
|
|
40
|
+
search(childProps["children"]);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
search(nodeChildren);
|
|
45
|
+
return hasBox;
|
|
46
|
+
};
|
|
47
|
+
const hasChildrenProp = (properties) => Object.hasOwn(properties, "children");
|
|
48
|
+
const isPlainTextNode = (node) => typeof node === "string" || typeof node === "number";
|
|
49
|
+
const isNonRenderableChild = (node) => node === null || node === void 0 || typeof node === "boolean";
|
|
50
|
+
function Gradient({ children, colors, name }) {
|
|
51
|
+
if (name && colors) {
|
|
52
|
+
throw new Error("The `name` and `colors` props are mutually exclusive");
|
|
53
|
+
}
|
|
54
|
+
if (!name && !colors) {
|
|
55
|
+
throw new Error("Either `name` or `colors` prop must be provided");
|
|
56
|
+
}
|
|
57
|
+
const gradientFunction = useMemo(
|
|
58
|
+
() => name ? multilineGradient(presets[name].colors, presets[name].options) : multilineGradient(colors ?? []),
|
|
59
|
+
[name, colors]
|
|
60
|
+
);
|
|
61
|
+
const applyGradient = (text) => gradientFunction(strip(text));
|
|
62
|
+
const childrenCount = Children.count(children);
|
|
63
|
+
if (isPlainTextNode(children)) {
|
|
64
|
+
return jsx(Transform, { transform: applyGradient, children });
|
|
65
|
+
}
|
|
66
|
+
if (childrenCount === 1 && !containsBoxDescendant(children)) {
|
|
67
|
+
return jsx(Transform, { transform: applyGradient, children });
|
|
68
|
+
}
|
|
69
|
+
const applyGradientToChildren = (nodeChildren) => {
|
|
70
|
+
const nodes = [];
|
|
71
|
+
let bufferedText = "";
|
|
72
|
+
let nodeIndex = 0;
|
|
73
|
+
const createKey = () => {
|
|
74
|
+
const key = `gradient-node-${String(nodeIndex)}`;
|
|
75
|
+
nodeIndex += 1;
|
|
76
|
+
return key;
|
|
77
|
+
};
|
|
78
|
+
const pushTransformed = (node, key) => {
|
|
79
|
+
nodes.push(
|
|
80
|
+
jsx(Transform, { transform: applyGradient, children: node }, key)
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
const flushText = () => {
|
|
84
|
+
if (bufferedText === "") {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const text = bufferedText;
|
|
88
|
+
bufferedText = "";
|
|
89
|
+
pushTransformed(jsx(Text, { children: text }), createKey());
|
|
90
|
+
};
|
|
91
|
+
Children.forEach(nodeChildren, (child) => {
|
|
92
|
+
if (isNonRenderableChild(child)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (isPlainTextNode(child)) {
|
|
96
|
+
bufferedText += String(child);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
flushText();
|
|
100
|
+
if (isValidElement(child)) {
|
|
101
|
+
const childKey = child.key ?? createKey();
|
|
102
|
+
const childProps = child.props;
|
|
103
|
+
if (child.type === Text) {
|
|
104
|
+
pushTransformed(child, childKey);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (child.type === Box) {
|
|
108
|
+
if (hasChildrenProp(childProps)) {
|
|
109
|
+
const childChildren = childProps["children"];
|
|
110
|
+
nodes.push(cloneElement(child, { key: childKey }, applyGradientToChildren(childChildren)));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
nodes.push(cloneElement(child, { key: childKey }));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (hasChildrenProp(childProps)) {
|
|
117
|
+
const childChildren = childProps["children"];
|
|
118
|
+
if (!containsBoxDescendant(childChildren)) {
|
|
119
|
+
pushTransformed(child, childKey);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
nodes.push(cloneElement(child, { key: childKey }, applyGradientToChildren(childChildren)));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
pushTransformed(child, childKey);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
nodes.push(child);
|
|
129
|
+
});
|
|
130
|
+
flushText();
|
|
131
|
+
return nodes;
|
|
132
|
+
};
|
|
133
|
+
return jsx(Fragment, { children: applyGradientToChildren(children) });
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export { Gradient as default };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import useWindowSize from './useWindowSize-ugEmGZJm.js';
|
|
3
|
+
import Box from './Box-D_pSJ9Jp.js';
|
|
4
|
+
import Text from './Text-DvAUdZcK.js';
|
|
5
|
+
|
|
6
|
+
const keyLabels = {
|
|
7
|
+
backspace: "backspace",
|
|
8
|
+
delete: "del",
|
|
9
|
+
downArrow: "↓",
|
|
10
|
+
end: "end",
|
|
11
|
+
escape: "esc",
|
|
12
|
+
home: "home",
|
|
13
|
+
leftArrow: "←",
|
|
14
|
+
pageDown: "pgdn",
|
|
15
|
+
pageUp: "pgup",
|
|
16
|
+
return: "enter",
|
|
17
|
+
rightArrow: "→",
|
|
18
|
+
tab: "tab",
|
|
19
|
+
upArrow: "↑"
|
|
20
|
+
};
|
|
21
|
+
function formatKeyLabel(spec) {
|
|
22
|
+
const plusIndex = spec.indexOf("+");
|
|
23
|
+
if (plusIndex !== -1) {
|
|
24
|
+
const modifier = spec.slice(0, plusIndex);
|
|
25
|
+
const rest = spec.slice(plusIndex + 1);
|
|
26
|
+
return `${modifier}+${keyLabels[rest] ?? rest}`;
|
|
27
|
+
}
|
|
28
|
+
return keyLabels[spec] ?? spec;
|
|
29
|
+
}
|
|
30
|
+
function formatKeys(key) {
|
|
31
|
+
const keys = typeof key === "string" ? [key] : key;
|
|
32
|
+
return keys.map((k) => formatKeyLabel(k)).join("/");
|
|
33
|
+
}
|
|
34
|
+
function Help({
|
|
35
|
+
bindings,
|
|
36
|
+
descriptionColor,
|
|
37
|
+
keyColor = "cyan",
|
|
38
|
+
maxColumns = 3,
|
|
39
|
+
mode = "short",
|
|
40
|
+
separator = " · "
|
|
41
|
+
}) {
|
|
42
|
+
const { columns } = useWindowSize();
|
|
43
|
+
if (mode === "full") {
|
|
44
|
+
return renderFull(bindings, { columns, descriptionColor, keyColor, maxColumns });
|
|
45
|
+
}
|
|
46
|
+
return renderShort(bindings, { columns, descriptionColor, keyColor, separator });
|
|
47
|
+
}
|
|
48
|
+
function renderShort(bindings, options) {
|
|
49
|
+
const items = [];
|
|
50
|
+
let totalWidth = 0;
|
|
51
|
+
for (const [index, binding] of bindings.entries()) {
|
|
52
|
+
const keys = formatKeys(binding.key);
|
|
53
|
+
const pairText = `${keys} ${binding.description}`;
|
|
54
|
+
const separatorWidth = index > 0 ? options.separator.length : 0;
|
|
55
|
+
const pairWidth = separatorWidth + pairText.length;
|
|
56
|
+
if (totalWidth + pairWidth > options.columns && items.length > 0) {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
if (index > 0) {
|
|
60
|
+
items.push(
|
|
61
|
+
jsx(Text, { dimColor: true, children: options.separator }, `sep-${index}`)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
items.push(
|
|
65
|
+
jsxs(Box, { children: [
|
|
66
|
+
jsx(Text, { color: options.keyColor, children: keys }),
|
|
67
|
+
jsx(Text, { children: " " }),
|
|
68
|
+
options.descriptionColor ? jsx(Text, { color: options.descriptionColor, children: binding.description }) : jsx(Text, { dimColor: true, children: binding.description })
|
|
69
|
+
] }, `pair-${index}`)
|
|
70
|
+
);
|
|
71
|
+
totalWidth += pairWidth;
|
|
72
|
+
}
|
|
73
|
+
return jsx(Box, { flexDirection: "row", children: items });
|
|
74
|
+
}
|
|
75
|
+
function renderFull(bindings, options) {
|
|
76
|
+
const groups = /* @__PURE__ */ new Map();
|
|
77
|
+
for (const binding of bindings) {
|
|
78
|
+
const group = binding.group ?? "";
|
|
79
|
+
if (!groups.has(group)) {
|
|
80
|
+
groups.set(group, []);
|
|
81
|
+
}
|
|
82
|
+
groups.get(group).push(binding);
|
|
83
|
+
}
|
|
84
|
+
const groupEntries = [...groups.entries()];
|
|
85
|
+
const columnCount = Math.min(options.maxColumns, groupEntries.length || 1);
|
|
86
|
+
const columnWidth = Math.floor(options.columns / columnCount);
|
|
87
|
+
const columnNodes = [];
|
|
88
|
+
for (const [index, [groupName, groupBindings]] of groupEntries.entries()) {
|
|
89
|
+
const rows = [];
|
|
90
|
+
if (groupName) {
|
|
91
|
+
rows.push(
|
|
92
|
+
jsx(Text, { bold: true, children: groupName }, "title")
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
for (const [bIndex, binding] of groupBindings.entries()) {
|
|
96
|
+
const keys = formatKeys(binding.key);
|
|
97
|
+
rows.push(
|
|
98
|
+
jsxs(Box, { children: [
|
|
99
|
+
jsx(Text, { color: options.keyColor, children: keys }),
|
|
100
|
+
jsx(Text, { children: " " }),
|
|
101
|
+
options.descriptionColor ? jsx(Text, { color: options.descriptionColor, children: binding.description }) : jsx(Text, { dimColor: true, children: binding.description })
|
|
102
|
+
] }, `b-${bIndex}`)
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
columnNodes.push(
|
|
106
|
+
jsx(Box, { flexDirection: "column", width: columnWidth, children: rows }, `col-${index}`)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return jsx(Box, { flexDirection: "row", children: columnNodes });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { Help as default };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const isIMEInput = (data) => {
|
|
2
|
+
if (data.length === 0) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
for (const character of data) {
|
|
6
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
7
|
+
if (codePoint <= 127) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (codePoint <= 255) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
class IMECompositionBuffer {
|
|
18
|
+
buffer = "";
|
|
19
|
+
timer;
|
|
20
|
+
onFlush;
|
|
21
|
+
timeout;
|
|
22
|
+
constructor({ onFlush, timeout }) {
|
|
23
|
+
this.onFlush = onFlush;
|
|
24
|
+
this.timeout = timeout;
|
|
25
|
+
}
|
|
26
|
+
add(text) {
|
|
27
|
+
this.buffer += text;
|
|
28
|
+
if (this.timer !== void 0) {
|
|
29
|
+
clearTimeout(this.timer);
|
|
30
|
+
}
|
|
31
|
+
this.timer = setTimeout(() => {
|
|
32
|
+
this.flush();
|
|
33
|
+
}, this.timeout);
|
|
34
|
+
}
|
|
35
|
+
flush() {
|
|
36
|
+
if (this.timer !== void 0) {
|
|
37
|
+
clearTimeout(this.timer);
|
|
38
|
+
this.timer = void 0;
|
|
39
|
+
}
|
|
40
|
+
if (this.buffer.length > 0) {
|
|
41
|
+
const text = this.buffer;
|
|
42
|
+
this.buffer = "";
|
|
43
|
+
this.onFlush(text);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
destroy() {
|
|
47
|
+
if (this.timer !== void 0) {
|
|
48
|
+
clearTimeout(this.timer);
|
|
49
|
+
this.timer = void 0;
|
|
50
|
+
}
|
|
51
|
+
this.buffer = "";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { IMECompositionBuffer, isIMEInput };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
|
|
3
|
+
class InputParser extends EventEmitter {
|
|
4
|
+
constructor(stdin) {
|
|
5
|
+
super();
|
|
6
|
+
this.stdin = stdin;
|
|
7
|
+
}
|
|
8
|
+
stdin;
|
|
9
|
+
_boundHandleData = null;
|
|
10
|
+
_pasteBuffer = null;
|
|
11
|
+
start() {
|
|
12
|
+
if (typeof this.stdin.setRawMode === "function") {
|
|
13
|
+
this.stdin.setRawMode(true);
|
|
14
|
+
}
|
|
15
|
+
this.stdin.resume();
|
|
16
|
+
this.stdin.setEncoding("utf8");
|
|
17
|
+
this._boundHandleData = this.handleData.bind(this);
|
|
18
|
+
this.stdin.on("data", this._boundHandleData);
|
|
19
|
+
}
|
|
20
|
+
stop() {
|
|
21
|
+
if (typeof this.stdin.setRawMode === "function") {
|
|
22
|
+
this.stdin.setRawMode(false);
|
|
23
|
+
}
|
|
24
|
+
this.stdin.pause();
|
|
25
|
+
if (this._boundHandleData) {
|
|
26
|
+
this.stdin.removeListener("data", this._boundHandleData);
|
|
27
|
+
this._boundHandleData = null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
handleData(data) {
|
|
31
|
+
if (data === "") {
|
|
32
|
+
this.emit("exit");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (data.includes("\x1B[200~") || this._pasteBuffer !== null) {
|
|
36
|
+
if (this._pasteBuffer === null) {
|
|
37
|
+
this._pasteBuffer = data.replace("\x1B[200~", "");
|
|
38
|
+
} else {
|
|
39
|
+
this._pasteBuffer += data;
|
|
40
|
+
}
|
|
41
|
+
if (this._pasteBuffer.includes("\x1B[201~")) {
|
|
42
|
+
const text = this._pasteBuffer.replace("\x1B[201~", "");
|
|
43
|
+
this._pasteBuffer = null;
|
|
44
|
+
this.emit("paste", text);
|
|
45
|
+
if (this.listenerCount("paste") === 0) {
|
|
46
|
+
this.emit("data", text);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (data.length === 1) {
|
|
52
|
+
const code = data.charCodeAt(0);
|
|
53
|
+
if (code >= 1 && code <= 26 && code !== 3 && code !== 9 && code !== 10 && code !== 13) {
|
|
54
|
+
const letter = String.fromCharCode(code + 96);
|
|
55
|
+
this.emit("ctrl", letter);
|
|
56
|
+
this.emit("data", data, { ctrl: true });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (data === "\x1B[A") {
|
|
61
|
+
this.emit("keydown", "up");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (data === "\x1B[B") {
|
|
65
|
+
this.emit("keydown", "down");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (data === "\x1B[C") {
|
|
69
|
+
this.emit("keydown", "right");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (data === "\x1B[D") {
|
|
73
|
+
this.emit("keydown", "left");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (data === " ") {
|
|
77
|
+
this.emit("keydown", "tab");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (data === "\x1B[Z") {
|
|
81
|
+
this.emit("keydown", "shift-tab");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (data === "\x1B") {
|
|
85
|
+
this.emit("keydown", "escape");
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (data === "\r" || data === "\n") {
|
|
89
|
+
this.emit("keydown", "enter");
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (data === "") {
|
|
93
|
+
this.emit("keydown", "backspace");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (data === "\x1B[3~") {
|
|
97
|
+
this.emit("keydown", "delete");
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (data === "\x1B[5~") {
|
|
101
|
+
this.emit("keydown", "pageUp");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (data === "\x1B[6~") {
|
|
105
|
+
this.emit("keydown", "pageDown");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (data === "\x1B[H" || data === "\x1B[1~") {
|
|
109
|
+
this.emit("keydown", "home");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (data === "\x1B[F" || data === "\x1B[4~") {
|
|
113
|
+
this.emit("keydown", "end");
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (data.length === 2 && data[0] === "\x1B") {
|
|
117
|
+
this.emit("meta", data[1]);
|
|
118
|
+
this.emit("data", data, { meta: true });
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (data.startsWith("\x1B[<")) {
|
|
122
|
+
const match = data.match(/\u001B\[<(\d+);(\d+);(\d+)(M)/i);
|
|
123
|
+
if (match) {
|
|
124
|
+
const buttonCode = Number.parseInt(match[1]);
|
|
125
|
+
const x = Number.parseInt(match[2]) - 1;
|
|
126
|
+
const y = Number.parseInt(match[3]) - 1;
|
|
127
|
+
const isRelease = match[4] === "m";
|
|
128
|
+
const shift = (buttonCode & 4) !== 0;
|
|
129
|
+
const meta = (buttonCode & 8) !== 0;
|
|
130
|
+
const ctrl = (buttonCode & 16) !== 0;
|
|
131
|
+
const base = buttonCode & -29;
|
|
132
|
+
let button = null;
|
|
133
|
+
if (base === 0 && !isRelease)
|
|
134
|
+
button = "left";
|
|
135
|
+
else if (base === 1 && !isRelease)
|
|
136
|
+
button = "middle";
|
|
137
|
+
else if (base === 2 && !isRelease)
|
|
138
|
+
button = "right";
|
|
139
|
+
else if (base === 64)
|
|
140
|
+
button = "scrollUp";
|
|
141
|
+
else if (base === 65)
|
|
142
|
+
button = "scrollDown";
|
|
143
|
+
if (button) {
|
|
144
|
+
const event = { button, ctrl, meta, shift, x, y };
|
|
145
|
+
this.emit("mouse", event);
|
|
146
|
+
if (button === "left")
|
|
147
|
+
this.emit("click", { x, y });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
this.emit("data", data);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { InputParser };
|