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,91 @@
|
|
|
1
|
+
import { EventEmitter } from 'events'
|
|
2
|
+
import React, { useContext, useEffect } from 'react'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
|
|
5
|
+
import StdinContext from './components/StdinContext.js'
|
|
6
|
+
import Text from './components/Text.js'
|
|
7
|
+
import Ink from './ink.js'
|
|
8
|
+
import { DISABLE_MOUSE_TRACKING } from './termio/dec.js'
|
|
9
|
+
|
|
10
|
+
class FakeTty extends EventEmitter {
|
|
11
|
+
chunks: string[] = []
|
|
12
|
+
columns = 80
|
|
13
|
+
rows = 24
|
|
14
|
+
isTTY = true
|
|
15
|
+
isRaw = false
|
|
16
|
+
|
|
17
|
+
ref(): void {}
|
|
18
|
+
unref(): void {}
|
|
19
|
+
read(): null {
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
setEncoding(): this {
|
|
23
|
+
return this
|
|
24
|
+
}
|
|
25
|
+
setRawMode(mode: boolean): this {
|
|
26
|
+
this.isRaw = mode
|
|
27
|
+
return this
|
|
28
|
+
}
|
|
29
|
+
write(chunk: string | Uint8Array, cb?: (err?: Error | null) => void): boolean {
|
|
30
|
+
this.chunks.push(typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString('utf8'))
|
|
31
|
+
cb?.()
|
|
32
|
+
return true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const tick = () => new Promise<void>(resolve => setImmediate(resolve))
|
|
37
|
+
|
|
38
|
+
// A child that grabs the last useInput consumer's raw-mode toggle. Mounting
|
|
39
|
+
// enables raw mode (count 0→1); unmounting disables it (count 1→0), which is
|
|
40
|
+
// the teardown path that must DISABLE_MOUSE_TRACKING so DEC 1003 hover can't
|
|
41
|
+
// leak as cooked-mode `35;col;row M` text over the prompt.
|
|
42
|
+
function RawModeConsumer({ active }: { active: boolean }) {
|
|
43
|
+
const { setRawMode, isRawModeSupported } = useContext(StdinContext)
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!active || !isRawModeSupported) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setRawMode(true)
|
|
51
|
+
|
|
52
|
+
return () => setRawMode(false)
|
|
53
|
+
}, [active, isRawModeSupported, setRawMode])
|
|
54
|
+
|
|
55
|
+
return React.createElement(Text, null, 'x')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('App raw-mode teardown', () => {
|
|
59
|
+
it('disables mouse tracking when the last raw-mode consumer detaches', async () => {
|
|
60
|
+
const stdout = new FakeTty()
|
|
61
|
+
const stdin = new FakeTty()
|
|
62
|
+
const stderr = new FakeTty()
|
|
63
|
+
const ink = new Ink({
|
|
64
|
+
exitOnCtrlC: false,
|
|
65
|
+
patchConsole: false,
|
|
66
|
+
stderr: stderr as unknown as NodeJS.WriteStream,
|
|
67
|
+
stdin: stdin as unknown as NodeJS.ReadStream,
|
|
68
|
+
stdout: stdout as unknown as NodeJS.WriteStream
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
// Mouse tracking is asserted on the alt screen; the teardown path lives in
|
|
72
|
+
// App, independent of who enabled tracking.
|
|
73
|
+
ink.setAltScreenActive(true, 'all')
|
|
74
|
+
ink.render(React.createElement(RawModeConsumer, { active: true }))
|
|
75
|
+
ink.onRender()
|
|
76
|
+
await tick()
|
|
77
|
+
expect(stdin.isRaw).toBe(true)
|
|
78
|
+
|
|
79
|
+
stdout.chunks = []
|
|
80
|
+
|
|
81
|
+
// Drop the consumer → raw-mode count hits 0 → teardown runs.
|
|
82
|
+
ink.render(React.createElement(RawModeConsumer, { active: false }))
|
|
83
|
+
ink.onRender()
|
|
84
|
+
await tick()
|
|
85
|
+
|
|
86
|
+
expect(stdin.isRaw).toBe(false)
|
|
87
|
+
expect(stdout.chunks.join('')).toContain(DISABLE_MOUSE_TRACKING)
|
|
88
|
+
|
|
89
|
+
ink.unmount()
|
|
90
|
+
})
|
|
91
|
+
})
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bidirectional text reordering for terminal rendering.
|
|
3
|
+
*
|
|
4
|
+
* Terminals on Windows do not implement the Unicode Bidi Algorithm,
|
|
5
|
+
* so RTL text (Hebrew, Arabic, etc.) appears reversed. This module
|
|
6
|
+
* applies the bidi algorithm to reorder ClusteredChar arrays from
|
|
7
|
+
* logical order to visual order before Ink's LTR cell placement loop.
|
|
8
|
+
*
|
|
9
|
+
* On macOS terminals (Terminal.app, iTerm2) bidi works natively.
|
|
10
|
+
* Windows Terminal (including WSL) does not implement bidi
|
|
11
|
+
* (https://github.com/microsoft/terminal/issues/538).
|
|
12
|
+
*
|
|
13
|
+
* Detection: Windows Terminal sets WT_SESSION; native Windows cmd/conhost
|
|
14
|
+
* also lacks bidi. We enable bidi reordering when running on Windows or
|
|
15
|
+
* inside Windows Terminal (covers WSL).
|
|
16
|
+
*/
|
|
17
|
+
import bidiFactory from 'bidi-js'
|
|
18
|
+
|
|
19
|
+
type ClusteredChar = {
|
|
20
|
+
value: string
|
|
21
|
+
width: number
|
|
22
|
+
styleId: number
|
|
23
|
+
hyperlink: string | undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let bidiInstance: ReturnType<typeof bidiFactory> | undefined
|
|
27
|
+
let needsSoftwareBidi: boolean | undefined
|
|
28
|
+
|
|
29
|
+
function needsBidi(): boolean {
|
|
30
|
+
if (needsSoftwareBidi === undefined) {
|
|
31
|
+
needsSoftwareBidi =
|
|
32
|
+
process.platform === 'win32' ||
|
|
33
|
+
typeof process.env['WT_SESSION'] === 'string' || // WSL in Windows Terminal
|
|
34
|
+
process.env['TERM_PROGRAM'] === 'vscode' // VS Code integrated terminal (xterm.js)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return needsSoftwareBidi
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getBidi() {
|
|
41
|
+
if (!bidiInstance) {
|
|
42
|
+
bidiInstance = bidiFactory()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return bidiInstance
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Reorder an array of ClusteredChars from logical order to visual order
|
|
50
|
+
* using the Unicode Bidi Algorithm. Active on terminals that lack native
|
|
51
|
+
* bidi support (Windows Terminal, conhost, WSL).
|
|
52
|
+
*
|
|
53
|
+
* Returns the same array on bidi-capable terminals (no-op).
|
|
54
|
+
*/
|
|
55
|
+
export function reorderBidi(characters: ClusteredChar[]): ClusteredChar[] {
|
|
56
|
+
if (!needsBidi() || characters.length === 0) {
|
|
57
|
+
return characters
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Build a plain string from the clustered chars to run through bidi
|
|
61
|
+
const plainText = characters.map(c => c.value).join('')
|
|
62
|
+
|
|
63
|
+
// Check if there are any RTL characters — skip bidi if pure LTR
|
|
64
|
+
if (!hasRTLCharacters(plainText)) {
|
|
65
|
+
return characters
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const bidi = getBidi()
|
|
69
|
+
const { levels } = bidi.getEmbeddingLevels(plainText, 'auto')
|
|
70
|
+
|
|
71
|
+
// Map bidi levels back to ClusteredChar indices.
|
|
72
|
+
// Each ClusteredChar may be multiple code units in the joined string.
|
|
73
|
+
const charLevels: number[] = []
|
|
74
|
+
let offset = 0
|
|
75
|
+
|
|
76
|
+
for (let i = 0; i < characters.length; i++) {
|
|
77
|
+
charLevels.push(levels[offset]!)
|
|
78
|
+
offset += characters[i]!.value.length
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Get reorder segments from bidi-js, but we need to work at the
|
|
82
|
+
// ClusteredChar level, not the string level. We'll implement the
|
|
83
|
+
// standard bidi reordering: find the max level, then for each level
|
|
84
|
+
// from max down to 1, reverse all contiguous runs >= that level.
|
|
85
|
+
const reordered = [...characters]
|
|
86
|
+
const maxLevel = Math.max(...charLevels)
|
|
87
|
+
|
|
88
|
+
for (let level = maxLevel; level >= 1; level--) {
|
|
89
|
+
let i = 0
|
|
90
|
+
|
|
91
|
+
while (i < reordered.length) {
|
|
92
|
+
if (charLevels[i]! >= level) {
|
|
93
|
+
// Find the end of this run
|
|
94
|
+
let j = i + 1
|
|
95
|
+
|
|
96
|
+
while (j < reordered.length && charLevels[j]! >= level) {
|
|
97
|
+
j++
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Reverse the run in both arrays
|
|
101
|
+
reverseRange(reordered, i, j - 1)
|
|
102
|
+
reverseRangeNumbers(charLevels, i, j - 1)
|
|
103
|
+
i = j
|
|
104
|
+
} else {
|
|
105
|
+
i++
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return reordered
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function reverseRange<T>(arr: T[], start: number, end: number): void {
|
|
114
|
+
while (start < end) {
|
|
115
|
+
const temp = arr[start]!
|
|
116
|
+
arr[start] = arr[end]!
|
|
117
|
+
arr[end] = temp
|
|
118
|
+
start++
|
|
119
|
+
end--
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function reverseRangeNumbers(arr: number[], start: number, end: number): void {
|
|
124
|
+
while (start < end) {
|
|
125
|
+
const temp = arr[start]!
|
|
126
|
+
arr[start] = arr[end]!
|
|
127
|
+
arr[end] = temp
|
|
128
|
+
start++
|
|
129
|
+
end--
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Quick check for RTL characters (Hebrew, Arabic, and related scripts).
|
|
135
|
+
* Avoids running the full bidi algorithm on pure-LTR text.
|
|
136
|
+
*/
|
|
137
|
+
function hasRTLCharacters(text: string): boolean {
|
|
138
|
+
// Hebrew: U+0590-U+05FF, U+FB1D-U+FB4F
|
|
139
|
+
// Arabic: U+0600-U+06FF, U+0750-U+077F, U+08A0-U+08FF, U+FB50-U+FDFF, U+FE70-U+FEFF
|
|
140
|
+
// Thaana: U+0780-U+07BF
|
|
141
|
+
// Syriac: U+0700-U+074F
|
|
142
|
+
return /[\u0590-\u05FF\uFB1D-\uFB4F\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0780-\u07BF\u0700-\u074F]/u.test(
|
|
143
|
+
text
|
|
144
|
+
)
|
|
145
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Unified cache eviction for the four hot Ink module-level caches:
|
|
2
|
+
// - widthCache (stringWidth.ts)
|
|
3
|
+
// - wrapCache (wrap-text.ts)
|
|
4
|
+
// - sliceCache (sliceAnsi.ts)
|
|
5
|
+
// - lineWidthCache (line-width-cache.ts)
|
|
6
|
+
//
|
|
7
|
+
// Used by the host (TUI) under memory pressure or on session swap to drop
|
|
8
|
+
// content-keyed entries that won't recur. All caches are content-keyed
|
|
9
|
+
// (not session-keyed), so cross-session sharing is normally beneficial —
|
|
10
|
+
// only evict when memory tightens or when the user explicitly resets.
|
|
11
|
+
|
|
12
|
+
import { evictSliceCache, sliceCacheSize } from '../utils/sliceAnsi.js'
|
|
13
|
+
|
|
14
|
+
import { evictLineWidthCache, lineWidthCacheSize } from './line-width-cache.js'
|
|
15
|
+
import { evictWidthCache, widthCacheSize } from './stringWidth.js'
|
|
16
|
+
import { evictWrapCache, wrapCacheSize } from './wrap-text.js'
|
|
17
|
+
|
|
18
|
+
export interface InkCacheSizes {
|
|
19
|
+
lineWidth: number
|
|
20
|
+
slice: number
|
|
21
|
+
width: number
|
|
22
|
+
wrap: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function inkCacheSizes(): InkCacheSizes {
|
|
26
|
+
return {
|
|
27
|
+
lineWidth: lineWidthCacheSize(),
|
|
28
|
+
slice: sliceCacheSize(),
|
|
29
|
+
width: widthCacheSize(),
|
|
30
|
+
wrap: wrapCacheSize()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type EvictLevel = 'all' | 'half'
|
|
35
|
+
|
|
36
|
+
export function evictInkCaches(level: EvictLevel = 'half'): InkCacheSizes {
|
|
37
|
+
const keep = level === 'half' ? 0.5 : 0
|
|
38
|
+
|
|
39
|
+
evictWidthCache(keep)
|
|
40
|
+
evictWrapCache(keep)
|
|
41
|
+
evictSliceCache(keep)
|
|
42
|
+
evictLineWidthCache(keep)
|
|
43
|
+
|
|
44
|
+
return inkCacheSizes()
|
|
45
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-platform terminal clearing with scrollback support.
|
|
3
|
+
* Detects modern terminals that support ESC[3J for clearing scrollback.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { csi, CURSOR_HOME, ERASE_SCREEN, ERASE_SCROLLBACK } from './termio/csi.js'
|
|
7
|
+
|
|
8
|
+
// HVP (Horizontal Vertical Position) - legacy Windows cursor home
|
|
9
|
+
const CURSOR_HOME_WINDOWS = csi(0, 'f')
|
|
10
|
+
|
|
11
|
+
function isWindowsTerminal(): boolean {
|
|
12
|
+
return process.platform === 'win32' && !!process.env.WT_SESSION
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isMintty(): boolean {
|
|
16
|
+
// mintty 3.1.5+ sets TERM_PROGRAM to 'mintty'
|
|
17
|
+
if (process.env.TERM_PROGRAM === 'mintty') {
|
|
18
|
+
return true
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// GitBash/MSYS2/MINGW use mintty and set MSYSTEM
|
|
22
|
+
if (process.platform === 'win32' && process.env.MSYSTEM) {
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isModernWindowsTerminal(): boolean {
|
|
30
|
+
// Windows Terminal sets WT_SESSION environment variable
|
|
31
|
+
if (isWindowsTerminal()) {
|
|
32
|
+
return true
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// VS Code integrated terminal on Windows with ConPTY support
|
|
36
|
+
if (process.platform === 'win32' && process.env.TERM_PROGRAM === 'vscode' && process.env.TERM_PROGRAM_VERSION) {
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// mintty (GitBash/MSYS2/Cygwin) supports modern escape sequences
|
|
41
|
+
if (isMintty()) {
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns the ANSI escape sequence to clear the terminal including scrollback.
|
|
50
|
+
* Automatically detects terminal capabilities.
|
|
51
|
+
*/
|
|
52
|
+
export function getClearTerminalSequence(): string {
|
|
53
|
+
if (process.platform === 'win32') {
|
|
54
|
+
if (isModernWindowsTerminal()) {
|
|
55
|
+
return ERASE_SCREEN + ERASE_SCROLLBACK + CURSOR_HOME
|
|
56
|
+
} else {
|
|
57
|
+
// Legacy Windows console - can't clear scrollback
|
|
58
|
+
return ERASE_SCREEN + CURSOR_HOME_WINDOWS
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return ERASE_SCREEN + ERASE_SCROLLBACK + CURSOR_HOME
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Clears the terminal screen. On supported terminals, also clears scrollback.
|
|
67
|
+
*/
|
|
68
|
+
export const clearTerminal = getClearTerminalSequence()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
CHALK_USES_RICH_EIGHT_BIT_DOWNGRADE,
|
|
5
|
+
richEightBitColorNumber,
|
|
6
|
+
shouldUseRichEightBitDowngradeForLegacyAppleTerminal
|
|
7
|
+
} from './colorize.js'
|
|
8
|
+
|
|
9
|
+
describe('shouldUseRichEightBitDowngradeForLegacyAppleTerminal', () => {
|
|
10
|
+
it('memoizes the current process decision for render hot paths', () => {
|
|
11
|
+
expect(typeof CHALK_USES_RICH_EIGHT_BIT_DOWNGRADE).toBe('boolean')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('uses Rich-compatible 256-color downgrade on legacy Apple Terminal', () => {
|
|
15
|
+
expect(
|
|
16
|
+
shouldUseRichEightBitDowngradeForLegacyAppleTerminal({ TERM_PROGRAM: 'Apple_Terminal' } as NodeJS.ProcessEnv, 2)
|
|
17
|
+
).toBe(true)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('normalizes Apple Terminal names before matching', () => {
|
|
21
|
+
expect(
|
|
22
|
+
shouldUseRichEightBitDowngradeForLegacyAppleTerminal({ TERM_PROGRAM: ' Apple_Terminal ' } as NodeJS.ProcessEnv, 2)
|
|
23
|
+
).toBe(true)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('does not rewrite when Apple Terminal advertises truecolor', () => {
|
|
27
|
+
expect(
|
|
28
|
+
shouldUseRichEightBitDowngradeForLegacyAppleTerminal(
|
|
29
|
+
{ COLORTERM: 'truecolor', TERM_PROGRAM: 'Apple_Terminal' } as NodeJS.ProcessEnv,
|
|
30
|
+
3
|
|
31
|
+
)
|
|
32
|
+
).toBe(false)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('does not override explicit color environment choices', () => {
|
|
36
|
+
expect(
|
|
37
|
+
shouldUseRichEightBitDowngradeForLegacyAppleTerminal(
|
|
38
|
+
{ FORCE_COLOR: '2', TERM_PROGRAM: 'Apple_Terminal' } as NodeJS.ProcessEnv,
|
|
39
|
+
2
|
|
40
|
+
)
|
|
41
|
+
).toBe(false)
|
|
42
|
+
expect(
|
|
43
|
+
shouldUseRichEightBitDowngradeForLegacyAppleTerminal(
|
|
44
|
+
{ NASTECH_TUI_TRUECOLOR: '1', TERM_PROGRAM: 'Apple_Terminal' } as NodeJS.ProcessEnv,
|
|
45
|
+
3
|
|
46
|
+
)
|
|
47
|
+
).toBe(false)
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
describe('richEightBitColorNumber', () => {
|
|
52
|
+
it('matches Rich downgrade output for default NasTech skin colors', () => {
|
|
53
|
+
expect(richEightBitColorNumber(0xff, 0xd7, 0x00)).toBe(220)
|
|
54
|
+
expect(richEightBitColorNumber(0xff, 0xbf, 0x00)).toBe(214)
|
|
55
|
+
expect(richEightBitColorNumber(0xcd, 0x7f, 0x32)).toBe(173)
|
|
56
|
+
expect(richEightBitColorNumber(0xb8, 0x86, 0x0b)).toBe(136)
|
|
57
|
+
expect(richEightBitColorNumber(0xff, 0xf8, 0xdc)).toBe(230)
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
|
|
3
|
+
import type { Color, TextStyles } from './styles.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* xterm.js (VS Code, Cursor, code-server, Coder) has supported truecolor
|
|
7
|
+
* since 2017, but code-server/Coder containers often don't set
|
|
8
|
+
* COLORTERM=truecolor. chalk's supports-color doesn't recognize
|
|
9
|
+
* TERM_PROGRAM=vscode (it only knows iTerm.app/Apple_Terminal), so it falls
|
|
10
|
+
* through to the -256color regex → level 2. At level 2, chalk.rgb()
|
|
11
|
+
* downgrades to the nearest 6×6×6 cube color: rgb(215,119,87) → idx 174
|
|
12
|
+
* rgb(215,135,135) — washed-out salmon.
|
|
13
|
+
*
|
|
14
|
+
* Gated on level === 2 (not < 3) to respect NO_COLOR / FORCE_COLOR=0 —
|
|
15
|
+
* those yield level 0 and are an explicit "no colors" request. Desktop VS
|
|
16
|
+
* Code sets COLORTERM=truecolor itself, so this is a no-op there (already 3).
|
|
17
|
+
*
|
|
18
|
+
* Must run BEFORE the tmux clamp — if tmux is running inside a VS Code
|
|
19
|
+
* terminal, tmux's passthrough limitation wins and we want level 2.
|
|
20
|
+
*/
|
|
21
|
+
function boostChalkLevelForXtermJs(): boolean {
|
|
22
|
+
if (process.env.TERM_PROGRAM === 'vscode' && chalk.level === 2) {
|
|
23
|
+
chalk.level = 3
|
|
24
|
+
|
|
25
|
+
return true
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function shouldUseRichEightBitDowngradeForLegacyAppleTerminal(
|
|
32
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
33
|
+
level = chalk.level
|
|
34
|
+
): boolean {
|
|
35
|
+
const termProgram = (env.TERM_PROGRAM ?? '').trim()
|
|
36
|
+
const truecolorOverride = /^(?:1|true|yes|on)$/i.test((env.NASTECH_TUI_TRUECOLOR ?? '').trim())
|
|
37
|
+
const advertisesTruecolor = /^(?:truecolor|24bit)$/i.test((env.COLORTERM ?? '').trim())
|
|
38
|
+
|
|
39
|
+
return termProgram === 'Apple_Terminal' && !truecolorOverride && !advertisesTruecolor && !('FORCE_COLOR' in env) && level === 2
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function richEightBitColorNumber(red: number, green: number, blue: number): number {
|
|
43
|
+
const rn = red / 255
|
|
44
|
+
const gn = green / 255
|
|
45
|
+
const bn = blue / 255
|
|
46
|
+
const max = Math.max(rn, gn, bn)
|
|
47
|
+
const min = Math.min(rn, gn, bn)
|
|
48
|
+
const lightness = (max + min) / 2
|
|
49
|
+
const saturation = max === min ? 0 : lightness > 0.5 ? (max - min) / (2 - max - min) : (max - min) / (max + min)
|
|
50
|
+
|
|
51
|
+
if (saturation < 0.15) {
|
|
52
|
+
const gray = Math.round(lightness * 25)
|
|
53
|
+
|
|
54
|
+
return gray === 0 ? 16 : gray === 25 ? 231 : 231 + gray
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const sixRed = red < 95 ? red / 95 : 1 + (red - 95) / 40
|
|
58
|
+
const sixGreen = green < 95 ? green / 95 : 1 + (green - 95) / 40
|
|
59
|
+
const sixBlue = blue < 95 ? blue / 95 : 1 + (blue - 95) / 40
|
|
60
|
+
|
|
61
|
+
return 16 + 36 * Math.round(sixRed) + 6 * Math.round(sixGreen) + Math.round(sixBlue)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* tmux parses truecolor SGR (\e[48;2;r;g;bm) into its cell buffer correctly,
|
|
66
|
+
* but its client-side emitter only re-emits truecolor to the outer terminal if
|
|
67
|
+
* the outer terminal advertises Tc/RGB capability (via terminal-overrides).
|
|
68
|
+
* Default tmux config doesn't set this, so tmux emits the cell to iTerm2/etc
|
|
69
|
+
* WITHOUT the bg sequence — outer terminal's buffer has bg=default → black on
|
|
70
|
+
* dark profiles. Clamping to level 2 makes chalk emit 256-color (\e[48;5;Nm),
|
|
71
|
+
* which tmux passes through cleanly. grey93 (255) is visually identical to
|
|
72
|
+
* rgb(240,240,240).
|
|
73
|
+
*
|
|
74
|
+
* Users who HAVE set `terminal-overrides ,*:Tc` get a technically-unnecessary
|
|
75
|
+
* downgrade, but the visual difference is imperceptible. Querying
|
|
76
|
+
* `tmux show -gv terminal-overrides` to detect this would add a subprocess on
|
|
77
|
+
* startup — not worth it.
|
|
78
|
+
*
|
|
79
|
+
* $TMUX is a pty-lifecycle env var set by tmux itself; it never comes from
|
|
80
|
+
* globalSettings.env, so reading it here is correct. chalk is a singleton, so
|
|
81
|
+
* this clamps ALL truecolor output (fg+bg+hex) across the entire app.
|
|
82
|
+
*/
|
|
83
|
+
function clampChalkLevelForTmux(): boolean {
|
|
84
|
+
if (process.env.TMUX && chalk.level > 2) {
|
|
85
|
+
chalk.level = 2
|
|
86
|
+
|
|
87
|
+
return true
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return false
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Computed once at module load — terminal/tmux environment doesn't change mid-session.
|
|
94
|
+
// Order matters: boost first; then tmux can still clamp RGB to 256.
|
|
95
|
+
// Exported for debugging — tree-shaken if unused.
|
|
96
|
+
export const CHALK_BOOSTED_FOR_XTERMJS = boostChalkLevelForXtermJs()
|
|
97
|
+
export const CHALK_CLAMPED_FOR_TMUX = clampChalkLevelForTmux()
|
|
98
|
+
export const CHALK_USES_RICH_EIGHT_BIT_DOWNGRADE = shouldUseRichEightBitDowngradeForLegacyAppleTerminal()
|
|
99
|
+
|
|
100
|
+
export type ColorType = 'foreground' | 'background'
|
|
101
|
+
|
|
102
|
+
const RGB_REGEX = /^rgb\(\s?(\d+),\s?(\d+),\s?(\d+)\s?\)$/
|
|
103
|
+
const ANSI_REGEX = /^ansi256\(\s?(\d+)\s?\)$/
|
|
104
|
+
const HEX_REGEX = /^#[0-9a-fA-F]{6}$/
|
|
105
|
+
|
|
106
|
+
export const colorize = (str: string, color: string | undefined, type: ColorType): string => {
|
|
107
|
+
if (!color) {
|
|
108
|
+
return str
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (color.startsWith('ansi:')) {
|
|
112
|
+
const value = color.substring('ansi:'.length)
|
|
113
|
+
|
|
114
|
+
switch (value) {
|
|
115
|
+
case 'black':
|
|
116
|
+
return type === 'foreground' ? chalk.black(str) : chalk.bgBlack(str)
|
|
117
|
+
|
|
118
|
+
case 'red':
|
|
119
|
+
return type === 'foreground' ? chalk.red(str) : chalk.bgRed(str)
|
|
120
|
+
|
|
121
|
+
case 'green':
|
|
122
|
+
return type === 'foreground' ? chalk.green(str) : chalk.bgGreen(str)
|
|
123
|
+
|
|
124
|
+
case 'yellow':
|
|
125
|
+
return type === 'foreground' ? chalk.yellow(str) : chalk.bgYellow(str)
|
|
126
|
+
|
|
127
|
+
case 'blue':
|
|
128
|
+
return type === 'foreground' ? chalk.blue(str) : chalk.bgBlue(str)
|
|
129
|
+
|
|
130
|
+
case 'magenta':
|
|
131
|
+
return type === 'foreground' ? chalk.magenta(str) : chalk.bgMagenta(str)
|
|
132
|
+
|
|
133
|
+
case 'cyan':
|
|
134
|
+
return type === 'foreground' ? chalk.cyan(str) : chalk.bgCyan(str)
|
|
135
|
+
|
|
136
|
+
case 'white':
|
|
137
|
+
return type === 'foreground' ? chalk.white(str) : chalk.bgWhite(str)
|
|
138
|
+
|
|
139
|
+
case 'blackBright':
|
|
140
|
+
return type === 'foreground' ? chalk.blackBright(str) : chalk.bgBlackBright(str)
|
|
141
|
+
|
|
142
|
+
case 'redBright':
|
|
143
|
+
return type === 'foreground' ? chalk.redBright(str) : chalk.bgRedBright(str)
|
|
144
|
+
|
|
145
|
+
case 'greenBright':
|
|
146
|
+
return type === 'foreground' ? chalk.greenBright(str) : chalk.bgGreenBright(str)
|
|
147
|
+
|
|
148
|
+
case 'yellowBright':
|
|
149
|
+
return type === 'foreground' ? chalk.yellowBright(str) : chalk.bgYellowBright(str)
|
|
150
|
+
|
|
151
|
+
case 'blueBright':
|
|
152
|
+
return type === 'foreground' ? chalk.blueBright(str) : chalk.bgBlueBright(str)
|
|
153
|
+
|
|
154
|
+
case 'magentaBright':
|
|
155
|
+
return type === 'foreground' ? chalk.magentaBright(str) : chalk.bgMagentaBright(str)
|
|
156
|
+
|
|
157
|
+
case 'cyanBright':
|
|
158
|
+
return type === 'foreground' ? chalk.cyanBright(str) : chalk.bgCyanBright(str)
|
|
159
|
+
|
|
160
|
+
case 'whiteBright':
|
|
161
|
+
return type === 'foreground' ? chalk.whiteBright(str) : chalk.bgWhiteBright(str)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (color.startsWith('#')) {
|
|
166
|
+
if (HEX_REGEX.test(color) && CHALK_USES_RICH_EIGHT_BIT_DOWNGRADE) {
|
|
167
|
+
const value = Number.parseInt(color.slice(1), 16)
|
|
168
|
+
const red = (value >> 16) & 0xff
|
|
169
|
+
const green = (value >> 8) & 0xff
|
|
170
|
+
const blue = value & 0xff
|
|
171
|
+
const ansi = richEightBitColorNumber(red, green, blue)
|
|
172
|
+
|
|
173
|
+
return type === 'foreground' ? chalk.ansi256(ansi)(str) : chalk.bgAnsi256(ansi)(str)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return type === 'foreground' ? chalk.hex(color)(str) : chalk.bgHex(color)(str)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (color.startsWith('ansi256')) {
|
|
180
|
+
const matches = ANSI_REGEX.exec(color)
|
|
181
|
+
|
|
182
|
+
if (!matches) {
|
|
183
|
+
return str
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const value = Number(matches[1])
|
|
187
|
+
|
|
188
|
+
return type === 'foreground' ? chalk.ansi256(value)(str) : chalk.bgAnsi256(value)(str)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (color.startsWith('rgb')) {
|
|
192
|
+
const matches = RGB_REGEX.exec(color)
|
|
193
|
+
|
|
194
|
+
if (!matches) {
|
|
195
|
+
return str
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const firstValue = Number(matches[1])
|
|
199
|
+
const secondValue = Number(matches[2])
|
|
200
|
+
const thirdValue = Number(matches[3])
|
|
201
|
+
|
|
202
|
+
if (CHALK_USES_RICH_EIGHT_BIT_DOWNGRADE) {
|
|
203
|
+
const ansi = richEightBitColorNumber(firstValue, secondValue, thirdValue)
|
|
204
|
+
|
|
205
|
+
return type === 'foreground' ? chalk.ansi256(ansi)(str) : chalk.bgAnsi256(ansi)(str)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return type === 'foreground'
|
|
209
|
+
? chalk.rgb(firstValue, secondValue, thirdValue)(str)
|
|
210
|
+
: chalk.bgRgb(firstValue, secondValue, thirdValue)(str)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return str
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Apply TextStyles to a string using chalk.
|
|
218
|
+
* This is the inverse of parsing ANSI codes - we generate them from structured styles.
|
|
219
|
+
* Theme resolution happens at component layer, not here.
|
|
220
|
+
*/
|
|
221
|
+
export function applyTextStyles(text: string, styles: TextStyles): string {
|
|
222
|
+
let result = text
|
|
223
|
+
|
|
224
|
+
// Apply styles in reverse order of desired nesting.
|
|
225
|
+
// chalk wraps text so later calls become outer wrappers.
|
|
226
|
+
// Desired order (outermost to innermost):
|
|
227
|
+
// background > foreground > text modifiers
|
|
228
|
+
// So we apply: text modifiers first, then foreground, then background last.
|
|
229
|
+
|
|
230
|
+
if (styles.inverse) {
|
|
231
|
+
result = chalk.inverse(result)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (styles.strikethrough) {
|
|
235
|
+
result = chalk.strikethrough(result)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (styles.underline) {
|
|
239
|
+
result = chalk.underline(result)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (styles.italic) {
|
|
243
|
+
result = chalk.italic(result)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (styles.bold) {
|
|
247
|
+
result = chalk.bold(result)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (styles.dim) {
|
|
251
|
+
result = chalk.dim(result)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (styles.color) {
|
|
255
|
+
// Color is now always a raw color value (theme resolution happens at component layer)
|
|
256
|
+
result = colorize(result, styles.color, 'foreground')
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (styles.backgroundColor) {
|
|
260
|
+
// backgroundColor is now always a raw color value
|
|
261
|
+
result = colorize(result, styles.backgroundColor, 'background')
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return result
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Apply a raw color value to text.
|
|
269
|
+
* Theme resolution should happen at component layer, not here.
|
|
270
|
+
*/
|
|
271
|
+
export function applyColor(text: string, color: Color | undefined): string {
|
|
272
|
+
if (!color) {
|
|
273
|
+
return text
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return colorize(text, color, 'foreground')
|
|
277
|
+
}
|