nastech-tui 0.0.1
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/.prettierrc +11 -0
- package/README.md +346 -0
- package/eslint.config.mjs +111 -0
- package/package.json +51 -0
- package/packages/nastech-ink/ambient.d.ts +83 -0
- package/packages/nastech-ink/index.d.ts +40 -0
- package/packages/nastech-ink/index.js +1 -0
- package/packages/nastech-ink/nastech-ink/ambient.d.ts +83 -0
- package/packages/nastech-ink/nastech-ink/index.d.ts +40 -0
- package/packages/nastech-ink/nastech-ink/index.js +1 -0
- package/packages/nastech-ink/nastech-ink/package.json +54 -0
- package/packages/nastech-ink/nastech-ink/src/bootstrap/state.ts +9 -0
- package/packages/nastech-ink/nastech-ink/src/entry-exports.ts +32 -0
- package/packages/nastech-ink/nastech-ink/src/hooks/use-stderr.ts +15 -0
- package/packages/nastech-ink/nastech-ink/src/hooks/use-stdout.ts +15 -0
- package/packages/nastech-ink/nastech-ink/src/ink/Ansi.tsx +435 -0
- package/packages/nastech-ink/nastech-ink/src/ink/app-mouse.test.ts +123 -0
- package/packages/nastech-ink/nastech-ink/src/ink/bidi.ts +145 -0
- package/packages/nastech-ink/nastech-ink/src/ink/cache-eviction.ts +45 -0
- package/packages/nastech-ink/nastech-ink/src/ink/clearTerminal.ts +68 -0
- package/packages/nastech-ink/nastech-ink/src/ink/colorize.test.ts +60 -0
- package/packages/nastech-ink/nastech-ink/src/ink/colorize.ts +277 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/AlternateScreen.tsx +133 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/App.tsx +830 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/AppContext.ts +20 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/Box.tsx +294 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/Button.tsx +236 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/ClockContext.tsx +133 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/CursorAdvanceContext.ts +35 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/CursorDeclarationContext.ts +28 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/ErrorOverview.tsx +130 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/Link.tsx +38 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/Newline.tsx +43 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/NoSelect.tsx +73 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/RawAnsi.tsx +61 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/ScrollBox.tsx +290 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/Spacer.tsx +23 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/StdinContext.ts +25 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/TerminalFocusContext.tsx +63 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/TerminalSizeContext.tsx +7 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/Text.test.ts +38 -0
- package/packages/nastech-ink/nastech-ink/src/ink/components/Text.tsx +336 -0
- package/packages/nastech-ink/nastech-ink/src/ink/constants.ts +6 -0
- package/packages/nastech-ink/nastech-ink/src/ink/cursor.ts +5 -0
- package/packages/nastech-ink/nastech-ink/src/ink/devtools.ts +2 -0
- package/packages/nastech-ink/nastech-ink/src/ink/dom.ts +495 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/click-event.ts +38 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/cmd-shortcuts.test.ts +65 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/dispatcher.ts +242 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/emitter.ts +40 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/event-handlers.ts +84 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/event.ts +11 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/focus-event.ts +18 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/input-event.ts +176 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/keyboard-event.ts +57 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/mouse-event.ts +18 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/paste-event.ts +10 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/resize-event.ts +12 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/terminal-event.ts +107 -0
- package/packages/nastech-ink/nastech-ink/src/ink/events/terminal-focus-event.ts +19 -0
- package/packages/nastech-ink/nastech-ink/src/ink/focus.ts +219 -0
- package/packages/nastech-ink/nastech-ink/src/ink/frame.ts +124 -0
- package/packages/nastech-ink/nastech-ink/src/ink/get-max-width.ts +27 -0
- package/packages/nastech-ink/nastech-ink/src/ink/global.d.ts +1 -0
- package/packages/nastech-ink/nastech-ink/src/ink/hit-test.test.ts +38 -0
- package/packages/nastech-ink/nastech-ink/src/ink/hit-test.ts +224 -0
- package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-animation-frame.ts +62 -0
- package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-app.ts +9 -0
- package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-cursor-advance.ts +33 -0
- package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-declared-cursor.ts +75 -0
- package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-external-process.ts +27 -0
- package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-input.ts +95 -0
- package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-interval.ts +71 -0
- package/packages/nastech-ink/package.json +57 -0
- package/packages/nastech-ink/src/bootstrap/state.ts +9 -0
- package/packages/nastech-ink/src/entry-exports.ts +32 -0
- package/packages/nastech-ink/src/hooks/use-stderr.ts +15 -0
- package/packages/nastech-ink/src/hooks/use-stdout.ts +15 -0
- package/packages/nastech-ink/src/ink/Ansi.tsx +435 -0
- package/packages/nastech-ink/src/ink/app-mouse.test.ts +123 -0
- package/packages/nastech-ink/src/ink/app-rawmode-mouse.test.ts +91 -0
- package/packages/nastech-ink/src/ink/bidi.ts +145 -0
- package/packages/nastech-ink/src/ink/cache-eviction.ts +45 -0
- package/packages/nastech-ink/src/ink/clearTerminal.ts +68 -0
- package/packages/nastech-ink/src/ink/colorize.test.ts +60 -0
- package/packages/nastech-ink/src/ink/colorize.ts +277 -0
- package/packages/nastech-ink/src/ink/components/AlternateScreen.tsx +133 -0
- package/packages/nastech-ink/src/ink/components/App.tsx +855 -0
- package/packages/nastech-ink/src/ink/components/AppContext.ts +20 -0
- package/packages/nastech-ink/src/ink/components/Box.tsx +294 -0
- package/packages/nastech-ink/src/ink/components/Button.tsx +236 -0
- package/packages/nastech-ink/src/ink/components/ClockContext.tsx +133 -0
- package/packages/nastech-ink/src/ink/components/CursorAdvanceContext.ts +35 -0
- package/packages/nastech-ink/src/ink/components/CursorDeclarationContext.ts +28 -0
- package/packages/nastech-ink/src/ink/components/ErrorOverview.tsx +130 -0
- package/packages/nastech-ink/src/ink/components/Link.tsx +38 -0
- package/packages/nastech-ink/src/ink/components/Newline.tsx +43 -0
- package/packages/nastech-ink/src/ink/components/NoSelect.tsx +73 -0
- package/packages/nastech-ink/src/ink/components/RawAnsi.tsx +61 -0
- package/packages/nastech-ink/src/ink/components/ScrollBox.tsx +290 -0
- package/packages/nastech-ink/src/ink/components/Spacer.tsx +23 -0
- package/packages/nastech-ink/src/ink/components/StdinContext.ts +25 -0
- package/packages/nastech-ink/src/ink/components/TerminalFocusContext.tsx +63 -0
- package/packages/nastech-ink/src/ink/components/TerminalSizeContext.tsx +7 -0
- package/packages/nastech-ink/src/ink/components/Text.test.ts +38 -0
- package/packages/nastech-ink/src/ink/components/Text.tsx +336 -0
- package/packages/nastech-ink/src/ink/constants.ts +6 -0
- package/packages/nastech-ink/src/ink/cursor.ts +5 -0
- package/packages/nastech-ink/src/ink/devtools.ts +2 -0
- package/packages/nastech-ink/src/ink/dom.ts +495 -0
- package/packages/nastech-ink/src/ink/events/click-event.ts +38 -0
- package/packages/nastech-ink/src/ink/events/cmd-shortcuts.test.ts +65 -0
- package/packages/nastech-ink/src/ink/events/dispatcher.ts +242 -0
- package/packages/nastech-ink/src/ink/events/emitter.ts +40 -0
- package/packages/nastech-ink/src/ink/events/event-handlers.ts +84 -0
- package/packages/nastech-ink/src/ink/events/event.ts +11 -0
- package/packages/nastech-ink/src/ink/events/focus-event.ts +18 -0
- package/packages/nastech-ink/src/ink/events/input-event.ts +176 -0
- package/packages/nastech-ink/src/ink/events/keyboard-event.ts +57 -0
- package/packages/nastech-ink/src/ink/events/mouse-event.ts +18 -0
- package/packages/nastech-ink/src/ink/events/paste-event.ts +10 -0
- package/packages/nastech-ink/src/ink/events/resize-event.ts +12 -0
- package/packages/nastech-ink/src/ink/events/terminal-event.ts +107 -0
- package/packages/nastech-ink/src/ink/events/terminal-focus-event.ts +19 -0
- package/packages/nastech-ink/src/ink/focus.ts +219 -0
- package/packages/nastech-ink/src/ink/frame.ts +124 -0
- package/packages/nastech-ink/src/ink/get-max-width.ts +27 -0
- package/packages/nastech-ink/src/ink/global.d.ts +1 -0
- package/packages/nastech-ink/src/ink/hit-test.test.ts +38 -0
- package/packages/nastech-ink/src/ink/hit-test.ts +224 -0
- package/packages/nastech-ink/src/ink/hooks/use-animation-frame.ts +62 -0
- package/packages/nastech-ink/src/ink/hooks/use-app.ts +9 -0
- package/packages/nastech-ink/src/ink/hooks/use-cursor-advance.ts +33 -0
- package/packages/nastech-ink/src/ink/hooks/use-declared-cursor.ts +75 -0
- package/packages/nastech-ink/src/ink/hooks/use-external-process.ts +27 -0
- package/packages/nastech-ink/src/ink/hooks/use-input.ts +95 -0
- package/packages/nastech-ink/src/ink/hooks/use-interval.ts +71 -0
- package/packages/nastech-ink/src/ink/hooks/use-search-highlight.ts +56 -0
- package/packages/nastech-ink/src/ink/hooks/use-selection.ts +101 -0
- package/packages/nastech-ink/src/ink/hooks/use-stdin.ts +9 -0
- package/packages/nastech-ink/src/ink/hooks/use-tab-status.ts +71 -0
- package/packages/nastech-ink/src/ink/hooks/use-terminal-focus.ts +18 -0
- package/packages/nastech-ink/src/ink/hooks/use-terminal-title.ts +34 -0
- package/packages/nastech-ink/src/ink/hooks/use-terminal-viewport.ts +100 -0
- package/packages/nastech-ink/src/ink/hyperlinkHover.ts +52 -0
- package/packages/nastech-ink/src/ink/ink-cursor-advance.test.ts +234 -0
- package/packages/nastech-ink/src/ink/ink-resize.test.ts +50 -0
- package/packages/nastech-ink/src/ink/ink.tsx +2705 -0
- package/packages/nastech-ink/src/ink/instances.ts +10 -0
- package/packages/nastech-ink/src/ink/layout/engine.ts +6 -0
- package/packages/nastech-ink/src/ink/layout/geometry.ts +98 -0
- package/packages/nastech-ink/src/ink/layout/node.ts +145 -0
- package/packages/nastech-ink/src/ink/layout/yoga.ts +313 -0
- package/packages/nastech-ink/src/ink/line-width-cache.ts +38 -0
- package/packages/nastech-ink/src/ink/log-update.test.ts +223 -0
- package/packages/nastech-ink/src/ink/log-update.ts +752 -0
- package/packages/nastech-ink/src/ink/lru.ts +14 -0
- package/packages/nastech-ink/src/ink/measure-element.ts +23 -0
- package/packages/nastech-ink/src/ink/measure-text.ts +50 -0
- package/packages/nastech-ink/src/ink/node-cache.ts +53 -0
- package/packages/nastech-ink/src/ink/optimizer.ts +99 -0
- package/packages/nastech-ink/src/ink/output.ts +845 -0
- package/packages/nastech-ink/src/ink/parse-keypress.test.ts +133 -0
- package/packages/nastech-ink/src/ink/parse-keypress.ts +848 -0
- package/packages/nastech-ink/src/ink/reconciler.ts +382 -0
- package/packages/nastech-ink/src/ink/render-border.ts +206 -0
- package/packages/nastech-ink/src/ink/render-node-to-output.ts +1582 -0
- package/packages/nastech-ink/src/ink/render-to-screen.ts +236 -0
- package/packages/nastech-ink/src/ink/renderer.ts +169 -0
- package/packages/nastech-ink/src/ink/root.ts +204 -0
- package/packages/nastech-ink/src/ink/screen.ts +1590 -0
- package/packages/nastech-ink/src/ink/searchHighlight.ts +91 -0
- package/packages/nastech-ink/src/ink/selection.test.ts +82 -0
- package/packages/nastech-ink/src/ink/selection.ts +1143 -0
- package/packages/nastech-ink/src/ink/squash-text-nodes.ts +74 -0
- package/packages/nastech-ink/src/ink/stringWidth.ts +341 -0
- package/packages/nastech-ink/src/ink/styles.ts +750 -0
- package/packages/nastech-ink/src/ink/supports-hyperlinks.ts +51 -0
- package/packages/nastech-ink/src/ink/tabstops.ts +44 -0
- package/packages/nastech-ink/src/ink/terminal-focus-state.ts +52 -0
- package/packages/nastech-ink/src/ink/terminal-querier.ts +222 -0
- package/packages/nastech-ink/src/ink/terminal.test.ts +15 -0
- package/packages/nastech-ink/src/ink/terminal.ts +299 -0
- package/packages/nastech-ink/src/ink/termio/ansi.ts +75 -0
- package/packages/nastech-ink/src/ink/termio/csi.ts +334 -0
- package/packages/nastech-ink/src/ink/termio/dec.ts +99 -0
- package/packages/nastech-ink/src/ink/termio/esc.ts +69 -0
- package/packages/nastech-ink/src/ink/termio/osc.test.ts +191 -0
- package/packages/nastech-ink/src/ink/termio/osc.ts +724 -0
- package/packages/nastech-ink/src/ink/termio/parser.ts +467 -0
- package/packages/nastech-ink/src/ink/termio/sgr.ts +362 -0
- package/packages/nastech-ink/src/ink/termio/tokenize.test.ts +185 -0
- package/packages/nastech-ink/src/ink/termio/tokenize.ts +350 -0
- package/packages/nastech-ink/src/ink/termio/types.ts +230 -0
- package/packages/nastech-ink/src/ink/termio.ts +42 -0
- package/packages/nastech-ink/src/ink/useTerminalNotification.ts +110 -0
- package/packages/nastech-ink/src/ink/warn.ts +15 -0
- package/packages/nastech-ink/src/ink/widest-line.ts +22 -0
- package/packages/nastech-ink/src/ink/wrap-text.test.ts +17 -0
- package/packages/nastech-ink/src/ink/wrap-text.ts +144 -0
- package/packages/nastech-ink/src/ink/wrapAnsi.ts +13 -0
- package/packages/nastech-ink/src/native-ts/yoga-layout/enums.ts +112 -0
- package/packages/nastech-ink/src/native-ts/yoga-layout/index.ts +2326 -0
- package/packages/nastech-ink/src/utils/debug.ts +6 -0
- package/packages/nastech-ink/src/utils/earlyInput.ts +131 -0
- package/packages/nastech-ink/src/utils/env.ts +66 -0
- package/packages/nastech-ink/src/utils/envUtils.ts +13 -0
- package/packages/nastech-ink/src/utils/execFileNoThrow.test.ts +146 -0
- package/packages/nastech-ink/src/utils/execFileNoThrow.ts +115 -0
- package/packages/nastech-ink/src/utils/fullscreen.ts +3 -0
- package/packages/nastech-ink/src/utils/intl.ts +87 -0
- package/packages/nastech-ink/src/utils/log.ts +7 -0
- package/packages/nastech-ink/src/utils/semver.ts +57 -0
- package/packages/nastech-ink/src/utils/sliceAnsi.ts +106 -0
- package/packages/nastech-ink/text-input.d.ts +2 -0
- package/packages/nastech-ink/text-input.js +1 -0
- package/scripts/build.mjs +61 -0
- package/scripts/profile-tui.mjs +121 -0
- package/src/__tests__/activeSessionSwitcher.test.ts +157 -0
- package/src/__tests__/appChromeStatusRule.test.tsx +84 -0
- package/src/__tests__/appChromeStatusRuleDevCredits.test.tsx +73 -0
- package/src/__tests__/approvalAction.test.ts +50 -0
- package/src/__tests__/asCommandDispatch.test.ts +27 -0
- package/src/__tests__/blockLayout.test.ts +122 -0
- package/src/__tests__/clipboard.test.ts +369 -0
- package/src/__tests__/constants.test.ts +53 -0
- package/src/__tests__/createGatewayEventHandler.test.ts +1091 -0
- package/src/__tests__/createSlashHandler.test.ts +822 -0
- package/src/__tests__/creditsCommand.test.ts +144 -0
- package/src/__tests__/cursorDriftRegression.test.ts +114 -0
- package/src/__tests__/details.test.ts +115 -0
- package/src/__tests__/emoji.test.ts +64 -0
- package/src/__tests__/externalLink.test.ts +144 -0
- package/src/__tests__/forceTruecolor.test.ts +191 -0
- package/src/__tests__/gatewayClient.test.ts +394 -0
- package/src/__tests__/gatewayRecovery.test.ts +47 -0
- package/src/__tests__/markdown.test.ts +331 -0
- package/src/__tests__/mathUnicode.test.ts +293 -0
- package/src/__tests__/memoryMonitor.test.ts +102 -0
- package/src/__tests__/messageLine.test.ts +19 -0
- package/src/__tests__/messages.test.ts +92 -0
- package/src/__tests__/orchestratorPromptSession.test.ts +64 -0
- package/src/__tests__/osc52.test.ts +67 -0
- package/src/__tests__/parentLog.test.ts +75 -0
- package/src/__tests__/paths.test.ts +70 -0
- package/src/__tests__/platform.test.ts +556 -0
- package/src/__tests__/precisionWheel.test.ts +44 -0
- package/src/__tests__/prompt.test.ts +31 -0
- package/src/__tests__/providers.test.ts +65 -0
- package/src/__tests__/reasoning.test.ts +76 -0
- package/src/__tests__/rpc.test.ts +27 -0
- package/src/__tests__/scroll.test.ts +99 -0
- package/src/__tests__/slashParity.test.ts +123 -0
- package/src/__tests__/spawnHistoryStore.test.ts +46 -0
- package/src/__tests__/stateIsolation.test.ts +46 -0
- package/src/__tests__/statusBarTicker.test.ts +18 -0
- package/src/__tests__/statusRule.test.ts +32 -0
- package/src/__tests__/streamingMarkdown.test.ts +121 -0
- package/src/__tests__/subagentTree.test.ts +407 -0
- package/src/__tests__/syntax.test.ts +45 -0
- package/src/__tests__/terminalModes.test.ts +39 -0
- package/src/__tests__/terminalParity.test.ts +77 -0
- package/src/__tests__/terminalSetup.test.ts +386 -0
- package/src/__tests__/termux.test.ts +35 -0
- package/src/__tests__/termuxComposerLayout.test.ts +40 -0
- package/src/__tests__/text.test.ts +233 -0
- package/src/__tests__/textInputBurstInput.test.ts +40 -0
- package/src/__tests__/textInputCursorSourceOfTruth.test.ts +50 -0
- package/src/__tests__/textInputFastEcho.test.ts +200 -0
- package/src/__tests__/textInputLineNav.test.ts +55 -0
- package/src/__tests__/textInputPassThrough.test.ts +59 -0
- package/src/__tests__/textInputRightClick.test.ts +48 -0
- package/src/__tests__/textInputWrap.test.ts +151 -0
- package/src/__tests__/theme.test.ts +311 -0
- package/src/__tests__/turnControllerNotice.test.ts +43 -0
- package/src/__tests__/turnStore.test.ts +66 -0
- package/src/__tests__/useCompletion.test.ts +35 -0
- package/src/__tests__/useComposerState.test.ts +59 -0
- package/src/__tests__/useConfigSync.test.ts +460 -0
- package/src/__tests__/useInputHandlers.test.ts +77 -0
- package/src/__tests__/useQueue.test.ts +28 -0
- package/src/__tests__/useSessionLifecycle.test.ts +60 -0
- package/src/__tests__/useVirtualHistoryHeights.test.ts +39 -0
- package/src/__tests__/viewport.test.ts +58 -0
- package/src/__tests__/viewportStore.test.ts +85 -0
- package/src/__tests__/virtualHeights.test.ts +96 -0
- package/src/__tests__/virtualHistoryClamp.test.ts +19 -0
- package/src/__tests__/virtualHistoryOffsetCache.test.ts +282 -0
- package/src/__tests__/wheelAccel.test.ts +138 -0
- package/src/app/createGatewayEventHandler.ts +833 -0
- package/src/app/createSlashHandler.ts +130 -0
- package/src/app/delegationStore.ts +77 -0
- package/src/app/gatewayContext.tsx +19 -0
- package/src/app/gatewayRecovery.ts +35 -0
- package/src/app/inputSelectionStore.ts +15 -0
- package/src/app/interfaces.ts +394 -0
- package/src/app/overlayStore.ts +53 -0
- package/src/app/scroll.ts +71 -0
- package/src/app/setupHandoff.ts +54 -0
- package/src/app/slash/commands/core.ts +648 -0
- package/src/app/slash/commands/credits.ts +57 -0
- package/src/app/slash/commands/debug.ts +48 -0
- package/src/app/slash/commands/ops.ts +717 -0
- package/src/app/slash/commands/session.ts +554 -0
- package/src/app/slash/commands/setup.ts +20 -0
- package/src/app/slash/registry.ts +20 -0
- package/src/app/slash/types.ts +21 -0
- package/src/app/spawnHistoryStore.ts +159 -0
- package/src/app/turnController.ts +866 -0
- package/src/app/turnStore.ts +85 -0
- package/src/app/uiStore.ts +44 -0
- package/src/app/useComposerState.ts +367 -0
- package/src/app/useConfigSync.ts +288 -0
- package/src/app/useInputHandlers.ts +576 -0
- package/src/app/useLongRunToolCharms.ts +69 -0
- package/src/app/useMainApp.ts +1039 -0
- package/src/app/useSessionLifecycle.ts +366 -0
- package/src/app/useSubmission.ts +429 -0
- package/src/app.tsx +25 -0
- package/src/banner.ts +93 -0
- package/src/components/activeSessionSwitcher.tsx +635 -0
- package/src/components/agentsOverlay.tsx +1073 -0
- package/src/components/appChrome.tsx +554 -0
- package/src/components/appLayout.tsx +444 -0
- package/src/components/appOverlays.tsx +254 -0
- package/src/components/branding.tsx +466 -0
- package/src/components/fpsOverlay.tsx +30 -0
- package/src/components/helpHint.tsx +73 -0
- package/src/components/markdown.tsx +1119 -0
- package/src/components/maskedPrompt.tsx +34 -0
- package/src/components/messageLine.tsx +237 -0
- package/src/components/modelPicker.tsx +527 -0
- package/src/components/overlayControls.tsx +50 -0
- package/src/components/pluginsHub.tsx +238 -0
- package/src/components/prompts.tsx +276 -0
- package/src/components/queuedMessages.tsx +64 -0
- package/src/components/sessionPicker.tsx +227 -0
- package/src/components/skillsHub.tsx +308 -0
- package/src/components/streamingAssistant.tsx +110 -0
- package/src/components/streamingMarkdown.tsx +174 -0
- package/src/components/textInput.tsx +1340 -0
- package/src/components/themed.tsx +30 -0
- package/src/components/thinking.tsx +1224 -0
- package/src/components/todoPanel.tsx +93 -0
- package/src/config/env.ts +64 -0
- package/src/config/limits.ts +13 -0
- package/src/config/timing.ts +6 -0
- package/src/content/charms.ts +1 -0
- package/src/content/faces.ts +17 -0
- package/src/content/fortunes.ts +30 -0
- package/src/content/hotkeys.ts +37 -0
- package/src/content/placeholders.ts +13 -0
- package/src/content/setup.ts +17 -0
- package/src/content/verbs.ts +38 -0
- package/src/domain/blockLayout.ts +146 -0
- package/src/domain/details.ts +76 -0
- package/src/domain/messages.ts +91 -0
- package/src/domain/paths.ts +16 -0
- package/src/domain/providers.ts +11 -0
- package/src/domain/roles.ts +9 -0
- package/src/domain/slash.ts +10 -0
- package/src/domain/usage.ts +3 -0
- package/src/domain/viewport.ts +51 -0
- package/src/entry.tsx +104 -0
- package/src/gatewayClient.ts +730 -0
- package/src/gatewayTypes.ts +568 -0
- package/src/hooks/useCompletion.ts +112 -0
- package/src/hooks/useGitBranch.ts +72 -0
- package/src/hooks/useInputHistory.ts +11 -0
- package/src/hooks/useQueue.ts +76 -0
- package/src/hooks/useVirtualHistory.ts +554 -0
- package/src/lib/circularBuffer.ts +48 -0
- package/src/lib/clipboard.ts +182 -0
- package/src/lib/editor.test.ts +74 -0
- package/src/lib/editor.ts +47 -0
- package/src/lib/emoji.ts +55 -0
- package/src/lib/externalCli.ts +16 -0
- package/src/lib/externalLink.ts +435 -0
- package/src/lib/forceTruecolor.ts +60 -0
- package/src/lib/fpsStore.ts +51 -0
- package/src/lib/fuzzy.test.ts +109 -0
- package/src/lib/fuzzy.ts +177 -0
- package/src/lib/gracefulExit.ts +47 -0
- package/src/lib/history.ts +82 -0
- package/src/lib/inputMetrics.ts +203 -0
- package/src/lib/liveProgress.test.ts +116 -0
- package/src/lib/liveProgress.ts +79 -0
- package/src/lib/mathUnicode.ts +770 -0
- package/src/lib/memory.test.ts +155 -0
- package/src/lib/memory.ts +188 -0
- package/src/lib/memoryMonitor.ts +109 -0
- package/src/lib/messages.test.ts +29 -0
- package/src/lib/messages.ts +8 -0
- package/src/lib/openExternalUrl.test.ts +217 -0
- package/src/lib/openExternalUrl.ts +158 -0
- package/src/lib/osc52.ts +73 -0
- package/src/lib/parentLog.ts +57 -0
- package/src/lib/perfPane.tsx +107 -0
- package/src/lib/platform.ts +409 -0
- package/src/lib/precisionWheel.ts +48 -0
- package/src/lib/prompt.ts +35 -0
- package/src/lib/reasoning.ts +55 -0
- package/src/lib/rpc.ts +41 -0
- package/src/lib/subagentTree.ts +355 -0
- package/src/lib/syntax.ts +117 -0
- package/src/lib/terminalModes.ts +51 -0
- package/src/lib/terminalParity.ts +78 -0
- package/src/lib/terminalSetup.ts +444 -0
- package/src/lib/termux.ts +29 -0
- package/src/lib/text.test.ts +18 -0
- package/src/lib/text.ts +339 -0
- package/src/lib/todo.test.ts +21 -0
- package/src/lib/todo.ts +9 -0
- package/src/lib/viewportStore.ts +124 -0
- package/src/lib/virtualHeights.ts +145 -0
- package/src/lib/wheelAccel.ts +190 -0
- package/src/protocol/interpolation.ts +3 -0
- package/src/protocol/paste.ts +1 -0
- package/src/theme.ts +589 -0
- package/src/types/nastech-ink.d.ts +176 -0
- package/src/types.ts +212 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +7 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import createReconciler from 'react-reconciler'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
appendChildNode,
|
|
5
|
+
clearYogaNodeReferences,
|
|
6
|
+
createNode,
|
|
7
|
+
createTextNode,
|
|
8
|
+
type DOMElement,
|
|
9
|
+
type DOMNodeAttribute,
|
|
10
|
+
type ElementNames,
|
|
11
|
+
insertBeforeNode,
|
|
12
|
+
markDirty,
|
|
13
|
+
removeChildNode,
|
|
14
|
+
setAttribute,
|
|
15
|
+
setStyle,
|
|
16
|
+
setTextNodeValue,
|
|
17
|
+
setTextStyles,
|
|
18
|
+
type TextNode
|
|
19
|
+
} from './dom.js'
|
|
20
|
+
import { Dispatcher } from './events/dispatcher.js'
|
|
21
|
+
import { EVENT_HANDLER_PROPS } from './events/event-handlers.js'
|
|
22
|
+
import { getFocusManager, getRootNode } from './focus.js'
|
|
23
|
+
import { LayoutDisplay } from './layout/node.js'
|
|
24
|
+
import applyStyles, { type Styles, type TextStyles } from './styles.js'
|
|
25
|
+
|
|
26
|
+
// We need to conditionally perform devtools connection to avoid
|
|
27
|
+
// accidentally breaking other third-party code.
|
|
28
|
+
// See https://github.com/vadimdemedes/ink/issues/384
|
|
29
|
+
if (process.env.NODE_ENV === 'development') {
|
|
30
|
+
try {
|
|
31
|
+
void import('./devtools.js')
|
|
32
|
+
} catch (error: any) {
|
|
33
|
+
if (error.code === 'ERR_MODULE_NOT_FOUND') {
|
|
34
|
+
// biome-ignore lint/suspicious/noConsole: intentional warning
|
|
35
|
+
console.warn(
|
|
36
|
+
`
|
|
37
|
+
The environment variable DEV is set to true, so Ink tried to import \`react-devtools-core\`,
|
|
38
|
+
but this failed as it was not installed. Debugging with React Devtools requires it.
|
|
39
|
+
|
|
40
|
+
To install use this command:
|
|
41
|
+
|
|
42
|
+
$ npm install --save-dev react-devtools-core
|
|
43
|
+
`.trim() + '\n'
|
|
44
|
+
)
|
|
45
|
+
} else {
|
|
46
|
+
throw error
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// --
|
|
52
|
+
|
|
53
|
+
type AnyObject = Record<string, unknown>
|
|
54
|
+
|
|
55
|
+
const diff = (before: AnyObject, after: AnyObject): AnyObject | undefined => {
|
|
56
|
+
if (before === after) {
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!before) {
|
|
61
|
+
return after
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const changed: AnyObject = {}
|
|
65
|
+
let isChanged = false
|
|
66
|
+
|
|
67
|
+
for (const key of Object.keys(before)) {
|
|
68
|
+
const isDeleted = after ? !Object.hasOwn(after, key) : true
|
|
69
|
+
|
|
70
|
+
if (isDeleted) {
|
|
71
|
+
changed[key] = undefined
|
|
72
|
+
isChanged = true
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (after) {
|
|
77
|
+
for (const key of Object.keys(after)) {
|
|
78
|
+
if (after[key] !== before[key]) {
|
|
79
|
+
changed[key] = after[key]
|
|
80
|
+
isChanged = true
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return isChanged ? changed : undefined
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const cleanupYogaNode = (node: DOMElement | TextNode): void => {
|
|
89
|
+
const yogaNode = node.yogaNode
|
|
90
|
+
|
|
91
|
+
if (yogaNode) {
|
|
92
|
+
yogaNode.unsetMeasureFunc()
|
|
93
|
+
// Clear all references BEFORE freeing to prevent other code from
|
|
94
|
+
// accessing freed WASM memory during concurrent operations
|
|
95
|
+
clearYogaNodeReferences(node)
|
|
96
|
+
yogaNode.freeRecursive()
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// --
|
|
101
|
+
|
|
102
|
+
type Props = Record<string, unknown>
|
|
103
|
+
|
|
104
|
+
type HostContext = {
|
|
105
|
+
isInsideText: boolean
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function setEventHandler(node: DOMElement, key: string, value: unknown): void {
|
|
109
|
+
if (!node._eventHandlers) {
|
|
110
|
+
node._eventHandlers = {}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
node._eventHandlers[key] = value
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function applyProp(node: DOMElement, key: string, value: unknown): void {
|
|
117
|
+
if (key === 'children') {
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (key === 'style') {
|
|
122
|
+
setStyle(node, value as Styles)
|
|
123
|
+
|
|
124
|
+
if (node.yogaNode) {
|
|
125
|
+
applyStyles(node.yogaNode, value as Styles)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (key === 'textStyles') {
|
|
132
|
+
node.textStyles = value as TextStyles
|
|
133
|
+
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (EVENT_HANDLER_PROPS.has(key)) {
|
|
138
|
+
setEventHandler(node, key, value)
|
|
139
|
+
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
setAttribute(node, key, value as DOMNodeAttribute)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// --
|
|
147
|
+
|
|
148
|
+
export const dispatcher = new Dispatcher()
|
|
149
|
+
|
|
150
|
+
// --- SCROLL PROFILING (bench/scroll-e2e.sh reads via getLastYogaMs) ---
|
|
151
|
+
// Set by onComputeLayout wrapper in ink.tsx; read by onRender for phases.
|
|
152
|
+
let _lastYogaMs = 0
|
|
153
|
+
let _lastCommitMs = 0
|
|
154
|
+
let _commitStart = 0
|
|
155
|
+
|
|
156
|
+
export function recordYogaMs(ms: number): void {
|
|
157
|
+
_lastYogaMs = ms
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function getLastYogaMs(): number {
|
|
161
|
+
return _lastYogaMs
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function markCommitStart(): void {
|
|
165
|
+
_commitStart = performance.now()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function getLastCommitMs(): number {
|
|
169
|
+
return _lastCommitMs
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function resetProfileCounters(): void {
|
|
173
|
+
_lastYogaMs = 0
|
|
174
|
+
_lastCommitMs = 0
|
|
175
|
+
_commitStart = 0
|
|
176
|
+
}
|
|
177
|
+
// --- END ---
|
|
178
|
+
|
|
179
|
+
const reconciler = createReconciler({
|
|
180
|
+
getRootHostContext: () => ({ isInsideText: false }),
|
|
181
|
+
prepareForCommit: () => null,
|
|
182
|
+
preparePortalMount: () => null,
|
|
183
|
+
clearContainer: () => false,
|
|
184
|
+
resetAfterCommit(rootNode: DOMElement) {
|
|
185
|
+
_lastCommitMs = _commitStart > 0 ? performance.now() - _commitStart : 0
|
|
186
|
+
_commitStart = 0
|
|
187
|
+
|
|
188
|
+
if (typeof rootNode.onComputeLayout === 'function') {
|
|
189
|
+
rootNode.onComputeLayout()
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (process.env.NODE_ENV === 'test') {
|
|
193
|
+
if (rootNode.childNodes.length === 0 && rootNode.hasRenderedContent) {
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (rootNode.childNodes.length > 0) {
|
|
198
|
+
rootNode.hasRenderedContent = true
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
rootNode.onImmediateRender?.()
|
|
202
|
+
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
rootNode.onRender?.()
|
|
207
|
+
},
|
|
208
|
+
getChildHostContext(parentHostContext: HostContext, type: ElementNames): HostContext {
|
|
209
|
+
const previousIsInsideText = parentHostContext.isInsideText
|
|
210
|
+
|
|
211
|
+
const isInsideText = type === 'ink-text' || type === 'ink-virtual-text' || type === 'ink-link'
|
|
212
|
+
|
|
213
|
+
if (previousIsInsideText === isInsideText) {
|
|
214
|
+
return parentHostContext
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return { isInsideText }
|
|
218
|
+
},
|
|
219
|
+
shouldSetTextContent: () => false,
|
|
220
|
+
createInstance(
|
|
221
|
+
originalType: ElementNames,
|
|
222
|
+
newProps: Props,
|
|
223
|
+
_root: DOMElement,
|
|
224
|
+
hostContext: HostContext,
|
|
225
|
+
_internalHandle?: unknown
|
|
226
|
+
): DOMElement {
|
|
227
|
+
if (hostContext.isInsideText && originalType === 'ink-box') {
|
|
228
|
+
throw new Error(`<Box> can't be nested inside <Text> component`)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const type = originalType === 'ink-text' && hostContext.isInsideText ? 'ink-virtual-text' : originalType
|
|
232
|
+
|
|
233
|
+
const node = createNode(type)
|
|
234
|
+
|
|
235
|
+
for (const [key, value] of Object.entries(newProps)) {
|
|
236
|
+
applyProp(node, key, value)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return node
|
|
240
|
+
},
|
|
241
|
+
createTextInstance(text: string, _root: DOMElement, hostContext: HostContext): TextNode {
|
|
242
|
+
if (!hostContext.isInsideText) {
|
|
243
|
+
throw new Error(`Text string "${text}" must be rendered inside <Text> component`)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return createTextNode(text)
|
|
247
|
+
},
|
|
248
|
+
resetTextContent() {},
|
|
249
|
+
hideTextInstance(node: TextNode) {
|
|
250
|
+
setTextNodeValue(node, '')
|
|
251
|
+
},
|
|
252
|
+
unhideTextInstance(node: TextNode, text: string) {
|
|
253
|
+
setTextNodeValue(node, text)
|
|
254
|
+
},
|
|
255
|
+
getPublicInstance: (instance: DOMElement): DOMElement => instance,
|
|
256
|
+
hideInstance(node: DOMElement) {
|
|
257
|
+
node.isHidden = true
|
|
258
|
+
node.yogaNode?.setDisplay(LayoutDisplay.None)
|
|
259
|
+
markDirty(node)
|
|
260
|
+
},
|
|
261
|
+
unhideInstance(node: DOMElement) {
|
|
262
|
+
node.isHidden = false
|
|
263
|
+
node.yogaNode?.setDisplay(LayoutDisplay.Flex)
|
|
264
|
+
markDirty(node)
|
|
265
|
+
},
|
|
266
|
+
appendInitialChild: appendChildNode,
|
|
267
|
+
appendChild: appendChildNode,
|
|
268
|
+
insertBefore: insertBeforeNode,
|
|
269
|
+
finalizeInitialChildren(_node: DOMElement, _type: ElementNames, props: Props): boolean {
|
|
270
|
+
return props['autoFocus'] === true
|
|
271
|
+
},
|
|
272
|
+
commitMount(node: DOMElement): void {
|
|
273
|
+
getFocusManager(node).handleAutoFocus(node)
|
|
274
|
+
},
|
|
275
|
+
isPrimaryRenderer: true,
|
|
276
|
+
supportsMutation: true,
|
|
277
|
+
supportsPersistence: false,
|
|
278
|
+
supportsHydration: false,
|
|
279
|
+
scheduleTimeout: setTimeout,
|
|
280
|
+
cancelTimeout: clearTimeout,
|
|
281
|
+
noTimeout: -1,
|
|
282
|
+
getCurrentUpdatePriority: () => dispatcher.currentUpdatePriority,
|
|
283
|
+
beforeActiveInstanceBlur() {},
|
|
284
|
+
afterActiveInstanceBlur() {},
|
|
285
|
+
detachDeletedInstance() {},
|
|
286
|
+
getInstanceFromNode: () => null,
|
|
287
|
+
prepareScopeUpdate() {},
|
|
288
|
+
getInstanceFromScope: () => null,
|
|
289
|
+
appendChildToContainer: appendChildNode,
|
|
290
|
+
insertInContainerBefore: insertBeforeNode,
|
|
291
|
+
removeChildFromContainer(node: DOMElement, removeNode: DOMElement): void {
|
|
292
|
+
removeChildNode(node, removeNode)
|
|
293
|
+
cleanupYogaNode(removeNode)
|
|
294
|
+
getFocusManager(node).handleNodeRemoved(removeNode, node)
|
|
295
|
+
},
|
|
296
|
+
// React 19 commitUpdate receives old and new props directly instead of an updatePayload
|
|
297
|
+
commitUpdate(node: DOMElement, _type: ElementNames, oldProps: Props, newProps: Props): void {
|
|
298
|
+
const props = diff(oldProps, newProps)
|
|
299
|
+
const style = diff(oldProps['style'] as Styles, newProps['style'] as Styles)
|
|
300
|
+
|
|
301
|
+
if (props) {
|
|
302
|
+
for (const [key, value] of Object.entries(props)) {
|
|
303
|
+
if (key === 'style') {
|
|
304
|
+
setStyle(node, value as Styles)
|
|
305
|
+
|
|
306
|
+
continue
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (key === 'textStyles') {
|
|
310
|
+
setTextStyles(node, value as TextStyles)
|
|
311
|
+
|
|
312
|
+
continue
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (EVENT_HANDLER_PROPS.has(key)) {
|
|
316
|
+
setEventHandler(node, key, value)
|
|
317
|
+
|
|
318
|
+
continue
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
setAttribute(node, key, value as DOMNodeAttribute)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (style && node.yogaNode) {
|
|
326
|
+
applyStyles(node.yogaNode, style, newProps['style'] as Styles)
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
commitTextUpdate(node: TextNode, _oldText: string, newText: string): void {
|
|
330
|
+
setTextNodeValue(node, newText)
|
|
331
|
+
},
|
|
332
|
+
removeChild(node: DOMElement, removeNode: DOMElement | TextNode) {
|
|
333
|
+
removeChildNode(node, removeNode)
|
|
334
|
+
cleanupYogaNode(removeNode)
|
|
335
|
+
|
|
336
|
+
if (removeNode.nodeName !== '#text') {
|
|
337
|
+
const root = getRootNode(node)
|
|
338
|
+
root.focusManager!.handleNodeRemoved(removeNode, root)
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
// React 19 required methods
|
|
342
|
+
maySuspendCommit(): boolean {
|
|
343
|
+
return false
|
|
344
|
+
},
|
|
345
|
+
preloadInstance(): boolean {
|
|
346
|
+
return true
|
|
347
|
+
},
|
|
348
|
+
startSuspendingCommit(): void {},
|
|
349
|
+
suspendInstance(): void {},
|
|
350
|
+
waitForCommitToBeReady(): null {
|
|
351
|
+
return null
|
|
352
|
+
},
|
|
353
|
+
NotPendingTransition: null,
|
|
354
|
+
HostTransitionContext: {
|
|
355
|
+
$$typeof: Symbol.for('react.context'),
|
|
356
|
+
_currentValue: null
|
|
357
|
+
} as never,
|
|
358
|
+
setCurrentUpdatePriority(newPriority: number): void {
|
|
359
|
+
dispatcher.currentUpdatePriority = newPriority
|
|
360
|
+
},
|
|
361
|
+
resolveUpdatePriority(): number {
|
|
362
|
+
return dispatcher.resolveEventPriority()
|
|
363
|
+
},
|
|
364
|
+
resetFormInstance(): void {},
|
|
365
|
+
requestPostPaintCallback(): void {},
|
|
366
|
+
shouldAttemptEagerTransition(): boolean {
|
|
367
|
+
return false
|
|
368
|
+
},
|
|
369
|
+
trackSchedulerEvent(): void {},
|
|
370
|
+
resolveEventType(): string | null {
|
|
371
|
+
return dispatcher.currentEvent?.type ?? null
|
|
372
|
+
},
|
|
373
|
+
resolveEventTimeStamp(): number {
|
|
374
|
+
return dispatcher.currentEvent?.timeStamp ?? -1.1
|
|
375
|
+
}
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
// Wire the reconciler's discreteUpdates into the dispatcher.
|
|
379
|
+
// This breaks the import cycle: dispatcher.ts doesn't import reconciler.ts.
|
|
380
|
+
dispatcher.discreteUpdates = reconciler.discreteUpdates.bind(reconciler)
|
|
381
|
+
|
|
382
|
+
export default reconciler
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import cliBoxes, { type Boxes, type BoxStyle } from 'cli-boxes'
|
|
3
|
+
|
|
4
|
+
import { applyColor } from './colorize.js'
|
|
5
|
+
import type { DOMNode } from './dom.js'
|
|
6
|
+
import type Output from './output.js'
|
|
7
|
+
import { stringWidth } from './stringWidth.js'
|
|
8
|
+
import type { Color } from './styles.js'
|
|
9
|
+
|
|
10
|
+
export type BorderTextOptions = {
|
|
11
|
+
content: string // Pre-rendered string with ANSI color codes
|
|
12
|
+
position: 'top' | 'bottom'
|
|
13
|
+
align: 'start' | 'end' | 'center'
|
|
14
|
+
offset?: number // Only used with 'start' or 'end' alignment. Number of characters from the edge.
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const CUSTOM_BORDER_STYLES = {
|
|
18
|
+
dashed: {
|
|
19
|
+
top: '╌',
|
|
20
|
+
left: '╎',
|
|
21
|
+
right: '╎',
|
|
22
|
+
bottom: '╌',
|
|
23
|
+
// there aren't any line-drawing characters for dashes unfortunately
|
|
24
|
+
topLeft: ' ',
|
|
25
|
+
topRight: ' ',
|
|
26
|
+
bottomLeft: ' ',
|
|
27
|
+
bottomRight: ' '
|
|
28
|
+
}
|
|
29
|
+
} as const
|
|
30
|
+
|
|
31
|
+
export type BorderStyle = keyof Boxes | keyof typeof CUSTOM_BORDER_STYLES | BoxStyle
|
|
32
|
+
|
|
33
|
+
function embedTextInBorder(
|
|
34
|
+
borderLine: string,
|
|
35
|
+
text: string,
|
|
36
|
+
align: 'start' | 'end' | 'center',
|
|
37
|
+
offset: number = 0,
|
|
38
|
+
borderChar: string
|
|
39
|
+
): [before: string, text: string, after: string] {
|
|
40
|
+
const textLength = stringWidth(text)
|
|
41
|
+
const borderLength = borderLine.length
|
|
42
|
+
|
|
43
|
+
if (textLength >= borderLength - 2) {
|
|
44
|
+
return ['', text.substring(0, borderLength), '']
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let position: number
|
|
48
|
+
|
|
49
|
+
if (align === 'center') {
|
|
50
|
+
position = Math.floor((borderLength - textLength) / 2)
|
|
51
|
+
} else if (align === 'start') {
|
|
52
|
+
position = offset + 1 // +1 to account for corner character
|
|
53
|
+
} else {
|
|
54
|
+
// align === 'end'
|
|
55
|
+
position = borderLength - textLength - offset - 1 // -1 for corner character
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Ensure position is valid
|
|
59
|
+
position = Math.max(1, Math.min(position, borderLength - textLength - 1))
|
|
60
|
+
|
|
61
|
+
const before = borderLine.substring(0, 1) + borderChar.repeat(position - 1)
|
|
62
|
+
|
|
63
|
+
const after = borderChar.repeat(borderLength - position - textLength - 1) + borderLine.substring(borderLength - 1)
|
|
64
|
+
|
|
65
|
+
return [before, text, after]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function styleBorderLine(line: string, color: Color | undefined, dim: boolean | undefined): string {
|
|
69
|
+
let styled = applyColor(line, color)
|
|
70
|
+
|
|
71
|
+
if (dim) {
|
|
72
|
+
styled = chalk.dim(styled)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return styled
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const renderBorder = (x: number, y: number, node: DOMNode, output: Output): void => {
|
|
79
|
+
if (node.style.borderStyle) {
|
|
80
|
+
const width = Math.floor(node.yogaNode!.getComputedWidth())
|
|
81
|
+
const height = Math.floor(node.yogaNode!.getComputedHeight())
|
|
82
|
+
|
|
83
|
+
const box =
|
|
84
|
+
typeof node.style.borderStyle === 'string'
|
|
85
|
+
? (CUSTOM_BORDER_STYLES[node.style.borderStyle as keyof typeof CUSTOM_BORDER_STYLES] ??
|
|
86
|
+
cliBoxes[node.style.borderStyle as keyof Boxes])
|
|
87
|
+
: node.style.borderStyle
|
|
88
|
+
|
|
89
|
+
const topBorderColor = node.style.borderTopColor ?? node.style.borderColor
|
|
90
|
+
|
|
91
|
+
const bottomBorderColor = node.style.borderBottomColor ?? node.style.borderColor
|
|
92
|
+
|
|
93
|
+
const leftBorderColor = node.style.borderLeftColor ?? node.style.borderColor
|
|
94
|
+
|
|
95
|
+
const rightBorderColor = node.style.borderRightColor ?? node.style.borderColor
|
|
96
|
+
|
|
97
|
+
const dimTopBorderColor = node.style.borderTopDimColor ?? node.style.borderDimColor
|
|
98
|
+
|
|
99
|
+
const dimBottomBorderColor = node.style.borderBottomDimColor ?? node.style.borderDimColor
|
|
100
|
+
|
|
101
|
+
const dimLeftBorderColor = node.style.borderLeftDimColor ?? node.style.borderDimColor
|
|
102
|
+
|
|
103
|
+
const dimRightBorderColor = node.style.borderRightDimColor ?? node.style.borderDimColor
|
|
104
|
+
|
|
105
|
+
const showTopBorder = node.style.borderTop !== false
|
|
106
|
+
const showBottomBorder = node.style.borderBottom !== false
|
|
107
|
+
const showLeftBorder = node.style.borderLeft !== false
|
|
108
|
+
const showRightBorder = node.style.borderRight !== false
|
|
109
|
+
|
|
110
|
+
const contentWidth = Math.max(0, width - (showLeftBorder ? 1 : 0) - (showRightBorder ? 1 : 0))
|
|
111
|
+
|
|
112
|
+
const topBorderLine = showTopBorder
|
|
113
|
+
? (showLeftBorder ? box.topLeft : '') + box.top.repeat(contentWidth) + (showRightBorder ? box.topRight : '')
|
|
114
|
+
: ''
|
|
115
|
+
|
|
116
|
+
// Handle text in top border
|
|
117
|
+
let topBorder: string | undefined
|
|
118
|
+
|
|
119
|
+
if (showTopBorder && node.style.borderText?.position === 'top') {
|
|
120
|
+
const [before, text, after] = embedTextInBorder(
|
|
121
|
+
topBorderLine,
|
|
122
|
+
node.style.borderText.content,
|
|
123
|
+
node.style.borderText.align,
|
|
124
|
+
node.style.borderText.offset,
|
|
125
|
+
box.top
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
topBorder =
|
|
129
|
+
styleBorderLine(before, topBorderColor, dimTopBorderColor) +
|
|
130
|
+
text +
|
|
131
|
+
styleBorderLine(after, topBorderColor, dimTopBorderColor)
|
|
132
|
+
} else if (showTopBorder) {
|
|
133
|
+
topBorder = styleBorderLine(topBorderLine, topBorderColor, dimTopBorderColor)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let verticalBorderHeight = height
|
|
137
|
+
|
|
138
|
+
if (showTopBorder) {
|
|
139
|
+
verticalBorderHeight -= 1
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (showBottomBorder) {
|
|
143
|
+
verticalBorderHeight -= 1
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
verticalBorderHeight = Math.max(0, verticalBorderHeight)
|
|
147
|
+
|
|
148
|
+
let leftBorder = (applyColor(box.left, leftBorderColor) + '\n').repeat(verticalBorderHeight)
|
|
149
|
+
|
|
150
|
+
if (dimLeftBorderColor) {
|
|
151
|
+
leftBorder = chalk.dim(leftBorder)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let rightBorder = (applyColor(box.right, rightBorderColor) + '\n').repeat(verticalBorderHeight)
|
|
155
|
+
|
|
156
|
+
if (dimRightBorderColor) {
|
|
157
|
+
rightBorder = chalk.dim(rightBorder)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const bottomBorderLine = showBottomBorder
|
|
161
|
+
? (showLeftBorder ? box.bottomLeft : '') +
|
|
162
|
+
box.bottom.repeat(contentWidth) +
|
|
163
|
+
(showRightBorder ? box.bottomRight : '')
|
|
164
|
+
: ''
|
|
165
|
+
|
|
166
|
+
// Handle text in bottom border
|
|
167
|
+
let bottomBorder: string | undefined
|
|
168
|
+
|
|
169
|
+
if (showBottomBorder && node.style.borderText?.position === 'bottom') {
|
|
170
|
+
const [before, text, after] = embedTextInBorder(
|
|
171
|
+
bottomBorderLine,
|
|
172
|
+
node.style.borderText.content,
|
|
173
|
+
node.style.borderText.align,
|
|
174
|
+
node.style.borderText.offset,
|
|
175
|
+
box.bottom
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
bottomBorder =
|
|
179
|
+
styleBorderLine(before, bottomBorderColor, dimBottomBorderColor) +
|
|
180
|
+
text +
|
|
181
|
+
styleBorderLine(after, bottomBorderColor, dimBottomBorderColor)
|
|
182
|
+
} else if (showBottomBorder) {
|
|
183
|
+
bottomBorder = styleBorderLine(bottomBorderLine, bottomBorderColor, dimBottomBorderColor)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const offsetY = showTopBorder ? 1 : 0
|
|
187
|
+
|
|
188
|
+
if (topBorder) {
|
|
189
|
+
output.write(x, y, topBorder)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (showLeftBorder) {
|
|
193
|
+
output.write(x, y + offsetY, leftBorder)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (showRightBorder) {
|
|
197
|
+
output.write(x + width - 1, y + offsetY, rightBorder)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (bottomBorder) {
|
|
201
|
+
output.write(x, y + height - 1, bottomBorder)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export default renderBorder
|