@iaforged/context-code 2.1.7 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/Task.js +1 -1
- package/dist/src/commands/login/login.js +1 -1
- package/dist/src/components/ConsoleOAuthFlow.js +1 -1
- package/dist/src/constants/oauth.js +1 -1
- package/dist/src/context/mailbox.js +1 -1
- package/dist/src/context/voice.js +1 -1
- package/dist/src/hooks/useTerminalSize.js +1 -1
- package/dist/src/ink/Ansi.js +1 -1
- package/dist/src/ink/clearTerminal.js +1 -1
- package/dist/src/ink/colorize.js +1 -1
- package/dist/src/ink/components/App.js +1 -1
- package/dist/src/ink/components/Button.js +1 -1
- package/dist/src/ink/components/ClockContext.js +1 -1
- package/dist/src/ink/components/CursorDeclarationContext.js +1 -1
- package/dist/src/ink/components/Link.js +1 -1
- package/dist/src/ink/components/StdinContext.js +1 -1
- package/dist/src/ink/components/TerminalFocusContext.js +1 -1
- package/dist/src/ink/dom.js +1 -1
- package/dist/src/ink/events/keyboard-event.js +1 -1
- package/dist/src/ink/hit-test.js +1 -1
- package/dist/src/ink/hooks/use-animation-frame.js +1 -1
- package/dist/src/ink/hooks/use-app.js +1 -1
- package/dist/src/ink/hooks/use-input.js +1 -1
- package/dist/src/ink/hooks/use-interval.js +1 -1
- package/dist/src/ink/hooks/use-selection.js +1 -1
- package/dist/src/ink/hooks/use-tab-status.js +1 -1
- package/dist/src/ink/hooks/use-terminal-focus.js +1 -1
- package/dist/src/ink/hooks/use-terminal-title.js +1 -1
- package/dist/src/ink/hooks/use-terminal-viewport.js +1 -1
- package/dist/src/ink/ink.js +1 -1
- package/dist/src/ink/layout/yoga.js +1 -1
- package/dist/src/ink/line-width-cache.js +1 -1
- package/dist/src/ink/log-update.js +1 -1
- package/dist/src/ink/measure-text.js +1 -1
- package/dist/src/ink/output.js +1 -1
- package/dist/src/ink/parse-keypress.js +1 -1
- package/dist/src/ink/reconciler.js +1 -1
- package/dist/src/ink/render-border.js +1 -1
- package/dist/src/ink/render-node-to-output.js +1 -1
- package/dist/src/ink/render-to-screen.js +1 -1
- package/dist/src/ink/renderer.js +1 -1
- package/dist/src/ink/root.js +1 -1
- package/dist/src/ink/screen.js +1 -1
- package/dist/src/ink/searchHighlight.js +1 -1
- package/dist/src/ink/selection.js +1 -1
- package/dist/src/ink/squash-text-nodes.js +1 -1
- package/dist/src/ink/stringWidth.js +1 -1
- package/dist/src/ink/tabstops.js +1 -1
- package/dist/src/ink/terminal.js +1 -1
- package/dist/src/ink/termio/osc.js +1 -1
- package/dist/src/ink/termio/parser.js +1 -1
- package/dist/src/ink/termio/tokenize.js +1 -1
- package/dist/src/ink/useTerminalNotification.js +1 -1
- package/dist/src/ink/warn.js +1 -1
- package/dist/src/ink/widest-line.js +1 -1
- package/dist/src/ink/wrap-text.js +1 -1
- package/dist/src/ink/wrapAnsi.js +1 -1
- package/dist/src/native-ts/yoga-layout/index.js +1 -1
- package/dist/src/schemas/hooks.js +1 -1
- package/dist/src/services/SessionMemory/sessionMemoryUtils.js +1 -1
- package/dist/src/services/api/client.js +1 -1
- package/dist/src/services/api/dumpPrompts.js +1 -1
- package/dist/src/services/api/errorUtils.js +1 -1
- package/dist/src/services/api/promptCacheBreakDetection.js +1 -1
- package/dist/src/services/api/withRetry.js +1 -1
- package/dist/src/services/autoDream/consolidationLock.js +1 -1
- package/dist/src/services/mcp/elicitationHandler.js +1 -1
- package/dist/src/services/mcp/mcpStringUtils.js +1 -1
- package/dist/src/services/mcp/oauthPort.js +1 -1
- package/dist/src/services/mcp/vscodeSdkMcp.js +1 -1
- package/dist/src/services/oauth/client.js +1 -1
- package/dist/src/services/oauth/getOauthProfile.js +1 -1
- package/dist/src/services/objetivo/types.js +1 -1
- package/dist/src/services/rateLimitMocking.js +1 -1
- package/dist/src/services/remoteManagedSettings/syncCacheState.js +1 -1
- package/dist/src/skills/bundledSkills.js +1 -1
- package/dist/src/tasks/DreamTask/DreamTask.js +1 -1
- package/dist/src/tools/AgentTool/agentMemory.js +1 -1
- package/dist/src/tools/AgentTool/forkSubagent.js +1 -1
- package/dist/src/tools/BashTool/BashToolResultMessage.js +1 -1
- package/dist/src/tools/BashTool/UI.js +1 -1
- package/dist/src/tools/BashTool/sedEditParser.js +1 -1
- package/dist/src/tools/BashTool/utils.js +1 -1
- package/dist/src/tools/FileReadTool/imageProcessor.js +1 -1
- package/dist/src/tools/FileReadTool/prompt.js +1 -1
- package/dist/src/tools/ListMcpResourcesTool/ListMcpResourcesTool.js +1 -1
- package/dist/src/tools/ListMcpResourcesTool/UI.js +1 -1
- package/dist/src/tools/MCPTool/MCPTool.js +1 -1
- package/dist/src/tools/MCPTool/UI.js +1 -1
- package/dist/src/tools/McpAuthTool/McpAuthTool.js +1 -1
- package/dist/src/tools/NotebookEditTool/prompt.js +1 -1
- package/dist/src/tools/PowerShellTool/PowerShellTool.js +1 -1
- package/dist/src/tools/PowerShellTool/UI.js +1 -1
- package/dist/src/tools/PowerShellTool/gitSafety.js +1 -1
- package/dist/src/tools/PowerShellTool/modeValidation.js +1 -1
- package/dist/src/tools/PowerShellTool/pathValidation.js +1 -1
- package/dist/src/tools/PowerShellTool/powershellPermissions.js +1 -1
- package/dist/src/tools/PowerShellTool/powershellSecurity.js +1 -1
- package/dist/src/tools/PowerShellTool/prompt.js +1 -1
- package/dist/src/tools/PowerShellTool/readOnlyValidation.js +1 -1
- package/dist/src/tools/REPLTool/constants.js +1 -1
- package/dist/src/tools/REPLTool/primitiveTools.js +1 -1
- package/dist/src/tools/ReadMcpResourceTool/ReadMcpResourceTool.js +1 -1
- package/dist/src/tools/ReadMcpResourceTool/UI.js +1 -1
- package/dist/src/tools/ScheduleCronTool/prompt.js +1 -1
- package/dist/src/tools/SkillTool/prompt.js +1 -1
- package/dist/src/tools/TodoWriteTool/TodoWriteTool.js +1 -1
- package/dist/src/tools/ToolSearchTool/prompt.js +1 -1
- package/dist/src/tools/WebSearchTool/prompt.js +1 -1
- package/dist/src/tools/shared/gitOperationTracking.js +1 -1
- package/dist/src/types/permissions.js +1 -1
- package/dist/src/utils/Cursor.js +1 -1
- package/dist/src/utils/QueryGuard.js +1 -1
- package/dist/src/utils/Shell.js +1 -1
- package/dist/src/utils/ShellCommand.js +1 -1
- package/dist/src/utils/activityManager.js +1 -1
- package/dist/src/utils/advisor.js +1 -1
- package/dist/src/utils/appleTerminalBackup.js +1 -1
- package/dist/src/utils/argumentSubstitution.js +1 -1
- package/dist/src/utils/authFileDescriptor.js +1 -1
- package/dist/src/utils/autoUpdater.js +1 -1
- package/dist/src/utils/background/remote/preconditions.js +1 -1
- package/dist/src/utils/background/remote/remoteSession.js +1 -1
- package/dist/src/utils/bash/ShellSnapshot.js +1 -1
- package/dist/src/utils/bash/ast.js +1 -1
- package/dist/src/utils/bash/bashParser.js +1 -1
- package/dist/src/utils/bash/bashPipeCommand.js +1 -1
- package/dist/src/utils/bash/parser.js +1 -1
- package/dist/src/utils/bash/shellQuote.js +1 -1
- package/dist/src/utils/bash/shellQuoting.js +1 -1
- package/dist/src/utils/billing.js +1 -1
- package/dist/src/utils/caCerts.js +1 -1
- package/dist/src/utils/claudeInChrome/common.js +1 -1
- package/dist/src/utils/claudeInChrome/setupPortable.js +1 -1
- package/dist/src/utils/claudemd.js +1 -1
- package/dist/src/utils/collapseBackgroundBashNotifications.js +1 -1
- package/dist/src/utils/collapseReadSearch.js +1 -1
- package/dist/src/utils/completionCache.js +1 -1
- package/dist/src/utils/computerUse/common.js +1 -1
- package/dist/src/utils/concurrentSessions.js +1 -1
- package/dist/src/utils/context.js +1 -1
- package/dist/src/utils/cron.js +1 -1
- package/dist/src/utils/cronTasks.js +1 -1
- package/dist/src/utils/cwd.js +1 -1
- package/dist/src/utils/debug.js +1 -1
- package/dist/src/utils/debugFilter.js +1 -1
- package/dist/src/utils/detectRepository.js +1 -1
- package/dist/src/utils/diagLogs.js +1 -1
- package/dist/src/utils/diff.js +1 -1
- package/dist/src/utils/directMemberMessage.js +1 -1
- package/dist/src/utils/doctorDiagnostic.js +1 -1
- package/dist/src/utils/dxt/helpers.js +1 -1
- package/dist/src/utils/dxt/zip.js +1 -1
- package/dist/src/utils/earlyInput.js +1 -1
- package/dist/src/utils/editor.js +1 -1
- package/dist/src/utils/effort.js +1 -1
- package/dist/src/utils/embeddedTools.js +1 -1
- package/dist/src/utils/envDynamic.js +1 -1
- package/dist/src/utils/envUtils.js +1 -1
- package/dist/src/utils/execFileNoThrowPortable.js +1 -1
- package/dist/src/utils/execSyncWrapper.js +1 -1
- package/dist/src/utils/exportRenderer.js +1 -1
- package/dist/src/utils/extraUsage.js +1 -1
- package/dist/src/utils/fastMode.js +1 -1
- package/dist/src/utils/fileOperationAnalytics.js +1 -1
- package/dist/src/utils/fileRead.js +1 -1
- package/dist/src/utils/findExecutable.js +1 -1
- package/dist/src/utils/format.js +1 -1
- package/dist/src/utils/frontmatterParser.js +1 -1
- package/dist/src/utils/fsOperations.js +1 -1
- package/dist/src/utils/fullscreen.js +1 -1
- package/dist/src/utils/genericProcessUtils.js +1 -1
- package/dist/src/utils/getWorktreePaths.js +1 -1
- package/dist/src/utils/git/gitConfigParser.js +1 -1
- package/dist/src/utils/git/gitFilesystem.js +1 -1
- package/dist/src/utils/git/gitignore.js +1 -1
- package/dist/src/utils/gitDiff.js +1 -1
- package/dist/src/utils/gitSettings.js +1 -1
- package/dist/src/utils/glob.js +1 -1
- package/dist/src/utils/gracefulShutdown.js +1 -1
- package/dist/src/utils/groupToolUses.js +1 -1
- package/dist/src/utils/handlePromptSubmit.js +1 -1
- package/dist/src/utils/hash.js +1 -1
- package/dist/src/utils/hooks/fileChangedWatcher.js +1 -1
- package/dist/src/utils/hooks/hooksSettings.js +1 -1
- package/dist/src/utils/hooks/registerSkillHooks.js +1 -1
- package/dist/src/utils/hooks/sessionHooks.js +1 -1
- package/dist/src/utils/http.js +1 -1
- package/dist/src/utils/hyperlink.js +1 -1
- package/dist/src/utils/ide.js +1 -1
- package/dist/src/utils/idePathConversion.js +1 -1
- package/dist/src/utils/imagePaste.js +1 -1
- package/dist/src/utils/imageResizer.js +1 -1
- package/dist/src/utils/imageStore.js +1 -1
- package/dist/src/utils/inProcessTeammateHelpers.js +1 -1
- package/dist/src/utils/ink.js +1 -1
- package/dist/src/utils/jetbrains.js +1 -1
- package/dist/src/utils/json.js +1 -1
- package/dist/src/utils/listSessionsImpl.js +1 -1
- package/dist/src/utils/localInstaller.js +1 -1
- package/dist/src/utils/lockfile.js +1 -1
- package/dist/src/utils/logoV2Utils.js +1 -1
- package/dist/src/utils/markdown.js +1 -1
- package/dist/src/utils/mcp/dateTimeParser.js +1 -1
- package/dist/src/utils/mcpOutputStorage.js +1 -1
- package/dist/src/utils/mcpValidation.js +1 -1
- package/dist/src/utils/memoize.js +1 -1
- package/dist/src/utils/memory/types.js +1 -1
- package/dist/src/utils/memoryFileDetection.js +1 -1
- package/dist/src/utils/messageQueueManager.js +1 -1
- package/dist/src/utils/messages/mappers.js +1 -1
- package/dist/src/utils/messages/systemInit.js +1 -1
- package/dist/src/utils/model/antModels.js +1 -1
- package/dist/src/utils/model/check1mAccess.js +1 -1
- package/dist/src/utils/model/contextWindowUpgradeCheck.js +1 -1
- package/dist/src/utils/model/model.js +1 -1
- package/dist/src/utils/model/modelAllowlist.js +1 -1
- package/dist/src/utils/model/modelCapabilities.js +1 -1
- package/dist/src/utils/model/modelOptions.js +1 -1
- package/dist/src/utils/model/modelStrings.js +1 -1
- package/dist/src/utils/model/providerBaseUrls.js +1 -1
- package/dist/src/utils/model/providerCatalog.js +1 -1
- package/dist/src/utils/model/providerModels.js +1 -1
- package/dist/src/utils/model/providerProfiles.js +1 -1
- package/dist/src/utils/model/providerProfilesDb.js +1 -1
- package/dist/src/utils/model/providerSwitch.js +1 -1
- package/dist/src/utils/model/providers.js +1 -1
- package/dist/src/utils/modelCost.js +1 -1
- package/dist/src/utils/modifiers.js +1 -1
- package/dist/src/utils/mtls.js +1 -1
- package/dist/src/utils/nativeInstaller/download.js +1 -1
- package/dist/src/utils/nativeInstaller/installer.js +1 -1
- package/dist/src/utils/nativeInstaller/packageManagers.js +1 -1
- package/dist/src/utils/nativeInstaller/pidLock.js +1 -1
- package/dist/src/utils/notebook.js +1 -1
- package/dist/src/utils/pasteStore.js +1 -1
- package/dist/src/utils/path.js +1 -1
- package/dist/src/utils/permissions/PermissionMode.js +1 -1
- package/dist/src/utils/permissions/PermissionPromptToolResultSchema.js +1 -1
- package/dist/src/utils/permissions/PermissionUpdate.js +1 -1
- package/dist/src/utils/permissions/PermissionUpdateSchema.js +1 -1
- package/dist/src/utils/permissions/autoModeState.js +1 -1
- package/dist/src/utils/permissions/bypassPermissionsKillswitch.js +1 -1
- package/dist/src/utils/permissions/filesystem.js +1 -1
- package/dist/src/utils/permissions/getNextPermissionMode.js +1 -1
- package/dist/src/utils/permissions/pathValidation.js +1 -1
- package/dist/src/utils/permissions/permissionRuleParser.js +1 -1
- package/dist/src/utils/permissions/permissionsDb.js +1 -1
- package/dist/src/utils/permissions/permissionsLoader.js +1 -1
- package/dist/src/utils/permissions/shellRuleMatching.js +1 -1
- package/dist/src/utils/planModeV2.js +1 -1
- package/dist/src/utils/plans.js +1 -1
- package/dist/src/utils/platform.js +1 -1
- package/dist/src/utils/plugins/addDirPluginSettings.js +1 -1
- package/dist/src/utils/plugins/cacheUtils.js +1 -1
- package/dist/src/utils/plugins/dependencyResolver.js +1 -1
- package/dist/src/utils/plugins/fetchTelemetry.js +1 -1
- package/dist/src/utils/plugins/gitAvailability.js +1 -1
- package/dist/src/utils/plugins/hintRecommendation.js +1 -1
- package/dist/src/utils/plugins/installedPluginsManager.js +1 -1
- package/dist/src/utils/plugins/loadPluginAgents.js +1 -1
- package/dist/src/utils/plugins/loadPluginCommands.js +1 -1
- package/dist/src/utils/plugins/loadPluginHooks.js +1 -1
- package/dist/src/utils/plugins/loadPluginOutputStyles.js +1 -1
- package/dist/src/utils/plugins/lspPluginIntegration.js +1 -1
- package/dist/src/utils/plugins/lspRecommendation.js +1 -1
- package/dist/src/utils/plugins/managedPlugins.js +1 -1
- package/dist/src/utils/plugins/marketplaceHelpers.js +1 -1
- package/dist/src/utils/plugins/marketplaceManager.js +1 -1
- package/dist/src/utils/plugins/mcpPluginIntegration.js +1 -1
- package/dist/src/utils/plugins/mcpbHandler.js +1 -1
- package/dist/src/utils/plugins/officialMarketplaceGcs.js +1 -1
- package/dist/src/utils/plugins/officialMarketplaceStartupCheck.js +1 -1
- package/dist/src/utils/plugins/orphanedPluginFilter.js +1 -1
- package/dist/src/utils/plugins/performStartupChecks.js +1 -1
- package/dist/src/utils/plugins/pluginAutoupdate.js +1 -1
- package/dist/src/utils/plugins/pluginBlocklist.js +1 -1
- package/dist/src/utils/plugins/pluginDirectories.js +1 -1
- package/dist/src/utils/plugins/pluginFlagging.js +1 -1
- package/dist/src/utils/plugins/pluginInstallationHelpers.js +1 -1
- package/dist/src/utils/plugins/pluginLoader.js +1 -1
- package/dist/src/utils/plugins/pluginOptionsStorage.js +1 -1
- package/dist/src/utils/plugins/pluginPolicy.js +1 -1
- package/dist/src/utils/plugins/pluginStartupCheck.js +1 -1
- package/dist/src/utils/plugins/pluginVersioning.js +1 -1
- package/dist/src/utils/plugins/reconciler.js +1 -1
- package/dist/src/utils/plugins/refresh.js +1 -1
- package/dist/src/utils/plugins/schemas.js +1 -1
- package/dist/src/utils/plugins/walkPluginMarkdown.js +1 -1
- package/dist/src/utils/plugins/zipCache.js +1 -1
- package/dist/src/utils/powershell/parser.js +1 -1
- package/dist/src/utils/processUserInput/processBashCommand.js +1 -1
- package/dist/src/utils/processUserInput/processSlashCommand.js +1 -1
- package/dist/src/utils/processUserInput/processTextPrompt.js +1 -1
- package/dist/src/utils/processUserInput/processUserInput.js +1 -1
- package/dist/src/utils/profilerBase.js +1 -1
- package/dist/src/utils/promptCategory.js +1 -1
- package/dist/src/utils/promptEditor.js +1 -1
- package/dist/src/utils/promptShellExecution.js +1 -1
- package/dist/src/utils/proxy.js +1 -1
- package/dist/src/utils/queryHelpers.js +1 -1
- package/dist/src/utils/queryProfiler.js +1 -1
- package/dist/src/utils/queueProcessor.js +1 -1
- package/dist/src/utils/readFileInRange.js +1 -1
- package/dist/src/utils/releaseNotes.js +1 -1
- package/dist/src/utils/renderOptions.js +1 -1
- package/dist/src/utils/ripgrep.js +1 -1
- package/dist/src/utils/sandbox/sandbox-adapter.js +1 -1
- package/dist/src/utils/sdkEventQueue.js +1 -1
- package/dist/src/utils/secureStorage/index.js +1 -1
- package/dist/src/utils/secureStorage/macOsKeychainHelpers.js +1 -1
- package/dist/src/utils/secureStorage/macOsKeychainStorage.js +1 -1
- package/dist/src/utils/secureStorage/plainTextStorage.js +1 -1
- package/dist/src/utils/secureStorage/sqliteStorage.js +1 -1
- package/dist/src/utils/sessionEnvironment.js +1 -1
- package/dist/src/utils/sessionIngressAuth.js +1 -1
- package/dist/src/utils/sessionRestore.js +1 -1
- package/dist/src/utils/sessionStart.js +1 -1
- package/dist/src/utils/sessionTitle.js +1 -1
- package/dist/src/utils/settings/managedPath.js +1 -1
- package/dist/src/utils/settings/mdm/rawRead.js +1 -1
- package/dist/src/utils/settings/mdm/settings.js +1 -1
- package/dist/src/utils/settings/permissionValidation.js +1 -1
- package/dist/src/utils/settings/pluginOnlyPolicy.js +1 -1
- package/dist/src/utils/settings/schemaOutput.js +1 -1
- package/dist/src/utils/settings/settings.js +1 -1
- package/dist/src/utils/settings/types.js +1 -1
- package/dist/src/utils/settings/validateEditTool.js +1 -1
- package/dist/src/utils/settings/validation.js +1 -1
- package/dist/src/utils/shell/bashProvider.js +1 -1
- package/dist/src/utils/shell/powershellDetection.js +1 -1
- package/dist/src/utils/shell/powershellProvider.js +1 -1
- package/dist/src/utils/shell/readOnlyCommandValidation.js +1 -1
- package/dist/src/utils/shell/resolveDefaultShell.js +1 -1
- package/dist/src/utils/shell/shellToolUtils.js +1 -1
- package/dist/src/utils/shell/specPrefix.js +1 -1
- package/dist/src/utils/shellConfig.js +1 -1
- package/dist/src/utils/sideQuestion.js +1 -1
- package/dist/src/utils/skills/skillChangeDetector.js +1 -1
- package/dist/src/utils/slashCommandParsing.js +1 -1
- package/dist/src/utils/sliceAnsi.js +1 -1
- package/dist/src/utils/slowOperations.js +1 -1
- package/dist/src/utils/standaloneAgent.js +1 -1
- package/dist/src/utils/startupProfiler.js +1 -1
- package/dist/src/utils/staticRender.js +1 -1
- package/dist/src/utils/status.js +1 -1
- package/dist/src/utils/statusNoticeDefinitions.js +1 -1
- package/dist/src/utils/suggestions/commandSuggestions.js +1 -1
- package/dist/src/utils/suggestions/directoryCompletion.js +1 -1
- package/dist/src/utils/suggestions/shellHistoryCompletion.js +1 -1
- package/dist/src/utils/suggestions/skillUsageTracking.js +1 -1
- package/dist/src/utils/suggestions/slackChannelSuggestions.js +1 -1
- package/dist/src/utils/swarm/backends/detection.js +1 -1
- package/dist/src/utils/swarm/permissionSync.js +1 -1
- package/dist/src/utils/swarm/reconnection.js +1 -1
- package/dist/src/utils/swarm/spawnUtils.js +1 -91
- package/dist/src/utils/swarm/teammateInit.js +1 -1
- package/dist/src/utils/systemDirectories.js +1 -1
- package/dist/src/utils/systemPrompt.js +1 -1
- package/dist/src/utils/systemTheme.js +1 -1
- package/dist/src/utils/task/TaskOutput.js +1 -1
- package/dist/src/utils/task/diskOutput.js +1 -1
- package/dist/src/utils/tasks.js +1 -1
- package/dist/src/utils/teamDiscovery.js +1 -1
- package/dist/src/utils/teamMemoryOps.js +1 -1
- package/dist/src/utils/teammateMailbox.js +1 -1
- package/dist/src/utils/telemetry/betaSessionTracing.js +1 -1
- package/dist/src/utils/telemetry/bigqueryExporter.js +1 -1
- package/dist/src/utils/telemetry/events.js +1 -1
- package/dist/src/utils/telemetry/instrumentation.js +1 -1
- package/dist/src/utils/telemetry/logger.js +1 -1
- package/dist/src/utils/telemetry/perfettoTracing.js +1 -1
- package/dist/src/utils/telemetry/pluginTelemetry.js +1 -1
- package/dist/src/utils/telemetry/sessionTracing.js +1 -1
- package/dist/src/utils/telemetryAttributes.js +1 -1
- package/dist/src/utils/teleport/api.js +1 -1
- package/dist/src/utils/teleport/environments.js +1 -1
- package/dist/src/utils/teleport/gitBundle.js +1 -1
- package/dist/src/utils/teleport.js +1 -1
- package/dist/src/utils/tempfile.js +1 -1
- package/dist/src/utils/terminal.js +1 -1
- package/dist/src/utils/terminalPanel.js +1 -1
- package/dist/src/utils/textHighlighting.js +1 -1
- package/dist/src/utils/theme.js +1 -1
- package/dist/src/utils/themes/bootstrap.js +1 -1
- package/dist/src/utils/themes/loader.js +1 -1
- package/dist/src/utils/thinking.js +1 -1
- package/dist/src/utils/tmuxSocket.js +1 -1
- package/dist/src/utils/tokens.js +1 -1
- package/dist/src/utils/toolPool.js +1 -1
- package/dist/src/utils/toolResultStorage.js +1 -1
- package/dist/src/utils/transcriptSearch.js +1 -1
- package/dist/src/utils/truncate.js +1 -1
- package/dist/src/utils/ultraplan/keyword.js +1 -1
- package/dist/src/utils/unaryLogging.js +1 -1
- package/dist/src/utils/undercover.js +1 -1
- package/dist/src/utils/user.js +1 -1
- package/dist/src/utils/userPromptKeywords.js +1 -1
- package/dist/src/utils/which.js +1 -1
- package/dist/src/utils/windowsPaths.js +1 -1
- package/dist/src/utils/worktree.js +1 -1
- package/dist/src/utils/zodToJsonSchema.js +1 -1
- package/dist/src/vim/operators.js +1 -1
- package/dist/src/vim/textObjects.js +1 -1
- package/dist/src/vim/transitions.js +1 -1
- package/dist/src/voice/voiceModeEnabled.js +1 -1
- package/dist/src/webapp/auth.js +1 -1
- package/dist/src/webapp/tunnel.js +1 -1
- package/dist/src/whatsapp/bridge.js +1 -1
- package/dist/src/whatsapp/mirror.js +1 -1
- package/package.json +41 -3
package/dist/src/ink/ink.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import t from"auto-bind";import{closeSync as s,constants as i,openSync as o,readSync as r,writeSync as n}from"fs";import a from"lodash-es/noop.js";import h from"lodash-es/throttle.js";import{ConcurrentRoot as l}from"react-reconciler/constants.js";import{onExit as c}from"signal-exit";import{flushInteractionTime as d}from"src/bootstrap/state.js";import{getYogaCounters as u}from"src/native-ts/yoga-layout/index.js";import{logForDebugging as m}from"src/utils/debug.js";import{logError as p}from"src/utils/log.js";import{format as f}from"util";import{colorize as g}from"./colorize.js";import S from"./components/App.js";import{FRAME_INTERVAL_MS as y}from"./constants.js";import*as w from"./dom.js";import{KeyboardEvent as P}from"./events/keyboard-event.js";import{FocusManager as v}from"./focus.js";import{emptyFrame as C}from"./frame.js";import{dispatchClick as R,dispatchHover as T}from"./hit-test.js";import F from"./instances.js";import{LogUpdate as k}from"./log-update.js";import{nodeCache as A}from"./node-cache.js";import{optimize as E}from"./optimizer.js";import b from"./output.js";import M,{dispatcher as N,getLastCommitMs as x,getLastYogaMs as j,isDebugRepaintsEnabled as H,recordYogaMs as L,resetProfileCounters as Y}from"./reconciler.js";import O,{consumeFollowScroll as _,didLayoutShift as D}from"./render-node-to-output.js";import{applyPositionedHighlight as B,scanPositions as $}from"./render-to-screen.js";import U from"./renderer.js";import{CharPool as I,cellAt as z,createScreen as K,HyperlinkPool as W,isEmptyCellAt as Q,migrateScreenPools as G,StylePool as X}from"./screen.js";import{applySearchHighlight as q}from"./searchHighlight.js";import{applySelectionOverlay as J,captureScrolledRows as V,clearSelection as Z,createSelectionState as ee,extendSelection as te,findPlainTextUrlAt as se,getSelectedText as ie,hasSelection as oe,moveFocus as re,selectLineAt as ne,selectWordAt as ae,shiftAnchor as he,shiftSelection as le,shiftSelectionForFollow as ce,startSelection as de,updateSelection as ue}from"./selection.js";import{SYNC_OUTPUT_SUPPORTED as me,supportsExtendedKeys as pe,writeDiffToTerminal as fe}from"./terminal.js";import{CURSOR_HOME as ge,cursorMove as Se,cursorPosition as ye,DISABLE_KITTY_KEYBOARD as we,DISABLE_MODIFY_OTHER_KEYS as Pe,ENABLE_KITTY_KEYBOARD as ve,ENABLE_MODIFY_OTHER_KEYS as Ce,ERASE_SCREEN as Re}from"./termio/csi.js";import{DBP as Te,DFE as Fe,DISABLE_MOUSE_TRACKING as ke,ENABLE_MOUSE_TRACKING as Ae,ENTER_ALT_SCREEN as Ee,EXIT_ALT_SCREEN as be,SHOW_CURSOR as Me}from"./termio/dec.js";import{CLEAR_ITERM2_PROGRESS as Ne,CLEAR_TAB_STATUS as xe,setClipboard as je,supportsTabStatus as He,wrapForMultiplexer as Le}from"./termio/osc.js";import{TerminalWriteProvider as Ye}from"./useTerminalNotification.js";const Oe=Object.freeze({x:0,y:0,visible:!1}),_e=Object.freeze({type:"stdout",content:ge}),De=Object.freeze({type:"stdout",content:Re+ge});function makeAltScreenParkPatch(e){return Object.freeze({type:"stdout",content:ye(e,1)})}export default class Ink{options;log;terminal;scheduleRender;isUnmounted=!1;isPaused=!1;container;rootNode;focusManager;renderer;stylePool;charPool;hyperlinkPool;exitPromise;restoreConsole;restoreStderr;unsubscribeTTYHandlers;terminalColumns;terminalRows;currentNode=null;frontFrame;backFrame;lastPoolResetTime=performance.now();drainTimer=null;lastYogaCounters={ms:0,visited:0,measured:0,cacheHits:0,live:0};altScreenParkPatch;selection=ee();searchHighlightQuery="";searchPositions=null;selectionListeners=new Set;hoveredNodes=new Set;altScreenActive=!1;altScreenMouseTracking=!1;prevFrameContaminated=!1;needsEraseBeforePaint=!1;cursorDeclaration=null;displayCursor=null;constructor(e){this.options=e,t(this),this.options.patchConsole&&(this.restoreConsole=this.patchConsole(),this.restoreStderr=this.patchStderr()),this.terminal={stdout:e.stdout,stderr:e.stderr},this.terminalColumns=e.stdout.columns||80,this.terminalRows=e.stdout.rows||24,this.altScreenParkPatch=makeAltScreenParkPatch(this.terminalRows),this.stylePool=new X,this.charPool=new I,this.hyperlinkPool=new W,this.frontFrame=C(this.terminalRows,this.terminalColumns,this.stylePool,this.charPool,this.hyperlinkPool),this.backFrame=C(this.terminalRows,this.terminalColumns,this.stylePool,this.charPool,this.hyperlinkPool),this.log=new k({isTTY:e.stdout.isTTY||!1,stylePool:this.stylePool}),this.scheduleRender=h(()=>queueMicrotask(this.onRender),y,{leading:!0,trailing:!0}),this.isUnmounted=!1,this.unsubscribeExit=c(this.unmount,{alwaysLast:!1}),e.stdout.isTTY&&(e.stdout.on("resize",this.handleResize),process.on("SIGCONT",this.handleResume),this.unsubscribeTTYHandlers=()=>{e.stdout.off("resize",this.handleResize),process.off("SIGCONT",this.handleResume)}),this.rootNode=w.createNode("ink-root"),this.focusManager=new v((e,t)=>N.dispatchDiscrete(e,t)),this.rootNode.focusManager=this.focusManager,this.renderer=U(this.rootNode,this.stylePool),this.rootNode.onRender=this.scheduleRender,this.rootNode.onImmediateRender=this.onRender,this.rootNode.onComputeLayout=()=>{if(!this.isUnmounted&&this.rootNode.yogaNode){const e=performance.now();this.rootNode.yogaNode.setWidth(this.terminalColumns),this.rootNode.yogaNode.calculateLayout(this.terminalColumns);const t=performance.now()-e;L(t);const s=u();this.lastYogaCounters={ms:t,...s}}},this.container=M.createContainer(this.rootNode,l,null,!1,null,"id",a,a,a,a)}handleResume=()=>{this.options.stdout.isTTY&&(this.altScreenActive?this.reenterAltScreen():(this.frontFrame=C(this.frontFrame.viewport.height,this.frontFrame.viewport.width,this.stylePool,this.charPool,this.hyperlinkPool),this.backFrame=C(this.backFrame.viewport.height,this.backFrame.viewport.width,this.stylePool,this.charPool,this.hyperlinkPool),this.log.reset(),this.displayCursor=null))};handleResize=()=>{const e=this.options.stdout.columns||80,t=this.options.stdout.rows||24;e===this.terminalColumns&&t===this.terminalRows||(this.terminalColumns=e,this.terminalRows=t,this.altScreenParkPatch=makeAltScreenParkPatch(this.terminalRows),this.altScreenActive&&!this.isPaused&&this.options.stdout.isTTY&&(this.altScreenMouseTracking&&this.options.stdout.write(Ae),this.resetFramesForAltScreen(),this.needsEraseBeforePaint=!0),null!==this.currentNode&&this.render(this.currentNode))};resolveExitPromise=()=>{};rejectExitPromise=()=>{};unsubscribeExit=()=>{};enterAlternateScreen(){this.pause(),this.suspendStdin(),this.options.stdout.write(we+Pe+(this.altScreenMouseTracking?ke:"")+(this.altScreenActive?"":"[?1049h")+"[?1004l[0m[?25h[2J[H")}exitAlternateScreen(){this.options.stdout.write((this.altScreenActive?Ee:"")+"[2J[H"+(this.altScreenMouseTracking?Ae:"")+(this.altScreenActive?"":"[?1049l")+"[?25l"),this.resumeStdin(),this.altScreenActive?this.resetFramesForAltScreen():this.repaint(),this.resume(),this.options.stdout.write("[?1004h"+(pe()?we+ve+Ce:""))}onRender(){if(this.isUnmounted||this.isPaused)return;null!==this.drainTimer&&(clearTimeout(this.drainTimer),this.drainTimer=null),d();const e=performance.now(),t=this.options.stdout.columns||80,s=this.options.stdout.rows||24,i=this.renderer({frontFrame:this.frontFrame,backFrame:this.backFrame,isTTY:this.options.stdout.isTTY,terminalWidth:t,terminalRows:s,altScreen:this.altScreenActive,prevFrameContaminated:this.prevFrameContaminated}),o=performance.now()-e,r=_();if(r&&this.selection.anchor&&this.selection.anchor.row>=r.viewportTop&&this.selection.anchor.row<=r.viewportBottom){const{delta:e,viewportTop:t,viewportBottom:s}=r;if(this.selection.isDragging)oe(this.selection)&&V(this.selection,this.frontFrame.screen,t,t+e-1,"above"),he(this.selection,-e,t,s);else if((!this.selection.focus||this.selection.focus.row>=t&&this.selection.focus.row<=s)&&(oe(this.selection)&&V(this.selection,this.frontFrame.screen,t,t+e-1,"above"),ce(this.selection,-e,t,s)))for(const e of this.selectionListeners)e()}let n=!1,a=!1;if(this.altScreenActive&&(n=oe(this.selection),n&&J(i.screen,this.selection,this.stylePool),a=q(i.screen,this.searchHighlightQuery,this.stylePool),this.searchPositions)){const e=this.searchPositions,t=B(i.screen,this.stylePool,e.positions,e.rowOffset,e.currentIdx);a=a||t}(D()||n||a||this.prevFrameContaminated)&&(i.screen.damage={x:0,y:0,width:i.screen.width,height:i.screen.height});let h=this.frontFrame;this.altScreenActive&&(h={...this.frontFrame,cursor:Oe});const l=performance.now(),c=this.log.render(h,i,this.altScreenActive,me),u=performance.now()-l;this.backFrame=this.frontFrame,this.frontFrame=i,e-this.lastPoolResetTime>3e5&&(this.resetPools(),this.lastPoolResetTime=e);const p=[];for(const e of c)if("clearTerminal"===e.type&&(p.push({desiredHeight:i.screen.height,availableHeight:i.viewport.height,reason:e.reason}),H()&&e.debug)){const t=w.findOwnerChainAtRow(this.rootNode,e.debug.triggerY);m(`[REPAINT] full reset · ${e.reason} · row ${e.debug.triggerY}\n prev: "${e.debug.prevLine}"\n next: "${e.debug.nextLine}"\n culprit: ${t.length?t.join(" < "):"(no owner chain captured)"}`,{level:"warn"})}const f=performance.now(),g=E(c),S=performance.now()-f,P=g.length>0;this.altScreenActive&&P&&(this.needsEraseBeforePaint?(this.needsEraseBeforePaint=!1,g.unshift(De)):g.unshift(_e),g.push(this.altScreenParkPatch));const v=this.cursorDeclaration,C=null!==v?A.get(v.node):void 0,R=null!==v&&void 0!==C?{x:C.x+v.relativeX,y:C.y+v.relativeY}:null,T=this.displayCursor,F=null!==R&&(null===T||T.x!==R.x||T.y!==R.y);if(P||F||null===R&&null!==T){if(null!==T&&!this.altScreenActive&&P){const e=h.cursor.x-T.x,t=h.cursor.y-T.y;0===e&&0===t||g.unshift({type:"stdout",content:Se(e,t)})}if(null!==R){if(this.altScreenActive){const e=Math.min(Math.max(R.y+1,1),s),i=Math.min(Math.max(R.x+1,1),t);g.push({type:"stdout",content:ye(e,i)})}else{const e=P||null===T?{x:i.cursor.x,y:i.cursor.y}:T,t=R.x-e.x,s=R.y-e.y;0===t&&0===s||g.push({type:"stdout",content:Se(t,s)})}this.displayCursor=R}else{if(null!==T&&!this.altScreenActive&&!P){const e=i.cursor.x-T.x,t=i.cursor.y-T.y;0===e&&0===t||g.push({type:"stdout",content:Se(e,t)})}this.displayCursor=null}}const k=performance.now();fe(this.terminal,g,this.altScreenActive&&!me);const b=performance.now()-k;this.prevFrameContaminated=n||a,i.scrollDrainPending&&(this.drainTimer=setTimeout(()=>this.onRender(),y>>2));const M=j(),N=x(),L=this.lastYogaCounters;Y(),this.lastYogaCounters={ms:0,visited:0,measured:0,cacheHits:0,live:0},this.options.onFrame?.({durationMs:performance.now()-e,phases:{renderer:o,diff:u,optimize:S,write:b,patches:c.length,yoga:M,commit:N,yogaVisited:L.visited,yogaMeasured:L.measured,yogaCacheHits:L.cacheHits,yogaLive:L.live},flickers:p})}pause(){M.flushSyncFromReconciler(),this.onRender(),this.isPaused=!0}resume(){this.isPaused=!1,this.onRender()}repaint(){this.frontFrame=C(this.frontFrame.viewport.height,this.frontFrame.viewport.width,this.stylePool,this.charPool,this.hyperlinkPool),this.backFrame=C(this.backFrame.viewport.height,this.backFrame.viewport.width,this.stylePool,this.charPool,this.hyperlinkPool),this.log.reset(),this.displayCursor=null}forceRedraw(){!this.options.stdout.isTTY||this.isUnmounted||this.isPaused||(this.options.stdout.write(Re+ge),this.altScreenActive?this.resetFramesForAltScreen():(this.repaint(),this.prevFrameContaminated=!0),this.onRender())}invalidatePrevFrame(){this.prevFrameContaminated=!0}setAltScreenActive(e,t=!1){this.altScreenActive!==e&&(this.altScreenActive=e,this.altScreenMouseTracking=e&&t,e?this.resetFramesForAltScreen():this.repaint())}get isAltScreenActive(){return this.altScreenActive}reassertTerminalModes=(e=!1)=>{this.options.stdout.isTTY&&(this.isPaused||(pe()&&this.options.stdout.write(we+ve+Ce),this.altScreenActive&&(this.altScreenMouseTracking&&this.options.stdout.write(Ae),e&&this.reenterAltScreen())))};detachForShutdown(){this.isUnmounted=!0,this.scheduleRender.cancel?.();const e=this.options.stdin;this.drainStdin(),e.isTTY&&e.isRaw&&e.setRawMode&&e.setRawMode(!1)}drainStdin(){drainStdin(this.options.stdin)}reenterAltScreen(){this.options.stdout.write(Ee+Re+ge+(this.altScreenMouseTracking?Ae:"")),this.resetFramesForAltScreen()}resetFramesForAltScreen(){const e=this.terminalRows,t=this.terminalColumns,blank=()=>({screen:K(t,e,this.stylePool,this.charPool,this.hyperlinkPool),viewport:{width:t,height:e+1},cursor:{x:0,y:0,visible:!0}});this.frontFrame=blank(),this.backFrame=blank(),this.log.reset(),this.displayCursor=null,this.prevFrameContaminated=!0}copySelectionNoClear(){if(!oe(this.selection))return"";const e=ie(this.selection,this.frontFrame.screen);return e&&je(e).then(e=>{e&&this.options.stdout.write(e)}),e}copySelection(){if(!oe(this.selection))return"";const e=this.copySelectionNoClear();return Z(this.selection),this.notifySelectionChange(),e}clearTextSelection(){oe(this.selection)&&(Z(this.selection),this.notifySelectionChange())}setSearchHighlight(e){this.searchHighlightQuery!==e&&(this.searchHighlightQuery=e,this.scheduleRender())}scanElementSubtree(e){if(!this.searchHighlightQuery||!e.yogaNode)return[];const t=Math.ceil(e.yogaNode.getComputedWidth()),s=Math.ceil(e.yogaNode.getComputedHeight());if(t<=0||s<=0)return[];const i=e.yogaNode.getComputedLeft(),o=e.yogaNode.getComputedTop(),r=K(t,s,this.stylePool,this.charPool,this.hyperlinkPool),n=new b({width:t,height:s,stylePool:this.stylePool,screen:r});O(e,n,{offsetX:-i,offsetY:-o,prevScreen:void 0});const a=n.get();w.markDirty(e);const h=$(a,this.searchHighlightQuery);return m(`scanElementSubtree: q='${this.searchHighlightQuery}' el=${t}x${s}@(${i},${o}) n=${h.length} [${h.slice(0,10).map(e=>`${e.row}:${e.col}`).join(",")}`+(h.length>10?",…":"")+"]"),h}setSearchPositions(e){this.searchPositions=e,this.scheduleRender()}setSelectionBgColor(e){const t=g("\0",e,"background"),s=t.indexOf("\0");s<=0||s===t.length-1?this.stylePool.setSelectionBg(null):this.stylePool.setSelectionBg({type:"ansi",code:t.slice(0,s),endCode:t.slice(s+1)})}captureScrolledRows(e,t,s){V(this.selection,this.frontFrame.screen,e,t,s)}shiftSelectionForScroll(e,t,s){const i=oe(this.selection);le(this.selection,e,t,s,this.frontFrame.screen.width),i&&!oe(this.selection)&&this.notifySelectionChange()}moveSelectionFocus(e){if(!this.altScreenActive)return;const{focus:t}=this.selection;if(!t)return;const{width:s,height:i}=this.frontFrame.screen,o=s-1,r=i-1;let{col:n,row:a}=t;switch(e){case"left":n>0?n--:a>0&&(n=o,a--);break;case"right":n<o?n++:a<r&&(n=0,a++);break;case"up":a>0&&a--;break;case"down":a<r&&a++;break;case"lineStart":n=0;break;case"lineEnd":n=o}n===t.col&&a===t.row||(re(this.selection,n,a),this.notifySelectionChange())}hasTextSelection(){return oe(this.selection)}subscribeToSelectionChange(e){return this.selectionListeners.add(e),()=>this.selectionListeners.delete(e)}notifySelectionChange(){this.onRender();for(const e of this.selectionListeners)e()}dispatchClick(e,t){if(!this.altScreenActive)return!1;const s=Q(this.frontFrame.screen,e,t);return R(this.rootNode,e,t,s)}dispatchHover(e,t){this.altScreenActive&&T(this.rootNode,e,t,this.hoveredNodes)}dispatchKeyboardEvent(e){const t=this.focusManager.activeElement??this.rootNode,s=new P(e);N.dispatchDiscrete(t,s),s.defaultPrevented||"tab"!==e.name||e.ctrl||e.meta||(e.shift?this.focusManager.focusPrevious(this.rootNode):this.focusManager.focusNext(this.rootNode))}getHyperlinkAt(e,t){if(!this.altScreenActive)return;const s=this.frontFrame.screen,i=z(s,e,t);let o=i?.hyperlink;return!o&&2===i?.width&&e>0&&(o=z(s,e-1,t)?.hyperlink),o??se(s,e,t)}onHyperlinkClick;openHyperlink(e){this.onHyperlinkClick?.(e)}handleMultiClick(e,t,s){if(!this.altScreenActive)return;const i=this.frontFrame.screen;de(this.selection,e,t),2===s?ae(this.selection,i,e,t):ne(this.selection,i,t),this.selection.focus||(this.selection.focus=this.selection.anchor),this.notifySelectionChange()}handleSelectionDrag(e,t){if(!this.altScreenActive)return;const s=this.selection;s.anchorSpan?te(s,this.frontFrame.screen,e,t):ue(s,e,t),this.notifySelectionChange()}stdinListeners=[];wasRawMode=!1;suspendStdin(){const e=this.options.stdin;if(!e.isTTY)return;const t=e.listeners("readable");m(`[stdin] suspendStdin: removing ${t.length} readable listener(s), wasRawMode=${e.isRaw??!1}`),t.forEach(t=>{this.stdinListeners.push({event:"readable",listener:t}),e.removeListener("readable",t)});const s=e;s.isRaw&&s.setRawMode&&(s.setRawMode(!1),this.wasRawMode=!0)}resumeStdin(){const e=this.options.stdin;if(e.isTTY&&(0!==this.stdinListeners.length||this.wasRawMode||m("[stdin] resumeStdin: called with no stored listeners and wasRawMode=false (possible desync)",{level:"warn"}),m(`[stdin] resumeStdin: re-attaching ${this.stdinListeners.length} listener(s), wasRawMode=${this.wasRawMode}`),this.stdinListeners.forEach(({event:t,listener:s})=>{e.addListener(t,s)}),this.stdinListeners=[],this.wasRawMode)){const t=e;t.setRawMode&&t.setRawMode(!0),this.wasRawMode=!1}}writeRaw(e){this.options.stdout.write(e)}setCursorDeclaration=(e,t)=>{null===e&&void 0!==t&&this.cursorDeclaration?.node!==t||(this.cursorDeclaration=e)};render(t){this.currentNode=t;const s=e(S,{stdin:this.options.stdin,stdout:this.options.stdout,stderr:this.options.stderr,exitOnCtrlC:this.options.exitOnCtrlC,onExit:this.unmount,terminalColumns:this.terminalColumns,terminalRows:this.terminalRows,selection:this.selection,onSelectionChange:this.notifySelectionChange,onClickAt:this.dispatchClick,onHoverAt:this.dispatchHover,getHyperlinkAt:this.getHyperlinkAt,onOpenHyperlink:this.openHyperlink,onMultiClick:this.handleMultiClick,onSelectionDrag:this.handleSelectionDrag,onStdinResume:this.reassertTerminalModes,onCursorDeclaration:this.setCursorDeclaration,dispatchKeyboardEvent:this.dispatchKeyboardEvent,children:e(Ye,{value:this.writeRaw,children:t})});M.updateContainerSync(s,this.container,null,a),M.flushSyncWork()}unmount(e){if(this.isUnmounted)return;this.onRender(),this.unsubscribeExit(),"function"==typeof this.restoreConsole&&this.restoreConsole(),this.restoreStderr?.(),this.unsubscribeTTYHandlers?.();const t=this.log.renderPreviousOutput_DEPRECATED(this.frontFrame);fe(this.terminal,E(t)),this.options.stdout.isTTY&&(this.altScreenActive&&n(1,be),n(1,ke),this.drainStdin(),n(1,Pe),n(1,we),n(1,Fe),n(1,Te),n(1,Me),n(1,Ne),He()&&n(1,Le(xe))),this.isUnmounted=!0,this.scheduleRender.cancel?.(),null!==this.drainTimer&&(clearTimeout(this.drainTimer),this.drainTimer=null),M.updateContainerSync(null,this.container,null,a),M.flushSyncWork(),F.delete(this.options.stdout),this.rootNode.yogaNode?.free(),this.rootNode.yogaNode=void 0,e instanceof Error?this.rejectExitPromise(e):this.resolveExitPromise()}async waitUntilExit(){return this.exitPromise||=new Promise((e,t)=>{this.resolveExitPromise=e,this.rejectExitPromise=t}),this.exitPromise}resetLineCount(){this.options.stdout.isTTY&&(this.backFrame=this.frontFrame,this.frontFrame=C(this.frontFrame.viewport.height,this.frontFrame.viewport.width,this.stylePool,this.charPool,this.hyperlinkPool),this.log.reset(),this.displayCursor=null)}resetPools(){this.charPool=new I,this.hyperlinkPool=new W,G(this.frontFrame.screen,this.charPool,this.hyperlinkPool),this.backFrame.screen.charPool=this.charPool,this.backFrame.screen.hyperlinkPool=this.hyperlinkPool}patchConsole(){const e=console,t={},toDebug=(...e)=>m(`console.log: ${f(...e)}`),toError=(...e)=>p(new Error(`console.error: ${f(...e)}`));for(const s of Be)t[s]=e[s],e[s]=toDebug;for(const s of $e)t[s]=e[s],e[s]=toError;return t.assert=e.assert,e.assert=(e,...t)=>{e||toError(...t)},()=>Object.assign(e,t)}patchStderr(){const e=process.stderr,t=e.write;let s=!1;const intercept=(i,o,r)=>{const n="function"==typeof o?o:r;if(s){const s="string"==typeof o?o:void 0;return t.call(e,i,s,n)}s=!0;try{const e="string"==typeof i?i:Buffer.from(i).toString("utf8");m(`[stderr] ${e}`,{level:"warn"}),!this.altScreenActive||this.isUnmounted||this.isPaused||(this.prevFrameContaminated=!0,this.scheduleRender())}finally{s=!1,n?.()}return!0};return e.write=intercept,()=>{e.write===intercept&&(e.write=t)}}}export function drainStdin(e=process.stdin){if(!e.isTTY)return;try{for(;null!==e.read(););}catch{}if("win32"===process.platform)return;const t=e,n=!0===t.isRaw;let a=-1;try{n||t.setRawMode?.(!0),a=o("/dev/tty",i.O_RDONLY|i.O_NONBLOCK);const e=Buffer.alloc(1024);for(let t=0;t<64&&!(r(a,e,0,e.length,null)<=0);t++);}catch{}finally{if(a>=0)try{s(a)}catch{}if(!n)try{t.setRawMode?.(!1)}catch{}}}const Be=["log","info","debug","dir","dirxml","count","countReset","group","groupCollapsed","groupEnd","table","time","timeEnd","timeLog"],$e=["warn","error","trace"];
|
|
1
|
+
import{jsx as t}from"react/jsx-runtime";import e from"auto-bind";import{closeSync as s,constants as i,openSync as o,readSync as r,writeSync as n}from"fs";import h from"lodash-es/noop.js";import a from"lodash-es/throttle.js";import{ConcurrentRoot as l}from"react-reconciler/constants.js";import{onExit as c}from"signal-exit";import{flushInteractionTime as d}from"../bootstrap/state.js";import{getYogaCounters as u}from"../native-ts/yoga-layout/index.js";import{logForDebugging as m}from"../utils/debug.js";import{logError as p}from"../utils/log.js";import{format as f}from"util";import{colorize as g}from"./colorize.js";import w from"./components/App.js";import{FRAME_INTERVAL_MS as y}from"./constants.js";import*as S from"./dom.js";import{KeyboardEvent as v}from"./events/keyboard-event.js";import{FocusManager as P}from"./focus.js";import{emptyFrame as C}from"./frame.js";import{dispatchClick as k,dispatchHover as F}from"./hit-test.js";import R from"./instances.js";import{LogUpdate as T}from"./log-update.js";import{nodeCache as b}from"./node-cache.js";import{optimize as A}from"./optimizer.js";import x from"./output.js";import N,{dispatcher as M,getLastCommitMs as j,getLastYogaMs as E,isDebugRepaintsEnabled as H,recordYogaMs as Y,resetProfileCounters as L}from"./reconciler.js";import $,{consumeFollowScroll as O,didLayoutShift as D}from"./render-node-to-output.js";import{applyPositionedHighlight as z,scanPositions as B}from"./render-to-screen.js";import U from"./renderer.js";import{CharPool as Q,cellAt as I,createScreen as W,HyperlinkPool as K,isEmptyCellAt as _,migrateScreenPools as q,StylePool as G}from"./screen.js";import{applySearchHighlight as J}from"./searchHighlight.js";import{applySelectionOverlay as X,captureScrolledRows as V,clearSelection as Z,createSelectionState as tt,extendSelection as et,findPlainTextUrlAt as st,getSelectedText as it,hasSelection as ot,moveFocus as rt,selectLineAt as nt,selectWordAt as ht,shiftAnchor as at,shiftSelection as lt,shiftSelectionForFollow as ct,startSelection as dt,updateSelection as ut}from"./selection.js";import{SYNC_OUTPUT_SUPPORTED as mt,supportsExtendedKeys as pt,writeDiffToTerminal as ft}from"./terminal.js";import{CURSOR_HOME as gt,cursorMove as wt,cursorPosition as yt,DISABLE_KITTY_KEYBOARD as St,DISABLE_MODIFY_OTHER_KEYS as vt,ENABLE_KITTY_KEYBOARD as Pt,ENABLE_MODIFY_OTHER_KEYS as Ct,ERASE_SCREEN as kt}from"./termio/csi.js";import{DBP as Ft,DFE as Rt,DISABLE_MOUSE_TRACKING as Tt,ENABLE_MOUSE_TRACKING as bt,ENTER_ALT_SCREEN as At,EXIT_ALT_SCREEN as xt,SHOW_CURSOR as Nt}from"./termio/dec.js";import{CLEAR_ITERM2_PROGRESS as Mt,CLEAR_TAB_STATUS as jt,setClipboard as Et,supportsTabStatus as Ht,wrapForMultiplexer as Yt}from"./termio/osc.js";import{TerminalWriteProvider as Lt}from"./useTerminalNotification.js";const $t=Object.freeze({x:0,y:0,visible:!1}),Ot=Object.freeze({type:"stdout",content:gt}),Dt=Object.freeze({type:"stdout",content:kt+gt});function makeAltScreenParkPatch(t){return Object.freeze({type:"stdout",content:yt(t,1)})}export default class Ink{options;log;terminal;scheduleRender;isUnmounted=!1;isPaused=!1;container;rootNode;focusManager;renderer;stylePool;charPool;hyperlinkPool;exitPromise;restoreConsole;restoreStderr;unsubscribeTTYHandlers;terminalColumns;terminalRows;currentNode=null;frontFrame;backFrame;lastPoolResetTime=performance.now();drainTimer=null;lastYogaCounters={ms:0,visited:0,measured:0,cacheHits:0,live:0};altScreenParkPatch;selection=tt();searchHighlightQuery="";searchPositions=null;selectionListeners=new Set;hoveredNodes=new Set;altScreenActive=!1;altScreenMouseTracking=!1;prevFrameContaminated=!1;needsEraseBeforePaint=!1;cursorDeclaration=null;displayCursor=null;constructor(t){this.options=t,e(this),this.options.patchConsole&&(this.restoreConsole=this.patchConsole(),this.restoreStderr=this.patchStderr()),this.terminal={stdout:t.stdout,stderr:t.stderr},this.terminalColumns=t.stdout.columns||80,this.terminalRows=t.stdout.rows||24,this.altScreenParkPatch=makeAltScreenParkPatch(this.terminalRows),this.stylePool=new G,this.charPool=new Q,this.hyperlinkPool=new K,this.frontFrame=C(this.terminalRows,this.terminalColumns,this.stylePool,this.charPool,this.hyperlinkPool),this.backFrame=C(this.terminalRows,this.terminalColumns,this.stylePool,this.charPool,this.hyperlinkPool),this.log=new T({isTTY:t.stdout.isTTY||!1,stylePool:this.stylePool});this.scheduleRender=a(()=>queueMicrotask(this.onRender),y,{leading:!0,trailing:!0}),this.isUnmounted=!1,this.unsubscribeExit=c(this.unmount,{alwaysLast:!1}),t.stdout.isTTY&&(t.stdout.on("resize",this.handleResize),process.on("SIGCONT",this.handleResume),this.unsubscribeTTYHandlers=()=>{t.stdout.off("resize",this.handleResize),process.off("SIGCONT",this.handleResume)}),this.rootNode=S.createNode("ink-root"),this.focusManager=new P((t,e)=>M.dispatchDiscrete(t,e)),this.rootNode.focusManager=this.focusManager,this.renderer=U(this.rootNode,this.stylePool),this.rootNode.onRender=this.scheduleRender,this.rootNode.onImmediateRender=this.onRender,this.rootNode.onComputeLayout=()=>{if(!this.isUnmounted&&this.rootNode.yogaNode){const t=performance.now();this.rootNode.yogaNode.setWidth(this.terminalColumns),this.rootNode.yogaNode.calculateLayout(this.terminalColumns);const e=performance.now()-t;Y(e);const s=u();this.lastYogaCounters={ms:e,...s}}},this.container=N.createContainer(this.rootNode,l,null,!1,null,"id",h,h,h,h)}handleResume=()=>{this.options.stdout.isTTY&&(this.altScreenActive?this.reenterAltScreen():(this.frontFrame=C(this.frontFrame.viewport.height,this.frontFrame.viewport.width,this.stylePool,this.charPool,this.hyperlinkPool),this.backFrame=C(this.backFrame.viewport.height,this.backFrame.viewport.width,this.stylePool,this.charPool,this.hyperlinkPool),this.log.reset(),this.displayCursor=null))};handleResize=()=>{const t=this.options.stdout.columns||80,e=this.options.stdout.rows||24;t===this.terminalColumns&&e===this.terminalRows||(this.terminalColumns=t,this.terminalRows=e,this.altScreenParkPatch=makeAltScreenParkPatch(this.terminalRows),this.altScreenActive&&!this.isPaused&&this.options.stdout.isTTY&&(this.altScreenMouseTracking&&this.options.stdout.write(bt),this.resetFramesForAltScreen(),this.needsEraseBeforePaint=!0),null!==this.currentNode&&this.render(this.currentNode))};resolveExitPromise=()=>{};rejectExitPromise=()=>{};unsubscribeExit=()=>{};enterAlternateScreen(){this.pause(),this.suspendStdin(),this.options.stdout.write(St+vt+(this.altScreenMouseTracking?Tt:"")+(this.altScreenActive?"":"[?1049h")+"[?1004l[0m[?25h[2J[H")}exitAlternateScreen(){this.options.stdout.write((this.altScreenActive?At:"")+"[2J[H"+(this.altScreenMouseTracking?bt:"")+(this.altScreenActive?"":"[?1049l")+"[?25l"),this.resumeStdin(),this.altScreenActive?this.resetFramesForAltScreen():this.repaint(),this.resume(),this.options.stdout.write("[?1004h"+(pt()?St+Pt+Ct:""))}onRender(){if(this.isUnmounted||this.isPaused)return;null!==this.drainTimer&&(clearTimeout(this.drainTimer),this.drainTimer=null),d();const t=performance.now(),e=this.options.stdout.columns||80,s=this.options.stdout.rows||24,i=this.renderer({frontFrame:this.frontFrame,backFrame:this.backFrame,isTTY:this.options.stdout.isTTY,terminalWidth:e,terminalRows:s,altScreen:this.altScreenActive,prevFrameContaminated:this.prevFrameContaminated}),o=performance.now()-t,r=O();if(r&&this.selection.anchor&&this.selection.anchor.row>=r.viewportTop&&this.selection.anchor.row<=r.viewportBottom){const{delta:t,viewportTop:e,viewportBottom:s}=r;if(this.selection.isDragging)ot(this.selection)&&V(this.selection,this.frontFrame.screen,e,e+t-1,"above"),at(this.selection,-t,e,s);else if(!this.selection.focus||this.selection.focus.row>=e&&this.selection.focus.row<=s){ot(this.selection)&&V(this.selection,this.frontFrame.screen,e,e+t-1,"above");if(ct(this.selection,-t,e,s))for(const t of this.selectionListeners)t()}}let n=!1,h=!1;if(this.altScreenActive&&(n=ot(this.selection),n&&X(i.screen,this.selection,this.stylePool),h=J(i.screen,this.searchHighlightQuery,this.stylePool),this.searchPositions)){const t=this.searchPositions,e=z(i.screen,this.stylePool,t.positions,t.rowOffset,t.currentIdx);h=h||e}(D()||n||h||this.prevFrameContaminated)&&(i.screen.damage={x:0,y:0,width:i.screen.width,height:i.screen.height});let a=this.frontFrame;this.altScreenActive&&(a={...this.frontFrame,cursor:$t});const l=performance.now(),c=this.log.render(a,i,this.altScreenActive,mt),u=performance.now()-l;this.backFrame=this.frontFrame,this.frontFrame=i,t-this.lastPoolResetTime>3e5&&(this.resetPools(),this.lastPoolResetTime=t);const p=[];for(const t of c)if("clearTerminal"===t.type&&(p.push({desiredHeight:i.screen.height,availableHeight:i.viewport.height,reason:t.reason}),H()&&t.debug)){const e=S.findOwnerChainAtRow(this.rootNode,t.debug.triggerY);m(`[REPAINT] full reset · ${t.reason} · row ${t.debug.triggerY}\n prev: "${t.debug.prevLine}"\n next: "${t.debug.nextLine}"\n culprit: ${e.length?e.join(" < "):"(no owner chain captured)"}`,{level:"warn"})}const f=performance.now(),g=A(c),w=performance.now()-f,v=g.length>0;this.altScreenActive&&v&&(this.needsEraseBeforePaint?(this.needsEraseBeforePaint=!1,g.unshift(Dt)):g.unshift(Ot),g.push(this.altScreenParkPatch));const P=this.cursorDeclaration,C=null!==P?b.get(P.node):void 0,k=null!==P&&void 0!==C?{x:C.x+P.relativeX,y:C.y+P.relativeY}:null,F=this.displayCursor,R=null!==k&&(null===F||F.x!==k.x||F.y!==k.y);if(v||R||null===k&&null!==F){if(null!==F&&!this.altScreenActive&&v){const t=a.cursor.x-F.x,e=a.cursor.y-F.y;0===t&&0===e||g.unshift({type:"stdout",content:wt(t,e)})}if(null!==k){if(this.altScreenActive){const t=Math.min(Math.max(k.y+1,1),s),i=Math.min(Math.max(k.x+1,1),e);g.push({type:"stdout",content:yt(t,i)})}else{const t=v||null===F?{x:i.cursor.x,y:i.cursor.y}:F,e=k.x-t.x,s=k.y-t.y;0===e&&0===s||g.push({type:"stdout",content:wt(e,s)})}this.displayCursor=k}else{if(null!==F&&!this.altScreenActive&&!v){const t=i.cursor.x-F.x,e=i.cursor.y-F.y;0===t&&0===e||g.push({type:"stdout",content:wt(t,e)})}this.displayCursor=null}}const T=performance.now();ft(this.terminal,g,this.altScreenActive&&!mt);const x=performance.now()-T;this.prevFrameContaminated=n||h,i.scrollDrainPending&&(this.drainTimer=setTimeout(()=>this.onRender(),y>>2));const N=E(),M=j(),Y=this.lastYogaCounters;L(),this.lastYogaCounters={ms:0,visited:0,measured:0,cacheHits:0,live:0},this.options.onFrame?.({durationMs:performance.now()-t,phases:{renderer:o,diff:u,optimize:w,write:x,patches:c.length,yoga:N,commit:M,yogaVisited:Y.visited,yogaMeasured:Y.measured,yogaCacheHits:Y.cacheHits,yogaLive:Y.live},flickers:p})}pause(){N.flushSyncFromReconciler(),this.onRender(),this.isPaused=!0}resume(){this.isPaused=!1,this.onRender()}repaint(){this.frontFrame=C(this.frontFrame.viewport.height,this.frontFrame.viewport.width,this.stylePool,this.charPool,this.hyperlinkPool),this.backFrame=C(this.backFrame.viewport.height,this.backFrame.viewport.width,this.stylePool,this.charPool,this.hyperlinkPool),this.log.reset(),this.displayCursor=null}forceRedraw(){!this.options.stdout.isTTY||this.isUnmounted||this.isPaused||(this.options.stdout.write(kt+gt),this.altScreenActive?this.resetFramesForAltScreen():(this.repaint(),this.prevFrameContaminated=!0),this.onRender())}invalidatePrevFrame(){this.prevFrameContaminated=!0}setAltScreenActive(t,e=!1){this.altScreenActive!==t&&(this.altScreenActive=t,this.altScreenMouseTracking=t&&e,t?this.resetFramesForAltScreen():this.repaint())}get isAltScreenActive(){return this.altScreenActive}reassertTerminalModes=(t=!1)=>{this.options.stdout.isTTY&&(this.isPaused||(pt()&&this.options.stdout.write(St+Pt+Ct),this.altScreenActive&&(this.altScreenMouseTracking&&this.options.stdout.write(bt),t&&this.reenterAltScreen())))};detachForShutdown(){this.isUnmounted=!0,this.scheduleRender.cancel?.();const t=this.options.stdin;this.drainStdin(),t.isTTY&&t.isRaw&&t.setRawMode&&t.setRawMode(!1)}drainStdin(){drainStdin(this.options.stdin)}reenterAltScreen(){this.options.stdout.write(At+kt+gt+(this.altScreenMouseTracking?bt:"")),this.resetFramesForAltScreen()}resetFramesForAltScreen(){const t=this.terminalRows,e=this.terminalColumns,blank=()=>({screen:W(e,t,this.stylePool,this.charPool,this.hyperlinkPool),viewport:{width:e,height:t+1},cursor:{x:0,y:0,visible:!0}});this.frontFrame=blank(),this.backFrame=blank(),this.log.reset(),this.displayCursor=null,this.prevFrameContaminated=!0}copySelectionNoClear(){if(!ot(this.selection))return"";const t=it(this.selection,this.frontFrame.screen);return t&&Et(t).then(t=>{t&&this.options.stdout.write(t)}),t}copySelection(){if(!ot(this.selection))return"";const t=this.copySelectionNoClear();return Z(this.selection),this.notifySelectionChange(),t}clearTextSelection(){ot(this.selection)&&(Z(this.selection),this.notifySelectionChange())}setSearchHighlight(t){this.searchHighlightQuery!==t&&(this.searchHighlightQuery=t,this.scheduleRender())}scanElementSubtree(t){if(!this.searchHighlightQuery||!t.yogaNode)return[];const e=Math.ceil(t.yogaNode.getComputedWidth()),s=Math.ceil(t.yogaNode.getComputedHeight());if(e<=0||s<=0)return[];const i=t.yogaNode.getComputedLeft(),o=t.yogaNode.getComputedTop(),r=W(e,s,this.stylePool,this.charPool,this.hyperlinkPool),n=new x({width:e,height:s,stylePool:this.stylePool,screen:r});$(t,n,{offsetX:-i,offsetY:-o,prevScreen:void 0});const h=n.get();S.markDirty(t);const a=B(h,this.searchHighlightQuery);return m(`scanElementSubtree: q='${this.searchHighlightQuery}' el=${e}x${s}@(${i},${o}) n=${a.length} [${a.slice(0,10).map(t=>`${t.row}:${t.col}`).join(",")}`+(a.length>10?",…":"")+"]"),a}setSearchPositions(t){this.searchPositions=t,this.scheduleRender()}setSelectionBgColor(t){const e=g("\0",t,"background"),s=e.indexOf("\0");s<=0||s===e.length-1?this.stylePool.setSelectionBg(null):this.stylePool.setSelectionBg({type:"ansi",code:e.slice(0,s),endCode:e.slice(s+1)})}captureScrolledRows(t,e,s){V(this.selection,this.frontFrame.screen,t,e,s)}shiftSelectionForScroll(t,e,s){const i=ot(this.selection);lt(this.selection,t,e,s,this.frontFrame.screen.width),i&&!ot(this.selection)&&this.notifySelectionChange()}moveSelectionFocus(t){if(!this.altScreenActive)return;const{focus:e}=this.selection;if(!e)return;const{width:s,height:i}=this.frontFrame.screen,o=s-1,r=i-1;let{col:n,row:h}=e;switch(t){case"left":n>0?n--:h>0&&(n=o,h--);break;case"right":n<o?n++:h<r&&(n=0,h++);break;case"up":h>0&&h--;break;case"down":h<r&&h++;break;case"lineStart":n=0;break;case"lineEnd":n=o}n===e.col&&h===e.row||(rt(this.selection,n,h),this.notifySelectionChange())}hasTextSelection(){return ot(this.selection)}subscribeToSelectionChange(t){return this.selectionListeners.add(t),()=>this.selectionListeners.delete(t)}notifySelectionChange(){this.onRender();for(const t of this.selectionListeners)t()}dispatchClick(t,e){if(!this.altScreenActive)return!1;const s=_(this.frontFrame.screen,t,e);return k(this.rootNode,t,e,s)}dispatchHover(t,e){this.altScreenActive&&F(this.rootNode,t,e,this.hoveredNodes)}dispatchKeyboardEvent(t){const e=this.focusManager.activeElement??this.rootNode,s=new v(t);M.dispatchDiscrete(e,s),s.defaultPrevented||"tab"!==t.name||t.ctrl||t.meta||(t.shift?this.focusManager.focusPrevious(this.rootNode):this.focusManager.focusNext(this.rootNode))}getHyperlinkAt(t,e){if(!this.altScreenActive)return;const s=this.frontFrame.screen,i=I(s,t,e);let o=i?.hyperlink;return!o&&2===i?.width&&t>0&&(o=I(s,t-1,e)?.hyperlink),o??st(s,t,e)}onHyperlinkClick;openHyperlink(t){this.onHyperlinkClick?.(t)}handleMultiClick(t,e,s){if(!this.altScreenActive)return;const i=this.frontFrame.screen;dt(this.selection,t,e),2===s?ht(this.selection,i,t,e):nt(this.selection,i,e),this.selection.focus||(this.selection.focus=this.selection.anchor),this.notifySelectionChange()}handleSelectionDrag(t,e){if(!this.altScreenActive)return;const s=this.selection;s.anchorSpan?et(s,this.frontFrame.screen,t,e):ut(s,t,e),this.notifySelectionChange()}stdinListeners=[];wasRawMode=!1;suspendStdin(){const t=this.options.stdin;if(!t.isTTY)return;const e=t.listeners("readable");m(`[stdin] suspendStdin: removing ${e.length} readable listener(s), wasRawMode=${t.isRaw??!1}`),e.forEach(e=>{this.stdinListeners.push({event:"readable",listener:e}),t.removeListener("readable",e)});const s=t;s.isRaw&&s.setRawMode&&(s.setRawMode(!1),this.wasRawMode=!0)}resumeStdin(){const t=this.options.stdin;if(t.isTTY&&(0!==this.stdinListeners.length||this.wasRawMode||m("[stdin] resumeStdin: called with no stored listeners and wasRawMode=false (possible desync)",{level:"warn"}),m(`[stdin] resumeStdin: re-attaching ${this.stdinListeners.length} listener(s), wasRawMode=${this.wasRawMode}`),this.stdinListeners.forEach(({event:e,listener:s})=>{t.addListener(e,s)}),this.stdinListeners=[],this.wasRawMode)){const e=t;e.setRawMode&&e.setRawMode(!0),this.wasRawMode=!1}}writeRaw(t){this.options.stdout.write(t)}setCursorDeclaration=(t,e)=>{null===t&&void 0!==e&&this.cursorDeclaration?.node!==e||(this.cursorDeclaration=t)};render(e){this.currentNode=e;const s=t(w,{stdin:this.options.stdin,stdout:this.options.stdout,stderr:this.options.stderr,exitOnCtrlC:this.options.exitOnCtrlC,onExit:this.unmount,terminalColumns:this.terminalColumns,terminalRows:this.terminalRows,selection:this.selection,onSelectionChange:this.notifySelectionChange,onClickAt:this.dispatchClick,onHoverAt:this.dispatchHover,getHyperlinkAt:this.getHyperlinkAt,onOpenHyperlink:this.openHyperlink,onMultiClick:this.handleMultiClick,onSelectionDrag:this.handleSelectionDrag,onStdinResume:this.reassertTerminalModes,onCursorDeclaration:this.setCursorDeclaration,dispatchKeyboardEvent:this.dispatchKeyboardEvent,children:t(Lt,{value:this.writeRaw,children:e})});N.updateContainerSync(s,this.container,null,h),N.flushSyncWork()}unmount(t){if(this.isUnmounted)return;this.onRender(),this.unsubscribeExit(),"function"==typeof this.restoreConsole&&this.restoreConsole(),this.restoreStderr?.(),this.unsubscribeTTYHandlers?.();const e=this.log.renderPreviousOutput_DEPRECATED(this.frontFrame);ft(this.terminal,A(e)),this.options.stdout.isTTY&&(this.altScreenActive&&n(1,xt),n(1,Tt),this.drainStdin(),n(1,vt),n(1,St),n(1,Rt),n(1,Ft),n(1,Nt),n(1,Mt),Ht()&&n(1,Yt(jt))),this.isUnmounted=!0,this.scheduleRender.cancel?.(),null!==this.drainTimer&&(clearTimeout(this.drainTimer),this.drainTimer=null),N.updateContainerSync(null,this.container,null,h),N.flushSyncWork(),R.delete(this.options.stdout),this.rootNode.yogaNode?.free(),this.rootNode.yogaNode=void 0,t instanceof Error?this.rejectExitPromise(t):this.resolveExitPromise()}async waitUntilExit(){return this.exitPromise||=new Promise((t,e)=>{this.resolveExitPromise=t,this.rejectExitPromise=e}),this.exitPromise}resetLineCount(){this.options.stdout.isTTY&&(this.backFrame=this.frontFrame,this.frontFrame=C(this.frontFrame.viewport.height,this.frontFrame.viewport.width,this.stylePool,this.charPool,this.hyperlinkPool),this.log.reset(),this.displayCursor=null)}resetPools(){this.charPool=new Q,this.hyperlinkPool=new K,q(this.frontFrame.screen,this.charPool,this.hyperlinkPool),this.backFrame.screen.charPool=this.charPool,this.backFrame.screen.hyperlinkPool=this.hyperlinkPool}patchConsole(){const t=console,e={},toDebug=(...t)=>m(`console.log: ${f(...t)}`),toError=(...t)=>p(new Error(`console.error: ${f(...t)}`));for(const s of zt)e[s]=t[s],t[s]=toDebug;for(const s of Bt)e[s]=t[s],t[s]=toError;return e.assert=t.assert,t.assert=(t,...e)=>{t||toError(...e)},()=>Object.assign(t,e)}patchStderr(){const t=process.stderr,e=t.write;let s=!1;const intercept=(i,o,r)=>{const n="function"==typeof o?o:r;if(s){const s="string"==typeof o?o:void 0;return e.call(t,i,s,n)}s=!0;try{const t="string"==typeof i?i:Buffer.from(i).toString("utf8");m(`[stderr] ${t}`,{level:"warn"}),!this.altScreenActive||this.isUnmounted||this.isPaused||(this.prevFrameContaminated=!0,this.scheduleRender())}finally{s=!1,n?.()}return!0};return t.write=intercept,()=>{t.write===intercept&&(t.write=e)}}}export function drainStdin(t=process.stdin){if(!t.isTTY)return;try{for(;null!==t.read(););}catch{}if("win32"===process.platform)return;const e=t,n=!0===e.isRaw;let h=-1;try{n||e.setRawMode?.(!0),h=o("/dev/tty",i.O_RDONLY|i.O_NONBLOCK);const t=Buffer.alloc(1024);for(let e=0;e<64&&!(r(h,t,0,t.length,null)<=0);e++);}catch{}finally{if(h>=0)try{s(h)}catch{}if(!n)try{e.setRawMode?.(!1)}catch{}}}const zt=["log","info","debug","dir","dirxml","count","countReset","group","groupCollapsed","groupEnd","table","time","timeEnd","timeLog"],Bt=["warn","error","trace"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t,{Align as e,Direction as s,Display as o,Edge as i,FlexDirection as a,Gutter as r,Justify as n,MeasureMode as g,Overflow as h,PositionType as l,Wrap as y}from"
|
|
1
|
+
import t,{Align as e,Direction as s,Display as o,Edge as i,FlexDirection as a,Gutter as r,Justify as n,MeasureMode as g,Overflow as h,PositionType as l,Wrap as y}from"../../native-ts/yoga-layout/index.js";import{LayoutDisplay as d,LayoutMeasureMode as u}from"./node.js";const c={all:i.All,horizontal:i.Horizontal,vertical:i.Vertical,left:i.Left,right:i.Right,top:i.Top,bottom:i.Bottom,start:i.Start,end:i.End},p={all:r.All,column:r.Column,row:r.Row};export class YogaLayoutNode{yoga;constructor(t){this.yoga=t}insertChild(t,e){this.yoga.insertChild(t.yoga,e)}removeChild(t){this.yoga.removeChild(t.yoga)}getChildCount(){return this.yoga.getChildCount()}getParent(){const t=this.yoga.getParent();return t?new YogaLayoutNode(t):null}calculateLayout(t,e){this.yoga.calculateLayout(t,void 0,s.LTR)}setMeasureFunc(t){this.yoga.setMeasureFunc((e,s)=>{const o=s===g.Exactly?u.Exactly:s===g.AtMost?u.AtMost:u.Undefined;return t(e,o)})}unsetMeasureFunc(){this.yoga.unsetMeasureFunc()}markDirty(){this.yoga.markDirty()}getComputedLeft(){return this.yoga.getComputedLeft()}getComputedTop(){return this.yoga.getComputedTop()}getComputedWidth(){return this.yoga.getComputedWidth()}getComputedHeight(){return this.yoga.getComputedHeight()}getComputedBorder(t){return this.yoga.getComputedBorder(c[t])}getComputedPadding(t){return this.yoga.getComputedPadding(c[t])}setWidth(t){this.yoga.setWidth(t)}setWidthPercent(t){this.yoga.setWidthPercent(t)}setWidthAuto(){this.yoga.setWidthAuto()}setHeight(t){this.yoga.setHeight(t)}setHeightPercent(t){this.yoga.setHeightPercent(t)}setHeightAuto(){this.yoga.setHeightAuto()}setMinWidth(t){this.yoga.setMinWidth(t)}setMinWidthPercent(t){this.yoga.setMinWidthPercent(t)}setMinHeight(t){this.yoga.setMinHeight(t)}setMinHeightPercent(t){this.yoga.setMinHeightPercent(t)}setMaxWidth(t){this.yoga.setMaxWidth(t)}setMaxWidthPercent(t){this.yoga.setMaxWidthPercent(t)}setMaxHeight(t){this.yoga.setMaxHeight(t)}setMaxHeightPercent(t){this.yoga.setMaxHeightPercent(t)}setFlexDirection(t){const e={row:a.Row,"row-reverse":a.RowReverse,column:a.Column,"column-reverse":a.ColumnReverse};this.yoga.setFlexDirection(e[t])}setFlexGrow(t){this.yoga.setFlexGrow(t)}setFlexShrink(t){this.yoga.setFlexShrink(t)}setFlexBasis(t){this.yoga.setFlexBasis(t)}setFlexBasisPercent(t){this.yoga.setFlexBasisPercent(t)}setFlexWrap(t){const e={nowrap:y.NoWrap,wrap:y.Wrap,"wrap-reverse":y.WrapReverse};this.yoga.setFlexWrap(e[t])}setAlignItems(t){const s={auto:e.Auto,stretch:e.Stretch,"flex-start":e.FlexStart,center:e.Center,"flex-end":e.FlexEnd};this.yoga.setAlignItems(s[t])}setAlignSelf(t){const s={auto:e.Auto,stretch:e.Stretch,"flex-start":e.FlexStart,center:e.Center,"flex-end":e.FlexEnd};this.yoga.setAlignSelf(s[t])}setJustifyContent(t){const e={"flex-start":n.FlexStart,center:n.Center,"flex-end":n.FlexEnd,"space-between":n.SpaceBetween,"space-around":n.SpaceAround,"space-evenly":n.SpaceEvenly};this.yoga.setJustifyContent(e[t])}setDisplay(t){this.yoga.setDisplay("flex"===t?o.Flex:o.None)}getDisplay(){return this.yoga.getDisplay()===o.None?d.None:d.Flex}setPositionType(t){this.yoga.setPositionType("absolute"===t?l.Absolute:l.Relative)}setPosition(t,e){this.yoga.setPosition(c[t],e)}setPositionPercent(t,e){this.yoga.setPositionPercent(c[t],e)}setOverflow(t){const e={visible:h.Visible,hidden:h.Hidden,scroll:h.Scroll};this.yoga.setOverflow(e[t])}setMargin(t,e){this.yoga.setMargin(c[t],e)}setPadding(t,e){this.yoga.setPadding(c[t],e)}setBorder(t,e){this.yoga.setBorder(c[t],e)}setGap(t,e){this.yoga.setGap(p[t],e)}free(){this.yoga.free()}freeRecursive(){this.yoga.freeRecursive()}}export function createYogaLayoutNode(){return new YogaLayoutNode(t.Node.create())}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{stringWidth as t}from"./stringWidth.js";const
|
|
1
|
+
import{stringWidth as t}from"./stringWidth.js";const n=new Map;export function lineWidth(e){const i=n.get(e);if(void 0!==i)return i;const r=t(e);return n.size>=4096&&n.clear(),n.set(e,r),r}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ansiCodesToString as e,diffAnsiCodes as t}from"@alcalzone/ansi-tokenize";import{logForDebugging as r}from"../utils/debug.js";import{cellAt as n,charInCellAt as i,diffEach as o,isEmptyCellAt as s,shiftRows as c,visibleCellAtIndex as h}from"./screen.js";import{CURSOR_HOME as
|
|
1
|
+
import{ansiCodesToString as e,diffAnsiCodes as t}from"@alcalzone/ansi-tokenize";import{logForDebugging as r}from"../utils/debug.js";import{cellAt as n,charInCellAt as i,diffEach as o,isEmptyCellAt as s,shiftRows as c,visibleCellAtIndex as h}from"./screen.js";import{CURSOR_HOME as u,scrollDown as l,scrollUp as d,RESET_SCROLL_REGION as p,setScrollRegion as f}from"./termio/csi.js";import{LINK_END as y,link as a}from"./termio/osc.js";const g={type:"carriageReturn"},x={type:"stdout",content:"\n"};export class LogUpdate{options;state;constructor(e){this.options=e,this.state={previousOutput:""}}renderPreviousOutput_DEPRECATED(e){return this.options.isTTY?this.getRenderOpsForDone(e):[x]}reset(){this.state.previousOutput=""}renderFullFrame(r){const{screen:i}=r,o=[];let s,c=[];for(let r=0;r<i.height;r++){let h="";for(let o=0;o<i.width;o++){const u=n(i,o,r);if(u&&2!==u.width){u.hyperlink!==s&&(void 0!==s&&(h+=y),void 0!==u.hyperlink&&(h+=a(u.hyperlink)),s=u.hyperlink);const r=this.options.stylePool.get(u.styleId),n=t(c,r);n.length>0&&(h+=e(n),c=r),h+=u.char}}void 0!==s&&(h+=y,s=void 0);const u=t(c,[]);u.length>0&&(h+=e(u),c=[]),o.push(h.trimEnd())}return 0===o.length?[]:[{type:"stdout",content:o.join("\n")}]}getRenderOpsForDone(e){return this.state.previousOutput="",e.cursor.visible?[]:[{type:"cursorShow"}]}render(e,t,n=!1,i=!0){if(!this.options.isTTY)return this.renderFullFrame(t);const h=performance.now(),y=this.options.stylePool;if(t.viewport.height<e.viewport.height||0!==e.viewport.width&&t.viewport.width!==e.viewport.width)return fullResetSequence_CAUSES_FLICKER(t,"resize",y);let a=[];if(n&&t.scrollHint&&i){const{top:r,bottom:n,delta:i}=t.scrollHint;r>=0&&n<e.screen.height&&n<t.screen.height&&(c(e.screen,r,n,i),a=[{type:"stdout",content:f(r+1,n+1)+(i>0?d(i):l(-i))+p+u}])}const w=e.cursor.y>=e.screen.height,v=t.screen.height>e.screen.height,S=w&&e.screen.height>=e.viewport.height,m=t.screen.height<e.screen.height,C=t.screen.height<=e.viewport.height;if(S&&C&&m)return r(`Full reset (shrink->below): prevHeight=${e.screen.height}, nextHeight=${t.screen.height}, viewport=${e.viewport.height}`),fullResetSequence_CAUSES_FLICKER(t,"offscreen",y);if(e.screen.height>=e.viewport.height&&e.screen.height>0&&w&&!v){const r=e.screen.height-e.viewport.height+1;let n=-1;if(o(e.screen,t.screen,(e,t)=>{if(t<r)return n=t,!0}),n>=0){const r=readLine(e.screen,n),i=readLine(t.screen,n);return fullResetSequence_CAUSES_FLICKER(t,"offscreen",y,{triggerY:n,prevLine:r,nextLine:i})}}const k=new VirtualScreen(e.cursor,t.viewport.width),E=Math.max(t.screen.height,1)-Math.max(e.screen.height,1),F=E>0;if(E<0){const r=e.screen.height-t.screen.height;if(r>e.viewport.height)return fullResetSequence_CAUSES_FLICKER(t,"offscreen",this.options.stylePool);k.txn(e=>[[{type:"clear",count:r},{type:"cursorMove",x:0,y:-1}],{dx:-e.x,dy:-r}])}const L=S?1:0,R=F?Math.max(0,e.screen.height-e.viewport.height+L):Math.max(e.screen.height,t.screen.height)-t.viewport.height+L;let T,_=y.none,I=!1,$=-1;if(o(e.screen,t.screen,(r,n,i,o)=>{if(!(F&&n>=e.screen.height)&&(!o||2!==o.width&&3!==o.width)&&(!i||2!==i.width&&3!==i.width||o)&&(!o||!s(t.screen,r,n)||i)){if(n<R)return I=!0,$=n,!0;if(moveCursorTo(k,r,n),o){const e=o.hyperlink;T=transitionHyperlink(k.diff,T,e);const t=y.transition(_,o.styleId);writeCellWithStyleStr(k,o,t)&&(_=o.styleId)}else if(i){const e=_,t=T;_=y.none,T=void 0,k.txn(()=>{const r=[];return transitionStyle(r,y,e,y.none),transitionHyperlink(r,t,void 0),r.push({type:"stdout",content:" "}),[r,{dx:1,dy:0}]})}}}),I)return fullResetSequence_CAUSES_FLICKER(t,"offscreen",y,{triggerY:$,prevLine:readLine(e.screen,$),nextLine:readLine(t.screen,$)});_=transitionStyle(k.diff,y,_,y.none),T=transitionHyperlink(k.diff,T,void 0),F&&renderFrameSlice(k,t,e.screen.height,t.screen.height,y),n||(t.cursor.y>=t.screen.height?k.txn(e=>{const r=t.cursor.y-e.y;if(r>0){const t=new Array(1+r);t[0]=g;for(let e=0;e<r;e++)t[1+e]=x;return[t,{dx:-e.x,dy:r}]}const n=t.cursor.y-e.y;if(0!==n||e.x!==t.cursor.x){const r=[g];return r.push({type:"cursorMove",x:t.cursor.x,y:n}),[r,{dx:t.cursor.x-e.x,dy:n}]}return[[],{dx:0,dy:0}]}):moveCursorTo(k,t.cursor.x,t.cursor.y));const A=performance.now()-h;if(A>50){const e=t.screen.damage,n=e?`${e.width}x${e.height} at (${e.x},${e.y})`:"none";r(`Slow render: ${A.toFixed(1)}ms, screen: ${t.screen.height}x${t.screen.width}, damage: ${n}, changes: ${k.diff.length}`)}return a.length>0?[...a,...k.diff]:k.diff}}function transitionHyperlink(e,t,r){return t!==r?(e.push({type:"hyperlink",uri:r??""}),r):t}function transitionStyle(e,t,r,n){const i=t.transition(r,n);return i.length>0&&e.push({type:"styleStr",str:i}),n}function readLine(e,t){let r="";for(let n=0;n<e.width;n++)r+=i(e,n,t)??" ";return r.trimEnd()}function fullResetSequence_CAUSES_FLICKER(e,t,r,n){const i=new VirtualScreen({x:0,y:0},e.viewport.width);return function(e,t,r){renderFrameSlice(e,t,0,t.screen.height,r)}(i,e,r),[{type:"clearTerminal",reason:t,debug:n},...i.diff]}function renderFrameSlice(e,t,r,n,i){let o,s=i.none,c=-1;const{width:u,cells:l,charPool:d,hyperlinkPool:p}=t.screen;let f=r*u;for(let t=r;t<n;t+=1){if(e.cursor.y<t){const r=t-e.cursor.y;e.txn(e=>{const t=new Array(1+r);t[0]=g;for(let e=0;e<r;e++)t[1+e]=x;return[t,{dx:-e.x,dy:r}]})}c=-1;for(let r=0;r<u;r+=1,f+=1){const n=h(l,d,p,f,c);if(!n)continue;moveCursorTo(e,r,t);const u=n.hyperlink;o=transitionHyperlink(e.diff,o,u);writeCellWithStyleStr(e,n,i.transition(s,n.styleId))&&(s=n.styleId,c=n.styleId)}s=transitionStyle(e.diff,i,s,i.none),o=transitionHyperlink(e.diff,o,void 0),e.txn(e=>[[g,x],{dx:-e.x,dy:1}])}return transitionStyle(e.diff,i,s,i.none),transitionHyperlink(e.diff,o,void 0),e}function writeCellWithStyleStr(e,t,r){const n=1===t.width?2:1,i=e.cursor.x,o=e.viewportWidth;if(2===n&&i<o){if(i+2>=(t.char.length>2?o:o+1))return!1}const s=e.diff;r.length>0&&s.push({type:"styleStr",str:r});const c=2===n&&function(e){const t=e.codePointAt(0);if(void 0===t)return!1;if(t>=129648&&t<=129791||t>=129792&&t<=130047)return!0;if(e.length>=2)for(let t=0;t<e.length;t++)if(65039===e.charCodeAt(t))return!0;return!1}(t.char);return c&&i+1<o&&(s.push({type:"cursorTo",col:i+2}),s.push({type:"stdout",content:" "}),s.push({type:"cursorTo",col:i+1})),s.push({type:"stdout",content:t.char}),c&&s.push({type:"cursorTo",col:i+n+1}),i>=o?(e.cursor.x=n,e.cursor.y++):e.cursor.x=i+n,!0}function moveCursorTo(e,t,r){e.txn(n=>{const i=t-n.x,o=r-n.y;return n.x>=e.viewportWidth||0!==o?[[g,{type:"cursorMove",x:t,y:o}],{dx:i,dy:o}]:[[{type:"cursorMove",x:i,y:o}],{dx:i,dy:o}]})}class VirtualScreen{viewportWidth;cursor;diff=[];constructor(e,t){this.viewportWidth=t,this.cursor={...e}}txn(e){const[t,r]=e(this.cursor);for(const e of t)this.diff.push(e);this.cursor.x+=r.dx,this.cursor.y+=r.dy}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lineWidth as t}from"./line-width-cache.js";function measureText(e,i){if(0===e.length)return{width:0,height:0};const n=i<=0||!Number.isFinite(i);let r=0,h=0,s=0;for(;s<=e.length;){const
|
|
1
|
+
import{lineWidth as t}from"./line-width-cache.js";function measureText(e,i){if(0===e.length)return{width:0,height:0};const n=i<=0||!Number.isFinite(i);let r=0,h=0,s=0;for(;s<=e.length;){const u=e.indexOf("\n",s),a=-1===u?e.substring(s):e.substring(s,u),f=t(a);if(h=Math.max(h,f),n?r++:r+=0===f?1:Math.ceil(f/i),-1===u)break;s=u+1}return{width:h,height:r}}export default measureText;
|
package/dist/src/ink/output.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{styledCharsFromTokens as t,tokenize as e}from"@alcalzone/ansi-tokenize";import{logForDebugging as i}from"../utils/debug.js";import{getGraphemeSegmenter as n}from"../utils/intl.js";import o from"../utils/sliceAnsi.js";import{reorderBidi as s}from"./bidi.js";import{unionRect as r}from"./layout/geometry.js";import{blitRegion as h,extractHyperlinkFromStyles as c,filterOutHyperlinkStyles as l,markNoSelectRegion as
|
|
1
|
+
import{styledCharsFromTokens as t,tokenize as e}from"@alcalzone/ansi-tokenize";import{logForDebugging as i}from"../utils/debug.js";import{getGraphemeSegmenter as n}from"../utils/intl.js";import o from"../utils/sliceAnsi.js";import{reorderBidi as s}from"./bidi.js";import{unionRect as r}from"./layout/geometry.js";import{blitRegion as h,extractHyperlinkFromStyles as c,filterOutHyperlinkStyles as l,markNoSelectRegion as f,OSC8_PREFIX as a,resetScreen as u,setCellAt as p,shiftRows as y}from"./screen.js";import{stringWidth as d}from"./stringWidth.js";import{widestLine as m}from"./widest-line.js";function intersectClip(t,e){return t?{x1:maxDefined(t.x1,e.x1),x2:minDefined(t.x2,e.x2),y1:maxDefined(t.y1,e.y1),y2:minDefined(t.y2,e.y2)}:e}function maxDefined(t,e){return void 0===t?e:void 0===e?t:Math.max(t,e)}function minDefined(t,e){return void 0===t?e:void 0===e?t:Math.min(t,e)}export default class Output{width;height;stylePool;screen;operations=[];charCache=new Map;constructor(t){const{width:e,height:i,stylePool:n,screen:o}=t;this.width=e,this.height=i,this.stylePool=n,this.screen=o,u(o,e,i)}reset(t,e,i){this.width=t,this.height=e,this.screen=i,this.operations.length=0,u(i,t,e),this.charCache.size>16384&&this.charCache.clear()}blit(t,e,i,n,o){this.operations.push({type:"blit",src:t,x:e,y:i,width:n,height:o})}shift(t,e,i){this.operations.push({type:"shift",top:t,bottom:e,n:i})}clear(t,e){this.operations.push({type:"clear",region:t,fromAbsolute:e})}noSelect(t){this.operations.push({type:"noSelect",region:t})}write(t,e,i,n){i&&this.operations.push({type:"write",x:t,y:e,text:i,softWrap:n})}clip(t){this.operations.push({type:"clip",clip:t})}unclip(){this.operations.push({type:"unclip"})}get(){const t=this.screen,e=this.width,n=this.height;let s=0,c=0;const l=[];for(const i of this.operations){if("clear"!==i.type)continue;const{x:o,y:s,width:h,height:c}=i.region,f=Math.max(0,o),a=Math.max(0,s),u=Math.min(o+h,e),p=Math.min(s+c,n);if(f>=u||a>=p)continue;const y={x:f,y:a,width:u-f,height:p-a};t.damage=t.damage?r(t.damage,y):y,i.fromAbsolute&&l.push(y)}const a=[];for(const i of this.operations)switch(i.type){case"clear":continue;case"clip":a.push(intersectClip(a.at(-1),i.clip));continue;case"unclip":a.pop();continue;case"blit":{const{src:o,x:r,y:c,width:f,height:u}=i,p=a.at(-1),y=Math.max(r,p?.x1??0),d=Math.max(c,p?.y1??0),m=Math.min(c+u,n,o.height,p?.y2??1/0),g=Math.min(r+f,e,o.width,p?.x2??1/0);if(y>=g||d>=m)continue;if(0===l.length){h(t,o,y,d,g,m),s+=(m-d)*(g-y);continue}let x=d;for(let e=d;e<=m;e++){(e<m&&l.some(t=>e>=t.y&&e<t.y+t.height&&y>=t.x&&g<=t.x+t.width)||e===m)&&(e>x&&(h(t,o,y,x,g,e),s+=(e-x)*(g-y)),x=e+1)}continue}case"shift":y(t,i.top,i.bottom,i.n);continue;case"write":{const{text:s,softWrap:r}=i;let{x:h,y:l}=i,f=s.split("\n"),u=0,p=0;const y=a.at(-1);if(y){const t="number"==typeof y?.x1&&"number"==typeof y?.x2,e="number"==typeof y?.y1&&"number"==typeof y?.y2;if(t){const t=m(s);if(h+t<=y.x1||h>=y.x2)continue}if(e){if(l+f.length<=y.y1||l>=y.y2)continue}if(t&&(f=f.map(t=>{const e=h<y.x1?y.x1-h:0,i=d(t),n=h+i>y.x2?y.x2-h:i;let s=o(t,e,n);return d(s)>n-e&&(s=o(t,e,n-1)),s}),h<y.x1&&(h=y.x1)),e){const t=l<y.y1?y.y1-l:0,e=f.length,i=l+e>y.y2?y.y2-l:e;r&&t>0&&!0===r[t]&&(p=h+d(f[t-1])),f=f.slice(t,i),u=t,l<y.y1&&(l=y.y1)}}const g=t.softWrap;let x=0;for(const i of f){const o=l+x;if(o>=n)break;const s=writeLineToScreen(t,i,h,o,e,this.stylePool,this.charCache);if(c+=s-h,r){const t=!0===r[u+x];g[o]=t?p:0,p=s}x++}continue}}for(const e of this.operations)if("noSelect"===e.type){const{x:i,y:n,width:o,height:s}=e.region;f(t,i,n,o,s)}const u=s+c;return u>1e3&&c>s&&i(`High write ratio: blit=${s}, write=${c} (${(c/u*100).toFixed(1)}% writes), screen=${n}x${e}`),t}}function stylesEqual(t,e){if(t===e)return!0;const i=t.length;if(i!==e.length)return!1;if(0===i)return!0;for(let n=0;n<i;n++)if(t[n].code!==e[n].code)return!1;return!0}function flushBuffer(t,e,i,o){const s=c(e)??void 0,r=void 0!==s||e.some(t=>t.code.length>=a.length&&t.code.startsWith(a))?l(e):e,h=i.intern(r);for(const{segment:e}of n().segment(t))o.push({value:e,width:d(e),styleId:h,hyperlink:s})}function writeLineToScreen(i,n,o,r,h,c,l){let f=l.get(n);f||(f=s(function(t,e){const i=t.length;if(0===i)return[];const n=[],o=[];let s=t[0].styles;for(let r=0;r<i;r++){const i=t[r],h=i.styles;o.length>0&&!stylesEqual(h,s)&&(flushBuffer(o.join(""),s,e,n),o.length=0),o.push(i.value),s=h}return o.length>0&&flushBuffer(o.join(""),s,e,n),n}(t(e(n)),c)),l.set(n,f));let a=o;for(let t=0;t<f.length;t++){const e=f[t],n=e.value.codePointAt(0);if(void 0!==n&&n<=31){if(9===n){const t=8,e=t-a%t;for(let t=0;t<e&&a<h;t++)p(i,a,r,{char:" ",styleId:c.none,width:0,hyperlink:void 0}),a++}else if(27===n){const e=f[t+1]?.value,i=e?.codePointAt(0);if("("===e||")"===e||"*"===e||"+"===e)t+=2;else if("["===e)for(t++;t<f.length-1;){t++;const e=f[t]?.value.codePointAt(0);if(void 0!==e&&e>=64&&e<=126)break}else if("]"===e||"P"===e||"_"===e||"^"===e||"X"===e)for(t++;t<f.length-1;){t++;const e=f[t]?.value;if(""===e)break;if(""===e){const e=f[t+1]?.value;if("\\"===e){t++;break}}}else void 0!==i&&i>=48&&i<=126&&t++}continue}const o=e.width;if(0===o)continue;const s=o>=2;s&&a+2>h?(p(i,a,r,{char:" ",styleId:c.none,width:3,hyperlink:void 0}),a++):(p(i,a,r,{char:e.value,styleId:e.styleId,width:s?1:0,hyperlink:e.hyperlink}),a+=s?2:1)}return a}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Buffer as e}from"buffer";import{PASTE_END as t,PASTE_START as r}from"./termio/csi.js";import{createTokenizer as s}from"./termio/tokenize.js";const
|
|
1
|
+
import{Buffer as e}from"buffer";import{PASTE_END as t,PASTE_START as r}from"./termio/csi.js";import{createTokenizer as s}from"./termio/tokenize.js";const n=/^(?:\x1b)([a-zA-Z0-9])$/,a=/^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/,c=/^\x1b\[(\d+)(?:;(\d+))?u/,o=/^\x1b\[27;(\d+);(\d+)~/,u=/^\x1b\[\?(\d+);(\d+)\$y$/,i=/^\x1b\[\?([\d;]*)c$/,f=/^\x1b\[>([\d;]*)c$/,p=/^\x1b\[\?(\d+)u$/,l=/^\x1b\[\?(\d+);(\d+)R$/,d=/^\x1b\](\d+);(.*?)(?:\x07|\x1b\\)$/s,m=/^\x1bP>\|(.*?)(?:\x07|\x1b\\)$/s,h=/^\x1b\[<(\d+);(\d+);(\d+)([Mm])$/;function createPasteKey(e){return{kind:"key",name:"",fn:!1,ctrl:!1,meta:!1,shift:!1,option:!1,super:!1,sequence:e,raw:e,isPasted:!0}}export const DECRPM_STATUS={NOT_RECOGNIZED:0,SET:1,RESET:2,PERMANENTLY_SET:3,PERMANENTLY_RESET:4};function parseTerminalResponse(e){if(e.startsWith("[")){let t;return(t=u.exec(e))?{type:"decrpm",mode:parseInt(t[1],10),status:parseInt(t[2],10)}:(t=i.exec(e))?{type:"da1",params:splitNumericParams(t[1])}:(t=f.exec(e))?{type:"da2",params:splitNumericParams(t[1])}:(t=p.exec(e))?{type:"kittyKeyboard",flags:parseInt(t[1],10)}:(t=l.exec(e))?{type:"cursorPosition",row:parseInt(t[1],10),col:parseInt(t[2],10)}:null}if(e.startsWith("]")){const t=d.exec(e);if(t)return{type:"osc",code:parseInt(t[1],10),data:t[2]}}if(e.startsWith("P")){const t=m.exec(e);if(t)return{type:"xtversion",name:t[1]}}return null}function splitNumericParams(e){return e?e.split(";").map(e=>parseInt(e,10)):[]}export const INITIAL_STATE={mode:"NORMAL",incomplete:"",pasteBuffer:""};export function parseMultipleKeypresses(n,a=""){const c=null===a,o=c?"":function(t){return e.isBuffer(t)?t[0]>127&&void 0===t[1]?(t[0]-=128,""+String(t)):String(t):void 0!==t&&"string"!=typeof t?String(t):t||""}(a),u=n._tokenizer??s({x10Mouse:!0}),i=c?u.flush():u.feed(o),f=[];let p="IN_PASTE"===n.mode,l=n.pasteBuffer;for(const e of i)if("sequence"===e.type)if(e.value===r)p=!0,l="";else if(e.value===t)f.push(createPasteKey(l)),p=!1,l="";else if(p)l+=e.value;else{const t=parseTerminalResponse(e.value);if(t)f.push({kind:"response",sequence:e.value,response:t});else{const t=parseMouseEvent(e.value);t?f.push(t):f.push(parseKeypress(e.value))}}else if("text"===e.type)if(p)l+=e.value;else if(/^\[<\d+;\d+;\d+[Mm]$/.test(e.value)||/^\[M[\x60-\x7f][\x20-\uffff]{2}$/.test(e.value)){const t=""+e.value,r=parseMouseEvent(t);f.push(r??parseKeypress(t))}else f.push(parseKeypress(e.value));c&&p&&l&&(f.push(createPasteKey(l)),p=!1,l="");return[f,{mode:p?"IN_PASTE":"NORMAL",incomplete:u.buffer(),pasteBuffer:l,_tokenizer:u}]}const O={OP:"f1",OQ:"f2",OR:"f3",OS:"f4",Op:"0",Oq:"1",Or:"2",Os:"3",Ot:"4",Ou:"5",Ov:"6",Ow:"7",Ox:"8",Oy:"9",Oj:"*",Ok:"+",Ol:",",Om:"-",On:".",Oo:"/",OM:"return","[11~":"f1","[12~":"f2","[13~":"f3","[14~":"f4","[[A":"f1","[[B":"f2","[[C":"f3","[[D":"f4","[[E":"f5","[15~":"f5","[17~":"f6","[18~":"f7","[19~":"f8","[20~":"f9","[21~":"f10","[23~":"f11","[24~":"f12","[A":"up","[B":"down","[C":"right","[D":"left","[E":"clear","[F":"end","[H":"home",OA:"up",OB:"down",OC:"right",OD:"left",OE:"clear",OF:"end",OH:"home","[1~":"home","[2~":"insert","[3~":"delete","[4~":"end","[5~":"pageup","[6~":"pagedown","[[5~":"pageup","[[6~":"pagedown","[7~":"home","[8~":"end","[a":"up","[b":"down","[c":"right","[d":"left","[e":"clear","[2$":"insert","[3$":"delete","[5$":"pageup","[6$":"pagedown","[7$":"home","[8$":"end",Oa:"up",Ob:"down",Oc:"right",Od:"left",Oe:"clear","[2^":"insert","[3^":"delete","[5^":"pageup","[6^":"pagedown","[7^":"home","[8^":"end","[Z":"tab"};export const nonAlphanumericKeys=[...Object.values(O).filter(e=>e.length>1),"escape","backspace","wheelup","wheeldown","mouse"];const isShiftKey=e=>["[a","[b","[c","[d","[e","[2$","[3$","[5$","[6$","[7$","[8$","[Z"].includes(e),isCtrlKey=e=>["Oa","Ob","Oc","Od","Oe","[2^","[3^","[5^","[6^","[7^","[8^"].includes(e);function decodeModifier(e){const t=e-1;return{shift:!!(1&t),meta:!!(2&t),ctrl:!!(4&t),super:!!(8&t)}}function keycodeToName(e){switch(e){case 9:return"tab";case 13:case 57414:return"return";case 27:return"escape";case 32:return"space";case 127:return"backspace";case 57399:return"0";case 57400:return"1";case 57401:return"2";case 57402:return"3";case 57403:return"4";case 57404:return"5";case 57405:return"6";case 57406:return"7";case 57407:return"8";case 57408:return"9";case 57409:return".";case 57410:return"/";case 57411:return"*";case 57412:return"-";case 57413:return"+";case 57415:return"=";default:return e>=32&&e<=126?String.fromCharCode(e).toLowerCase():void 0}}function parseMouseEvent(e){const t=h.exec(e);if(!t)return null;const r=parseInt(t[1],10);return 64&r?null:{kind:"mouse",button:r,action:"M"===t[4]?"press":"release",col:parseInt(t[2],10),row:parseInt(t[3],10),sequence:e}}function parseKeypress(e=""){let t;const r={kind:"key",name:"",fn:!1,ctrl:!1,meta:!1,shift:!1,option:!1,super:!1,sequence:e,raw:e,isPasted:!1};let s;if(r.sequence=r.sequence||e||r.name,s=c.exec(e)){const t=parseInt(s[1],10),r=decodeModifier(s[2]?parseInt(s[2],10):1);return{kind:"key",name:keycodeToName(t),fn:!1,ctrl:r.ctrl,meta:r.meta,shift:r.shift,option:!1,super:r.super,sequence:e,raw:e,isPasted:!1}}if(s=o.exec(e)){const t=decodeModifier(parseInt(s[1],10));return{kind:"key",name:keycodeToName(parseInt(s[2],10)),fn:!1,ctrl:t.ctrl,meta:t.meta,shift:t.shift,option:!1,super:t.super,sequence:e,raw:e,isPasted:!1}}if(s=h.exec(e)){const t=parseInt(s[1],10);return createNavKey(e,64==(67&t)?"wheelup":65==(67&t)?"wheeldown":"mouse",!1)}if(6===e.length&&e.startsWith("[M")){const t=e.charCodeAt(3)-32;return createNavKey(e,64==(67&t)?"wheelup":65==(67&t)?"wheeldown":"mouse",!1)}if("\r"===e)r.raw=void 0,r.name="return";else if("\n"===e)r.name="enter";else if("\t"===e)r.name="tab";else if("\b"===e||"\b"===e)r.name="backspace",r.meta=""===e.charAt(0);else if(""===e||""===e)r.name="backspace",r.meta=""===e.charAt(0);else if(""===e||""===e)r.name="escape",r.meta=2===e.length;else if(" "===e||" "===e)r.name="space",r.meta=2===e.length;else if(""===e)r.name="_",r.ctrl=!0;else if(e<=""&&1===e.length)r.name=String.fromCharCode(e.charCodeAt(0)+"a".charCodeAt(0)-1),r.ctrl=!0;else if(1===e.length&&e>="0"&&e<="9")r.name="number";else if(1===e.length&&e>="a"&&e<="z")r.name=e;else if(1===e.length&&e>="A"&&e<="Z")r.name=e.toLowerCase(),r.shift=!0;else if(t=n.exec(e))r.meta=!0,r.shift=/^[A-Z]$/.test(t[1]);else if(t=a.exec(e)){const s=[...e];""===s[0]&&""===s[1]&&(r.option=!0);const n=[t[1],t[2],t[4],t[6]].filter(Boolean).join(""),a=(t[3]||t[5]||1)-1;r.ctrl=!!(4&a),r.meta=!!(2&a),r.super=!!(8&a),r.shift=!!(1&a),r.code=n,r.name=O[n],r.shift=isShiftKey(n)||r.shift,r.ctrl=isCtrlKey(n)||r.ctrl}switch("b"===r.raw?(r.meta=!0,r.name="left"):"f"===r.raw&&(r.meta=!0,r.name="right"),e){case"[1~":return createNavKey(e,"home",!1);case"[4~":return createNavKey(e,"end",!1);case"[5~":return createNavKey(e,"pageup",!1);case"[6~":return createNavKey(e,"pagedown",!1);case"[1;5D":return createNavKey(e,"left",!0);case"[1;5C":return createNavKey(e,"right",!0)}return r}function createNavKey(e,t,r){return{kind:"key",name:t,ctrl:r,meta:!1,shift:!1,option:!1,super:!1,fn:!1,sequence:e,raw:e,isPasted:!1}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{appendFileSync as e}from"fs";import t from"react-reconciler";import{getYogaCounters as n}from"
|
|
1
|
+
import{appendFileSync as e}from"fs";import t from"react-reconciler";import{getYogaCounters as n}from"../native-ts/yoga-layout/index.js";import{isEnvTruthy as o}from"../utils/envUtils.js";import{appendChildNode as r,clearYogaNodeReferences as s,createNode as i,createTextNode as a,insertBeforeNode as d,markDirty as c,removeChildNode as l,setAttribute as p,setStyle as m,setTextNodeValue as u,setTextStyles as f}from"./dom.js";import{Dispatcher as v}from"./events/dispatcher.js";import{EVENT_HANDLER_PROPS as h}from"./events/event-handlers.js";import{getFocusManager as x,getRootNode as y}from"./focus.js";import{LayoutDisplay as C}from"./layout/node.js";import T from"./styles.js";if("development"===process.env.NODE_ENV)try{import("./devtools.js")}catch(S){if("ERR_MODULE_NOT_FOUND"!==S.code)throw S;console.warn("\nThe environment variable DEV is set to true, so Ink tried to import `react-devtools-core`,\nbut this failed as it was not installed. Debugging with React Devtools requires it.\n\nTo install use this command:\n\n$ npm install --save-dev react-devtools-core\n\t\t\t\t".trim()+"\n")}const diff=(e,t)=>{if(e===t)return;if(!e)return t;const n={};let o=!1;for(const r of Object.keys(e)){(!t||!Object.hasOwn(t,r))&&(n[r]=void 0,o=!0)}if(t)for(const r of Object.keys(t))t[r]!==e[r]&&(n[r]=t[r],o=!0);return o?n:void 0},cleanupYogaNode=e=>{const t=e.yogaNode;t&&(t.unsetMeasureFunc(),s(e),t.freeRecursive())};function setEventHandler(e,t,n){e._eventHandlers||(e._eventHandlers={}),e._eventHandlers[t]=n}function applyProp(e,t,n){if("children"!==t)return"style"===t?(m(e,n),void(e.yogaNode&&T(e.yogaNode,n))):void("textStyles"!==t?h.has(t)?setEventHandler(e,t,n):p(e,t,n):e.textStyles=n)}export function getOwnerChain(e){const t=[],n=new Set;let o=e;for(let e=0;o&&e<50&&!n.has(o);e++){n.add(o);const e=o.elementType,r="function"==typeof e?e.displayName||e.name:"string"==typeof e?void 0:e?.displayName||e?.name;r&&r!==t[t.length-1]&&t.push(r),o=o._debugOwner??o.return}return t}let g;export function isDebugRepaintsEnabled(){return void 0===g&&(g=o(process.env.CONTEXT_CODE_DEBUG_REPAINTS)||o(process.env.CLAUDE_CODE_DEBUG_REPAINTS)),g}export const dispatcher=new v;const E=process.env.CONTEXT_CODE_COMMIT_LOG??process.env.CLAUDE_CODE_COMMIT_LOG;let I=0,N=0,O=0,w=0,_=0,b=0,D=0,F=0,P=0;export function recordYogaMs(e){D=e}export function getLastYogaMs(){return D}export function markCommitStart(){P=performance.now()}export function getLastCommitMs(){return F}export function resetProfileCounters(){D=0,F=0,P=0}const $=t({getRootHostContext:()=>({isInsideText:!1}),prepareForCommit:()=>(E&&(b=performance.now()),null),preparePortalMount:()=>null,clearContainer:()=>!1,resetAfterCommit(t){if(F=P>0?performance.now()-P:0,P=0,E){const t=performance.now();I++;const n=O>0?t-O:0;n>w&&(w=n),O=t;const o=b>0?t-b:0;(n>30||o>20||_>50)&&e(E,`${t.toFixed(1)} gap=${n.toFixed(1)}ms reconcile=${o.toFixed(1)}ms creates=${_}\n`),_=0,t-N>1e3&&(e(E,`${t.toFixed(1)} commits=${I}/s maxGap=${w.toFixed(1)}ms\n`),I=0,w=0,N=t)}const o=E?performance.now():0;if("function"==typeof t.onComputeLayout&&t.onComputeLayout(),E){const t=performance.now()-o;if(t>20){const r=n();e(E,`${o.toFixed(1)} SLOW_YOGA ${t.toFixed(1)}ms visited=${r.visited} measured=${r.measured} hits=${r.cacheHits} live=${r.live}\n`)}}if("test"===process.env.NODE_ENV){if(0===t.childNodes.length&&t.hasRenderedContent)return;return t.childNodes.length>0&&(t.hasRenderedContent=!0),void t.onImmediateRender?.()}const r=E?performance.now():0;if(t.onRender?.(),E){const t=performance.now()-r;t>10&&e(E,`${r.toFixed(1)} SLOW_PAINT ${t.toFixed(1)}ms\n`)}},getChildHostContext(e,t){const n="ink-text"===t||"ink-virtual-text"===t||"ink-link"===t;return e.isInsideText===n?e:{isInsideText:n}},shouldSetTextContent:()=>!1,createInstance(e,t,n,o,r){if(o.isInsideText&&"ink-box"===e)throw new Error("<Box> can't be nested inside <Text> component");const s="ink-text"===e&&o.isInsideText?"ink-virtual-text":e,a=i(s);E&&_++;for(const[e,n]of Object.entries(t))applyProp(a,e,n);return isDebugRepaintsEnabled()&&(a.debugOwnerChain=getOwnerChain(r)),a},createTextInstance(e,t,n){if(!n.isInsideText)throw new Error(`Text string "${e}" must be rendered inside <Text> component`);return a(e)},resetTextContent(){},hideTextInstance(e){u(e,"")},unhideTextInstance(e,t){u(e,t)},getPublicInstance:e=>e,hideInstance(e){e.isHidden=!0,e.yogaNode?.setDisplay(C.None),c(e)},unhideInstance(e){e.isHidden=!1,e.yogaNode?.setDisplay(C.Flex),c(e)},appendInitialChild:r,appendChild:r,insertBefore:d,finalizeInitialChildren:(e,t,n)=>!0===n.autoFocus,commitMount(e){x(e).handleAutoFocus(e)},isPrimaryRenderer:!0,supportsMutation:!0,supportsPersistence:!1,supportsHydration:!1,scheduleTimeout:setTimeout,cancelTimeout:clearTimeout,noTimeout:-1,getCurrentUpdatePriority:()=>dispatcher.currentUpdatePriority,beforeActiveInstanceBlur(){},afterActiveInstanceBlur(){},detachDeletedInstance(){},getInstanceFromNode:()=>null,prepareScopeUpdate(){},getInstanceFromScope:()=>null,appendChildToContainer:r,insertInContainerBefore:d,removeChildFromContainer(e,t){l(e,t),cleanupYogaNode(t),x(e).handleNodeRemoved(t,e)},commitUpdate(e,t,n,o){const r=diff(n,o),s=diff(n.style,o.style);if(r)for(const[t,n]of Object.entries(r))"style"!==t?"textStyles"!==t?h.has(t)?setEventHandler(e,t,n):p(e,t,n):f(e,n):m(e,n);s&&e.yogaNode&&T(e.yogaNode,s,o.style)},commitTextUpdate(e,t,n){u(e,n)},removeChild(e,t){if(l(e,t),cleanupYogaNode(t),"#text"!==t.nodeName){const n=y(e);n.focusManager.handleNodeRemoved(t,n)}},maySuspendCommit:()=>!1,preloadInstance:()=>!0,startSuspendingCommit(){},suspendInstance(){},waitForCommitToBeReady:()=>null,NotPendingTransition:null,HostTransitionContext:{$$typeof:Symbol.for("react.context"),_currentValue:null},setCurrentUpdatePriority(e){dispatcher.currentUpdatePriority=e},resolveUpdatePriority:()=>dispatcher.resolveEventPriority(),resetFormInstance(){},requestPostPaintCallback(){},shouldAttemptEagerTransition:()=>!1,trackSchedulerEvent(){},resolveEventType:()=>dispatcher.currentEvent?.type??null,resolveEventTimeStamp:()=>dispatcher.currentEvent?.timeStamp??-1.1});dispatcher.discreteUpdates=$.discreteUpdates.bind($);export default $;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import e from"chalk";import t from"cli-boxes";import{applyColor as o}from"./colorize.js";import{stringWidth as r}from"./stringWidth.js";export const CUSTOM_BORDER_STYLES={dashed:{top:"╌",left:"╎",right:"╎",bottom:"╌",topLeft:" ",topRight:" ",bottomLeft:" ",bottomRight:" "}};function embedTextInBorder(e,t,o,l=0,s){const d=r(t),i=e.length;if(d>=i-2)return["",t.substring(0,i),""];let b;b="center"===o?Math.floor((i-d)/2):"start"===o?l+1:i-d-l-1,b=Math.max(1,Math.min(b,i-d-1));return[e.substring(0,1)+s.repeat(b-1),t,s.repeat(i-b-d-1)+e.substring(i-1)]}function styleBorderLine(t,r,l){let s=o(t,r);return l&&(s=e.dim(s)),s}export default(r,l,s,d)=>{if(s.style.borderStyle){const i=Math.floor(s.yogaNode.getComputedWidth()),b=Math.floor(s.yogaNode.getComputedHeight()),y="string"==typeof s.style.borderStyle?CUSTOM_BORDER_STYLES[s.style.borderStyle]??t[s.style.borderStyle]:s.style.borderStyle,n=s.style.borderTopColor??s.style.borderColor,m=s.style.borderBottomColor??s.style.borderColor,f=s.style.borderLeftColor??s.style.borderColor,p=s.style.borderRightColor??s.style.borderColor,a=s.style.borderTopDimColor??s.style.borderDimColor,g=s.style.borderBottomDimColor??s.style.borderDimColor,h=s.style.borderLeftDimColor??s.style.borderDimColor,C=s.style.borderRightDimColor??s.style.borderDimColor,T=!1!==s.style.borderTop,x=!1!==s.style.borderBottom,L=!1!==s.style.borderLeft,c=!1!==s.style.borderRight,B=Math.max(0,i-(L?1:0)-(c?1:0)),u=T?(L?y.topLeft:"")+y.top.repeat(B)+(c?y.topRight:""):"";let R;if(T&&"top"===s.style.borderText?.position){const[e,t,o]=embedTextInBorder(u,s.style.borderText.content,s.style.borderText.align,s.style.borderText.offset,y.top);R=styleBorderLine(e,n,a)+t+styleBorderLine(o,n,a)}else T&&(R=styleBorderLine(u,n,a));let S=b;T&&(S-=1),x&&(S-=1),S=Math.max(0,S);let D=(o(y.left,f)+"\n").repeat(S);h&&(D=e.dim(D));let M=(o(y.right,p)+"\n").repeat(S);C&&(M=e.dim(M));const w=x?(L?y.bottomLeft:"")+y.bottom.repeat(B)+(c?y.bottomRight:""):"";let E;if(x&&"bottom"===s.style.borderText?.position){const[e,t,o]=embedTextInBorder(w,s.style.borderText.content,s.style.borderText.align,s.style.borderText.offset,y.bottom);E=styleBorderLine(e,m,g)+t+styleBorderLine(o,m,g)}else x&&(E=styleBorderLine(w,m,g));const O=T?1:0;R&&d.write(r,l,R),L&&d.write(r,l+O,D),c&&d.write(r+i-1,l+O,M),E&&d.write(r,l+b-1,E)}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"indent-string";import{applyTextStyles as o}from"./colorize.js";import e from"./get-max-width.js";import{LayoutDisplay as r,LayoutEdge as l}from"./layout/node.js";import{nodeCache as n,pendingClears as i}from"./node-cache.js";import s from"./render-border.js";import{squashTextNodesToSegments as d}from"./squash-text-nodes.js";import{isXtermJs as c}from"./terminal.js";import{widestLine as a}from"./widest-line.js";import h from"./wrap-text.js";let p=!1;export function resetLayoutShifted(){p=!1}export function didLayoutShift(){return p}let f=null,u=[],g=[];export function resetScrollHint(){f=null,u=g,g=[]}export function getScrollHint(){return f}let y=null;export function resetScrollDrainNode(){y=null}export function getScrollDrainNode(){return y}let m=null;export function consumeFollowScroll(){const t=m;return m=null,t}function wrapWithOsc8Link(t,o){return`]8;;${o}${t}]8;;`}function buildCharToSegmentMap(t){const o=[];for(let e=0;e<t.length;e++){const r=t[e].text.length;for(let t=0;t<r;t++)o.push(e)}return o}function applyStylesToWrappedText(t,e,r,l,n=!1){const i=t.split("\n"),s=[];let d=0;for(let t=0;t<i.length;t++){const c=i[t];if(n&&c.length>0){const t=/\s/.test(c[0]);if(d<l.length&&/\s/.test(l[d])&&!t)for(;d<l.length&&/\s/.test(l[d]);)d++}let a="",h=0,p=r[d]??0;for(let t=0;t<c.length;t++){const l=r[d]??p;if(l!==p){const r=c.slice(h,t),n=e[p];if(n){let t=o(r,n.styles);n.hyperlink&&(t=wrapWithOsc8Link(t,n.hyperlink)),a+=t}else a+=r;h=t,p=l}d++}const f=c.slice(h),u=e[p];if(u){let t=o(f,u.styles);u.hyperlink&&(t=wrapWithOsc8Link(t,u.hyperlink)),a+=t}else a+=f;if(s.push(a),d<l.length&&"\n"===l[d]&&d++,n&&t<i.length-1){const o=i[t+1],e=o.length>0?o[0]:null;for(;d<l.length&&/\s/.test(l[d])&&(null===e||l[d]!==e);)d++}}return s.join("\n")}function wrapWithSoftWrap(t,o,e){if("wrap"!==e&&"wrap-trim"!==e)return{wrapped:h(t,o,e),softWrap:void 0};const r=t.split("\n"),l=[],n=[];for(const t of r){const r=h(t,o,e).split("\n");for(let t=0;t<r.length;t++)l.push(r[t]),n.push(t>0)}return{wrapped:l.join("\n"),softWrap:n}}function renderNodeToOutput(h,M,{offsetX:x=0,offsetY:C=0,prevScreen:w,skipSelfBlit:v=!1,inheritedBackgroundColor:S}){const{yogaNode:T}=h;if(T){if(T.getDisplay()===r.None){if(h.dirty){const t=n.get(h);t&&(M.clear({x:Math.floor(t.x),y:Math.floor(t.y),width:Math.floor(t.width),height:Math.floor(t.height)}),dropSubtreeCache(h),p=!0)}return}const b=x+T.getComputedLeft(),N=T.getComputedTop();let k=C+N;const W=T.getComputedWidth(),B=T.getComputedHeight();k<0&&"absolute"===h.style.position&&(k=0);const D=n.get(h);if(!h.dirty&&!v&&void 0===h.pendingScrollDelta&&D&&D.x===b&&D.y===k&&D.width===W&&D.height===B&&w){const t=Math.floor(b),o=Math.floor(k),e=Math.floor(W),r=Math.floor(B);return M.blit(w,t,o,e,r),"absolute"===h.style.position&&g.push(D),void blitEscapingAbsoluteDescendants(h,M,w,t,o,e,r)}const j=void 0!==D&&(D.x!==b||D.y!==k||D.width!==W||D.height!==B);j&&(p=!0),D&&(h.dirty||j)&&M.clear({x:Math.floor(D.x),y:Math.floor(D.y),width:Math.floor(D.width),height:Math.floor(D.height)},"absolute"===h.style.position);const L=i.get(h),A=void 0!==L;if(A){p=!0;for(const t of L)M.clear({x:Math.floor(t.x),y:Math.floor(t.y),width:Math.floor(t.width),height:Math.floor(t.height)});i.delete(h)}if(0===B&&function(t,o){const e=t.parentNode;if(!e)return!1;const r=o.getComputedTop(),l=e.childNodes,n=l.indexOf(t);for(let t=n+1;t<l.length;t++){const o=l[t].yogaNode;if(o)return o.getComputedTop()===r}for(let t=n-1;t>=0;t--){const o=l[t].yogaNode;if(o)return o.getComputedTop()===r}return!1}(h,T))return n.set(h,{x:b,y:k,width:W,height:B,top:N}),void(h.dirty=!1);if("ink-raw-ansi"===h.nodeName){const t=h.attributes.rawText;t&&M.write(b,k,t)}else if("ink-text"===h.nodeName){const r=d(h,S?{backgroundColor:S}:void 0),l=r.map(t=>t.text).join("");if(l.length>0){const n=Math.min(e(T),M.width-b),i=h.style.textWrap??"wrap",s=a(l)>n;let d,c;if(s&&1===r.length){const t=r[0],e=wrapWithSoftWrap(l,n,i);c=e.softWrap,d=e.wrapped.split("\n").map(e=>{let r=o(e,t.styles);return t.hyperlink&&(r=wrapWithOsc8Link(r,t.hyperlink)),r}).join("\n")}else if(s){const t=wrapWithSoftWrap(l,n,i);c=t.softWrap;const o=buildCharToSegmentMap(r);d=applyStylesToWrappedText(t.wrapped,r,o,l,"wrap-trim"===i)}else d=r.map(t=>{let e=o(t.text,t.styles);return t.hyperlink&&(e=wrapWithOsc8Link(e,t.hyperlink)),e}).join("");d=function(o,e,r){const l=o.childNodes[0]?.yogaNode;if(l){const o=l.getComputedLeft(),n=l.getComputedTop();e="\n".repeat(n)+t(e,o),r&&n>0&&r.unshift(...Array(n).fill(!1))}return e}(h,d,c),M.write(b,k,d,c)}}else if("ink-box"===h.nodeName){const t=h.style.backgroundColor??S;if(h.style.noSelect){const t=Math.floor(b),o="from-left-edge"===h.style.noSelect;M.noSelect({x:o?0:t,y:Math.floor(k),width:o?t+Math.floor(W):Math.floor(W),height:Math.floor(B)})}const e=h.style.overflowX??h.style.overflow,r=h.style.overflowY??h.style.overflow,i="hidden"===e||"scroll"===e,d="hidden"===r||"scroll"===r,a="scroll"===r,g=i||d;let x,C;if(g){const t=i?b+T.getComputedBorder(l.Left):void 0,o=i?b+T.getComputedWidth()-T.getComputedBorder(l.Right):void 0;x=d?k+T.getComputedBorder(l.Top):void 0,C=d?k+T.getComputedHeight()-T.getComputedBorder(l.Bottom):void 0,M.clip({x1:t,x2:o,y1:x,y2:C})}if(a){const o=T.getComputedPadding(l.Top),e=Math.max(0,(C??k+B)-(x??k)-o-T.getComputedPadding(l.Bottom)),r=h.childNodes.find(t=>t.yogaNode),i=r?.yogaNode,s=i?.getComputedHeight()??0,d=h.scrollHeight??s,a=h.scrollViewportHeight??e;h.scrollHeight=s,h.scrollViewportHeight=e,h.scrollViewportTop=(x??k)+o;const g=Math.max(0,s-e);if(h.scrollAnchor){const t=h.scrollAnchor.el.yogaNode?.getComputedTop();null!=t&&(h.scrollTop=t+h.scrollAnchor.offset,h.pendingScrollDelta=void 0),h.scrollAnchor=void 0}const v=h.scrollTop??0,S=h.stickyScroll??Boolean(h.attributes.stickyScroll),N=Math.max(0,d-a);(S||s>=d&&v>=N)&&(h.pendingScrollDelta??0)>=0&&(h.scrollTop=g,h.pendingScrollDelta=void 0,!1===h.stickyScroll&&v>=N&&(h.stickyScroll=!0));const L=(h.scrollTop??0)-v;if(L>0){const t=h.scrollViewportTop??0;m={delta:L,viewportTop:t,viewportBottom:t+e-1}}let H=h.scrollTop??0;const O=h.pendingScrollDelta,X=h.scrollClampMin,Y=h.scrollClampMax,q=void 0!==X&&void 0!==Y;if(void 0!==O&&0!==O){const t=q&&(O<0&&H<X||O>0&&H>Y)?Math.min(4,e>>3):e;H+="vscode"===process.env.TERM_PROGRAM||c()?function(t,o,e){const r=o>0?1:-1;let l=Math.abs(o),n=0;l>30&&(n+=r*(l-30),l=30);const i=l<=5?l:l<12?2:3;n+=r*i;const s=l-i,d=Math.max(1,e-1),c=Math.abs(n);if(c>d){const o=c-d;return t.pendingScrollDelta=r*(s+o),r*d}return t.pendingScrollDelta=s>0?r*s:void 0,n}(h,O,t):function(t,o,e){const r=Math.abs(o),l=Math.max(1,e-1),n=Math.min(l,Math.max(4,3*r>>2));if(r<=n)return t.pendingScrollDelta=void 0,o;const i=o>0?n:-n;return t.pendingScrollDelta=o-i,i}(h,O,t)}else 0===O&&(h.pendingScrollDelta=void 0);let E=Math.max(0,Math.min(H,g));const R=q?Math.max(X,Math.min(E,Y)):E;if(h.scrollTop=E,E!==H&&(h.pendingScrollDelta=void 0),void 0!==h.pendingScrollDelta&&(y=h),E=R,r&&i){const l=b+i.getComputedLeft(),s=k+i.getComputedTop()-E,d=n.get(r);let c=null;if(d&&d.y!==s){const t=d.y-s,o=Math.floor(k+i.getComputedTop()),r=o+e-1;D?.y===k&&D.height===B&&e>0&&Math.abs(t)<e?(c={top:o,bottom:r,delta:t},f=c):p=!0}const a=i.getComputedHeight(),h=a-(d?.height??a),g=!c||0===h||c.delta>0&&h===c.delta;if(g||(f=null),c&&w&&g){const{top:i,bottom:d,delta:a}=c,h=Math.floor(W);M.blit(w,Math.floor(b),i,h,d-i+1),M.shift(i,d,a);const p=a>0?d-a+1:i,f=a>0?d:i-a-1;M.clear({x:Math.floor(b),y:p,width:h,height:f-p+1}),M.clip({x1:void 0,x2:void 0,y1:p,y2:f+1});const g=r.dirty?new Set(r.childNodes.filter(t=>t.dirty)):null;if(renderScrolledChildren(r,M,l,s,A,void 0,p-s,f+1-s,t,!0),M.unclip(),g){const i=p-s,d=f+1-s,c=" ".repeat(h);let u=0;for(const h of r.childNodes){const r=h,p=g.has(h);if(!p&&0===u&&n.has(r))continue;const f=r.yogaNode;if(!f)continue;const y=f.getComputedTop(),m=f.getComputedHeight(),C=y+m;if(p){const t=n.get(r);u+=m-(t?t.height:0)}if(C<=E||y>=E+e)continue;if(y>=i&&C<=d)continue;const w=Math.floor(s+y);if(!p){const t=n.get(r);if(t&&Math.floor(t.y)-a===w)continue}const v=Math.min(Math.floor(s+C),Math.floor((x??k)+o+e));if(w<v){const o=Array(v-w).fill(c).join("\n");M.write(Math.floor(b),w,o),M.clip({x1:void 0,x2:void 0,y1:w,y2:v}),renderNodeToOutput(r,M,{offsetX:l,offsetY:s,prevScreen:void 0,inheritedBackgroundColor:t}),M.unclip()}}}const y=u.length?" ".repeat(h):"";for(const o of u){if(o.y>=d+1||o.y+o.height<=i)continue;const e=Math.max(i,Math.floor(o.y)-a),n=Math.min(d+1,Math.floor(o.y+o.height)-a);if(e>=p&&n<=f+1)continue;if(e>=n)continue;const c=Array(n-e).fill(y).join("\n");M.write(Math.floor(b),e,c),M.clip({x1:void 0,x2:void 0,y1:e,y2:n}),renderScrolledChildren(r,M,l,s,A,void 0,e-s,n-s,t,!0),M.unclip()}}else{const o=d&&d.y!==s;o&&void 0!==x&&void 0!==C&&M.clear({x:Math.floor(b),y:Math.floor(x),width:Math.floor(W),height:Math.floor(C-x)}),renderScrolledChildren(r,M,l,s,A,o||j?void 0:w,E,E+e,t)}n.set(r,{x:l,y:s,width:i.getComputedWidth(),height:i.getComputedHeight()}),r.dirty=!1}}else{const e=h.style.backgroundColor;if(e||h.style.opaque){const t=T.getComputedBorder(l.Left),r=T.getComputedBorder(l.Right),n=T.getComputedBorder(l.Top),i=T.getComputedBorder(l.Bottom),s=Math.floor(W)-t-r,d=Math.floor(B)-n-i;if(s>0&&d>0){const r=" ".repeat(s),l=e?o(r,{backgroundColor:e}):r,i=Array(d).fill(l).join("\n");M.write(b+t,k+n,i)}}renderChildren(h,M,b,k,A,e||h.style.opaque?void 0:w,t)}g&&M.unclip(),s(b,k,h,M)}else"ink-root"===h.nodeName&&renderChildren(h,M,b,k,A,w,S);const H={x:b,y:k,width:W,height:B,top:N};n.set(h,H),"absolute"===h.style.position&&g.push(H),h.dirty=!1}}function renderChildren(t,o,e,r,l,n,i){let s=!1,d=!1;for(const c of t.childNodes){const t=c,a=t.dirty,h="absolute"===t.style.position;renderNodeToOutput(t,o,{offsetX:e,offsetY:r,prevScreen:l||s?void 0:n,skipSelfBlit:d&&h&&!t.style.opaque&&void 0===t.style.backgroundColor,inheritedBackgroundColor:i}),a&&!s&&(!clipsBothAxes(t)||h?s=!0:d=!0)}}function clipsBothAxes(t){const o=t.style.overflowX??t.style.overflow,e=t.style.overflowY??t.style.overflow;return!("hidden"!==o&&"scroll"!==o||"hidden"!==e&&"scroll"!==e)}function blitEscapingAbsoluteDescendants(t,o,e,r,l,i,s){const d=r+i,c=l+s;for(const a of t.childNodes){if("#text"===a.nodeName)continue;const t=a;if("absolute"===t.style.position){const i=n.get(t);if(i){g.push(i);const t=Math.floor(i.x),n=Math.floor(i.y),s=Math.floor(i.width),a=Math.floor(i.height);(t<r||n<l||t+s>d||n+a>c)&&o.blit(e,t,n,s,a)}}blitEscapingAbsoluteDescendants(t,o,e,r,l,i,s)}}function renderScrolledChildren(t,o,e,r,l,i,s,d,c,a=!1){let h=!1,p=0;for(const f of t.childNodes){const t=f,u=t.yogaNode;if(u){const o=n.get(t);let e,r;if(void 0===o?.top||t.dirty||0!==p?(e=u.getComputedTop(),r=u.getComputedHeight(),t.dirty&&(p+=r-(o?o.height:0)),o&&(o.top=e)):(e=o.top,r=o.height),e+r<=s||e>=d){a||dropSubtreeCache(t);continue}}const g=t.dirty;renderNodeToOutput(t,o,{offsetX:e,offsetY:r,prevScreen:l||h?void 0:i,inheritedBackgroundColor:c}),g&&(h=!0)}}function dropSubtreeCache(t){n.delete(t);for(const o of t.childNodes)"#text"!==o.nodeName&&dropSubtreeCache(o)}export{buildCharToSegmentMap,applyStylesToWrappedText};export default renderNodeToOutput;
|
|
1
|
+
import t from"indent-string";import{applyTextStyles as o}from"./colorize.js";import e from"./get-max-width.js";import{LayoutDisplay as r,LayoutEdge as l}from"./layout/node.js";import{nodeCache as n,pendingClears as i}from"./node-cache.js";import s from"./render-border.js";import{squashTextNodesToSegments as d}from"./squash-text-nodes.js";import{isXtermJs as c}from"./terminal.js";import{widestLine as h}from"./widest-line.js";import a from"./wrap-text.js";let p=!1;export function resetLayoutShifted(){p=!1}export function didLayoutShift(){return p}let f=null,u=[],g=[];export function resetScrollHint(){f=null,u=g,g=[]}export function getScrollHint(){return f}let y=null;export function resetScrollDrainNode(){y=null}export function getScrollDrainNode(){return y}let m=null;export function consumeFollowScroll(){const t=m;return m=null,t}function wrapWithOsc8Link(t,o){return`]8;;${o}${t}]8;;`}function buildCharToSegmentMap(t){const o=[];for(let e=0;e<t.length;e++){const r=t[e].text.length;for(let t=0;t<r;t++)o.push(e)}return o}function applyStylesToWrappedText(t,e,r,l,n=!1){const i=t.split("\n"),s=[];let d=0;for(let t=0;t<i.length;t++){const c=i[t];if(n&&c.length>0){const t=/\s/.test(c[0]);if(d<l.length&&/\s/.test(l[d])&&!t)for(;d<l.length&&/\s/.test(l[d]);)d++}let h="",a=0,p=r[d]??0;for(let t=0;t<c.length;t++){const l=r[d]??p;if(l!==p){const r=c.slice(a,t),n=e[p];if(n){let t=o(r,n.styles);n.hyperlink&&(t=wrapWithOsc8Link(t,n.hyperlink)),h+=t}else h+=r;a=t,p=l}d++}const f=c.slice(a),u=e[p];if(u){let t=o(f,u.styles);u.hyperlink&&(t=wrapWithOsc8Link(t,u.hyperlink)),h+=t}else h+=f;if(s.push(h),d<l.length&&"\n"===l[d]&&d++,n&&t<i.length-1){const o=i[t+1],e=o.length>0?o[0]:null;for(;d<l.length&&/\s/.test(l[d])&&(null===e||l[d]!==e);)d++}}return s.join("\n")}function wrapWithSoftWrap(t,o,e){if("wrap"!==e&&"wrap-trim"!==e)return{wrapped:a(t,o,e),softWrap:void 0};const r=t.split("\n"),l=[],n=[];for(const t of r){const r=a(t,o,e).split("\n");for(let t=0;t<r.length;t++)l.push(r[t]),n.push(t>0)}return{wrapped:l.join("\n"),softWrap:n}}function renderNodeToOutput(a,M,{offsetX:x=0,offsetY:w=0,prevScreen:C,skipSelfBlit:v=!1,inheritedBackgroundColor:S}){const{yogaNode:T}=a;if(T){if(T.getDisplay()===r.None){if(a.dirty){const t=n.get(a);t&&(M.clear({x:Math.floor(t.x),y:Math.floor(t.y),width:Math.floor(t.width),height:Math.floor(t.height)}),dropSubtreeCache(a),p=!0)}return}const b=x+T.getComputedLeft(),N=T.getComputedTop();let k=w+N;const W=T.getComputedWidth(),B=T.getComputedHeight();k<0&&"absolute"===a.style.position&&(k=0);const D=n.get(a);if(!a.dirty&&!v&&void 0===a.pendingScrollDelta&&D&&D.x===b&&D.y===k&&D.width===W&&D.height===B&&C){const t=Math.floor(b),o=Math.floor(k),e=Math.floor(W),r=Math.floor(B);return M.blit(C,t,o,e,r),"absolute"===a.style.position&&g.push(D),void blitEscapingAbsoluteDescendants(a,M,C,t,o,e,r)}const j=void 0!==D&&(D.x!==b||D.y!==k||D.width!==W||D.height!==B);j&&(p=!0),D&&(a.dirty||j)&&M.clear({x:Math.floor(D.x),y:Math.floor(D.y),width:Math.floor(D.width),height:Math.floor(D.height)},"absolute"===a.style.position);const A=i.get(a),H=void 0!==A;if(H){p=!0;for(const t of A)M.clear({x:Math.floor(t.x),y:Math.floor(t.y),width:Math.floor(t.width),height:Math.floor(t.height)});i.delete(a)}if(0===B&&function(t,o){const e=t.parentNode;if(!e)return!1;const r=o.getComputedTop(),l=e.childNodes,n=l.indexOf(t);for(let t=n+1;t<l.length;t++){const o=l[t].yogaNode;if(o)return o.getComputedTop()===r}for(let t=n-1;t>=0;t--){const o=l[t].yogaNode;if(o)return o.getComputedTop()===r}return!1}(a,T))return n.set(a,{x:b,y:k,width:W,height:B,top:N}),void(a.dirty=!1);if("ink-raw-ansi"===a.nodeName){const t=a.attributes.rawText;t&&M.write(b,k,t)}else if("ink-text"===a.nodeName){const r=d(a,S?{backgroundColor:S}:void 0),l=r.map(t=>t.text).join("");if(l.length>0){const n=Math.min(e(T),M.width-b),i=a.style.textWrap??"wrap",s=h(l)>n;let d,c;if(s&&1===r.length){const t=r[0],e=wrapWithSoftWrap(l,n,i);c=e.softWrap,d=e.wrapped.split("\n").map(e=>{let r=o(e,t.styles);return t.hyperlink&&(r=wrapWithOsc8Link(r,t.hyperlink)),r}).join("\n")}else if(s){const t=wrapWithSoftWrap(l,n,i);c=t.softWrap;const o=buildCharToSegmentMap(r);d=applyStylesToWrappedText(t.wrapped,r,o,l,"wrap-trim"===i)}else d=r.map(t=>{let e=o(t.text,t.styles);return t.hyperlink&&(e=wrapWithOsc8Link(e,t.hyperlink)),e}).join("");d=function(o,e,r){const l=o.childNodes[0]?.yogaNode;if(l){const o=l.getComputedLeft(),n=l.getComputedTop();e="\n".repeat(n)+t(e,o),r&&n>0&&r.unshift(...Array(n).fill(!1))}return e}(a,d,c),M.write(b,k,d,c)}}else if("ink-box"===a.nodeName){const t=a.style.backgroundColor??S;if(a.style.noSelect){const t=Math.floor(b),o="from-left-edge"===a.style.noSelect;M.noSelect({x:o?0:t,y:Math.floor(k),width:o?t+Math.floor(W):Math.floor(W),height:Math.floor(B)})}const e=a.style.overflowX??a.style.overflow,r=a.style.overflowY??a.style.overflow,i="hidden"===e||"scroll"===e,d="hidden"===r||"scroll"===r,h="scroll"===r,g=i||d;let x,w;if(g){const t=i?b+T.getComputedBorder(l.Left):void 0,o=i?b+T.getComputedWidth()-T.getComputedBorder(l.Right):void 0;x=d?k+T.getComputedBorder(l.Top):void 0,w=d?k+T.getComputedHeight()-T.getComputedBorder(l.Bottom):void 0,M.clip({x1:t,x2:o,y1:x,y2:w})}if(h){const o=T.getComputedPadding(l.Top),e=Math.max(0,(w??k+B)-(x??k)-o-T.getComputedPadding(l.Bottom)),r=a.childNodes.find(t=>t.yogaNode),i=r?.yogaNode,s=i?.getComputedHeight()??0,d=a.scrollHeight??s,h=a.scrollViewportHeight??e;a.scrollHeight=s,a.scrollViewportHeight=e,a.scrollViewportTop=(x??k)+o;const g=Math.max(0,s-e);if(a.scrollAnchor){const t=a.scrollAnchor.el.yogaNode?.getComputedTop();null!=t&&(a.scrollTop=t+a.scrollAnchor.offset,a.pendingScrollDelta=void 0),a.scrollAnchor=void 0}const v=a.scrollTop??0,S=a.stickyScroll??Boolean(a.attributes.stickyScroll),N=Math.max(0,d-h);(S||s>=d&&v>=N)&&(a.pendingScrollDelta??0)>=0&&(a.scrollTop=g,a.pendingScrollDelta=void 0,!1===a.stickyScroll&&v>=N&&(a.stickyScroll=!0));const A=(a.scrollTop??0)-v;if(A>0){const t=a.scrollViewportTop??0;m={delta:A,viewportTop:t,viewportBottom:t+e-1}}let L=a.scrollTop??0;const O=a.pendingScrollDelta,X=a.scrollClampMin,Y=a.scrollClampMax,R=void 0!==X&&void 0!==Y;if(void 0!==O&&0!==O){const t=R&&(O<0&&L<X||O>0&&L>Y)?Math.min(4,e>>3):e;L+="vscode"===process.env.TERM_PROGRAM||c()?function(t,o,e){const r=o>0?1:-1;let l=Math.abs(o),n=0;l>30&&(n+=r*(l-30),l=30);const i=l<=5?l:l<12?2:3;n+=r*i;const s=l-i,d=Math.max(1,e-1),c=Math.abs(n);if(c>d){const o=c-d;return t.pendingScrollDelta=r*(s+o),r*d}return t.pendingScrollDelta=s>0?r*s:void 0,n}(a,O,t):function(t,o,e){const r=Math.abs(o),l=Math.max(1,e-1),n=Math.min(l,Math.max(4,3*r>>2));if(r<=n)return t.pendingScrollDelta=void 0,o;const i=o>0?n:-n;return t.pendingScrollDelta=o-i,i}(a,O,t)}else 0===O&&(a.pendingScrollDelta=void 0);let q=Math.max(0,Math.min(L,g));const E=R?Math.max(X,Math.min(q,Y)):q;if(a.scrollTop=q,q!==L&&(a.pendingScrollDelta=void 0),void 0!==a.pendingScrollDelta&&(y=a),q=E,r&&i){const l=b+i.getComputedLeft(),s=k+i.getComputedTop()-q,d=n.get(r);let c=null;if(d&&d.y!==s){const t=d.y-s,o=Math.floor(k+i.getComputedTop()),r=o+e-1;D?.y===k&&D.height===B&&e>0&&Math.abs(t)<e?(c={top:o,bottom:r,delta:t},f=c):p=!0}const h=i.getComputedHeight(),a=h-(d?.height??h),g=!c||0===a||c.delta>0&&a===c.delta;if(g||(f=null),c&&C&&g){const{top:i,bottom:d,delta:h}=c,a=Math.floor(W);M.blit(C,Math.floor(b),i,a,d-i+1),M.shift(i,d,h);const p=h>0?d-h+1:i,f=h>0?d:i-h-1;M.clear({x:Math.floor(b),y:p,width:a,height:f-p+1}),M.clip({x1:void 0,x2:void 0,y1:p,y2:f+1});const g=r.dirty?new Set(r.childNodes.filter(t=>t.dirty)):null;if(renderScrolledChildren(r,M,l,s,H,void 0,p-s,f+1-s,t,!0),M.unclip(),g){const i=p-s,d=f+1-s,c=" ".repeat(a);let u=0;for(const a of r.childNodes){const r=a,p=g.has(a);if(!p&&0===u&&n.has(r))continue;const f=r.yogaNode;if(!f)continue;const y=f.getComputedTop(),m=f.getComputedHeight(),w=y+m;if(p){const t=n.get(r);u+=m-(t?t.height:0)}if(w<=q||y>=q+e)continue;if(y>=i&&w<=d)continue;const C=Math.floor(s+y);if(!p){const t=n.get(r);if(t&&Math.floor(t.y)-h===C)continue}const v=Math.min(Math.floor(s+w),Math.floor((x??k)+o+e));if(C<v){const o=Array(v-C).fill(c).join("\n");M.write(Math.floor(b),C,o),M.clip({x1:void 0,x2:void 0,y1:C,y2:v}),renderNodeToOutput(r,M,{offsetX:l,offsetY:s,prevScreen:void 0,inheritedBackgroundColor:t}),M.unclip()}}}const y=u.length?" ".repeat(a):"";for(const o of u){if(o.y>=d+1||o.y+o.height<=i)continue;const e=Math.max(i,Math.floor(o.y)-h),n=Math.min(d+1,Math.floor(o.y+o.height)-h);if(e>=p&&n<=f+1)continue;if(e>=n)continue;const c=Array(n-e).fill(y).join("\n");M.write(Math.floor(b),e,c),M.clip({x1:void 0,x2:void 0,y1:e,y2:n}),renderScrolledChildren(r,M,l,s,H,void 0,e-s,n-s,t,!0),M.unclip()}}else{const o=d&&d.y!==s;o&&void 0!==x&&void 0!==w&&M.clear({x:Math.floor(b),y:Math.floor(x),width:Math.floor(W),height:Math.floor(w-x)}),renderScrolledChildren(r,M,l,s,H,o||j?void 0:C,q,q+e,t)}n.set(r,{x:l,y:s,width:i.getComputedWidth(),height:i.getComputedHeight()}),r.dirty=!1}}else{const e=a.style.backgroundColor;if(e||a.style.opaque){const t=T.getComputedBorder(l.Left),r=T.getComputedBorder(l.Right),n=T.getComputedBorder(l.Top),i=T.getComputedBorder(l.Bottom),s=Math.floor(W)-t-r,d=Math.floor(B)-n-i;if(s>0&&d>0){const r=" ".repeat(s),l=e?o(r,{backgroundColor:e}):r,i=Array(d).fill(l).join("\n");M.write(b+t,k+n,i)}}renderChildren(a,M,b,k,H,e||a.style.opaque?void 0:C,t)}g&&M.unclip(),s(b,k,a,M)}else"ink-root"===a.nodeName&&renderChildren(a,M,b,k,H,C,S);const L={x:b,y:k,width:W,height:B,top:N};n.set(a,L),"absolute"===a.style.position&&g.push(L),a.dirty=!1}}function renderChildren(t,o,e,r,l,n,i){let s=!1,d=!1;for(const c of t.childNodes){const t=c,h=t.dirty,a="absolute"===t.style.position;renderNodeToOutput(t,o,{offsetX:e,offsetY:r,prevScreen:l||s?void 0:n,skipSelfBlit:d&&a&&!t.style.opaque&&void 0===t.style.backgroundColor,inheritedBackgroundColor:i}),h&&!s&&(!clipsBothAxes(t)||a?s=!0:d=!0)}}function clipsBothAxes(t){const o=t.style.overflowX??t.style.overflow,e=t.style.overflowY??t.style.overflow;return!("hidden"!==o&&"scroll"!==o||"hidden"!==e&&"scroll"!==e)}function blitEscapingAbsoluteDescendants(t,o,e,r,l,i,s){const d=r+i,c=l+s;for(const h of t.childNodes){if("#text"===h.nodeName)continue;const t=h;if("absolute"===t.style.position){const i=n.get(t);if(i){g.push(i);const t=Math.floor(i.x),n=Math.floor(i.y),s=Math.floor(i.width),h=Math.floor(i.height);(t<r||n<l||t+s>d||n+h>c)&&o.blit(e,t,n,s,h)}}blitEscapingAbsoluteDescendants(t,o,e,r,l,i,s)}}function renderScrolledChildren(t,o,e,r,l,i,s,d,c,h=!1){let a=!1,p=0;for(const f of t.childNodes){const t=f,u=t.yogaNode;if(u){const o=n.get(t);let e,r;void 0===o?.top||t.dirty||0!==p?(e=u.getComputedTop(),r=u.getComputedHeight(),t.dirty&&(p+=r-(o?o.height:0)),o&&(o.top=e)):(e=o.top,r=o.height);if(e+r<=s||e>=d){h||dropSubtreeCache(t);continue}}const g=t.dirty;renderNodeToOutput(t,o,{offsetX:e,offsetY:r,prevScreen:l||a?void 0:i,inheritedBackgroundColor:c}),g&&(a=!0)}}function dropSubtreeCache(t){n.delete(t);for(const o of t.childNodes)"#text"!==o.nodeName&&dropSubtreeCache(o)}export{buildCharToSegmentMap,applyStylesToWrappedText};export default renderNodeToOutput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"lodash-es/noop.js";import{LegacyRoot as o}from"react-reconciler/constants.js";import{logForDebugging as t}from"../utils/debug.js";import{createNode as n}from"./dom.js";import{FocusManager as r}from"./focus.js";import c from"./output.js";import s from"./reconciler.js";import
|
|
1
|
+
import e from"lodash-es/noop.js";import{LegacyRoot as o}from"react-reconciler/constants.js";import{logForDebugging as t}from"../utils/debug.js";import{createNode as n}from"./dom.js";import{FocusManager as r}from"./focus.js";import c from"./output.js";import s from"./reconciler.js";import i,{resetLayoutShifted as l}from"./render-node-to-output.js";import{CharPool as a,cellAtIndex as f,createScreen as p,HyperlinkPool as u,StylePool as h,setCellStyleId as m}from"./screen.js";let d,g,w,y,x,j;const S={reconcile:0,yoga:0,paint:0,scan:0,calls:0};export function renderToScreen(f,m){d||(d=n("ink-root"),d.focusManager=new r(()=>!1),w=new h,y=new a,x=new u,g=s.createContainer(d,o,null,!1,null,"search-render",e,e,e,e));const C=performance.now();s.updateContainerSync(f,g,null,e),s.flushSyncWork();const $=performance.now();d.yogaNode?.setWidth(m),d.yogaNode?.calculateLayout(m);const F=Math.ceil(d.yogaNode?.getComputedHeight()??0),M=performance.now(),k=p(m,Math.max(1,F),w,y,x);j?j.reset(m,F,k):j=new c({width:m,height:F,stylePool:w,screen:k}),l(),i(d,j,{prevScreen:void 0});const v=j.get(),L=performance.now();if(s.updateContainerSync(null,g,null,e),s.flushSyncWork(),S.reconcile+=$-C,S.yoga+=M-$,S.paint+=L-M,++S.calls%20==0){const e=S.reconcile+S.yoga+S.paint+S.scan;t(`renderToScreen: ${S.calls} calls · reconcile=${S.reconcile.toFixed(1)}ms yoga=${S.yoga.toFixed(1)}ms paint=${S.paint.toFixed(1)}ms scan=${S.scan.toFixed(1)}ms · total=${e.toFixed(1)}ms · avg ${(e/S.calls).toFixed(2)}ms/call`)}return{screen:v,height:F}}export function scanPositions(e,o){const t=o.toLowerCase();if(!t)return[];const n=t.length,r=e.width,c=e.height,s=e.noSelect,i=[],l=performance.now();for(let o=0;o<c;o++){const c=o*r;let l="";const a=[],p=[];for(let o=0;o<r;o++){const t=c+o,n=f(e,t);if(2===n.width||3===n.width||1===s[t])continue;const r=n.char.toLowerCase(),i=a.length;for(let e=0;e<r.length;e++)p.push(i);l+=r,a.push(o)}let u=l.indexOf(t);for(;u>=0;){const e=p[u],r=p[u+n-1],c=a[e],s=a[r]+1;i.push({row:o,col:c,len:s-c}),u=l.indexOf(t,u+n)}}return S.scan+=performance.now()-l,i}export function applyPositionedHighlight(e,o,t,n,r){if(r<0||r>=t.length)return!1;const c=t[r],s=c.row+n;if(s<0||s>=e.height)return!1;const transform=e=>o.withCurrentMatch(e),i=s*e.width;for(let o=c.col;o<c.col+c.len;o++){if(o<0||o>=e.width)continue;const t=f(e,i+o);m(e,o,s,transform(t.styleId))}return!0}
|
package/dist/src/ink/renderer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{logForDebugging as e}from"
|
|
1
|
+
import{logForDebugging as e}from"../utils/debug.js";import{markDirty as t}from"./dom.js";import{consumeAbsoluteRemovedFlag as o}from"./node-cache.js";import r from"./output.js";import i,{getScrollDrainNode as n,getScrollHint as l,resetLayoutShifted as s,resetScrollDrainNode as d,resetScrollHint as a}from"./render-node-to-output.js";import{createScreen as h}from"./screen.js";export default function createRenderer(c,m){let g;return u=>{const{frontFrame:p,backFrame:f,isTTY:v,terminalWidth:w,terminalRows:y}=u,N=p.screen,S=f.screen,$=S.charPool,b=S.hyperlinkPool,j=c.yogaNode?.getComputedHeight(),C=c.yogaNode?.getComputedWidth(),F=void 0===j||!Number.isFinite(j)||j<0,x=void 0===C||!Number.isFinite(C)||C<0;if(!c.yogaNode||F||x)return c.yogaNode&&(F||x)&&e(`Invalid yoga dimensions: width=${C}, height=${j}, childNodes=${c.childNodes.length}, terminalWidth=${w}, terminalRows=${y}`),{screen:h(w,0,m,$,b),viewport:{width:w,height:y},cursor:{x:0,y:0,visible:!0}};const M=Math.floor(c.yogaNode.getComputedWidth()),P=Math.floor(c.yogaNode.getComputedHeight()),R=u.altScreen?y:P;u.altScreen&&P>y&&e(`alt-screen: yoga height ${P} > terminalRows ${y} — something is rendering outside <AlternateScreen>. Overflow clipped.`,{level:"warn"});const W=S??h(M,R,m,$,b);g?g.reset(M,R,W):g=new r({width:M,height:R,stylePool:m,screen:W}),s(),a(),d();const H=o();i(c,g,{prevScreen:H||u.prevFrameContaminated?void 0:N});const k=g.get(),T=n();return T&&t(T),{scrollHint:u.altScreen?l():null,scrollDrainPending:null!==T,screen:k,viewport:{width:w,height:u.altScreen?y+1:y},cursor:{x:0,y:u.altScreen?Math.max(0,Math.min(W.height,y)-1):W.height,visible:!v||0===W.height}}}}
|
package/dist/src/ink/root.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{logForDebugging as t}from"
|
|
1
|
+
import{logForDebugging as t}from"../utils/debug.js";import{Stream as e}from"stream";import r from"./ink.js";import s from"./instances.js";export const renderSync=(t,e)=>{const n=getOptions(e),o={stdout:process.stdout,stdin:process.stdin,stderr:process.stderr,exitOnCtrlC:!0,patchConsole:!0,...n},i=getInstance(o.stdout,()=>new r(o));return i.render(t),{rerender:i.render,unmount(){i.unmount()},waitUntilExit:i.waitUntilExit,cleanup:()=>s.delete(o.stdout)}};export default async(e,r)=>{await Promise.resolve();const s=renderSync(e,r);return t(`[render] first ink render: ${Math.round(1e3*process.uptime())}ms since process start`),s};export async function createRoot({stdout:t=process.stdout,stdin:e=process.stdin,stderr:n=process.stderr,exitOnCtrlC:o=!0,patchConsole:i=!0,onFrame:d}={}){await Promise.resolve();const c=new r({stdout:t,stdin:e,stderr:n,exitOnCtrlC:o,patchConsole:i,onFrame:d});return s.set(t,c),{render:t=>c.render(t),unmount:()=>c.unmount(),waitUntilExit:()=>c.waitUntilExit()}}const getOptions=(t={})=>t instanceof e?{stdout:t,stdin:process.stdin}:t,getInstance=(t,e)=>{let r=s.get(t);return r||(r=e(),s.set(t,r)),r};
|
package/dist/src/ink/screen.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ansiCodesToString as t,diffAnsiCodes as e}from"@alcalzone/ansi-tokenize";import{unionRect as i}from"./layout/geometry.js";import{BEL as n,ESC as r,SEP as o}from"./termio/ansi.js";import*as s from"./warn.js";export class CharPool{strings=[" ",""];stringMap=new Map([[" ",0],["",1]]);ascii=function(){const t=new Int32Array(128);return t.fill(-1),t[32]=f,t}();intern(t){if(1===t.length){const e=t.charCodeAt(0);if(e<128){const i=this.ascii[e];if(-1!==i)return i;const n=this.strings.length;return this.strings.push(t),this.ascii[e]=n,n}}const e=this.stringMap.get(t);if(void 0!==e)return e;const i=this.strings.length;return this.strings.push(t),this.stringMap.set(t,i),i}get(t){return this.strings[t]??" "}}export class HyperlinkPool{strings=[""];stringMap=new Map;intern(t){if(!t)return 0;let e=this.stringMap.get(t);return void 0===e&&(e=this.strings.length,this.strings.push(t),this.stringMap.set(t,e)),e}get(t){return 0===t?void 0:this.strings[t]}}const h={type:"ansi",code:"[7m",endCode:"[27m"},l={type:"ansi",code:"[1m",endCode:"[22m"},c={type:"ansi",code:"[4m",endCode:"[24m"},a={type:"ansi",code:"[33m",endCode:"[39m"};export class StylePool{ids=new Map;styles=[];transitionCache=new Map;none;constructor(){this.none=this.intern([])}intern(t){const e=0===t.length?"":t.map(t=>t.code).join("\0");let i=this.ids.get(e);if(void 0===i){const n=this.styles.length;this.styles.push(0===t.length?[]:t),i=n<<1|(t.length>0&&function(t){for(const e of t)if(d.has(e.endCode))return!0;return!1}(t)?1:0),this.ids.set(e,i)}return i}get(t){return this.styles[t>>>1]??[]}transition(i,n){if(i===n)return"";const r=1048576*i+n;let o=this.transitionCache.get(r);return void 0===o&&(o=t(e(this.get(i),this.get(n))),this.transitionCache.set(r,o)),o}inverseCache=new Map;withInverse(t){let e=this.inverseCache.get(t);if(void 0===e){const i=this.get(t);e=i.some(t=>"[27m"===t.endCode)?t:this.intern([...i,h]),this.inverseCache.set(t,e)}return e}currentMatchCache=new Map;withCurrentMatch(t){let e=this.currentMatchCache.get(t);if(void 0===e){const i=this.get(t),n=i.filter(t=>"[39m"!==t.endCode&&"[49m"!==t.endCode);n.push(a),i.some(t=>"[27m"===t.endCode)||n.push(h),i.some(t=>"[22m"===t.endCode)||n.push(l),i.some(t=>"[24m"===t.endCode)||n.push(c),e=this.intern(n),this.currentMatchCache.set(t,e)}return e}selectionBgCode=null;selectionBgCache=new Map;setSelectionBg(t){this.selectionBgCode?.code!==t?.code&&(this.selectionBgCode=t,this.selectionBgCache.clear())}withSelectionBg(t){const e=this.selectionBgCode;if(null===e)return this.withInverse(t);let i=this.selectionBgCache.get(t);if(void 0===i){const n=this.get(t).filter(t=>"[49m"!==t.endCode&&"[27m"!==t.endCode);n.push(e),i=this.intern(n),this.selectionBgCache.set(t,i)}return i}}const d=new Set(["[49m","[27m","[24m","[29m","[55m"]),f=0,g=17,u=32767;function packWord1(t,e,i){return t<<g|e<<2|i}export function isEmptyCellAt(t,e,i){return e<0||i<0||e>=t.width||i>=t.height||function(t,e){const i=e<<1;return 0===t.cells[i]&&0===t.cells[1|i]}(t,i*t.width+e)}export function isCellEmpty(t,e){return" "===e.char&&e.styleId===t.emptyStyleId&&0===e.width&&!e.hyperlink}export function createScreen(t,e,i,n,r){s.ifNotInteger(t,"createScreen width"),s.ifNotInteger(e,"createScreen height"),(!Number.isInteger(t)||t<0)&&(t=Math.max(0,Math.floor(t)||0)),(!Number.isInteger(e)||e<0)&&(e=Math.max(0,Math.floor(e)||0));const o=t*e,h=new ArrayBuffer(o<<3);return{width:t,height:e,cells:new Int32Array(h),cells64:new BigInt64Array(h),charPool:n,hyperlinkPool:r,emptyStyleId:i.none,damage:void 0,noSelect:new Uint8Array(o),softWrap:new Int32Array(e)}}export function resetScreen(t,e,i){s.ifNotInteger(e,"resetScreen width"),s.ifNotInteger(i,"resetScreen height"),(!Number.isInteger(e)||e<0)&&(e=Math.max(0,Math.floor(e)||0)),(!Number.isInteger(i)||i<0)&&(i=Math.max(0,Math.floor(i)||0));const n=e*i;if(t.cells64.length<n){const e=new ArrayBuffer(n<<3);t.cells=new Int32Array(e),t.cells64=new BigInt64Array(e),t.noSelect=new Uint8Array(n)}t.softWrap.length<i&&(t.softWrap=new Int32Array(i)),t.cells64.fill(0n,0,n),t.noSelect.fill(0,0,n),t.softWrap.fill(0,0,i),t.width=e,t.height=i,t.damage=void 0}export function migrateScreenPools(t,e,i){const n=t.charPool,r=t.hyperlinkPool;if(n===e&&r===i)return;const o=t.width*t.height,s=t.cells;for(let t=0;t<o<<1;t+=2){const o=s[t];s[t]=e.intern(n.get(o));const h=s[t+1],l=h>>>2&u;if(0!==l){const e=r.get(l),n=i.intern(e),o=h>>>g,c=3&h;s[t+1]=packWord1(o,n,c)}}t.charPool=e,t.hyperlinkPool=i}export function cellAt(t,e,i){if(!(e<0||i<0||e>=t.width||i>=t.height))return cellAtIndex(t,i*t.width+e)}export function cellAtIndex(t,e){const i=e<<1,n=t.cells[i+1],r=n>>>2&u;return{char:t.charPool.get(t.cells[i]),styleId:n>>>g,width:3&n,hyperlink:0===r?void 0:t.hyperlinkPool.get(r)}}export function visibleCellAtIndex(t,e,i,n,r){const o=n<<1,s=t[o];if(1===s)return;const h=t[o+1];if(0===s&&!(262140&h)){const t=h>>>g;if(0===t||t===r)return}const l=h>>>2&u;return{char:e.get(s),styleId:h>>>g,width:3&h,hyperlink:0===l?void 0:i.get(l)}}function cellAtCI(t,e,i){const n=1|e,r=t.cells[n];i.char=t.charPool.get(t.cells[e]),i.styleId=r>>>g,i.width=3&r;const o=r>>>2&u;i.hyperlink=0===o?void 0:t.hyperlinkPool.get(o)}export function charInCellAt(t,e,i){if(e<0||i<0||e>=t.width||i>=t.height)return;const n=i*t.width+e<<1;return t.charPool.get(t.cells[n])}export function setCellAt(t,e,i,n){if(e<0||i<0||e>=t.width||i>=t.height)return;const r=i*t.width+e<<1,o=t.cells,s=3&o[r+1];if(1===s&&1!==n.width&&e+1<t.width){const e=r+2;2==(3&o[e+1])&&(o[e]=f,o[e+1]=packWord1(t.emptyStyleId,0,0))}let h=-1;if(2===s&&2!==n.width&&e>0){const i=r-2;1==(3&o[i+1])&&(o[i]=f,o[i+1]=packWord1(t.emptyStyleId,0,0),h=e-1)}o[r]=function(t,e){return t.charPool.intern(e)}(t,n.char),o[r+1]=packWord1(n.styleId,function(t,e){return t.hyperlinkPool.intern(e)}(t,n.hyperlink),n.width);const l=h>=0?Math.min(e,h):e,c=t.damage;if(c){const t=c.x+c.width,n=c.y+c.height;l<c.x?(c.width+=c.x-l,c.x=l):e>=t&&(c.width=e-c.x+1),i<c.y?(c.height+=c.y-i,c.y=i):i>=n&&(c.height=i-c.y+1)}else t.damage={x:l,y:i,width:e-l+1,height:1};if(1===n.width){const i=e+1;if(i<t.width){const e=r+2;if(1==(3&o[e+1])){const n=e+2;i+1<t.width&&2==(3&o[n+1])&&(o[n]=f,o[n+1]=packWord1(t.emptyStyleId,0,0))}o[e]=1,o[e+1]=packWord1(t.emptyStyleId,0,2);const n=t.damage;n&&i>=n.x+n.width&&(n.width=i-n.x+1)}}}export function setCellStyleId(t,e,n,r){if(e<0||n<0||e>=t.width||n>=t.height)return;const o=n*t.width+e<<1,s=t.cells,h=s[o+1],l=3&h;if(2===l||3===l)return;const c=h>>>2&u;s[o+1]=packWord1(r,c,l);const a=t.damage;t.damage=a?i(a,{x:e,y:n,width:1,height:1}):{x:e,y:n,width:1,height:1}}export function blitRegion(t,e,n,r,o,s){if(n=Math.max(0,n),r=Math.max(0,r),n>=o||r>=s)return;const h=o-n,l=e.width<<1,c=t.width<<1,a=h<<1,d=e.cells,f=t.cells,g=e.noSelect,u=t.noSelect;if(t.softWrap.set(e.softWrap.subarray(r,s),r),0===n&&o===e.width&&e.width===t.width){const t=r*l,i=(s-r)*l;f.set(d.subarray(t,t+i),t);const n=r*e.width,o=(s-r)*e.width;u.set(g.subarray(n,n+o),n)}else{let i=r*l+(n<<1),o=r*c+(n<<1),p=r*e.width+n,m=r*t.width+n;for(let n=r;n<s;n++)f.set(d.subarray(i,i+a),o),u.set(g.subarray(p,p+h),m),i+=l,o+=c,p+=e.width,m+=t.width}const p={x:n,y:r,width:h,height:s-r};if(t.damage?t.damage=i(t.damage,p):t.damage=p,o<t.width){let i=r*e.width+(o-1)<<1,n=r*t.width+o<<1,h=!1;for(let e=r;e<s;e++)1==(3&d[i+1])&&(f[n]=1,f[n+1]=packWord1(t.emptyStyleId,0,2),h=!0),i+=l,n+=c;h&&t.damage&&t.damage.x+t.damage.width===o&&(t.damage={...t.damage,width:t.damage.width+1})}}export function clearRegion(t,e,n,r,o){const s=Math.max(0,e),h=Math.max(0,n),l=Math.min(e+r,t.width),c=Math.min(n+o,t.height);if(s>=l||h>=c)return;const a=t.cells,d=t.cells64,g=t.width,u=h*g;let p=s,m=l;if(0===s&&l===g)d.fill(0n,u,u+(c-h)*g);else{const e=g<<1,i=l-s,n=s>0,r=l<g;let o=u+s<<1,w=u+l-1<<1,y=u+s;for(let u=h;u<c;u++){if(n&&2==(3&a[o+1])){const e=o-1;1==(3&a[e])&&(a[e-1]=f,a[e]=packWord1(t.emptyStyleId,0,0),p=s-1)}if(r&&1==(3&a[w+1])){const e=w+3;2==(3&a[e])&&(a[e-1]=f,a[e]=packWord1(t.emptyStyleId,0,0),m=l+1)}d.fill(0n,y,y+i),o+=e,w+=e,y+=g}}const w={x:p,y:h,width:m-p,height:c-h};t.damage?t.damage=i(t.damage,w):t.damage=w}export function shiftRows(t,e,i,n){if(0===n||e<0||i>=t.height||e>i)return;const r=t.width,o=t.cells64,s=t.noSelect,h=t.softWrap;if(Math.abs(n)>i-e)return o.fill(0n,e*r,(i+1)*r),s.fill(0,e*r,(i+1)*r),void h.fill(0,e,i+1);n>0?(o.copyWithin(e*r,(e+n)*r,(i+1)*r),s.copyWithin(e*r,(e+n)*r,(i+1)*r),h.copyWithin(e,e+n,i+1),o.fill(0n,(i-n+1)*r,(i+1)*r),s.fill(0,(i-n+1)*r,(i+1)*r),h.fill(0,i-n+1,i+1)):(o.copyWithin((e-n)*r,e*r,(i+n+1)*r),s.copyWithin((e-n)*r,e*r,(i+n+1)*r),h.copyWithin(e-n,e,i+n+1),o.fill(0n,e*r,(e-n)*r),s.fill(0,e*r,(e-n)*r),h.fill(0,e,e-n))}const p=new RegExp(`^${r}\\]8${o}${o}([^${n}]*)${n}$`);export const OSC8_PREFIX=`${r}]8${o}`;export function extractHyperlinkFromStyles(t){for(const e of t){const t=e.code;if(t.length<5||!t.startsWith(OSC8_PREFIX))continue;const i=t.match(p);if(i)return i[1]||null}return null}export function filterOutHyperlinkStyles(t){return t.filter(t=>!t.code.startsWith(OSC8_PREFIX)||!p.test(t.code))}export function diff(t,e){const i=[];return diffEach(t,e,(t,e,n,r)=>{i.push([{x:t,y:e},n?{...n}:void 0,r?{...r}:void 0])}),i}export function diffEach(t,e,n){const r=t.width,o=e.width,s=t.height,h=e.height;let l;0===r&&0===s?l={x:0,y:0,width:o,height:h}:e.damage?(l=e.damage,t.damage&&(l=i(l,t.damage))):l=t.damage?t.damage:{x:0,y:0,width:0,height:0},s>h&&(l=i(l,{x:0,y:h,width:r,height:s-h})),r>o&&(l=i(l,{x:o,y:0,width:r-o,height:s}));const c=Math.max(s,h),a=Math.max(r,o),d=Math.min(l.y+l.height,c),f=Math.min(l.x+l.width,a);return r===o?function(t,e,i,n,r,o,s){const h=t.cells,l=e.cells,c=t.width,a=t.height,d=e.height,f=c<<1,g={char:" ",styleId:0,width:0,hyperlink:void 0},u={char:" ",styleId:0,width:0,hyperlink:void 0},p=Math.min(n,c);let m=r*c+i<<1;for(let n=r;n<o;n++){const r=n<a,o=n<d;if(r&&o){if(diffRowBoth(h,l,t,e,m,n,i,p,g,u,s))return!0}else if(r){if(diffRowRemoved(t,m,n,i,p,g,s))return!0}else if(o&&diffRowAdded(l,e,m,n,i,p,u,s))return!0;m+=f}return!1}(t,e,l.x,f,l.y,d,n):function(t,e,i,n,r,o,s){const h=t.width,l=e.width,c=t.cells,a=e.cells,d={char:" ",styleId:0,width:0,hyperlink:void 0},f={char:" ",styleId:0,width:0,hyperlink:void 0},g=h<<1,u=l<<1;let p=r*h+i<<1,m=r*l+i<<1;for(let w=r;w<o;w++){const r=w<t.height,o=w<e.height,y=r?Math.min(n,h):i,x=o?Math.min(n,l):i,C=Math.min(y,x);let I=p,M=m;for(let n=i;n<C;n++)if(c[I]!==a[M]||c[I+1]!==a[M+1]){if(cellAtCI(t,I,d),cellAtCI(e,M,f),I+=2,M+=2,s(n,w,d,f))return!0}else I+=2,M+=2;if(y>C){I=p+(C-i<<1);for(let e=C;e<y;e++)if(cellAtCI(t,I,d),I+=2,s(e,w,d,void 0))return!0}if(x>C){M=m+(C-i<<1);for(let t=C;t<x;t++)if(0!==a[M]||0!==a[1|M]){if(cellAtCI(e,M,f),M+=2,s(t,w,void 0,f))return!0}else M+=2}p+=g,m+=u}return!1}(t,e,l.x,f,l.y,d,n)}function findNextDiff(t,e,i,n){for(let r=0;r<n;r++,i+=2){const n=1|i;if(t[i]!==e[i]||t[n]!==e[n])return r}return n}function diffRowBoth(t,e,i,n,r,o,s,h,l,c,a){let d=s;for(;d<h;){const s=findNextDiff(t,e,r,h-d);if(d+=s,r+=s<<1,d>=h)break;if(cellAtCI(i,r,l),cellAtCI(n,r,c),a(d,o,l,c))return!0;d++,r+=2}return!1}function diffRowRemoved(t,e,i,n,r,o,s){for(let h=n;h<r;h++,e+=2)if(cellAtCI(t,e,o),s(h,i,o,void 0))return!0;return!1}function diffRowAdded(t,e,i,n,r,o,s,h){for(let l=r;l<o;l++,i+=2)if((0!==t[i]||0!==t[1|i])&&(cellAtCI(e,i,s),h(l,n,void 0,s)))return!0;return!1}export function markNoSelectRegion(t,e,i,n,r){const o=Math.min(e+n,t.width),s=Math.min(i+r,t.height),h=t.noSelect,l=t.width;for(let t=Math.max(0,i);t<s;t++){const i=t*l;h.fill(1,i+Math.max(0,e),i+o)}}
|
|
1
|
+
import{ansiCodesToString as t,diffAnsiCodes as e}from"@alcalzone/ansi-tokenize";import{unionRect as i}from"./layout/geometry.js";import{BEL as n,ESC as r,SEP as o}from"./termio/ansi.js";import*as h from"./warn.js";export class CharPool{strings=[" ",""];stringMap=new Map([[" ",0],["",1]]);ascii=function(){const t=new Int32Array(128);return t.fill(-1),t[32]=f,t}();intern(t){if(1===t.length){const e=t.charCodeAt(0);if(e<128){const i=this.ascii[e];if(-1!==i)return i;const n=this.strings.length;return this.strings.push(t),this.ascii[e]=n,n}}const e=this.stringMap.get(t);if(void 0!==e)return e;const i=this.strings.length;return this.strings.push(t),this.stringMap.set(t,i),i}get(t){return this.strings[t]??" "}}export class HyperlinkPool{strings=[""];stringMap=new Map;intern(t){if(!t)return 0;let e=this.stringMap.get(t);return void 0===e&&(e=this.strings.length,this.strings.push(t),this.stringMap.set(t,e)),e}get(t){return 0===t?void 0:this.strings[t]}}const s={type:"ansi",code:"[7m",endCode:"[27m"},l={type:"ansi",code:"[1m",endCode:"[22m"},c={type:"ansi",code:"[4m",endCode:"[24m"},a={type:"ansi",code:"[33m",endCode:"[39m"};export class StylePool{ids=new Map;styles=[];transitionCache=new Map;none;constructor(){this.none=this.intern([])}intern(t){const e=0===t.length?"":t.map(t=>t.code).join("\0");let i=this.ids.get(e);if(void 0===i){const n=this.styles.length;this.styles.push(0===t.length?[]:t),i=n<<1|(t.length>0&&function(t){for(const e of t)if(d.has(e.endCode))return!0;return!1}(t)?1:0),this.ids.set(e,i)}return i}get(t){return this.styles[t>>>1]??[]}transition(i,n){if(i===n)return"";const r=1048576*i+n;let o=this.transitionCache.get(r);return void 0===o&&(o=t(e(this.get(i),this.get(n))),this.transitionCache.set(r,o)),o}inverseCache=new Map;withInverse(t){let e=this.inverseCache.get(t);if(void 0===e){const i=this.get(t);e=i.some(t=>"[27m"===t.endCode)?t:this.intern([...i,s]),this.inverseCache.set(t,e)}return e}currentMatchCache=new Map;withCurrentMatch(t){let e=this.currentMatchCache.get(t);if(void 0===e){const i=this.get(t),n=i.filter(t=>"[39m"!==t.endCode&&"[49m"!==t.endCode);n.push(a),i.some(t=>"[27m"===t.endCode)||n.push(s),i.some(t=>"[22m"===t.endCode)||n.push(l),i.some(t=>"[24m"===t.endCode)||n.push(c),e=this.intern(n),this.currentMatchCache.set(t,e)}return e}selectionBgCode=null;selectionBgCache=new Map;setSelectionBg(t){this.selectionBgCode?.code!==t?.code&&(this.selectionBgCode=t,this.selectionBgCache.clear())}withSelectionBg(t){const e=this.selectionBgCode;if(null===e)return this.withInverse(t);let i=this.selectionBgCache.get(t);if(void 0===i){const n=this.get(t).filter(t=>"[49m"!==t.endCode&&"[27m"!==t.endCode);n.push(e),i=this.intern(n),this.selectionBgCache.set(t,i)}return i}}const d=new Set(["[49m","[27m","[24m","[29m","[55m"]);const f=0;const g=17,u=32767;function packWord1(t,e,i){return t<<g|e<<2|i}export function isEmptyCellAt(t,e,i){return e<0||i<0||e>=t.width||i>=t.height||function(t,e){const i=e<<1;return 0===t.cells[i]&&0===t.cells[1|i]}(t,i*t.width+e)}export function isCellEmpty(t,e){return" "===e.char&&e.styleId===t.emptyStyleId&&0===e.width&&!e.hyperlink}export function createScreen(t,e,i,n,r){h.ifNotInteger(t,"createScreen width"),h.ifNotInteger(e,"createScreen height"),(!Number.isInteger(t)||t<0)&&(t=Math.max(0,Math.floor(t)||0)),(!Number.isInteger(e)||e<0)&&(e=Math.max(0,Math.floor(e)||0));const o=t*e,s=new ArrayBuffer(o<<3);return{width:t,height:e,cells:new Int32Array(s),cells64:new BigInt64Array(s),charPool:n,hyperlinkPool:r,emptyStyleId:i.none,damage:void 0,noSelect:new Uint8Array(o),softWrap:new Int32Array(e)}}export function resetScreen(t,e,i){h.ifNotInteger(e,"resetScreen width"),h.ifNotInteger(i,"resetScreen height"),(!Number.isInteger(e)||e<0)&&(e=Math.max(0,Math.floor(e)||0)),(!Number.isInteger(i)||i<0)&&(i=Math.max(0,Math.floor(i)||0));const n=e*i;if(t.cells64.length<n){const e=new ArrayBuffer(n<<3);t.cells=new Int32Array(e),t.cells64=new BigInt64Array(e),t.noSelect=new Uint8Array(n)}t.softWrap.length<i&&(t.softWrap=new Int32Array(i)),t.cells64.fill(0n,0,n),t.noSelect.fill(0,0,n),t.softWrap.fill(0,0,i),t.width=e,t.height=i,t.damage=void 0}export function migrateScreenPools(t,e,i){const n=t.charPool,r=t.hyperlinkPool;if(n===e&&r===i)return;const o=t.width*t.height,h=t.cells;for(let t=0;t<o<<1;t+=2){const o=h[t];h[t]=e.intern(n.get(o));const s=h[t+1],l=s>>>2&u;if(0!==l){const e=r.get(l),n=i.intern(e),o=s>>>g,c=3&s;h[t+1]=packWord1(o,n,c)}}t.charPool=e,t.hyperlinkPool=i}export function cellAt(t,e,i){if(!(e<0||i<0||e>=t.width||i>=t.height))return cellAtIndex(t,i*t.width+e)}export function cellAtIndex(t,e){const i=e<<1,n=t.cells[i+1],r=n>>>2&u;return{char:t.charPool.get(t.cells[i]),styleId:n>>>g,width:3&n,hyperlink:0===r?void 0:t.hyperlinkPool.get(r)}}export function visibleCellAtIndex(t,e,i,n,r){const o=n<<1,h=t[o];if(1===h)return;const s=t[o+1];if(0===h&&!(262140&s)){const t=s>>>g;if(0===t||t===r)return}const l=s>>>2&u;return{char:e.get(h),styleId:s>>>g,width:3&s,hyperlink:0===l?void 0:i.get(l)}}function cellAtCI(t,e,i){const n=1|e,r=t.cells[n];i.char=t.charPool.get(t.cells[e]),i.styleId=r>>>g,i.width=3&r;const o=r>>>2&u;i.hyperlink=0===o?void 0:t.hyperlinkPool.get(o)}export function charInCellAt(t,e,i){if(e<0||i<0||e>=t.width||i>=t.height)return;const n=i*t.width+e<<1;return t.charPool.get(t.cells[n])}export function setCellAt(t,e,i,n){if(e<0||i<0||e>=t.width||i>=t.height)return;const r=i*t.width+e<<1,o=t.cells,h=3&o[r+1];if(1===h&&1!==n.width){if(e+1<t.width){const e=r+2;2==(3&o[e+1])&&(o[e]=f,o[e+1]=packWord1(t.emptyStyleId,0,0))}}let s=-1;if(2===h&&2!==n.width&&e>0){const i=r-2;1==(3&o[i+1])&&(o[i]=f,o[i+1]=packWord1(t.emptyStyleId,0,0),s=e-1)}o[r]=function(t,e){return t.charPool.intern(e)}(t,n.char),o[r+1]=packWord1(n.styleId,function(t,e){return t.hyperlinkPool.intern(e)}(t,n.hyperlink),n.width);const l=s>=0?Math.min(e,s):e,c=t.damage;if(c){const t=c.x+c.width,n=c.y+c.height;l<c.x?(c.width+=c.x-l,c.x=l):e>=t&&(c.width=e-c.x+1),i<c.y?(c.height+=c.y-i,c.y=i):i>=n&&(c.height=i-c.y+1)}else t.damage={x:l,y:i,width:e-l+1,height:1};if(1===n.width){const i=e+1;if(i<t.width){const e=r+2;if(1==(3&o[e+1])){const n=e+2;i+1<t.width&&2==(3&o[n+1])&&(o[n]=f,o[n+1]=packWord1(t.emptyStyleId,0,0))}o[e]=1,o[e+1]=packWord1(t.emptyStyleId,0,2);const n=t.damage;n&&i>=n.x+n.width&&(n.width=i-n.x+1)}}}export function setCellStyleId(t,e,n,r){if(e<0||n<0||e>=t.width||n>=t.height)return;const o=n*t.width+e<<1,h=t.cells,s=h[o+1],l=3&s;if(2===l||3===l)return;const c=s>>>2&u;h[o+1]=packWord1(r,c,l);const a=t.damage;t.damage=a?i(a,{x:e,y:n,width:1,height:1}):{x:e,y:n,width:1,height:1}}export function blitRegion(t,e,n,r,o,h){if(n=Math.max(0,n),r=Math.max(0,r),n>=o||r>=h)return;const s=o-n,l=e.width<<1,c=t.width<<1,a=s<<1,d=e.cells,f=t.cells,g=e.noSelect,u=t.noSelect;if(t.softWrap.set(e.softWrap.subarray(r,h),r),0===n&&o===e.width&&e.width===t.width){const t=r*l,i=(h-r)*l;f.set(d.subarray(t,t+i),t);const n=r*e.width,o=(h-r)*e.width;u.set(g.subarray(n,n+o),n)}else{let i=r*l+(n<<1),o=r*c+(n<<1),p=r*e.width+n,m=r*t.width+n;for(let n=r;n<h;n++)f.set(d.subarray(i,i+a),o),u.set(g.subarray(p,p+s),m),i+=l,o+=c,p+=e.width,m+=t.width}const p={x:n,y:r,width:s,height:h-r};if(t.damage?t.damage=i(t.damage,p):t.damage=p,o<t.width){let i=r*e.width+(o-1)<<1,n=r*t.width+o<<1,s=!1;for(let e=r;e<h;e++)1==(3&d[i+1])&&(f[n]=1,f[n+1]=packWord1(t.emptyStyleId,0,2),s=!0),i+=l,n+=c;if(s&&t.damage){t.damage.x+t.damage.width===o&&(t.damage={...t.damage,width:t.damage.width+1})}}}export function clearRegion(t,e,n,r,o){const h=Math.max(0,e),s=Math.max(0,n),l=Math.min(e+r,t.width),c=Math.min(n+o,t.height);if(h>=l||s>=c)return;const a=t.cells,d=t.cells64,g=t.width,u=s*g;let p=h,m=l;if(0===h&&l===g)d.fill(0n,u,u+(c-s)*g);else{const e=g<<1,i=l-h,n=h>0,r=l<g;let o=u+h<<1,w=u+l-1<<1,y=u+h;for(let u=s;u<c;u++){if(n&&2==(3&a[o+1])){const e=o-1;1==(3&a[e])&&(a[e-1]=f,a[e]=packWord1(t.emptyStyleId,0,0),p=h-1)}if(r&&1==(3&a[w+1])){const e=w+3;2==(3&a[e])&&(a[e-1]=f,a[e]=packWord1(t.emptyStyleId,0,0),m=l+1)}d.fill(0n,y,y+i),o+=e,w+=e,y+=g}}const w={x:p,y:s,width:m-p,height:c-s};t.damage?t.damage=i(t.damage,w):t.damage=w}export function shiftRows(t,e,i,n){if(0===n||e<0||i>=t.height||e>i)return;const r=t.width,o=t.cells64,h=t.noSelect,s=t.softWrap;if(Math.abs(n)>i-e)return o.fill(0n,e*r,(i+1)*r),h.fill(0,e*r,(i+1)*r),void s.fill(0,e,i+1);n>0?(o.copyWithin(e*r,(e+n)*r,(i+1)*r),h.copyWithin(e*r,(e+n)*r,(i+1)*r),s.copyWithin(e,e+n,i+1),o.fill(0n,(i-n+1)*r,(i+1)*r),h.fill(0,(i-n+1)*r,(i+1)*r),s.fill(0,i-n+1,i+1)):(o.copyWithin((e-n)*r,e*r,(i+n+1)*r),h.copyWithin((e-n)*r,e*r,(i+n+1)*r),s.copyWithin(e-n,e,i+n+1),o.fill(0n,e*r,(e-n)*r),h.fill(0,e*r,(e-n)*r),s.fill(0,e,e-n))}const p=new RegExp(`^${r}\\]8${o}${o}([^${n}]*)${n}$`);export const OSC8_PREFIX=`${r}]8${o}`;export function extractHyperlinkFromStyles(t){for(const e of t){const t=e.code;if(t.length<5||!t.startsWith(OSC8_PREFIX))continue;const i=t.match(p);if(i)return i[1]||null}return null}export function filterOutHyperlinkStyles(t){return t.filter(t=>!t.code.startsWith(OSC8_PREFIX)||!p.test(t.code))}export function diff(t,e){const i=[];return diffEach(t,e,(t,e,n,r)=>{i.push([{x:t,y:e},n?{...n}:void 0,r?{...r}:void 0])}),i}export function diffEach(t,e,n){const r=t.width,o=e.width,h=t.height,s=e.height;let l;0===r&&0===h?l={x:0,y:0,width:o,height:s}:e.damage?(l=e.damage,t.damage&&(l=i(l,t.damage))):l=t.damage?t.damage:{x:0,y:0,width:0,height:0},h>s&&(l=i(l,{x:0,y:s,width:r,height:h-s})),r>o&&(l=i(l,{x:o,y:0,width:r-o,height:h}));const c=Math.max(h,s),a=Math.max(r,o),d=Math.min(l.y+l.height,c),f=Math.min(l.x+l.width,a);return r===o?function(t,e,i,n,r,o,h){const s=t.cells,l=e.cells,c=t.width,a=t.height,d=e.height,f=c<<1,g={char:" ",styleId:0,width:0,hyperlink:void 0},u={char:" ",styleId:0,width:0,hyperlink:void 0},p=Math.min(n,c);let m=r*c+i<<1;for(let n=r;n<o;n++){const r=n<a,o=n<d;if(r&&o){if(diffRowBoth(s,l,t,e,m,n,i,p,g,u,h))return!0}else if(r){if(diffRowRemoved(t,m,n,i,p,g,h))return!0}else if(o&&diffRowAdded(l,e,m,n,i,p,u,h))return!0;m+=f}return!1}(t,e,l.x,f,l.y,d,n):function(t,e,i,n,r,o,h){const s=t.width,l=e.width,c=t.cells,a=e.cells,d={char:" ",styleId:0,width:0,hyperlink:void 0},f={char:" ",styleId:0,width:0,hyperlink:void 0},g=s<<1,u=l<<1;let p=r*s+i<<1,m=r*l+i<<1;for(let w=r;w<o;w++){const r=w<t.height,o=w<e.height,y=r?Math.min(n,s):i,x=o?Math.min(n,l):i,I=Math.min(y,x);let C=p,M=m;for(let n=i;n<I;n++)if(c[C]!==a[M]||c[C+1]!==a[M+1]){if(cellAtCI(t,C,d),cellAtCI(e,M,f),C+=2,M+=2,h(n,w,d,f))return!0}else C+=2,M+=2;if(y>I){C=p+(I-i<<1);for(let e=I;e<y;e++)if(cellAtCI(t,C,d),C+=2,h(e,w,d,void 0))return!0}if(x>I){M=m+(I-i<<1);for(let t=I;t<x;t++)if(0!==a[M]||0!==a[1|M]){if(cellAtCI(e,M,f),M+=2,h(t,w,void 0,f))return!0}else M+=2}p+=g,m+=u}return!1}(t,e,l.x,f,l.y,d,n)}function findNextDiff(t,e,i,n){for(let r=0;r<n;r++,i+=2){const n=1|i;if(t[i]!==e[i]||t[n]!==e[n])return r}return n}function diffRowBoth(t,e,i,n,r,o,h,s,l,c,a){let d=h;for(;d<s;){const h=findNextDiff(t,e,r,s-d);if(d+=h,r+=h<<1,d>=s)break;if(cellAtCI(i,r,l),cellAtCI(n,r,c),a(d,o,l,c))return!0;d++,r+=2}return!1}function diffRowRemoved(t,e,i,n,r,o,h){for(let s=n;s<r;s++,e+=2)if(cellAtCI(t,e,o),h(s,i,o,void 0))return!0;return!1}function diffRowAdded(t,e,i,n,r,o,h,s){for(let l=r;l<o;l++,i+=2)if((0!==t[i]||0!==t[1|i])&&(cellAtCI(e,i,h),s(l,n,void 0,h)))return!0;return!1}export function markNoSelectRegion(t,e,i,n,r){const o=Math.min(e+n,t.width),h=Math.min(i+r,t.height),s=t.noSelect,l=t.width;for(let t=Math.max(0,i);t<h;t++){const i=t*l;s.fill(1,i+Math.max(0,e),i+o)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cellAtIndex as t,setCellStyleId as e}from"./screen.js";export function applySearchHighlight(n,
|
|
1
|
+
import{cellAtIndex as t,setCellStyleId as e}from"./screen.js";export function applySearchHighlight(o,n,r){if(!n)return!1;const h=n.toLowerCase(),s=h.length,i=o.width,l=o.noSelect,c=o.height;let f=!1;for(let n=0;n<c;n++){const c=n*i;let d="";const g=[],p=[];for(let e=0;e<i;e++){const n=c+e,r=t(o,n);if(2===r.width||3===r.width||1===l[n])continue;const h=r.char.toLowerCase(),s=g.length;for(let t=0;t<h.length;t++)p.push(s);d+=h,g.push(e)}let u=d.indexOf(h);for(;u>=0;){f=!0;const i=p[u],l=p[u+s-1];for(let h=i;h<=l;h++){const s=g[h],i=t(o,c+s);e(o,s,n,r.withInverse(i.styleId))}u=d.indexOf(h,u+s)}}return f}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{clamp as o}from"./layout/geometry.js";import{cellAt as r,cellAtIndex as n,setCellStyleId as c}from"./screen.js";export function createSelectionState(){return{anchor:null,focus:null,isDragging:!1,anchorSpan:null,scrolledOffAbove:[],scrolledOffBelow:[],scrolledOffAboveSW:[],scrolledOffBelowSW:[],lastPressHadAlt:!1}}export function startSelection(o,r,n){o.anchor={col:r,row:n},o.focus=null,o.isDragging=!0,o.anchorSpan=null,o.scrolledOffAbove=[],o.scrolledOffBelow=[],o.scrolledOffAboveSW=[],o.scrolledOffBelowSW=[],o.virtualAnchorRow=void 0,o.virtualFocusRow=void 0,o.lastPressHadAlt=!1}export function updateSelection(o,r,n){o.isDragging&&(!o.focus&&o.anchor&&o.anchor.col===r&&o.anchor.row===n||(o.focus={col:r,row:n}))}export function finishSelection(o){o.isDragging=!1}export function clearSelection(o){o.anchor=null,o.focus=null,o.isDragging=!1,o.anchorSpan=null,o.scrolledOffAbove=[],o.scrolledOffBelow=[],o.scrolledOffAboveSW=[],o.scrolledOffBelowSW=[],o.virtualAnchorRow=void 0,o.virtualFocusRow=void 0,o.lastPressHadAlt=!1}const t=/[\p{L}\p{N}_/.\-+~\\]/u;function charClass(o){return" "===o||""===o?0:t.test(o)?1:2}function wordBoundsAt(o,n,c){if(c<0||c>=o.height)return null;const t=o.width,l=o.noSelect,e=c*t;let i=n;if(i>0){const n=r(o,i,c);n&&2===n.width&&(i-=1)}if(i<0||i>=t||1===l[e+i])return null;const a=r(o,i,c);if(!a)return null;const s=charClass(a.char);let f=i;for(;f>0;){const n=f-1;if(1===l[e+n])break;const t=r(o,n,c);if(!t)break;if(2===t.width){if(0===n||1===l[e+n-1])break;const t=r(o,n-1,c);if(!t||charClass(t.char)!==s)break;f=n-1;continue}if(charClass(t.char)!==s)break;f=n}let h=i;for(;h<t-1;){const n=h+1;if(1===l[e+n])break;const t=r(o,n,c);if(!t)break;if(2!==t.width){if(charClass(t.char)!==s)break;h=n}else h=n}return{lo:f,hi:h}}function comparePoints(o,r){return o.row!==r.row?o.row<r.row?-1:1:o.col!==r.col?o.col<r.col?-1:1:0}export function selectWordAt(o,r,n,c){const t=wordBoundsAt(r,n,c);if(!t)return;const l={col:t.lo,row:c},e={col:t.hi,row:c};o.anchor=l,o.focus=e,o.isDragging=!0,o.anchorSpan={lo:l,hi:e,kind:"word"}}const l=new Set([..."<>\"'` "]);function isUrlChar(o){if(1!==o.length)return!1;const r=o.charCodeAt(0);return r>=33&&r<=126&&!l.has(o)}export function findPlainTextUrlAt(o,n,c){if(c<0||c>=o.height)return;const t=o.width,l=o.noSelect,e=c*t;let i=n;if(i>0){const n=r(o,i,c);n&&2===n.width&&(i-=1)}if(i<0||i>=t||1===l[e+i])return;const a=r(o,i,c);if(!a||!isUrlChar(a.char))return;let s=i;for(;s>0;){const n=s-1;if(1===l[e+n])break;const t=r(o,n,c);if(!t||0!==t.width||!isUrlChar(t.char))break;s=n}let f=i;for(;f<t-1;){const n=f+1;if(1===l[e+n])break;const t=r(o,n,c);if(!t||0!==t.width||!isUrlChar(t.char))break;f=n}let h="";for(let n=s;n<=f;n++)h+=r(o,n,c).char;const u=i-s,w=/(?:https?|file):\/\//g;let d=-1,p=h.length;for(let o;o=w.exec(h);){if(o.index>u){p=o.index;break}d=o.index}if(d<0)return;let S=h.slice(d,p);const v={")":"(","]":"[","}":"{"};for(;S.length>0;){const o=S.at(-1);if(".,;:!?".includes(o)){S=S.slice(0,-1);continue}const r=v[o];if(!r)break;let n=0,c=0;for(let t=0;t<S.length;t++){const l=S.charAt(t);l===r?n++:l===o&&c++}if(!(c>n))break;S=S.slice(0,-1)}return u>=d+S.length?void 0:S}export function selectLineAt(o,r,n){if(n<0||n>=r.height)return;const c={col:0,row:n},t={col:r.width-1,row:n};o.anchor=c,o.focus=t,o.isDragging=!0,o.anchorSpan={lo:c,hi:t,kind:"line"}}export function extendSelection(r,n,c,t){if(!r.isDragging||!r.anchorSpan)return;const l=r.anchorSpan;let e,i;if("word"===l.kind){const o=wordBoundsAt(n,c,t);e={col:o?o.lo:c,row:t},i={col:o?o.hi:c,row:t}}else{const r=o(t,0,n.height-1);e={col:0,row:r},i={col:n.width-1,row:r}}comparePoints(i,l.lo)<0?(r.anchor=l.hi,r.focus=e):comparePoints(e,l.hi)>0?(r.anchor=l.lo,r.focus=i):(r.anchor=l.lo,r.focus=l.hi)}export function moveFocus(o,r,n){o.focus&&(o.anchorSpan=null,o.focus={col:r,row:n},o.virtualFocusRow=void 0)}export function shiftSelection(o,r,n,c,t){if(!o.anchor||!o.focus)return;const l=(o.virtualAnchorRow??o.anchor.row)+r,e=(o.virtualFocusRow??o.focus.row)+r;if(l<n&&e<n||l>c&&e>c)return void clearSelection(o);const i=Math.min(o.virtualAnchorRow??o.anchor.row,o.virtualFocusRow??o.focus.row),a=Math.max(o.virtualAnchorRow??o.anchor.row,o.virtualFocusRow??o.focus.row),s=Math.max(0,n-i),f=Math.max(0,a-c),h=Math.max(0,n-Math.min(l,e)),u=Math.max(0,Math.max(l,e)-c);if(h<s){const r=s-h;o.scrolledOffAbove.length-=r,o.scrolledOffAboveSW.length=o.scrolledOffAbove.length}if(u<f){const r=f-u;o.scrolledOffBelow.splice(0,r),o.scrolledOffBelowSW.splice(0,r)}o.scrolledOffAbove.length>h&&(o.scrolledOffAbove=h>0?o.scrolledOffAbove.slice(-h):[],o.scrolledOffAboveSW=h>0?o.scrolledOffAboveSW.slice(-h):[]),o.scrolledOffBelow.length>u&&(o.scrolledOffBelow=o.scrolledOffBelow.slice(0,u),o.scrolledOffBelowSW=o.scrolledOffBelowSW.slice(0,u));const shift=(o,r)=>r<n?{col:0,row:n}:r>c?{col:t-1,row:c}:{col:o.col,row:r};if(o.anchor=shift(o.anchor,l),o.focus=shift(o.focus,e),o.virtualAnchorRow=l<n||l>c?l:void 0,o.virtualFocusRow=e<n||e>c?e:void 0,o.anchorSpan){const sp=o=>{const l=o.row+r;return l<n?{col:0,row:n}:l>c?{col:t-1,row:c}:{col:o.col,row:l}};o.anchorSpan={lo:sp(o.anchorSpan.lo),hi:sp(o.anchorSpan.hi),kind:o.anchorSpan.kind}}}export function shiftAnchor(r,n,c,t){if(!r.anchor)return;const l=(r.virtualAnchorRow??r.anchor.row)+n;if(r.anchor={col:r.anchor.col,row:o(l,c,t)},r.virtualAnchorRow=l<c||l>t?l:void 0,r.anchorSpan){const shift=r=>({col:r.col,row:o(r.row+n,c,t)});r.anchorSpan={lo:shift(r.anchorSpan.lo),hi:shift(r.anchorSpan.hi),kind:r.anchorSpan.kind}}}export function shiftSelectionForFollow(r,n,c,t){if(!r.anchor)return!1;const l=(r.virtualAnchorRow??r.anchor.row)+n,e=r.focus?(r.virtualFocusRow??r.focus.row)+n:void 0;if(l<c&&void 0!==e&&e<c)return clearSelection(r),!0;if(r.anchor={col:r.anchor.col,row:o(l,c,t)},r.focus&&void 0!==e&&(r.focus={col:r.focus.col,row:o(e,c,t)}),r.virtualAnchorRow=l<c||l>t?l:void 0,r.virtualFocusRow=void 0!==e&&(e<c||e>t)?e:void 0,r.anchorSpan){const shift=r=>({col:r.col,row:o(r.row+n,c,t)});r.anchorSpan={lo:shift(r.anchorSpan.lo),hi:shift(r.anchorSpan.hi),kind:r.anchorSpan.kind}}return!1}export function hasSelection(o){return null!==o.anchor&&null!==o.focus}export function selectionBounds(o){return o.anchor&&o.focus?comparePoints(o.anchor,o.focus)<=0?{start:o.anchor,end:o.focus}:{start:o.focus,end:o.anchor}:null}export function isCellSelected(o,r,n){const c=selectionBounds(o);if(!c)return!1;const{start:t,end:l}=c;return!(n<t.row||n>l.row
|
|
1
|
+
import{clamp as o}from"./layout/geometry.js";import{cellAt as r,cellAtIndex as n,setCellStyleId as c}from"./screen.js";export function createSelectionState(){return{anchor:null,focus:null,isDragging:!1,anchorSpan:null,scrolledOffAbove:[],scrolledOffBelow:[],scrolledOffAboveSW:[],scrolledOffBelowSW:[],lastPressHadAlt:!1}}export function startSelection(o,r,n){o.anchor={col:r,row:n},o.focus=null,o.isDragging=!0,o.anchorSpan=null,o.scrolledOffAbove=[],o.scrolledOffBelow=[],o.scrolledOffAboveSW=[],o.scrolledOffBelowSW=[],o.virtualAnchorRow=void 0,o.virtualFocusRow=void 0,o.lastPressHadAlt=!1}export function updateSelection(o,r,n){o.isDragging&&(!o.focus&&o.anchor&&o.anchor.col===r&&o.anchor.row===n||(o.focus={col:r,row:n}))}export function finishSelection(o){o.isDragging=!1}export function clearSelection(o){o.anchor=null,o.focus=null,o.isDragging=!1,o.anchorSpan=null,o.scrolledOffAbove=[],o.scrolledOffBelow=[],o.scrolledOffAboveSW=[],o.scrolledOffBelowSW=[],o.virtualAnchorRow=void 0,o.virtualFocusRow=void 0,o.lastPressHadAlt=!1}const t=/[\p{L}\p{N}_/.\-+~\\]/u;function charClass(o){return" "===o||""===o?0:t.test(o)?1:2}function wordBoundsAt(o,n,c){if(c<0||c>=o.height)return null;const t=o.width,l=o.noSelect,e=c*t;let i=n;if(i>0){const n=r(o,i,c);n&&2===n.width&&(i-=1)}if(i<0||i>=t||1===l[e+i])return null;const a=r(o,i,c);if(!a)return null;const s=charClass(a.char);let f=i;for(;f>0;){const n=f-1;if(1===l[e+n])break;const t=r(o,n,c);if(!t)break;if(2===t.width){if(0===n||1===l[e+n-1])break;const t=r(o,n-1,c);if(!t||charClass(t.char)!==s)break;f=n-1;continue}if(charClass(t.char)!==s)break;f=n}let h=i;for(;h<t-1;){const n=h+1;if(1===l[e+n])break;const t=r(o,n,c);if(!t)break;if(2!==t.width){if(charClass(t.char)!==s)break;h=n}else h=n}return{lo:f,hi:h}}function comparePoints(o,r){return o.row!==r.row?o.row<r.row?-1:1:o.col!==r.col?o.col<r.col?-1:1:0}export function selectWordAt(o,r,n,c){const t=wordBoundsAt(r,n,c);if(!t)return;const l={col:t.lo,row:c},e={col:t.hi,row:c};o.anchor=l,o.focus=e,o.isDragging=!0,o.anchorSpan={lo:l,hi:e,kind:"word"}}const l=new Set([..."<>\"'` "]);function isUrlChar(o){if(1!==o.length)return!1;const r=o.charCodeAt(0);return r>=33&&r<=126&&!l.has(o)}export function findPlainTextUrlAt(o,n,c){if(c<0||c>=o.height)return;const t=o.width,l=o.noSelect,e=c*t;let i=n;if(i>0){const n=r(o,i,c);n&&2===n.width&&(i-=1)}if(i<0||i>=t||1===l[e+i])return;const a=r(o,i,c);if(!a||!isUrlChar(a.char))return;let s=i;for(;s>0;){const n=s-1;if(1===l[e+n])break;const t=r(o,n,c);if(!t||0!==t.width||!isUrlChar(t.char))break;s=n}let f=i;for(;f<t-1;){const n=f+1;if(1===l[e+n])break;const t=r(o,n,c);if(!t||0!==t.width||!isUrlChar(t.char))break;f=n}let h="";for(let n=s;n<=f;n++)h+=r(o,n,c).char;const u=i-s,w=/(?:https?|file):\/\//g;let d=-1,p=h.length;for(let o;o=w.exec(h);){if(o.index>u){p=o.index;break}d=o.index}if(d<0)return;let S=h.slice(d,p);const v={")":"(","]":"[","}":"{"};for(;S.length>0;){const o=S.at(-1);if(".,;:!?".includes(o)){S=S.slice(0,-1);continue}const r=v[o];if(!r)break;let n=0,c=0;for(let t=0;t<S.length;t++){const l=S.charAt(t);l===r?n++:l===o&&c++}if(!(c>n))break;S=S.slice(0,-1)}return u>=d+S.length?void 0:S}export function selectLineAt(o,r,n){if(n<0||n>=r.height)return;const c={col:0,row:n},t={col:r.width-1,row:n};o.anchor=c,o.focus=t,o.isDragging=!0,o.anchorSpan={lo:c,hi:t,kind:"line"}}export function extendSelection(r,n,c,t){if(!r.isDragging||!r.anchorSpan)return;const l=r.anchorSpan;let e,i;if("word"===l.kind){const o=wordBoundsAt(n,c,t);e={col:o?o.lo:c,row:t},i={col:o?o.hi:c,row:t}}else{const r=o(t,0,n.height-1);e={col:0,row:r},i={col:n.width-1,row:r}}comparePoints(i,l.lo)<0?(r.anchor=l.hi,r.focus=e):comparePoints(e,l.hi)>0?(r.anchor=l.lo,r.focus=i):(r.anchor=l.lo,r.focus=l.hi)}export function moveFocus(o,r,n){o.focus&&(o.anchorSpan=null,o.focus={col:r,row:n},o.virtualFocusRow=void 0)}export function shiftSelection(o,r,n,c,t){if(!o.anchor||!o.focus)return;const l=(o.virtualAnchorRow??o.anchor.row)+r,e=(o.virtualFocusRow??o.focus.row)+r;if(l<n&&e<n||l>c&&e>c)return void clearSelection(o);const i=Math.min(o.virtualAnchorRow??o.anchor.row,o.virtualFocusRow??o.focus.row),a=Math.max(o.virtualAnchorRow??o.anchor.row,o.virtualFocusRow??o.focus.row),s=Math.max(0,n-i),f=Math.max(0,a-c),h=Math.max(0,n-Math.min(l,e)),u=Math.max(0,Math.max(l,e)-c);if(h<s){const r=s-h;o.scrolledOffAbove.length-=r,o.scrolledOffAboveSW.length=o.scrolledOffAbove.length}if(u<f){const r=f-u;o.scrolledOffBelow.splice(0,r),o.scrolledOffBelowSW.splice(0,r)}o.scrolledOffAbove.length>h&&(o.scrolledOffAbove=h>0?o.scrolledOffAbove.slice(-h):[],o.scrolledOffAboveSW=h>0?o.scrolledOffAboveSW.slice(-h):[]),o.scrolledOffBelow.length>u&&(o.scrolledOffBelow=o.scrolledOffBelow.slice(0,u),o.scrolledOffBelowSW=o.scrolledOffBelowSW.slice(0,u));const shift=(o,r)=>r<n?{col:0,row:n}:r>c?{col:t-1,row:c}:{col:o.col,row:r};if(o.anchor=shift(o.anchor,l),o.focus=shift(o.focus,e),o.virtualAnchorRow=l<n||l>c?l:void 0,o.virtualFocusRow=e<n||e>c?e:void 0,o.anchorSpan){const sp=o=>{const l=o.row+r;return l<n?{col:0,row:n}:l>c?{col:t-1,row:c}:{col:o.col,row:l}};o.anchorSpan={lo:sp(o.anchorSpan.lo),hi:sp(o.anchorSpan.hi),kind:o.anchorSpan.kind}}}export function shiftAnchor(r,n,c,t){if(!r.anchor)return;const l=(r.virtualAnchorRow??r.anchor.row)+n;if(r.anchor={col:r.anchor.col,row:o(l,c,t)},r.virtualAnchorRow=l<c||l>t?l:void 0,r.anchorSpan){const shift=r=>({col:r.col,row:o(r.row+n,c,t)});r.anchorSpan={lo:shift(r.anchorSpan.lo),hi:shift(r.anchorSpan.hi),kind:r.anchorSpan.kind}}}export function shiftSelectionForFollow(r,n,c,t){if(!r.anchor)return!1;const l=(r.virtualAnchorRow??r.anchor.row)+n,e=r.focus?(r.virtualFocusRow??r.focus.row)+n:void 0;if(l<c&&void 0!==e&&e<c)return clearSelection(r),!0;if(r.anchor={col:r.anchor.col,row:o(l,c,t)},r.focus&&void 0!==e&&(r.focus={col:r.focus.col,row:o(e,c,t)}),r.virtualAnchorRow=l<c||l>t?l:void 0,r.virtualFocusRow=void 0!==e&&(e<c||e>t)?e:void 0,r.anchorSpan){const shift=r=>({col:r.col,row:o(r.row+n,c,t)});r.anchorSpan={lo:shift(r.anchorSpan.lo),hi:shift(r.anchorSpan.hi),kind:r.anchorSpan.kind}}return!1}export function hasSelection(o){return null!==o.anchor&&null!==o.focus}export function selectionBounds(o){return o.anchor&&o.focus?comparePoints(o.anchor,o.focus)<=0?{start:o.anchor,end:o.focus}:{start:o.focus,end:o.anchor}:null}export function isCellSelected(o,r,n){const c=selectionBounds(o);if(!c)return!1;const{start:t,end:l}=c;return!(n<t.row||n>l.row)&&(!(n===t.row&&r<t.col)&&!(n===l.row&&r>l.col))}function extractRowText(o,n,c,t){const l=o.noSelect,e=n*o.width,i=n+1<o.height?o.softWrap[n+1]:0,a=i>0?Math.min(t,i-1):t;let s="";for(let t=c;t<=a;t++){if(1===l[e+t])continue;const c=r(o,t,n);c&&(2!==c.width&&3!==c.width&&(s+=c.char))}return i>0?s:s.replace(/\s+$/,"")}function joinRows(o,r,n){n&&o.length>0?o[o.length-1]+=r:o.push(r)}export function getSelectedText(o,r){const n=selectionBounds(o);if(!n)return"";const{start:c,end:t}=n,l=r.softWrap,e=[];for(let r=0;r<o.scrolledOffAbove.length;r++)joinRows(e,o.scrolledOffAbove[r],o.scrolledOffAboveSW[r]);for(let o=c.row;o<=t.row;o++){joinRows(e,extractRowText(r,o,o===c.row?c.col:0,o===t.row?t.col:r.width-1),l[o]>0)}for(let r=0;r<o.scrolledOffBelow.length;r++)joinRows(e,o.scrolledOffBelow[r],o.scrolledOffBelowSW[r]);return e.join("\n")}export function captureScrolledRows(o,r,n,c,t){const l=selectionBounds(o);if(!l||n>c)return;const{start:e,end:i}=l,a=Math.max(n,e.row),s=Math.min(c,i.row);if(a>s)return;const f=r.width,h=r.softWrap,u=[],w=[];for(let o=a;o<=s;o++){const n=o===e.row?e.col:0,c=o===i.row?i.col:f-1;u.push(extractRowText(r,o,n,c)),w.push(h[o]>0)}"above"===t?(o.scrolledOffAbove.push(...u),o.scrolledOffAboveSW.push(...w),o.anchor&&o.anchor.row===e.row&&a===e.row&&(o.anchor={col:0,row:o.anchor.row},o.anchorSpan&&(o.anchorSpan={kind:o.anchorSpan.kind,lo:{col:0,row:o.anchorSpan.lo.row},hi:{col:f-1,row:o.anchorSpan.hi.row}}))):(o.scrolledOffBelow.unshift(...u),o.scrolledOffBelowSW.unshift(...w),o.anchor&&o.anchor.row===i.row&&s===i.row&&(o.anchor={col:f-1,row:o.anchor.row},o.anchorSpan&&(o.anchorSpan={kind:o.anchorSpan.kind,lo:{col:0,row:o.anchorSpan.lo.row},hi:{col:f-1,row:o.anchorSpan.hi.row}})))}export function applySelectionOverlay(o,r,t){const l=selectionBounds(r);if(!l)return;const{start:e,end:i}=l,a=o.width,s=o.noSelect;for(let r=e.row;r<=i.row&&r<o.height;r++){const l=r===e.row?e.col:0,f=r===i.row?Math.min(i.col,a-1):a-1,h=r*a;for(let e=l;e<=f;e++){const l=h+e;if(1===s[l])continue;const i=n(o,l);c(o,e,r,t.withSelectionBg(i.styleId))}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function squashTextNodesToSegments(e,t={},o,
|
|
1
|
+
export function squashTextNodesToSegments(e,t={},o,s=[]){const n=e.textStyles?{...t,...e.textStyles}:t;for(const t of e.childNodes)if(void 0!==t)if("#text"===t.nodeName)t.nodeValue.length>0&&s.push({text:t.nodeValue,styles:n,hyperlink:o});else if("ink-text"===t.nodeName||"ink-virtual-text"===t.nodeName)squashTextNodesToSegments(t,n,o,s);else if("ink-link"===t.nodeName){squashTextNodesToSegments(t,n,t.attributes.href||o,s)}return s}function squashTextNodes(e){let t="";for(const o of e.childNodes)void 0!==o&&("#text"===o.nodeName?t+=o.nodeValue:("ink-text"===o.nodeName||"ink-virtual-text"===o.nodeName||"ink-link"===o.nodeName)&&(t+=squashTextNodes(o)));return t}export default squashTextNodes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"emoji-regex";import{eastAsianWidth as r}from"get-east-asian-width";import
|
|
1
|
+
import t from"emoji-regex";import{eastAsianWidth as r}from"get-east-asian-width";import n from"strip-ansi";import{getGraphemeSegmenter as e}from"../utils/intl.js";const i=t();function getEmojiWidth(t){const r=t.codePointAt(0);if(r>=127462&&r<=127487){let r=0;for(const n of t)r++;return 1===r?1:2}if(2===t.length){if(65039===t.codePointAt(1)&&(r>=48&&r<=57||35===r||42===r))return 1}return 2}function isZeroWidth(t){if(t>=32&&t<127)return!1;if(t>=160&&t<768)return 173===t;if(t<=31||t>=127&&t<=159)return!0;if(t>=8203&&t<=8205||65279===t||t>=8288&&t<=8292)return!0;if(t>=65024&&t<=65039||t>=917760&&t<=917999)return!0;if(t>=768&&t<=879||t>=6832&&t<=6911||t>=7616&&t<=7679||t>=8400&&t<=8447||t>=65056&&t<=65071)return!0;if(t>=2304&&t<=3407){const r=127&t;if(r<=3)return!0;if(r>=58&&r<=79)return!0;if(r>=81&&r<=87)return!0;if(r>=98&&r<=99)return!0}return 3633===t||t>=3636&&t<=3642||t>=3655&&t<=3662||3761===t||t>=3764&&t<=3772||t>=3784&&t<=3789||(t>=1536&&t<=1541||1757===t||1807===t||2274===t||(t>=55296&&t<=57343||t>=917504&&t<=917631))}const o="undefined"!=typeof Bun&&"function"==typeof Bun.stringWidth?Bun.stringWidth:null,f={ambiguousIsNarrow:!0};export const stringWidth=o?t=>o(t,f):function(t){if("string"!=typeof t||0===t.length)return 0;let o=!0;for(let r=0;r<t.length;r++){const n=t.charCodeAt(r);if(n>=127||27===n){o=!1;break}}if(o){let r=0;for(let n=0;n<t.length;n++){t.charCodeAt(n)>31&&r++}return r}if(t.includes("")&&0===(t=n(t)).length)return 0;if(!function(t){for(const r of t){const t=r.codePointAt(0);if(t>=127744&&t<=129791)return!0;if(t>=9728&&t<=10175)return!0;if(t>=127462&&t<=127487)return!0;if(t>=65024&&t<=65039)return!0;if(8205===t)return!0}return!1}(t)){let n=0;for(const e of t){const t=e.codePointAt(0);isZeroWidth(t)||(n+=r(t,{ambiguousAsWide:!1}))}return n}let f=0;for(const{segment:n}of e().segment(t))if(i.lastIndex=0,i.test(n))f+=getEmojiWidth(n);else for(const t of n){const n=t.codePointAt(0);if(!isZeroWidth(n)){f+=r(n,{ambiguousAsWide:!1});break}}return f};
|