whale-code 6.5.5 → 6.5.6
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/README.md +39 -31
- package/bin/{swagmanager-mcp.js → whale-code.js} +17 -2
- package/dist/cli/app.js +148 -72
- package/dist/cli/app.js.map +1 -0
- package/dist/cli/chat/AgentSelector.js +105 -10
- package/dist/cli/chat/AgentSelector.js.map +1 -0
- package/dist/cli/chat/ChatApp.d.ts +31 -0
- package/dist/cli/chat/ChatApp.js +539 -286
- package/dist/cli/chat/ChatApp.js.map +1 -0
- package/dist/cli/chat/ChatInput.js +1088 -770
- package/dist/cli/chat/ChatInput.js.map +1 -0
- package/dist/cli/chat/MarkdownText.js +39 -14
- package/dist/cli/chat/MarkdownText.js.map +1 -0
- package/dist/cli/chat/MemoryManager.js +181 -46
- package/dist/cli/chat/MemoryManager.js.map +1 -0
- package/dist/cli/chat/MessageList.d.ts +2 -3
- package/dist/cli/chat/MessageList.js +186 -45
- package/dist/cli/chat/MessageList.js.map +1 -0
- package/dist/cli/chat/ModelSelector.js +282 -63
- package/dist/cli/chat/ModelSelector.js.map +1 -0
- package/dist/cli/chat/NodeManager.js +165 -75
- package/dist/cli/chat/NodeManager.js.map +1 -0
- package/dist/cli/chat/NodeSelector.js +171 -30
- package/dist/cli/chat/NodeSelector.js.map +1 -0
- package/dist/cli/chat/PlanApproval.js +281 -57
- package/dist/cli/chat/PlanApproval.js.map +1 -0
- package/dist/cli/chat/RewindViewer.js +559 -144
- package/dist/cli/chat/RewindViewer.js.map +1 -0
- package/dist/cli/chat/SessionManager.js +137 -30
- package/dist/cli/chat/SessionManager.js.map +1 -0
- package/dist/cli/chat/SlashMenu.js +293 -164
- package/dist/cli/chat/SlashMenu.js.map +1 -0
- package/dist/cli/chat/StatusBar.js +172 -9
- package/dist/cli/chat/StatusBar.js.map +1 -0
- package/dist/cli/chat/StoreSelector.js +147 -18
- package/dist/cli/chat/StoreSelector.js.map +1 -0
- package/dist/cli/chat/StreamingText.d.ts +1 -5
- package/dist/cli/chat/StreamingText.js +22 -7
- package/dist/cli/chat/StreamingText.js.map +1 -0
- package/dist/cli/chat/SubagentPanel.d.ts +1 -2
- package/dist/cli/chat/SubagentPanel.js +612 -72
- package/dist/cli/chat/SubagentPanel.js.map +1 -0
- package/dist/cli/chat/TeamPanel.d.ts +1 -0
- package/dist/cli/chat/TeamPanel.js +230 -30
- package/dist/cli/chat/TeamPanel.js.map +1 -0
- package/dist/cli/chat/ThemeSelector.js +84 -24
- package/dist/cli/chat/ThemeSelector.js.map +1 -0
- package/dist/cli/chat/ToolIndicator.js +1476 -371
- package/dist/cli/chat/ToolIndicator.js.map +1 -0
- package/dist/cli/chat/hooks/useAgentLoop.d.ts +1 -0
- package/dist/cli/chat/hooks/useAgentLoop.js +481 -367
- package/dist/cli/chat/hooks/useAgentLoop.js.map +1 -0
- package/dist/cli/chat/hooks/useSlashCommands.d.ts +3 -14
- package/dist/cli/chat/hooks/useSlashCommands.js +744 -572
- package/dist/cli/chat/hooks/useSlashCommands.js.map +1 -0
- package/dist/cli/commands/config-cmd.js +56 -57
- package/dist/cli/commands/config-cmd.js.map +1 -0
- package/dist/cli/commands/db.js +184 -169
- package/dist/cli/commands/db.js.map +1 -0
- package/dist/cli/commands/doctor.js +212 -122
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/init.js +211 -244
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/mcp.js +127 -122
- package/dist/cli/commands/mcp.js.map +1 -0
- package/dist/cli/login/LoginApp.js +355 -141
- package/dist/cli/login/LoginApp.js.map +1 -0
- package/dist/cli/print-mode.js +196 -177
- package/dist/cli/print-mode.js.map +1 -0
- package/dist/cli/serve-mode.js +615 -530
- package/dist/cli/serve-mode.js.map +1 -0
- package/dist/cli/services/agent-config.d.ts +5 -1
- package/dist/cli/services/agent-config.js +66 -36
- package/dist/cli/services/agent-config.js.map +1 -0
- package/dist/cli/services/agent-definitions.d.ts +4 -1
- package/dist/cli/services/agent-definitions.js +97 -56
- package/dist/cli/services/agent-definitions.js.map +1 -0
- package/dist/cli/services/agent-events.js +225 -162
- package/dist/cli/services/agent-events.js.map +1 -0
- package/dist/cli/services/agent-loop.js +976 -688
- package/dist/cli/services/agent-loop.js.map +1 -0
- package/dist/cli/services/agent-worker-base.d.ts +35 -5
- package/dist/cli/services/agent-worker-base.js +337 -153
- package/dist/cli/services/agent-worker-base.js.map +1 -0
- package/dist/cli/services/api-retry.js +69 -64
- package/dist/cli/services/api-retry.js.map +1 -0
- package/dist/cli/services/auth-service.d.ts +3 -3
- package/dist/cli/services/auth-service.js +209 -132
- package/dist/cli/services/auth-service.js.map +1 -0
- package/dist/cli/services/background-processes.js +343 -267
- package/dist/cli/services/background-processes.js.map +1 -0
- package/dist/cli/services/browser-auth.d.ts +2 -2
- package/dist/cli/services/browser-auth.js +159 -118
- package/dist/cli/services/browser-auth.js.map +1 -0
- package/dist/cli/services/claude-md-loader.js +40 -36
- package/dist/cli/services/claude-md-loader.js.map +1 -0
- package/dist/cli/services/config-store.d.ts +9 -4
- package/dist/cli/services/config-store.js +164 -117
- package/dist/cli/services/config-store.js.map +1 -0
- package/dist/cli/services/debug-log.d.ts +1 -1
- package/dist/cli/services/debug-log.js +34 -35
- package/dist/cli/services/debug-log.js.map +1 -0
- package/dist/cli/services/env-detect.d.ts +7 -0
- package/dist/cli/services/env-detect.js +9 -0
- package/dist/cli/services/env-detect.js.map +1 -0
- package/dist/cli/services/error-logger.js +187 -169
- package/dist/cli/services/error-logger.js.map +1 -0
- package/dist/cli/services/file-history.d.ts +1 -1
- package/dist/cli/services/file-history.js +50 -54
- package/dist/cli/services/file-history.js.map +1 -0
- package/dist/cli/services/format-server-response.js +332 -372
- package/dist/cli/services/format-server-response.js.map +1 -0
- package/dist/cli/services/git-context.js +61 -45
- package/dist/cli/services/git-context.js.map +1 -0
- package/dist/cli/services/hooks.d.ts +2 -2
- package/dist/cli/services/hooks.js +195 -180
- package/dist/cli/services/hooks.js.map +1 -0
- package/dist/cli/services/ink-incremental.d.ts +19 -0
- package/dist/cli/services/ink-incremental.js +59 -0
- package/dist/cli/services/ink-incremental.js.map +1 -0
- package/dist/cli/services/ink-resize-fix.js +54 -44
- package/dist/cli/services/ink-resize-fix.js.map +1 -0
- package/dist/cli/services/ink-sync-output.d.ts +12 -0
- package/dist/cli/services/ink-sync-output.js +16 -0
- package/dist/cli/services/ink-sync-output.js.map +1 -0
- package/dist/cli/services/interactive-tools.js +268 -212
- package/dist/cli/services/interactive-tools.js.map +1 -0
- package/dist/cli/services/keybinding-manager.d.ts +11 -1
- package/dist/cli/services/keybinding-manager.js +126 -63
- package/dist/cli/services/keybinding-manager.js.map +1 -0
- package/dist/cli/services/local-tools.d.ts +1 -1
- package/dist/cli/services/local-tools.js +939 -656
- package/dist/cli/services/local-tools.js.map +1 -0
- package/dist/cli/services/lsp-manager.js +757 -594
- package/dist/cli/services/lsp-manager.js.map +1 -0
- package/dist/cli/services/mcp-client.d.ts +1 -1
- package/dist/cli/services/mcp-client.js +173 -134
- package/dist/cli/services/mcp-client.js.map +1 -0
- package/dist/cli/services/memory-manager.js +53 -40
- package/dist/cli/services/memory-manager.js.map +1 -0
- package/dist/cli/services/model-manager.js +55 -40
- package/dist/cli/services/model-manager.js.map +1 -0
- package/dist/cli/services/model-router.js +115 -85
- package/dist/cli/services/model-router.js.map +1 -0
- package/dist/cli/services/paths.d.ts +30 -0
- package/dist/cli/services/paths.js +81 -0
- package/dist/cli/services/paths.js.map +1 -0
- package/dist/cli/services/permission-modes.js +32 -25
- package/dist/cli/services/permission-modes.js.map +1 -0
- package/dist/cli/services/rewind.js +182 -168
- package/dist/cli/services/rewind.js.map +1 -0
- package/dist/cli/services/ripgrep.js +115 -115
- package/dist/cli/services/ripgrep.js.map +1 -0
- package/dist/cli/services/sandbox.d.ts +1 -1
- package/dist/cli/services/sandbox.js +58 -37
- package/dist/cli/services/sandbox.js.map +1 -0
- package/dist/cli/services/server-tools.js +738 -565
- package/dist/cli/services/server-tools.js.map +1 -0
- package/dist/cli/services/session-persistence.js +69 -74
- package/dist/cli/services/session-persistence.js.map +1 -0
- package/dist/cli/services/subagent-worker.js +42 -27
- package/dist/cli/services/subagent-worker.js.map +1 -0
- package/dist/cli/services/subagent.d.ts +2 -0
- package/dist/cli/services/subagent.js +605 -433
- package/dist/cli/services/subagent.js.map +1 -0
- package/dist/cli/services/system-prompt.js +86 -78
- package/dist/cli/services/system-prompt.js.map +1 -0
- package/dist/cli/services/task-decomposer.d.ts +1 -1
- package/dist/cli/services/task-decomposer.js +172 -139
- package/dist/cli/services/task-decomposer.js.map +1 -0
- package/dist/cli/services/team-lead.d.ts +2 -2
- package/dist/cli/services/team-lead.js +727 -529
- package/dist/cli/services/team-lead.js.map +1 -0
- package/dist/cli/services/team-state.js +319 -319
- package/dist/cli/services/team-state.js.map +1 -0
- package/dist/cli/services/teammate.d.ts +8 -2
- package/dist/cli/services/teammate.js +857 -569
- package/dist/cli/services/teammate.js.map +1 -0
- package/dist/cli/services/telemetry.d.ts +6 -1
- package/dist/cli/services/telemetry.js +180 -157
- package/dist/cli/services/telemetry.js.map +1 -0
- package/dist/cli/services/tools/agent-tools.d.ts +3 -3
- package/dist/cli/services/tools/agent-tools.js +480 -322
- package/dist/cli/services/tools/agent-tools.js.map +1 -0
- package/dist/cli/services/tools/file-ops.js +563 -450
- package/dist/cli/services/tools/file-ops.js.map +1 -0
- package/dist/cli/services/tools/search-tools.js +231 -162
- package/dist/cli/services/tools/search-tools.js.map +1 -0
- package/dist/cli/services/tools/shell-exec.js +197 -151
- package/dist/cli/services/tools/shell-exec.js.map +1 -0
- package/dist/cli/services/tools/task-manager.js +206 -173
- package/dist/cli/services/tools/task-manager.js.map +1 -0
- package/dist/cli/services/tools/web-tools.js +388 -341
- package/dist/cli/services/tools/web-tools.js.map +1 -0
- package/dist/cli/setup/SetupApp.d.ts +2 -2
- package/dist/cli/setup/SetupApp.js +608 -160
- package/dist/cli/setup/SetupApp.js.map +1 -0
- package/dist/cli/shared/ErrorBoundary.d.ts +22 -0
- package/dist/cli/shared/ErrorBoundary.js +73 -0
- package/dist/cli/shared/ErrorBoundary.js.map +1 -0
- package/dist/cli/shared/MatrixIntro.js +66 -69
- package/dist/cli/shared/MatrixIntro.js.map +1 -0
- package/dist/cli/shared/SpinnerSlot.d.ts +14 -0
- package/dist/cli/shared/SpinnerSlot.js +63 -0
- package/dist/cli/shared/SpinnerSlot.js.map +1 -0
- package/dist/cli/shared/Theme.d.ts +1 -1
- package/dist/cli/shared/Theme.js +136 -92
- package/dist/cli/shared/Theme.js.map +1 -0
- package/dist/cli/shared/WhaleBanner.js +99 -11
- package/dist/cli/shared/WhaleBanner.js.map +1 -0
- package/dist/cli/shared/markdown.d.ts +3 -1
- package/dist/cli/shared/markdown.js +736 -674
- package/dist/cli/shared/markdown.js.map +1 -0
- package/dist/cli/shared/marked-terminal.d.js +2 -0
- package/dist/cli/shared/marked-terminal.d.js.map +1 -0
- package/dist/cli/shared/theme-manager.js +99 -90
- package/dist/cli/shared/theme-manager.js.map +1 -0
- package/dist/cli/shared/theme-presets.js +256 -254
- package/dist/cli/shared/theme-presets.js.map +1 -0
- package/dist/cli/status/StatusApp.js +235 -86
- package/dist/cli/status/StatusApp.js.map +1 -0
- package/dist/cli/stores/StoreApp.js +275 -65
- package/dist/cli/stores/StoreApp.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +509 -396
- package/dist/index.js.map +1 -0
- package/dist/local-agent/connection.d.ts +2 -2
- package/dist/local-agent/connection.js +352 -293
- package/dist/local-agent/connection.js.map +1 -0
- package/dist/local-agent/discovery.js +259 -122
- package/dist/local-agent/discovery.js.map +1 -0
- package/dist/local-agent/executor.js +216 -193
- package/dist/local-agent/executor.js.map +1 -0
- package/dist/local-agent/index.d.ts +2 -2
- package/dist/local-agent/index.js +156 -156
- package/dist/local-agent/index.js.map +1 -0
- package/dist/node/adapters/base.js +18 -8
- package/dist/node/adapters/base.js.map +1 -0
- package/dist/node/adapters/discord.js +286 -275
- package/dist/node/adapters/discord.js.map +1 -0
- package/dist/node/adapters/email.js +189 -202
- package/dist/node/adapters/email.js.map +1 -0
- package/dist/node/adapters/imessage.js +145 -142
- package/dist/node/adapters/imessage.js.map +1 -0
- package/dist/node/adapters/slack.js +237 -236
- package/dist/node/adapters/slack.js.map +1 -0
- package/dist/node/adapters/sms.js +149 -151
- package/dist/node/adapters/sms.js.map +1 -0
- package/dist/node/adapters/telegram.js +88 -92
- package/dist/node/adapters/telegram.js.map +1 -0
- package/dist/node/adapters/webchat.js +160 -136
- package/dist/node/adapters/webchat.js.map +1 -0
- package/dist/node/adapters/whatsapp.js +212 -215
- package/dist/node/adapters/whatsapp.js.map +1 -0
- package/dist/node/cli.js +884 -653
- package/dist/node/cli.js.map +1 -0
- package/dist/node/config.js +20 -18
- package/dist/node/config.js.map +1 -0
- package/dist/node/gateway-client.js +191 -181
- package/dist/node/gateway-client.js.map +1 -0
- package/dist/node/portal/clipboard.js +161 -130
- package/dist/node/portal/clipboard.js.map +1 -0
- package/dist/node/portal/discovery.js +51 -45
- package/dist/node/portal/discovery.js.map +1 -0
- package/dist/node/portal/forward.js +64 -58
- package/dist/node/portal/forward.js.map +1 -0
- package/dist/node/portal/index.js +246 -221
- package/dist/node/portal/index.js.map +1 -0
- package/dist/node/portal/multiplexer.js +192 -182
- package/dist/node/portal/multiplexer.js.map +1 -0
- package/dist/node/portal/permissions.js +102 -70
- package/dist/node/portal/permissions.js.map +1 -0
- package/dist/node/portal/protocol.js +153 -116
- package/dist/node/portal/protocol.js.map +1 -0
- package/dist/node/portal/screen.js +80 -69
- package/dist/node/portal/screen.js.map +1 -0
- package/dist/node/portal/session.js +124 -117
- package/dist/node/portal/session.js.map +1 -0
- package/dist/node/portal/shell.js +140 -113
- package/dist/node/portal/shell.js.map +1 -0
- package/dist/node/portal/stream.js +77 -75
- package/dist/node/portal/stream.js.map +1 -0
- package/dist/node/portal/transfer.js +190 -167
- package/dist/node/portal/transfer.js.map +1 -0
- package/dist/node/portal/ui.js +124 -99
- package/dist/node/portal/ui.js.map +1 -0
- package/dist/node/remote-desktop/compile-helper.js +50 -45
- package/dist/node/remote-desktop/compile-helper.js.map +1 -0
- package/dist/node/remote-desktop/index.js +215 -187
- package/dist/node/remote-desktop/index.js.map +1 -0
- package/dist/node/remote-desktop/protocol.js +45 -29
- package/dist/node/remote-desktop/protocol.js.map +1 -0
- package/dist/node/runtime.js +493 -410
- package/dist/node/runtime.js.map +1 -0
- package/dist/server/handlers/__test-utils__/test-db.js +39 -89
- package/dist/server/handlers/__test-utils__/test-db.js.map +1 -0
- package/dist/server/handlers/analytics.js +467 -261
- package/dist/server/handlers/analytics.js.map +1 -0
- package/dist/server/handlers/api-docs.js +1030 -895
- package/dist/server/handlers/api-docs.js.map +1 -0
- package/dist/server/handlers/api-keys.js +291 -242
- package/dist/server/handlers/api-keys.js.map +1 -0
- package/dist/server/handlers/billing.js +330 -239
- package/dist/server/handlers/billing.js.map +1 -0
- package/dist/server/handlers/browser.js +468 -395
- package/dist/server/handlers/browser.js.map +1 -0
- package/dist/server/handlers/catalog.js +1377 -978
- package/dist/server/handlers/catalog.js.map +1 -0
- package/dist/server/handlers/clickhouse.js +157 -109
- package/dist/server/handlers/clickhouse.js.map +1 -0
- package/dist/server/handlers/comms.js +1439 -984
- package/dist/server/handlers/comms.js.map +1 -0
- package/dist/server/handlers/creations.js +461 -394
- package/dist/server/handlers/creations.js.map +1 -0
- package/dist/server/handlers/crm.js +1082 -791
- package/dist/server/handlers/crm.js.map +1 -0
- package/dist/server/handlers/discovery.js +251 -232
- package/dist/server/handlers/discovery.js.map +1 -0
- package/dist/server/handlers/embeddings.js +241 -164
- package/dist/server/handlers/embeddings.js.map +1 -0
- package/dist/server/handlers/enrichment.js +887 -718
- package/dist/server/handlers/enrichment.js.map +1 -0
- package/dist/server/handlers/image-gen.js +467 -376
- package/dist/server/handlers/image-gen.js.map +1 -0
- package/dist/server/handlers/inventory.js +797 -424
- package/dist/server/handlers/inventory.js.map +1 -0
- package/dist/server/handlers/kali.js +272 -230
- package/dist/server/handlers/kali.js.map +1 -0
- package/dist/server/handlers/llm-providers.js +803 -580
- package/dist/server/handlers/llm-providers.js.map +1 -0
- package/dist/server/handlers/local-agent.js +133 -105
- package/dist/server/handlers/local-agent.js.map +1 -0
- package/dist/server/handlers/media.js +1179 -857
- package/dist/server/handlers/media.js.map +1 -0
- package/dist/server/handlers/meta-ads.js +2669 -2093
- package/dist/server/handlers/meta-ads.js.map +1 -0
- package/dist/server/handlers/nodes.js +1321 -913
- package/dist/server/handlers/nodes.js.map +1 -0
- package/dist/server/handlers/operations.js +183 -157
- package/dist/server/handlers/operations.js.map +1 -0
- package/dist/server/handlers/platform.js +346 -210
- package/dist/server/handlers/platform.js.map +1 -0
- package/dist/server/handlers/remove-bg.js +118 -86
- package/dist/server/handlers/remove-bg.js.map +1 -0
- package/dist/server/handlers/storefront.js +586 -446
- package/dist/server/handlers/storefront.js.map +1 -0
- package/dist/server/handlers/supply-chain.js +546 -326
- package/dist/server/handlers/supply-chain.js.map +1 -0
- package/dist/server/handlers/transcription.js +106 -97
- package/dist/server/handlers/transcription.js.map +1 -0
- package/dist/server/handlers/video-gen.js +593 -424
- package/dist/server/handlers/video-gen.js.map +1 -0
- package/dist/server/handlers/voice.js +1458 -1039
- package/dist/server/handlers/voice.js.map +1 -0
- package/dist/server/handlers/workflow-steps.js +2837 -2116
- package/dist/server/handlers/workflow-steps.js.map +1 -0
- package/dist/server/handlers/workflows.js +1630 -933
- package/dist/server/handlers/workflows.js.map +1 -0
- package/dist/server/index.js +3167 -2422
- package/dist/server/index.js.map +1 -0
- package/dist/server/lib/batch-client.js +471 -409
- package/dist/server/lib/batch-client.js.map +1 -0
- package/dist/server/lib/clickhouse-buffer.js +118 -104
- package/dist/server/lib/clickhouse-buffer.js.map +1 -0
- package/dist/server/lib/clickhouse-client.js +107 -107
- package/dist/server/lib/clickhouse-client.js.map +1 -0
- package/dist/server/lib/coa-renderer.js +1786 -356
- package/dist/server/lib/coa-renderer.js.map +1 -0
- package/dist/server/lib/code-worker-pool.js +227 -177
- package/dist/server/lib/code-worker-pool.js.map +1 -0
- package/dist/server/lib/code-worker.js +174 -164
- package/dist/server/lib/code-worker.js.map +1 -0
- package/dist/server/lib/compaction-service.d.ts +2 -12
- package/dist/server/lib/compaction-service.js +74 -184
- package/dist/server/lib/compaction-service.js.map +1 -0
- package/dist/server/lib/logger.js +36 -24
- package/dist/server/lib/logger.js.map +1 -0
- package/dist/server/lib/otel.js +101 -80
- package/dist/server/lib/otel.js.map +1 -0
- package/dist/server/lib/pdf-renderer.js +952 -788
- package/dist/server/lib/pdf-renderer.js.map +1 -0
- package/dist/server/lib/prompt-sanitizer.js +188 -108
- package/dist/server/lib/prompt-sanitizer.js.map +1 -0
- package/dist/server/lib/provider-capabilities.js +136 -138
- package/dist/server/lib/provider-capabilities.js.map +1 -0
- package/dist/server/lib/provider-failover.js +190 -168
- package/dist/server/lib/provider-failover.js.map +1 -0
- package/dist/server/lib/rate-limiter.js +186 -117
- package/dist/server/lib/rate-limiter.js.map +1 -0
- package/dist/server/lib/react-pdf-layout.js +551 -382
- package/dist/server/lib/react-pdf-layout.js.map +1 -0
- package/dist/server/lib/server-agent-loop.d.ts +4 -1
- package/dist/server/lib/server-agent-loop.js +906 -634
- package/dist/server/lib/server-agent-loop.js.map +1 -0
- package/dist/server/lib/server-subagent.js +260 -164
- package/dist/server/lib/server-subagent.js.map +1 -0
- package/dist/server/lib/session-checkpoint.js +105 -96
- package/dist/server/lib/session-checkpoint.js.map +1 -0
- package/dist/server/lib/ssrf-guard.js +193 -184
- package/dist/server/lib/ssrf-guard.js.map +1 -0
- package/dist/server/lib/supabase-client.js +94 -82
- package/dist/server/lib/supabase-client.js.map +1 -0
- package/dist/server/lib/template-resolver.js +154 -176
- package/dist/server/lib/template-resolver.js.map +1 -0
- package/dist/server/lib/utils.js +242 -133
- package/dist/server/lib/utils.js.map +1 -0
- package/dist/server/local-agent-gateway.d.ts +2 -2
- package/dist/server/local-agent-gateway.js +785 -627
- package/dist/server/local-agent-gateway.js.map +1 -0
- package/dist/server/providers/anthropic.js +250 -172
- package/dist/server/providers/anthropic.js.map +1 -0
- package/dist/server/providers/bedrock.js +217 -158
- package/dist/server/providers/bedrock.js.map +1 -0
- package/dist/server/providers/gemini.js +548 -418
- package/dist/server/providers/gemini.js.map +1 -0
- package/dist/server/providers/openai.js +571 -437
- package/dist/server/providers/openai.js.map +1 -0
- package/dist/server/providers/registry.js +23 -18
- package/dist/server/providers/registry.js.map +1 -0
- package/dist/server/providers/shared.js +123 -95
- package/dist/server/providers/shared.js.map +1 -0
- package/dist/server/providers/types.js +1 -11
- package/dist/server/providers/types.js.map +1 -0
- package/dist/server/proxy-handlers.js +209 -165
- package/dist/server/proxy-handlers.js.map +1 -0
- package/dist/server/tool-router.js +959 -599
- package/dist/server/tool-router.js.map +1 -0
- package/dist/server/validation.js +248 -188
- package/dist/server/validation.js.map +1 -0
- package/dist/server/worker.js +202 -133
- package/dist/server/worker.js.map +1 -0
- package/dist/setup.d.ts +2 -2
- package/dist/setup.js +151 -147
- package/dist/setup.js.map +1 -0
- package/dist/shared/agent-core.d.ts +115 -26
- package/dist/shared/agent-core.js +956 -522
- package/dist/shared/agent-core.js.map +1 -0
- package/dist/shared/anthropic-types.js +1 -6
- package/dist/shared/anthropic-types.js.map +1 -0
- package/dist/shared/api-client.d.ts +16 -9
- package/dist/shared/api-client.js +419 -327
- package/dist/shared/api-client.js.map +1 -0
- package/dist/shared/compaction.d.ts +36 -0
- package/dist/shared/compaction.js +138 -0
- package/dist/shared/compaction.js.map +1 -0
- package/dist/shared/constants.js +67 -64
- package/dist/shared/constants.js.map +1 -0
- package/dist/shared/sse-parser.js +221 -219
- package/dist/shared/sse-parser.js.map +1 -0
- package/dist/shared/tool-dispatch.d.ts +4 -0
- package/dist/shared/tool-dispatch.js +226 -165
- package/dist/shared/tool-dispatch.js.map +1 -0
- package/dist/shared/types.js +1 -6
- package/dist/shared/types.js.map +1 -0
- package/dist/types/cli-highlight.d.js +2 -0
- package/dist/types/cli-highlight.d.js.map +1 -0
- package/dist/types/diff.d.js +2 -0
- package/dist/types/diff.d.js.map +1 -0
- package/dist/types/pdf-parse.d.js +2 -0
- package/dist/types/pdf-parse.d.js.map +1 -0
- package/dist/updater.d.ts +1 -1
- package/dist/updater.js +118 -92
- package/dist/updater.js.map +1 -0
- package/dist/webchat/widget.js +227 -380
- package/dist/webchat/widget.js.map +1 -0
- package/package.json +22 -10
- package/vendor/ink/build/ansi-tokenizer.d.ts +38 -0
- package/vendor/ink/build/ansi-tokenizer.js +316 -0
- package/vendor/ink/build/ansi-tokenizer.js.map +1 -0
- package/vendor/ink/build/apply-styles.js +175 -0
- package/vendor/ink/build/build-layout.js +77 -0
- package/vendor/ink/build/calculate-wrapped-text.js +53 -0
- package/vendor/ink/build/colorize.d.ts +3 -0
- package/vendor/ink/build/colorize.js +48 -0
- package/vendor/ink/build/colorize.js.map +1 -0
- package/vendor/ink/build/components/AccessibilityContext.d.ts +3 -0
- package/vendor/ink/build/components/AccessibilityContext.js +5 -0
- package/vendor/ink/build/components/AccessibilityContext.js.map +1 -0
- package/vendor/ink/build/components/App.d.ts +18 -0
- package/vendor/ink/build/components/App.js +351 -0
- package/vendor/ink/build/components/App.js.map +1 -0
- package/vendor/ink/build/components/AppContext.d.ts +15 -0
- package/vendor/ink/build/components/AppContext.js +11 -0
- package/vendor/ink/build/components/AppContext.js.map +1 -0
- package/vendor/ink/build/components/BackgroundContext.d.ts +4 -0
- package/vendor/ink/build/components/BackgroundContext.js +3 -0
- package/vendor/ink/build/components/BackgroundContext.js.map +1 -0
- package/vendor/ink/build/components/Box.d.ts +117 -0
- package/vendor/ink/build/components/Box.js +34 -0
- package/vendor/ink/build/components/Box.js.map +1 -0
- package/vendor/ink/build/components/Color.js +62 -0
- package/vendor/ink/build/components/Cursor.d.ts +83 -0
- package/vendor/ink/build/components/Cursor.js +53 -0
- package/vendor/ink/build/components/Cursor.js.map +1 -0
- package/vendor/ink/build/components/CursorContext.d.ts +11 -0
- package/vendor/ink/build/components/CursorContext.js +8 -0
- package/vendor/ink/build/components/CursorContext.js.map +1 -0
- package/vendor/ink/build/components/ErrorBoundary.d.ts +18 -0
- package/vendor/ink/build/components/ErrorBoundary.js +23 -0
- package/vendor/ink/build/components/ErrorBoundary.js.map +1 -0
- package/vendor/ink/build/components/ErrorOverview.d.ts +6 -0
- package/vendor/ink/build/components/ErrorOverview.js +84 -0
- package/vendor/ink/build/components/ErrorOverview.js.map +1 -0
- package/vendor/ink/build/components/FocusContext.d.ts +16 -0
- package/vendor/ink/build/components/FocusContext.js +17 -0
- package/vendor/ink/build/components/FocusContext.js.map +1 -0
- package/vendor/ink/build/components/Newline.d.ts +13 -0
- package/vendor/ink/build/components/Newline.js +8 -0
- package/vendor/ink/build/components/Newline.js.map +1 -0
- package/vendor/ink/build/components/Spacer.d.ts +7 -0
- package/vendor/ink/build/components/Spacer.js +11 -0
- package/vendor/ink/build/components/Spacer.js.map +1 -0
- package/vendor/ink/build/components/Static.d.ts +24 -0
- package/vendor/ink/build/components/Static.js +28 -0
- package/vendor/ink/build/components/Static.js.map +1 -0
- package/vendor/ink/build/components/StderrContext.d.ts +15 -0
- package/vendor/ink/build/components/StderrContext.js +13 -0
- package/vendor/ink/build/components/StderrContext.js.map +1 -0
- package/vendor/ink/build/components/StdinContext.d.ts +22 -0
- package/vendor/ink/build/components/StdinContext.js +19 -0
- package/vendor/ink/build/components/StdinContext.js.map +1 -0
- package/vendor/ink/build/components/StdoutContext.d.ts +15 -0
- package/vendor/ink/build/components/StdoutContext.js +13 -0
- package/vendor/ink/build/components/StdoutContext.js.map +1 -0
- package/vendor/ink/build/components/Text.d.ts +55 -0
- package/vendor/ink/build/components/Text.js +50 -0
- package/vendor/ink/build/components/Text.js.map +1 -0
- package/vendor/ink/build/components/Transform.d.ts +16 -0
- package/vendor/ink/build/components/Transform.js +15 -0
- package/vendor/ink/build/components/Transform.js.map +1 -0
- package/vendor/ink/build/cursor-helpers.d.ts +38 -0
- package/vendor/ink/build/cursor-helpers.js +56 -0
- package/vendor/ink/build/cursor-helpers.js.map +1 -0
- package/vendor/ink/build/devtools-window-polyfill.d.ts +1 -0
- package/vendor/ink/build/devtools-window-polyfill.js +65 -0
- package/vendor/ink/build/devtools-window-polyfill.js.map +1 -0
- package/vendor/ink/build/devtools.d.ts +1 -0
- package/vendor/ink/build/devtools.js +11 -0
- package/vendor/ink/build/devtools.js.map +1 -0
- package/vendor/ink/build/dom.d.ts +56 -0
- package/vendor/ink/build/dom.js +124 -0
- package/vendor/ink/build/dom.js.map +1 -0
- package/vendor/ink/build/experimental/apply-style.js +140 -0
- package/vendor/ink/build/experimental/dom.js +123 -0
- package/vendor/ink/build/experimental/output.js +91 -0
- package/vendor/ink/build/experimental/reconciler.js +141 -0
- package/vendor/ink/build/experimental/renderer.js +81 -0
- package/vendor/ink/build/get-max-width.d.ts +3 -0
- package/vendor/ink/build/get-max-width.js +10 -0
- package/vendor/ink/build/get-max-width.js.map +1 -0
- package/vendor/ink/build/hooks/use-app.d.ts +5 -0
- package/vendor/ink/build/hooks/use-app.js +8 -0
- package/vendor/ink/build/hooks/use-app.js.map +1 -0
- package/vendor/ink/build/hooks/use-cursor.d.ts +12 -0
- package/vendor/ink/build/hooks/use-cursor.js +29 -0
- package/vendor/ink/build/hooks/use-cursor.js.map +1 -0
- package/vendor/ink/build/hooks/use-focus-manager.d.ts +28 -0
- package/vendor/ink/build/hooks/use-focus-manager.js +17 -0
- package/vendor/ink/build/hooks/use-focus-manager.js.map +1 -0
- package/vendor/ink/build/hooks/use-focus.d.ts +29 -0
- package/vendor/ink/build/hooks/use-focus.js +42 -0
- package/vendor/ink/build/hooks/use-focus.js.map +1 -0
- package/vendor/ink/build/hooks/use-input.d.ts +131 -0
- package/vendor/ink/build/hooks/use-input.js +124 -0
- package/vendor/ink/build/hooks/use-input.js.map +1 -0
- package/vendor/ink/build/hooks/use-is-screen-reader-enabled.d.ts +5 -0
- package/vendor/ink/build/hooks/use-is-screen-reader-enabled.js +11 -0
- package/vendor/ink/build/hooks/use-is-screen-reader-enabled.js.map +1 -0
- package/vendor/ink/build/hooks/use-stderr.d.ts +5 -0
- package/vendor/ink/build/hooks/use-stderr.js +8 -0
- package/vendor/ink/build/hooks/use-stderr.js.map +1 -0
- package/vendor/ink/build/hooks/use-stdin.d.ts +5 -0
- package/vendor/ink/build/hooks/use-stdin.js +8 -0
- package/vendor/ink/build/hooks/use-stdin.js.map +1 -0
- package/vendor/ink/build/hooks/use-stdout.d.ts +5 -0
- package/vendor/ink/build/hooks/use-stdout.js +8 -0
- package/vendor/ink/build/hooks/use-stdout.js.map +1 -0
- package/vendor/ink/build/hooks/useInput.js +38 -0
- package/vendor/ink/build/index.d.ts +34 -0
- package/vendor/ink/build/index.js +20 -0
- package/vendor/ink/build/index.js.map +1 -0
- package/vendor/ink/build/ink.d.ts +90 -0
- package/vendor/ink/build/ink.js +654 -0
- package/vendor/ink/build/ink.js.map +1 -0
- package/vendor/ink/build/input-parser.d.ts +7 -0
- package/vendor/ink/build/input-parser.js +154 -0
- package/vendor/ink/build/input-parser.js.map +1 -0
- package/vendor/ink/build/instance.js +205 -0
- package/vendor/ink/build/instances.d.ts +3 -0
- package/vendor/ink/build/instances.js +8 -0
- package/vendor/ink/build/instances.js.map +1 -0
- package/vendor/ink/build/kitty-keyboard.d.ts +23 -0
- package/vendor/ink/build/kitty-keyboard.js +32 -0
- package/vendor/ink/build/kitty-keyboard.js.map +1 -0
- package/vendor/ink/build/layout.d.ts +7 -0
- package/vendor/ink/build/layout.js +33 -0
- package/vendor/ink/build/layout.js.map +1 -0
- package/vendor/ink/build/log-update.d.ts +19 -0
- package/vendor/ink/build/log-update.js +243 -0
- package/vendor/ink/build/log-update.js.map +1 -0
- package/vendor/ink/build/measure-element.d.ts +16 -0
- package/vendor/ink/build/measure-element.js +9 -0
- package/vendor/ink/build/measure-element.js.map +1 -0
- package/vendor/ink/build/measure-text.d.ts +6 -0
- package/vendor/ink/build/measure-text.js +21 -0
- package/vendor/ink/build/measure-text.js.map +1 -0
- package/vendor/ink/build/options.d.ts +52 -0
- package/vendor/ink/build/options.js +2 -0
- package/vendor/ink/build/options.js.map +1 -0
- package/vendor/ink/build/output.d.ts +35 -0
- package/vendor/ink/build/output.js +183 -0
- package/vendor/ink/build/output.js.map +1 -0
- package/vendor/ink/build/parse-keypress.d.ts +22 -0
- package/vendor/ink/build/parse-keypress.js +493 -0
- package/vendor/ink/build/parse-keypress.js.map +1 -0
- package/vendor/ink/build/reconciler.d.ts +4 -0
- package/vendor/ink/build/reconciler.js +274 -0
- package/vendor/ink/build/reconciler.js.map +1 -0
- package/vendor/ink/build/render-background.d.ts +4 -0
- package/vendor/ink/build/render-background.js +25 -0
- package/vendor/ink/build/render-background.js.map +1 -0
- package/vendor/ink/build/render-border.d.ts +4 -0
- package/vendor/ink/build/render-border.js +73 -0
- package/vendor/ink/build/render-border.js.map +1 -0
- package/vendor/ink/build/render-node-to-output.d.ts +14 -0
- package/vendor/ink/build/render-node-to-output.js +147 -0
- package/vendor/ink/build/render-node-to-output.js.map +1 -0
- package/vendor/ink/build/render-to-string.d.ts +38 -0
- package/vendor/ink/build/render-to-string.js +115 -0
- package/vendor/ink/build/render-to-string.js.map +1 -0
- package/vendor/ink/build/render.d.ts +121 -0
- package/vendor/ink/build/render.js +55 -0
- package/vendor/ink/build/render.js.map +1 -0
- package/vendor/ink/build/renderer.d.ts +8 -0
- package/vendor/ink/build/renderer.js +55 -0
- package/vendor/ink/build/renderer.js.map +1 -0
- package/vendor/ink/build/sanitize-ansi.d.ts +2 -0
- package/vendor/ink/build/sanitize-ansi.js +27 -0
- package/vendor/ink/build/sanitize-ansi.js.map +1 -0
- package/vendor/ink/build/screen-reader-update.d.ts +13 -0
- package/vendor/ink/build/screen-reader-update.js +38 -0
- package/vendor/ink/build/screen-reader-update.js.map +1 -0
- package/vendor/ink/build/squash-text-nodes.d.ts +3 -0
- package/vendor/ink/build/squash-text-nodes.js +36 -0
- package/vendor/ink/build/squash-text-nodes.js.map +1 -0
- package/vendor/ink/build/styles.d.ts +240 -0
- package/vendor/ink/build/styles.js +232 -0
- package/vendor/ink/build/styles.js.map +1 -0
- package/vendor/ink/build/utils.d.ts +2 -0
- package/vendor/ink/build/utils.js +4 -0
- package/vendor/ink/build/utils.js.map +1 -0
- package/vendor/ink/build/wrap-text.d.ts +3 -0
- package/vendor/ink/build/wrap-text.js +31 -0
- package/vendor/ink/build/wrap-text.js.map +1 -0
- package/vendor/ink/build/write-synchronized.d.ts +4 -0
- package/vendor/ink/build/write-synchronized.js +7 -0
- package/vendor/ink/build/write-synchronized.js.map +1 -0
- package/vendor/ink/license +10 -0
- package/vendor/ink/node_modules/@types/node/LICENSE +21 -0
- package/vendor/ink/node_modules/@types/node/README.md +15 -0
- package/vendor/ink/node_modules/@types/node/assert/strict.d.ts +105 -0
- package/vendor/ink/node_modules/@types/node/assert.d.ts +955 -0
- package/vendor/ink/node_modules/@types/node/async_hooks.d.ts +623 -0
- package/vendor/ink/node_modules/@types/node/buffer.buffer.d.ts +466 -0
- package/vendor/ink/node_modules/@types/node/buffer.d.ts +1810 -0
- package/vendor/ink/node_modules/@types/node/child_process.d.ts +1428 -0
- package/vendor/ink/node_modules/@types/node/cluster.d.ts +486 -0
- package/vendor/ink/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- package/vendor/ink/node_modules/@types/node/console.d.ts +151 -0
- package/vendor/ink/node_modules/@types/node/constants.d.ts +20 -0
- package/vendor/ink/node_modules/@types/node/crypto.d.ts +4065 -0
- package/vendor/ink/node_modules/@types/node/dgram.d.ts +564 -0
- package/vendor/ink/node_modules/@types/node/diagnostics_channel.d.ts +576 -0
- package/vendor/ink/node_modules/@types/node/dns/promises.d.ts +503 -0
- package/vendor/ink/node_modules/@types/node/dns.d.ts +922 -0
- package/vendor/ink/node_modules/@types/node/domain.d.ts +166 -0
- package/vendor/ink/node_modules/@types/node/events.d.ts +1054 -0
- package/vendor/ink/node_modules/@types/node/fs/promises.d.ts +1329 -0
- package/vendor/ink/node_modules/@types/node/fs.d.ts +4676 -0
- package/vendor/ink/node_modules/@types/node/globals.d.ts +150 -0
- package/vendor/ink/node_modules/@types/node/globals.typedarray.d.ts +101 -0
- package/vendor/ink/node_modules/@types/node/http.d.ts +2167 -0
- package/vendor/ink/node_modules/@types/node/http2.d.ts +2480 -0
- package/vendor/ink/node_modules/@types/node/https.d.ts +405 -0
- package/vendor/ink/node_modules/@types/node/index.d.ts +115 -0
- package/vendor/ink/node_modules/@types/node/inspector/promises.d.ts +41 -0
- package/vendor/ink/node_modules/@types/node/inspector.d.ts +224 -0
- package/vendor/ink/node_modules/@types/node/inspector.generated.d.ts +4226 -0
- package/vendor/ink/node_modules/@types/node/module.d.ts +819 -0
- package/vendor/ink/node_modules/@types/node/net.d.ts +933 -0
- package/vendor/ink/node_modules/@types/node/os.d.ts +507 -0
- package/vendor/ink/node_modules/@types/node/package.json +155 -0
- package/vendor/ink/node_modules/@types/node/path/posix.d.ts +8 -0
- package/vendor/ink/node_modules/@types/node/path/win32.d.ts +8 -0
- package/vendor/ink/node_modules/@types/node/path.d.ts +187 -0
- package/vendor/ink/node_modules/@types/node/perf_hooks.d.ts +643 -0
- package/vendor/ink/node_modules/@types/node/process.d.ts +2156 -0
- package/vendor/ink/node_modules/@types/node/punycode.d.ts +117 -0
- package/vendor/ink/node_modules/@types/node/querystring.d.ts +152 -0
- package/vendor/ink/node_modules/@types/node/quic.d.ts +910 -0
- package/vendor/ink/node_modules/@types/node/readline/promises.d.ts +161 -0
- package/vendor/ink/node_modules/@types/node/readline.d.ts +541 -0
- package/vendor/ink/node_modules/@types/node/repl.d.ts +415 -0
- package/vendor/ink/node_modules/@types/node/sea.d.ts +162 -0
- package/vendor/ink/node_modules/@types/node/sqlite.d.ts +955 -0
- package/vendor/ink/node_modules/@types/node/stream/consumers.d.ts +38 -0
- package/vendor/ink/node_modules/@types/node/stream/promises.d.ts +211 -0
- package/vendor/ink/node_modules/@types/node/stream/web.d.ts +296 -0
- package/vendor/ink/node_modules/@types/node/stream.d.ts +1760 -0
- package/vendor/ink/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/vendor/ink/node_modules/@types/node/test/reporters.d.ts +96 -0
- package/vendor/ink/node_modules/@types/node/test.d.ts +2240 -0
- package/vendor/ink/node_modules/@types/node/timers/promises.d.ts +108 -0
- package/vendor/ink/node_modules/@types/node/timers.d.ts +159 -0
- package/vendor/ink/node_modules/@types/node/tls.d.ts +1198 -0
- package/vendor/ink/node_modules/@types/node/trace_events.d.ts +197 -0
- package/vendor/ink/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +462 -0
- package/vendor/ink/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
- package/vendor/ink/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
- package/vendor/ink/node_modules/@types/node/ts5.6/index.d.ts +117 -0
- package/vendor/ink/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
- package/vendor/ink/node_modules/@types/node/ts5.7/index.d.ts +117 -0
- package/vendor/ink/node_modules/@types/node/tty.d.ts +250 -0
- package/vendor/ink/node_modules/@types/node/url.d.ts +519 -0
- package/vendor/ink/node_modules/@types/node/util/types.d.ts +558 -0
- package/vendor/ink/node_modules/@types/node/util.d.ts +1662 -0
- package/vendor/ink/node_modules/@types/node/v8.d.ts +983 -0
- package/vendor/ink/node_modules/@types/node/vm.d.ts +1208 -0
- package/vendor/ink/node_modules/@types/node/wasi.d.ts +202 -0
- package/vendor/ink/node_modules/@types/node/web-globals/abortcontroller.d.ts +59 -0
- package/vendor/ink/node_modules/@types/node/web-globals/blob.d.ts +23 -0
- package/vendor/ink/node_modules/@types/node/web-globals/console.d.ts +9 -0
- package/vendor/ink/node_modules/@types/node/web-globals/crypto.d.ts +39 -0
- package/vendor/ink/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
- package/vendor/ink/node_modules/@types/node/web-globals/encoding.d.ts +11 -0
- package/vendor/ink/node_modules/@types/node/web-globals/events.d.ts +106 -0
- package/vendor/ink/node_modules/@types/node/web-globals/fetch.d.ts +69 -0
- package/vendor/ink/node_modules/@types/node/web-globals/importmeta.d.ts +13 -0
- package/vendor/ink/node_modules/@types/node/web-globals/messaging.d.ts +23 -0
- package/vendor/ink/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
- package/vendor/ink/node_modules/@types/node/web-globals/performance.d.ts +45 -0
- package/vendor/ink/node_modules/@types/node/web-globals/storage.d.ts +24 -0
- package/vendor/ink/node_modules/@types/node/web-globals/streams.d.ts +115 -0
- package/vendor/ink/node_modules/@types/node/web-globals/timers.d.ts +44 -0
- package/vendor/ink/node_modules/@types/node/web-globals/url.d.ts +24 -0
- package/vendor/ink/node_modules/@types/node/worker_threads.d.ts +717 -0
- package/vendor/ink/node_modules/@types/node/zlib.d.ts +618 -0
- package/vendor/ink/node_modules/node-pty/LICENSE +69 -0
- package/vendor/ink/node_modules/node-pty/README.md +164 -0
- package/vendor/ink/node_modules/node-pty/binding.gyp +150 -0
- package/vendor/ink/node_modules/node-pty/lib/conpty_console_list_agent.js +25 -0
- package/vendor/ink/node_modules/node-pty/lib/eventEmitter2.js +47 -0
- package/vendor/ink/node_modules/node-pty/lib/index.js +52 -0
- package/vendor/ink/node_modules/node-pty/lib/interfaces.js +7 -0
- package/vendor/ink/node_modules/node-pty/lib/shared/conout.js +11 -0
- package/vendor/ink/node_modules/node-pty/lib/terminal.js +190 -0
- package/vendor/ink/node_modules/node-pty/lib/types.js +7 -0
- package/vendor/ink/node_modules/node-pty/lib/unixTerminal.js +349 -0
- package/vendor/ink/node_modules/node-pty/lib/utils.js +39 -0
- package/vendor/ink/node_modules/node-pty/lib/windowsConoutConnection.js +125 -0
- package/vendor/ink/node_modules/node-pty/lib/windowsPtyAgent.js +287 -0
- package/vendor/ink/node_modules/node-pty/lib/windowsTerminal.js +201 -0
- package/vendor/ink/node_modules/node-pty/lib/worker/conoutSocketWorker.js +22 -0
- package/vendor/ink/node_modules/node-pty/package.json +65 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/darwin-arm64/pty.node +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/darwin-arm64/spawn-helper +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/darwin-x64/pty.node +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/darwin-x64/spawn-helper +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/linux-arm64/pty.node +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/linux-x64/pty.node +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty/OpenConsole.exe +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty/conpty.dll +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty.node +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty.pdb +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty_console_list.node +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty_console_list.pdb +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty/OpenConsole.exe +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty/conpty.dll +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty.node +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty.pdb +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty_console_list.node +0 -0
- package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty_console_list.pdb +0 -0
- package/vendor/ink/node_modules/node-pty/scripts/post-install.js +76 -0
- package/vendor/ink/node_modules/node-pty/scripts/prebuild.js +34 -0
- package/vendor/ink/node_modules/node-pty/src/unix/pty.cc +875 -0
- package/vendor/ink/node_modules/node-pty/src/unix/spawn-helper.cc +23 -0
- package/vendor/ink/node_modules/node-pty/src/win/conpty.cc +582 -0
- package/vendor/ink/node_modules/node-pty/src/win/conpty.h +41 -0
- package/vendor/ink/node_modules/node-pty/src/win/conpty_console_list.cc +44 -0
- package/vendor/ink/node_modules/node-pty/src/win/path_util.cc +95 -0
- package/vendor/ink/node_modules/node-pty/src/win/path_util.h +26 -0
- package/vendor/ink/node_modules/node-pty/third_party/conpty/1.23.251008001/win10-arm64/OpenConsole.exe +0 -0
- package/vendor/ink/node_modules/node-pty/third_party/conpty/1.23.251008001/win10-arm64/conpty.dll +0 -0
- package/vendor/ink/node_modules/node-pty/third_party/conpty/1.23.251008001/win10-x64/OpenConsole.exe +0 -0
- package/vendor/ink/node_modules/node-pty/third_party/conpty/1.23.251008001/win10-x64/conpty.dll +0 -0
- package/vendor/ink/node_modules/node-pty/typings/node-pty.d.ts +215 -0
- package/vendor/ink/node_modules/undici-types/LICENSE +21 -0
- package/vendor/ink/node_modules/undici-types/README.md +6 -0
- package/vendor/ink/node_modules/undici-types/agent.d.ts +32 -0
- package/vendor/ink/node_modules/undici-types/api.d.ts +43 -0
- package/vendor/ink/node_modules/undici-types/balanced-pool.d.ts +30 -0
- package/vendor/ink/node_modules/undici-types/cache-interceptor.d.ts +173 -0
- package/vendor/ink/node_modules/undici-types/cache.d.ts +36 -0
- package/vendor/ink/node_modules/undici-types/client-stats.d.ts +15 -0
- package/vendor/ink/node_modules/undici-types/client.d.ts +108 -0
- package/vendor/ink/node_modules/undici-types/connector.d.ts +34 -0
- package/vendor/ink/node_modules/undici-types/content-type.d.ts +21 -0
- package/vendor/ink/node_modules/undici-types/cookies.d.ts +30 -0
- package/vendor/ink/node_modules/undici-types/diagnostics-channel.d.ts +74 -0
- package/vendor/ink/node_modules/undici-types/dispatcher.d.ts +276 -0
- package/vendor/ink/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
- package/vendor/ink/node_modules/undici-types/errors.d.ts +161 -0
- package/vendor/ink/node_modules/undici-types/eventsource.d.ts +66 -0
- package/vendor/ink/node_modules/undici-types/fetch.d.ts +211 -0
- package/vendor/ink/node_modules/undici-types/formdata.d.ts +108 -0
- package/vendor/ink/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/vendor/ink/node_modules/undici-types/global-origin.d.ts +7 -0
- package/vendor/ink/node_modules/undici-types/h2c-client.d.ts +73 -0
- package/vendor/ink/node_modules/undici-types/handlers.d.ts +15 -0
- package/vendor/ink/node_modules/undici-types/header.d.ts +160 -0
- package/vendor/ink/node_modules/undici-types/index.d.ts +88 -0
- package/vendor/ink/node_modules/undici-types/interceptors.d.ts +73 -0
- package/vendor/ink/node_modules/undici-types/mock-agent.d.ts +68 -0
- package/vendor/ink/node_modules/undici-types/mock-call-history.d.ts +111 -0
- package/vendor/ink/node_modules/undici-types/mock-client.d.ts +27 -0
- package/vendor/ink/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/vendor/ink/node_modules/undici-types/mock-interceptor.d.ts +94 -0
- package/vendor/ink/node_modules/undici-types/mock-pool.d.ts +27 -0
- package/vendor/ink/node_modules/undici-types/package.json +55 -0
- package/vendor/ink/node_modules/undici-types/patch.d.ts +29 -0
- package/vendor/ink/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/vendor/ink/node_modules/undici-types/pool.d.ts +41 -0
- package/vendor/ink/node_modules/undici-types/proxy-agent.d.ts +29 -0
- package/vendor/ink/node_modules/undici-types/readable.d.ts +68 -0
- package/vendor/ink/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/vendor/ink/node_modules/undici-types/retry-handler.d.ts +125 -0
- package/vendor/ink/node_modules/undici-types/round-robin-pool.d.ts +41 -0
- package/vendor/ink/node_modules/undici-types/snapshot-agent.d.ts +109 -0
- package/vendor/ink/node_modules/undici-types/util.d.ts +18 -0
- package/vendor/ink/node_modules/undici-types/utility.d.ts +7 -0
- package/vendor/ink/node_modules/undici-types/webidl.d.ts +341 -0
- package/vendor/ink/node_modules/undici-types/websocket.d.ts +186 -0
- package/vendor/ink/package.json +201 -0
- package/vendor/ink/readme.md +2636 -0
- package/bin/swag-agent.js +0 -9
- package/dist/server/lib/pg-rate-limiter.d.ts +0 -21
- package/dist/server/lib/pg-rate-limiter.js +0 -86
|
@@ -0,0 +1,2636 @@
|
|
|
1
|
+
[](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
<br>
|
|
7
|
+
<br>
|
|
8
|
+
<img width="240" alt="Ink" src="media/logo.png">
|
|
9
|
+
<br>
|
|
10
|
+
<br>
|
|
11
|
+
<br>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
> React for CLIs. Build and test your CLI output using components.
|
|
15
|
+
|
|
16
|
+
[](https://github.com/vadimdemedes/ink/actions)
|
|
17
|
+
[](https://npmjs.com/package/ink)
|
|
18
|
+
|
|
19
|
+
Ink provides the same component-based UI building experience that React offers in the browser, but for command-line apps.
|
|
20
|
+
It uses [Yoga](https://github.com/facebook/yoga) to build Flexbox layouts in the terminal, so most CSS-like properties are available in Ink as well.
|
|
21
|
+
If you are already familiar with React, you already know Ink.
|
|
22
|
+
|
|
23
|
+
Since Ink is a React renderer, all features of React are supported.
|
|
24
|
+
Head over to the [React](https://reactjs.org) website for documentation on how to use it.
|
|
25
|
+
Only Ink's methods are documented in this readme.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
<div align="center">
|
|
30
|
+
<p>
|
|
31
|
+
<p>
|
|
32
|
+
<sup>
|
|
33
|
+
<a href="https://opencollective.com/vadimdemedes">My open source work is supported by the community ❤️</a>
|
|
34
|
+
</sup>
|
|
35
|
+
</p>
|
|
36
|
+
</p>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
npm install ink react
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
```jsx
|
|
48
|
+
import React, {useState, useEffect} from 'react';
|
|
49
|
+
import {render, Text} from 'ink';
|
|
50
|
+
|
|
51
|
+
const Counter = () => {
|
|
52
|
+
const [counter, setCounter] = useState(0);
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const timer = setInterval(() => {
|
|
56
|
+
setCounter(previousCounter => previousCounter + 1);
|
|
57
|
+
}, 100);
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
clearInterval(timer);
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
return <Text color="green">{counter} tests passed</Text>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
render(<Counter />);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
<img src="media/demo.svg" width="600">
|
|
71
|
+
|
|
72
|
+
## Who's Using Ink?
|
|
73
|
+
|
|
74
|
+
- [Claude Code](https://github.com/anthropics/claude-code) - An agentic coding tool made by Anthropic.
|
|
75
|
+
- [Gemini CLI](https://github.com/google-gemini/gemini-cli) - An agentic coding tool made by Google.
|
|
76
|
+
- [GitHub Copilot CLI](https://github.com/features/copilot/cli) - Just say what you want the shell to do.
|
|
77
|
+
- [Canva CLI](https://www.canva.dev/docs/apps/canva-cli/) - CLI for creating and managing Canva Apps.
|
|
78
|
+
- [Cloudflare's Wrangler](https://github.com/cloudflare/wrangler2) - The CLI for Cloudflare Workers.
|
|
79
|
+
- [Linear](https://linear.app) - Linear built an internal CLI for managing deployments, configs, and other housekeeping tasks.
|
|
80
|
+
- [Gatsby](https://www.gatsbyjs.org) - Gatsby is a modern web framework for blazing-fast websites.
|
|
81
|
+
- [tap](https://node-tap.org) - A Test-Anything-Protocol library for JavaScript.
|
|
82
|
+
- [Terraform CDK](https://github.com/hashicorp/terraform-cdk) - Cloud Development Kit (CDK) for HashiCorp Terraform.
|
|
83
|
+
- [Specify CLI](https://specifyapp.com) - Automate the distribution of your design tokens.
|
|
84
|
+
- [Twilio's SIGNAL](https://github.com/twilio-labs/plugin-signal2020) - CLI for Twilio's SIGNAL conference. [Blog post](https://www.twilio.com/blog/building-conference-cli-in-react).
|
|
85
|
+
- [Typewriter](https://github.com/segmentio/typewriter) - Generates strongly-typed [Segment](https://segment.com) analytics clients from arbitrary JSON Schema.
|
|
86
|
+
- [Prisma](https://www.prisma.io) - The unified data layer for modern applications.
|
|
87
|
+
- [Blitz](https://blitzjs.com) - The Fullstack React Framework.
|
|
88
|
+
- [New York Times](https://github.com/nytimes/kyt) - NYT uses Ink's `kyt` - a toolkit that encapsulates and manages the configuration for web apps.
|
|
89
|
+
- [tink](https://github.com/npm/tink) - A next-generation runtime and package manager.
|
|
90
|
+
- [Inkle](https://github.com/jrr/inkle) - A Wordle game.
|
|
91
|
+
- [loki](https://github.com/oblador/loki) - Visual regression testing tool for Storybook.
|
|
92
|
+
- [Bit](https://github.com/teambit/bit) - Build, distribute, and collaborate on components.
|
|
93
|
+
- [Remirror](https://github.com/remirror/remirror) - Your friendly, world-class editor toolkit.
|
|
94
|
+
- [Prime](https://github.com/birkir/prime) - Open-source GraphQL CMS.
|
|
95
|
+
- [emoj](https://github.com/sindresorhus/emoj) - Find relevant emojis.
|
|
96
|
+
- [emma](https://github.com/maticzav/emma-cli) - Find and install npm packages easily.
|
|
97
|
+
- [npm-check-extras](https://github.com/akgondber/npm-check-extras) - Check for outdated and unused dependencies, and run update/delete actions on selected ones.
|
|
98
|
+
- [swiff](https://github.com/simple-integrated-marketing/swiff) - Multi-environment command-line tools for time-saving web developers.
|
|
99
|
+
- [share](https://github.com/marionebl/share-cli) - Share files quickly.
|
|
100
|
+
- [Kubelive](https://github.com/ameerthehacker/kubelive) - A CLI for Kubernetes that provides live data about the cluster and its resources.
|
|
101
|
+
- [changelog-view](https://github.com/jdeniau/changelog-view) - View changelogs.
|
|
102
|
+
- [cfpush](https://github.com/mamachanko/cfpush) - Interactive Cloud Foundry tutorial.
|
|
103
|
+
- [startd](https://github.com/mgrip/startd) - Turn your React component into a web app.
|
|
104
|
+
- [wiki-cli](https://github.com/hexrcs/wiki-cli) - Search Wikipedia and read article summaries.
|
|
105
|
+
- [garson](https://github.com/goliney/garson) - Build interactive, config-based command-line interfaces.
|
|
106
|
+
- [git-contrib-calendar](https://github.com/giannisp/git-contrib-calendar) - Display a contributions calendar for any Git repository.
|
|
107
|
+
- [gitgud](https://github.com/GitGud-org/GitGud) - Interactive command-line GUI for Git.
|
|
108
|
+
- [Autarky](https://github.com/pranshuchittora/autarky) - Find and delete old `node_modules` directories to free up disk space.
|
|
109
|
+
- [fast-cli](https://github.com/sindresorhus/fast-cli) - Test your download and upload speeds.
|
|
110
|
+
- [tasuku](https://github.com/privatenumber/tasuku) - Minimal task runner.
|
|
111
|
+
- [mnswpr](https://github.com/mordv/mnswpr) - A Minesweeper game.
|
|
112
|
+
- [lrn](https://github.com/krychu/lrn) - Learning by repetition.
|
|
113
|
+
- [turdle](https://github.com/mynameisankit/turdle) - A Wordle game.
|
|
114
|
+
- [Shopify CLI](https://github.com/Shopify/cli) - Build apps, themes, and storefronts for the Shopify platform.
|
|
115
|
+
- [ToDesktop CLI](https://www.todesktop.com/electron) - All-in-one platform for building Electron apps.
|
|
116
|
+
- [Walle](https://github.com/Pobepto/walle) - A full-featured crypto wallet for EVM networks.
|
|
117
|
+
- [Sudoku](https://github.com/mrozio13pl/sudoku-in-terminal) - A Sudoku game.
|
|
118
|
+
- [Sea Trader](https://github.com/zyishai/sea-trader) - A Taipan!-inspired trading simulator game.
|
|
119
|
+
- [srtd](https://github.com/t1mmen/srtd) - Live-reloading SQL templates for Supabase projects.
|
|
120
|
+
- [tweakcc](https://github.com/Piebald-AI/tweakcc) - Customize your Claude Code styling.
|
|
121
|
+
- [argonaut](https://github.com/darksworm/argonaut) - Manage Argo CD resources.
|
|
122
|
+
- [Qodo Command](https://github.com/qodo-ai/command) - Build, run, and manage AI agents.
|
|
123
|
+
- [Nanocoder](https://github.com/nano-collective/nanocoder) - A community-built, local-first AI coding agent with multi-provider support.
|
|
124
|
+
- [dev3000](https://github.com/vercel-labs/dev3000) - An AI agent MCP orchestrator and developer browser.
|
|
125
|
+
- [Neovate Code](https://github.com/neovateai/neovate-code) - An agentic coding tool made by AntGroup.
|
|
126
|
+
- [instagram-cli](https://github.com/supreme-gg-gg/instagram-cli) - Instagram client.
|
|
127
|
+
- [ElevenLabs CLI](https://github.com/elevenlabs/cli) - ElevenLabs agents client.
|
|
128
|
+
- [SSH AI Chat](https://github.com/miantiao-me/ssh-ai-chat) - Chat with AI over SSH.
|
|
129
|
+
|
|
130
|
+
*(PRs welcome. Append new entries at the end. Repos must have 100+ stars and showcase Ink beyond a basic list picker.)*
|
|
131
|
+
|
|
132
|
+
## Contents
|
|
133
|
+
|
|
134
|
+
- [Getting Started](#getting-started)
|
|
135
|
+
- [App Lifecycle](#app-lifecycle)
|
|
136
|
+
- [Components](#components)
|
|
137
|
+
- [`<Text>`](#text)
|
|
138
|
+
- [`<Box>`](#box)
|
|
139
|
+
- [`<Newline>`](#newline)
|
|
140
|
+
- [`<Spacer>`](#spacer)
|
|
141
|
+
- [`<Static>`](#static)
|
|
142
|
+
- [`<Transform>`](#transform)
|
|
143
|
+
- [Hooks](#hooks)
|
|
144
|
+
- [`useInput`](#useinputinputhandler-options)
|
|
145
|
+
- [`useApp`](#useapp)
|
|
146
|
+
- [`useStdin`](#usestdin)
|
|
147
|
+
- [`useStdout`](#usestdout)
|
|
148
|
+
- [`useStderr`](#usestderr)
|
|
149
|
+
- [`useFocus`](#usefocusoptions)
|
|
150
|
+
- [`useFocusManager`](#usefocusmanager)
|
|
151
|
+
- [`useCursor`](#usecursor)
|
|
152
|
+
- [API](#api)
|
|
153
|
+
- [Testing](#testing)
|
|
154
|
+
- [Using React Devtools](#using-react-devtools)
|
|
155
|
+
- [Screen Reader Support](#screen-reader-support)
|
|
156
|
+
- [Useful Components](#useful-components)
|
|
157
|
+
- [Useful Hooks](#useful-hooks)
|
|
158
|
+
- [Recipes](#recipes)
|
|
159
|
+
- [Examples](#examples)
|
|
160
|
+
- [Continuous Integration](#continuous-integration)
|
|
161
|
+
|
|
162
|
+
## Getting Started
|
|
163
|
+
|
|
164
|
+
Use [create-ink-app](https://github.com/vadimdemedes/create-ink-app) to quickly scaffold a new Ink-based CLI.
|
|
165
|
+
|
|
166
|
+
```sh
|
|
167
|
+
npx create-ink-app my-ink-cli
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Alternatively, create a TypeScript project:
|
|
171
|
+
|
|
172
|
+
```sh
|
|
173
|
+
npx create-ink-app --typescript my-ink-cli
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
<details><summary>Manual JavaScript setup</summary>
|
|
177
|
+
<p>
|
|
178
|
+
Ink requires the same Babel setup as you would do for regular React-based apps in the browser.
|
|
179
|
+
|
|
180
|
+
Set up Babel with a React preset to ensure all examples in this readme work as expected.
|
|
181
|
+
After [installing Babel](https://babeljs.io/docs/en/usage), install `@babel/preset-react` and insert the following configuration in `babel.config.json`:
|
|
182
|
+
|
|
183
|
+
```sh
|
|
184
|
+
npm install --save-dev @babel/preset-react
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
```json
|
|
188
|
+
{
|
|
189
|
+
"presets": ["@babel/preset-react"]
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Next, create a file `source.js`, where you'll type code that uses Ink:
|
|
194
|
+
|
|
195
|
+
```jsx
|
|
196
|
+
import React from 'react';
|
|
197
|
+
import {render, Text} from 'ink';
|
|
198
|
+
|
|
199
|
+
const Demo = () => <Text>Hello World</Text>;
|
|
200
|
+
|
|
201
|
+
render(<Demo />);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Then, transpile this file with Babel:
|
|
205
|
+
|
|
206
|
+
```sh
|
|
207
|
+
npx babel source.js -o cli.js
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Now you can run `cli.js` with Node.js:
|
|
211
|
+
|
|
212
|
+
```sh
|
|
213
|
+
node cli
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
If you don't like transpiling files during development, you can use [import-jsx](https://github.com/vadimdemedes/import-jsx) or [@esbuild-kit/esm-loader](https://github.com/esbuild-kit/esm-loader) to `import` a JSX file and transpile it on the fly.
|
|
217
|
+
|
|
218
|
+
</p>
|
|
219
|
+
</details>
|
|
220
|
+
|
|
221
|
+
Ink uses [Yoga](https://github.com/facebook/yoga), a Flexbox layout engine, to build great user interfaces for your CLIs using familiar CSS-like properties you've used when building apps for the browser.
|
|
222
|
+
It's important to remember that each element is a Flexbox container.
|
|
223
|
+
Think of it as if every `<div>` in the browser had `display: flex`.
|
|
224
|
+
See [`<Box>`](#box) built-in component below for documentation on how to use Flexbox layouts in Ink.
|
|
225
|
+
Note that all text must be wrapped in a [`<Text>`](#text) component.
|
|
226
|
+
|
|
227
|
+
## App Lifecycle
|
|
228
|
+
|
|
229
|
+
An Ink app is a Node.js process, so it stays alive only while there is active work in the event loop (timers, pending promises, [`useInput`](#useinputinputhandler-options) listening on `stdin`, etc.). If your component tree has no async work, the app will render once and exit immediately.
|
|
230
|
+
|
|
231
|
+
To exit the app, press **Ctrl+C** (enabled by default via [`exitOnCtrlC`](#exitonctrlc)), call [`exit()`](#exiterrororresult) from [`useApp`](#useapp) inside a component, or call [`unmount()`](#unmount) on the object returned by [`render()`](#rendertree-options).
|
|
232
|
+
|
|
233
|
+
Use [`waitUntilExit()`](#waituntilexit) to run code after the app is unmounted:
|
|
234
|
+
|
|
235
|
+
```jsx
|
|
236
|
+
const {waitUntilExit} = render(<MyApp />);
|
|
237
|
+
|
|
238
|
+
await waitUntilExit();
|
|
239
|
+
|
|
240
|
+
console.log('App exited');
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Components
|
|
244
|
+
|
|
245
|
+
### `<Text>`
|
|
246
|
+
|
|
247
|
+
This component can display text and change its style to make it bold, underlined, italic, or strikethrough.
|
|
248
|
+
|
|
249
|
+
```jsx
|
|
250
|
+
import {render, Text} from 'ink';
|
|
251
|
+
|
|
252
|
+
const Example = () => (
|
|
253
|
+
<>
|
|
254
|
+
<Text color="green">I am green</Text>
|
|
255
|
+
<Text color="black" backgroundColor="white">
|
|
256
|
+
I am black on white
|
|
257
|
+
</Text>
|
|
258
|
+
<Text color="#ffffff">I am white</Text>
|
|
259
|
+
<Text bold>I am bold</Text>
|
|
260
|
+
<Text italic>I am italic</Text>
|
|
261
|
+
<Text underline>I am underline</Text>
|
|
262
|
+
<Text strikethrough>I am strikethrough</Text>
|
|
263
|
+
<Text inverse>I am inversed</Text>
|
|
264
|
+
</>
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
render(<Example />);
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Note:** `<Text>` allows only text nodes and nested `<Text>` components inside of it. For example, `<Box>` component can't be used inside `<Text>`.
|
|
271
|
+
|
|
272
|
+
#### color
|
|
273
|
+
|
|
274
|
+
Type: `string`
|
|
275
|
+
|
|
276
|
+
Change text color.
|
|
277
|
+
Ink uses [chalk](https://github.com/chalk/chalk) under the hood, so all its functionality is supported.
|
|
278
|
+
|
|
279
|
+
```jsx
|
|
280
|
+
<Text color="green">Green</Text>
|
|
281
|
+
<Text color="#005cc5">Blue</Text>
|
|
282
|
+
<Text color="rgb(232, 131, 136)">Red</Text>
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
<img src="media/text-color.jpg" width="247">
|
|
286
|
+
|
|
287
|
+
#### backgroundColor
|
|
288
|
+
|
|
289
|
+
Type: `string`
|
|
290
|
+
|
|
291
|
+
Same as `color` above, but for background.
|
|
292
|
+
|
|
293
|
+
```jsx
|
|
294
|
+
<Text backgroundColor="green" color="white">Green</Text>
|
|
295
|
+
<Text backgroundColor="#005cc5" color="white">Blue</Text>
|
|
296
|
+
<Text backgroundColor="rgb(232, 131, 136)" color="white">Red</Text>
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
<img src="media/text-backgroundColor.jpg" width="226">
|
|
300
|
+
|
|
301
|
+
#### dimColor
|
|
302
|
+
|
|
303
|
+
Type: `boolean`\
|
|
304
|
+
Default: `false`
|
|
305
|
+
|
|
306
|
+
Dim the color (make it less bright).
|
|
307
|
+
|
|
308
|
+
```jsx
|
|
309
|
+
<Text color="red" dimColor>
|
|
310
|
+
Dimmed Red
|
|
311
|
+
</Text>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
<img src="media/text-dimColor.jpg" width="138">
|
|
315
|
+
|
|
316
|
+
#### bold
|
|
317
|
+
|
|
318
|
+
Type: `boolean`\
|
|
319
|
+
Default: `false`
|
|
320
|
+
|
|
321
|
+
Make the text bold.
|
|
322
|
+
|
|
323
|
+
#### italic
|
|
324
|
+
|
|
325
|
+
Type: `boolean`\
|
|
326
|
+
Default: `false`
|
|
327
|
+
|
|
328
|
+
Make the text italic.
|
|
329
|
+
|
|
330
|
+
#### underline
|
|
331
|
+
|
|
332
|
+
Type: `boolean`\
|
|
333
|
+
Default: `false`
|
|
334
|
+
|
|
335
|
+
Make the text underlined.
|
|
336
|
+
|
|
337
|
+
#### strikethrough
|
|
338
|
+
|
|
339
|
+
Type: `boolean`\
|
|
340
|
+
Default: `false`
|
|
341
|
+
|
|
342
|
+
Make the text crossed with a line.
|
|
343
|
+
|
|
344
|
+
#### inverse
|
|
345
|
+
|
|
346
|
+
Type: `boolean`\
|
|
347
|
+
Default: `false`
|
|
348
|
+
|
|
349
|
+
Invert background and foreground colors.
|
|
350
|
+
|
|
351
|
+
```jsx
|
|
352
|
+
<Text inverse color="yellow">
|
|
353
|
+
Inversed Yellow
|
|
354
|
+
</Text>
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
<img src="media/text-inverse.jpg" width="138">
|
|
358
|
+
|
|
359
|
+
#### wrap
|
|
360
|
+
|
|
361
|
+
Type: `string`\
|
|
362
|
+
Allowed values: `wrap` `truncate` `truncate-start` `truncate-middle` `truncate-end`\
|
|
363
|
+
Default: `wrap`
|
|
364
|
+
|
|
365
|
+
This property tells Ink to wrap or truncate text if its width is larger than the container.
|
|
366
|
+
If `wrap` is passed (the default), Ink will wrap text and split it into multiple lines.
|
|
367
|
+
If `truncate-*` is passed, Ink will truncate text instead, resulting in one line of text with the rest cut off.
|
|
368
|
+
|
|
369
|
+
```jsx
|
|
370
|
+
<Box width={7}>
|
|
371
|
+
<Text>Hello World</Text>
|
|
372
|
+
</Box>
|
|
373
|
+
//=> 'Hello\nWorld'
|
|
374
|
+
|
|
375
|
+
// `truncate` is an alias to `truncate-end`
|
|
376
|
+
<Box width={7}>
|
|
377
|
+
<Text wrap="truncate">Hello World</Text>
|
|
378
|
+
</Box>
|
|
379
|
+
//=> 'Hello…'
|
|
380
|
+
|
|
381
|
+
<Box width={7}>
|
|
382
|
+
<Text wrap="truncate-middle">Hello World</Text>
|
|
383
|
+
</Box>
|
|
384
|
+
//=> 'He…ld'
|
|
385
|
+
|
|
386
|
+
<Box width={7}>
|
|
387
|
+
<Text wrap="truncate-start">Hello World</Text>
|
|
388
|
+
</Box>
|
|
389
|
+
//=> '…World'
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### `<Box>`
|
|
393
|
+
|
|
394
|
+
`<Box>` is an essential Ink component to build your layout.
|
|
395
|
+
It's like `<div style="display: flex">` in the browser.
|
|
396
|
+
|
|
397
|
+
```jsx
|
|
398
|
+
import {render, Box, Text} from 'ink';
|
|
399
|
+
|
|
400
|
+
const Example = () => (
|
|
401
|
+
<Box margin={2}>
|
|
402
|
+
<Text>This is a box with margin</Text>
|
|
403
|
+
</Box>
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
render(<Example />);
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
#### Dimensions
|
|
410
|
+
|
|
411
|
+
##### width
|
|
412
|
+
|
|
413
|
+
Type: `number` `string`
|
|
414
|
+
|
|
415
|
+
Width of the element in spaces.
|
|
416
|
+
You can also set it as a percentage, which will calculate the width based on the width of the parent element.
|
|
417
|
+
|
|
418
|
+
```jsx
|
|
419
|
+
<Box width={4}>
|
|
420
|
+
<Text>X</Text>
|
|
421
|
+
</Box>
|
|
422
|
+
//=> 'X '
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
```jsx
|
|
426
|
+
<Box width={10}>
|
|
427
|
+
<Box width="50%">
|
|
428
|
+
<Text>X</Text>
|
|
429
|
+
</Box>
|
|
430
|
+
<Text>Y</Text>
|
|
431
|
+
</Box>
|
|
432
|
+
//=> 'X Y'
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
##### height
|
|
436
|
+
|
|
437
|
+
Type: `number` `string`
|
|
438
|
+
|
|
439
|
+
Height of the element in lines (rows).
|
|
440
|
+
You can also set it as a percentage, which will calculate the height based on the height of the parent element.
|
|
441
|
+
|
|
442
|
+
```jsx
|
|
443
|
+
<Box height={4}>
|
|
444
|
+
<Text>X</Text>
|
|
445
|
+
</Box>
|
|
446
|
+
//=> 'X\n\n\n'
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
```jsx
|
|
450
|
+
<Box height={6} flexDirection="column">
|
|
451
|
+
<Box height="50%">
|
|
452
|
+
<Text>X</Text>
|
|
453
|
+
</Box>
|
|
454
|
+
<Text>Y</Text>
|
|
455
|
+
</Box>
|
|
456
|
+
//=> 'X\n\n\nY\n\n'
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
##### minWidth
|
|
460
|
+
|
|
461
|
+
Type: `number`
|
|
462
|
+
|
|
463
|
+
Sets a minimum width of the element.
|
|
464
|
+
Percentages aren't supported yet; see https://github.com/facebook/yoga/issues/872.
|
|
465
|
+
|
|
466
|
+
##### minHeight
|
|
467
|
+
|
|
468
|
+
Type: `number`
|
|
469
|
+
|
|
470
|
+
Sets a minimum height of the element.
|
|
471
|
+
Percentages aren't supported yet; see https://github.com/facebook/yoga/issues/872.
|
|
472
|
+
|
|
473
|
+
#### Padding
|
|
474
|
+
|
|
475
|
+
##### paddingTop
|
|
476
|
+
|
|
477
|
+
Type: `number`\
|
|
478
|
+
Default: `0`
|
|
479
|
+
|
|
480
|
+
Top padding.
|
|
481
|
+
|
|
482
|
+
##### paddingBottom
|
|
483
|
+
|
|
484
|
+
Type: `number`\
|
|
485
|
+
Default: `0`
|
|
486
|
+
|
|
487
|
+
Bottom padding.
|
|
488
|
+
|
|
489
|
+
##### paddingLeft
|
|
490
|
+
|
|
491
|
+
Type: `number`\
|
|
492
|
+
Default: `0`
|
|
493
|
+
|
|
494
|
+
Left padding.
|
|
495
|
+
|
|
496
|
+
##### paddingRight
|
|
497
|
+
|
|
498
|
+
Type: `number`\
|
|
499
|
+
Default: `0`
|
|
500
|
+
|
|
501
|
+
Right padding.
|
|
502
|
+
|
|
503
|
+
##### paddingX
|
|
504
|
+
|
|
505
|
+
Type: `number`\
|
|
506
|
+
Default: `0`
|
|
507
|
+
|
|
508
|
+
Horizontal padding. Equivalent to setting `paddingLeft` and `paddingRight`.
|
|
509
|
+
|
|
510
|
+
##### paddingY
|
|
511
|
+
|
|
512
|
+
Type: `number`\
|
|
513
|
+
Default: `0`
|
|
514
|
+
|
|
515
|
+
Vertical padding. Equivalent to setting `paddingTop` and `paddingBottom`.
|
|
516
|
+
|
|
517
|
+
##### padding
|
|
518
|
+
|
|
519
|
+
Type: `number`\
|
|
520
|
+
Default: `0`
|
|
521
|
+
|
|
522
|
+
Padding on all sides. Equivalent to setting `paddingTop`, `paddingBottom`, `paddingLeft` and `paddingRight`.
|
|
523
|
+
|
|
524
|
+
```jsx
|
|
525
|
+
<Box paddingTop={2}><Text>Top</Text></Box>
|
|
526
|
+
<Box paddingBottom={2}><Text>Bottom</Text></Box>
|
|
527
|
+
<Box paddingLeft={2}><Text>Left</Text></Box>
|
|
528
|
+
<Box paddingRight={2}><Text>Right</Text></Box>
|
|
529
|
+
<Box paddingX={2}><Text>Left and right</Text></Box>
|
|
530
|
+
<Box paddingY={2}><Text>Top and bottom</Text></Box>
|
|
531
|
+
<Box padding={2}><Text>Top, bottom, left and right</Text></Box>
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
#### Margin
|
|
535
|
+
|
|
536
|
+
##### marginTop
|
|
537
|
+
|
|
538
|
+
Type: `number`\
|
|
539
|
+
Default: `0`
|
|
540
|
+
|
|
541
|
+
Top margin.
|
|
542
|
+
|
|
543
|
+
##### marginBottom
|
|
544
|
+
|
|
545
|
+
Type: `number`\
|
|
546
|
+
Default: `0`
|
|
547
|
+
|
|
548
|
+
Bottom margin.
|
|
549
|
+
|
|
550
|
+
##### marginLeft
|
|
551
|
+
|
|
552
|
+
Type: `number`\
|
|
553
|
+
Default: `0`
|
|
554
|
+
|
|
555
|
+
Left margin.
|
|
556
|
+
|
|
557
|
+
##### marginRight
|
|
558
|
+
|
|
559
|
+
Type: `number`\
|
|
560
|
+
Default: `0`
|
|
561
|
+
|
|
562
|
+
Right margin.
|
|
563
|
+
|
|
564
|
+
##### marginX
|
|
565
|
+
|
|
566
|
+
Type: `number`\
|
|
567
|
+
Default: `0`
|
|
568
|
+
|
|
569
|
+
Horizontal margin. Equivalent to setting `marginLeft` and `marginRight`.
|
|
570
|
+
|
|
571
|
+
##### marginY
|
|
572
|
+
|
|
573
|
+
Type: `number`\
|
|
574
|
+
Default: `0`
|
|
575
|
+
|
|
576
|
+
Vertical margin. Equivalent to setting `marginTop` and `marginBottom`.
|
|
577
|
+
|
|
578
|
+
##### margin
|
|
579
|
+
|
|
580
|
+
Type: `number`\
|
|
581
|
+
Default: `0`
|
|
582
|
+
|
|
583
|
+
Margin on all sides. Equivalent to setting `marginTop`, `marginBottom`, `marginLeft` and `marginRight`.
|
|
584
|
+
|
|
585
|
+
```jsx
|
|
586
|
+
<Box marginTop={2}><Text>Top</Text></Box>
|
|
587
|
+
<Box marginBottom={2}><Text>Bottom</Text></Box>
|
|
588
|
+
<Box marginLeft={2}><Text>Left</Text></Box>
|
|
589
|
+
<Box marginRight={2}><Text>Right</Text></Box>
|
|
590
|
+
<Box marginX={2}><Text>Left and right</Text></Box>
|
|
591
|
+
<Box marginY={2}><Text>Top and bottom</Text></Box>
|
|
592
|
+
<Box margin={2}><Text>Top, bottom, left and right</Text></Box>
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
#### Gap
|
|
596
|
+
|
|
597
|
+
#### gap
|
|
598
|
+
|
|
599
|
+
Type: `number`\
|
|
600
|
+
Default: `0`
|
|
601
|
+
|
|
602
|
+
Size of the gap between an element's columns and rows. A shorthand for `columnGap` and `rowGap`.
|
|
603
|
+
|
|
604
|
+
```jsx
|
|
605
|
+
<Box gap={1} width={3} flexWrap="wrap">
|
|
606
|
+
<Text>A</Text>
|
|
607
|
+
<Text>B</Text>
|
|
608
|
+
<Text>C</Text>
|
|
609
|
+
</Box>
|
|
610
|
+
// A B
|
|
611
|
+
//
|
|
612
|
+
// C
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
#### columnGap
|
|
616
|
+
|
|
617
|
+
Type: `number`\
|
|
618
|
+
Default: `0`
|
|
619
|
+
|
|
620
|
+
Size of the gap between an element's columns.
|
|
621
|
+
|
|
622
|
+
```jsx
|
|
623
|
+
<Box columnGap={1}>
|
|
624
|
+
<Text>A</Text>
|
|
625
|
+
<Text>B</Text>
|
|
626
|
+
</Box>
|
|
627
|
+
// A B
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
#### rowGap
|
|
631
|
+
|
|
632
|
+
Type: `number`\
|
|
633
|
+
Default: `0`
|
|
634
|
+
|
|
635
|
+
Size of the gap between an element's rows.
|
|
636
|
+
|
|
637
|
+
```jsx
|
|
638
|
+
<Box flexDirection="column" rowGap={1}>
|
|
639
|
+
<Text>A</Text>
|
|
640
|
+
<Text>B</Text>
|
|
641
|
+
</Box>
|
|
642
|
+
// A
|
|
643
|
+
//
|
|
644
|
+
// B
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
#### Flex
|
|
648
|
+
|
|
649
|
+
##### flexGrow
|
|
650
|
+
|
|
651
|
+
Type: `number`\
|
|
652
|
+
Default: `0`
|
|
653
|
+
|
|
654
|
+
See [flex-grow](https://css-tricks.com/almanac/properties/f/flex-grow/).
|
|
655
|
+
|
|
656
|
+
```jsx
|
|
657
|
+
<Box>
|
|
658
|
+
<Text>Label:</Text>
|
|
659
|
+
<Box flexGrow={1}>
|
|
660
|
+
<Text>Fills all remaining space</Text>
|
|
661
|
+
</Box>
|
|
662
|
+
</Box>
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
##### flexShrink
|
|
666
|
+
|
|
667
|
+
Type: `number`\
|
|
668
|
+
Default: `1`
|
|
669
|
+
|
|
670
|
+
See [flex-shrink](https://css-tricks.com/almanac/properties/f/flex-shrink/).
|
|
671
|
+
|
|
672
|
+
```jsx
|
|
673
|
+
<Box width={20}>
|
|
674
|
+
<Box flexShrink={2} width={10}>
|
|
675
|
+
<Text>Will be 1/4</Text>
|
|
676
|
+
</Box>
|
|
677
|
+
<Box width={10}>
|
|
678
|
+
<Text>Will be 3/4</Text>
|
|
679
|
+
</Box>
|
|
680
|
+
</Box>
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
##### flexBasis
|
|
684
|
+
|
|
685
|
+
Type: `number` `string`
|
|
686
|
+
|
|
687
|
+
See [flex-basis](https://css-tricks.com/almanac/properties/f/flex-basis/).
|
|
688
|
+
|
|
689
|
+
```jsx
|
|
690
|
+
<Box width={6}>
|
|
691
|
+
<Box flexBasis={3}>
|
|
692
|
+
<Text>X</Text>
|
|
693
|
+
</Box>
|
|
694
|
+
<Text>Y</Text>
|
|
695
|
+
</Box>
|
|
696
|
+
//=> 'X Y'
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
```jsx
|
|
700
|
+
<Box width={6}>
|
|
701
|
+
<Box flexBasis="50%">
|
|
702
|
+
<Text>X</Text>
|
|
703
|
+
</Box>
|
|
704
|
+
<Text>Y</Text>
|
|
705
|
+
</Box>
|
|
706
|
+
//=> 'X Y'
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
##### flexDirection
|
|
710
|
+
|
|
711
|
+
Type: `string`\
|
|
712
|
+
Allowed values: `row` `row-reverse` `column` `column-reverse`
|
|
713
|
+
|
|
714
|
+
See [flex-direction](https://css-tricks.com/almanac/properties/f/flex-direction/).
|
|
715
|
+
|
|
716
|
+
```jsx
|
|
717
|
+
<Box>
|
|
718
|
+
<Box marginRight={1}>
|
|
719
|
+
<Text>X</Text>
|
|
720
|
+
</Box>
|
|
721
|
+
<Text>Y</Text>
|
|
722
|
+
</Box>
|
|
723
|
+
// X Y
|
|
724
|
+
|
|
725
|
+
<Box flexDirection="row-reverse">
|
|
726
|
+
<Text>X</Text>
|
|
727
|
+
<Box marginRight={1}>
|
|
728
|
+
<Text>Y</Text>
|
|
729
|
+
</Box>
|
|
730
|
+
</Box>
|
|
731
|
+
// Y X
|
|
732
|
+
|
|
733
|
+
<Box flexDirection="column">
|
|
734
|
+
<Text>X</Text>
|
|
735
|
+
<Text>Y</Text>
|
|
736
|
+
</Box>
|
|
737
|
+
// X
|
|
738
|
+
// Y
|
|
739
|
+
|
|
740
|
+
<Box flexDirection="column-reverse">
|
|
741
|
+
<Text>X</Text>
|
|
742
|
+
<Text>Y</Text>
|
|
743
|
+
</Box>
|
|
744
|
+
// Y
|
|
745
|
+
// X
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
##### flexWrap
|
|
749
|
+
|
|
750
|
+
Type: `string`\
|
|
751
|
+
Allowed values: `nowrap` `wrap` `wrap-reverse`
|
|
752
|
+
|
|
753
|
+
See [flex-wrap](https://css-tricks.com/almanac/properties/f/flex-wrap/).
|
|
754
|
+
|
|
755
|
+
```jsx
|
|
756
|
+
<Box width={2} flexWrap="wrap">
|
|
757
|
+
<Text>A</Text>
|
|
758
|
+
<Text>BC</Text>
|
|
759
|
+
</Box>
|
|
760
|
+
// A
|
|
761
|
+
// B C
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
```jsx
|
|
765
|
+
<Box flexDirection="column" height={2} flexWrap="wrap">
|
|
766
|
+
<Text>A</Text>
|
|
767
|
+
<Text>B</Text>
|
|
768
|
+
<Text>C</Text>
|
|
769
|
+
</Box>
|
|
770
|
+
// A C
|
|
771
|
+
// B
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
##### alignItems
|
|
775
|
+
|
|
776
|
+
Type: `string`\
|
|
777
|
+
Allowed values: `flex-start` `center` `flex-end`
|
|
778
|
+
|
|
779
|
+
See [align-items](https://css-tricks.com/almanac/properties/a/align-items/).
|
|
780
|
+
|
|
781
|
+
```jsx
|
|
782
|
+
<Box alignItems="flex-start">
|
|
783
|
+
<Box marginRight={1}>
|
|
784
|
+
<Text>X</Text>
|
|
785
|
+
</Box>
|
|
786
|
+
<Text>
|
|
787
|
+
A
|
|
788
|
+
<Newline/>
|
|
789
|
+
B
|
|
790
|
+
<Newline/>
|
|
791
|
+
C
|
|
792
|
+
</Text>
|
|
793
|
+
</Box>
|
|
794
|
+
// X A
|
|
795
|
+
// B
|
|
796
|
+
// C
|
|
797
|
+
|
|
798
|
+
<Box alignItems="center">
|
|
799
|
+
<Box marginRight={1}>
|
|
800
|
+
<Text>X</Text>
|
|
801
|
+
</Box>
|
|
802
|
+
<Text>
|
|
803
|
+
A
|
|
804
|
+
<Newline/>
|
|
805
|
+
B
|
|
806
|
+
<Newline/>
|
|
807
|
+
C
|
|
808
|
+
</Text>
|
|
809
|
+
</Box>
|
|
810
|
+
// A
|
|
811
|
+
// X B
|
|
812
|
+
// C
|
|
813
|
+
|
|
814
|
+
<Box alignItems="flex-end">
|
|
815
|
+
<Box marginRight={1}>
|
|
816
|
+
<Text>X</Text>
|
|
817
|
+
</Box>
|
|
818
|
+
<Text>
|
|
819
|
+
A
|
|
820
|
+
<Newline/>
|
|
821
|
+
B
|
|
822
|
+
<Newline/>
|
|
823
|
+
C
|
|
824
|
+
</Text>
|
|
825
|
+
</Box>
|
|
826
|
+
// A
|
|
827
|
+
// B
|
|
828
|
+
// X C
|
|
829
|
+
```
|
|
830
|
+
|
|
831
|
+
##### alignSelf
|
|
832
|
+
|
|
833
|
+
Type: `string`\
|
|
834
|
+
Default: `auto`\
|
|
835
|
+
Allowed values: `auto` `flex-start` `center` `flex-end`
|
|
836
|
+
|
|
837
|
+
See [align-self](https://css-tricks.com/almanac/properties/a/align-self/).
|
|
838
|
+
|
|
839
|
+
```jsx
|
|
840
|
+
<Box height={3}>
|
|
841
|
+
<Box alignSelf="flex-start">
|
|
842
|
+
<Text>X</Text>
|
|
843
|
+
</Box>
|
|
844
|
+
</Box>
|
|
845
|
+
// X
|
|
846
|
+
//
|
|
847
|
+
//
|
|
848
|
+
|
|
849
|
+
<Box height={3}>
|
|
850
|
+
<Box alignSelf="center">
|
|
851
|
+
<Text>X</Text>
|
|
852
|
+
</Box>
|
|
853
|
+
</Box>
|
|
854
|
+
//
|
|
855
|
+
// X
|
|
856
|
+
//
|
|
857
|
+
|
|
858
|
+
<Box height={3}>
|
|
859
|
+
<Box alignSelf="flex-end">
|
|
860
|
+
<Text>X</Text>
|
|
861
|
+
</Box>
|
|
862
|
+
</Box>
|
|
863
|
+
//
|
|
864
|
+
//
|
|
865
|
+
// X
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
##### justifyContent
|
|
869
|
+
|
|
870
|
+
Type: `string`\
|
|
871
|
+
Allowed values: `flex-start` `center` `flex-end` `space-between` `space-around` `space-evenly`
|
|
872
|
+
|
|
873
|
+
See [justify-content](https://css-tricks.com/almanac/properties/j/justify-content/).
|
|
874
|
+
|
|
875
|
+
```jsx
|
|
876
|
+
<Box justifyContent="flex-start">
|
|
877
|
+
<Text>X</Text>
|
|
878
|
+
</Box>
|
|
879
|
+
// [X ]
|
|
880
|
+
|
|
881
|
+
<Box justifyContent="center">
|
|
882
|
+
<Text>X</Text>
|
|
883
|
+
</Box>
|
|
884
|
+
// [ X ]
|
|
885
|
+
|
|
886
|
+
<Box justifyContent="flex-end">
|
|
887
|
+
<Text>X</Text>
|
|
888
|
+
</Box>
|
|
889
|
+
// [ X]
|
|
890
|
+
|
|
891
|
+
<Box justifyContent="space-between">
|
|
892
|
+
<Text>X</Text>
|
|
893
|
+
<Text>Y</Text>
|
|
894
|
+
</Box>
|
|
895
|
+
// [X Y]
|
|
896
|
+
|
|
897
|
+
<Box justifyContent="space-around">
|
|
898
|
+
<Text>X</Text>
|
|
899
|
+
<Text>Y</Text>
|
|
900
|
+
</Box>
|
|
901
|
+
// [ X Y ]
|
|
902
|
+
|
|
903
|
+
<Box justifyContent="space-evenly">
|
|
904
|
+
<Text>X</Text>
|
|
905
|
+
<Text>Y</Text>
|
|
906
|
+
</Box>
|
|
907
|
+
// [ X Y ]
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
#### Visibility
|
|
911
|
+
|
|
912
|
+
##### display
|
|
913
|
+
|
|
914
|
+
Type: `string`\
|
|
915
|
+
Allowed values: `flex` `none`\
|
|
916
|
+
Default: `flex`
|
|
917
|
+
|
|
918
|
+
Set this property to `none` to hide the element.
|
|
919
|
+
|
|
920
|
+
##### overflowX
|
|
921
|
+
|
|
922
|
+
Type: `string`\
|
|
923
|
+
Allowed values: `visible` `hidden`\
|
|
924
|
+
Default: `visible`
|
|
925
|
+
|
|
926
|
+
Behavior for an element's overflow in the horizontal direction.
|
|
927
|
+
|
|
928
|
+
##### overflowY
|
|
929
|
+
|
|
930
|
+
Type: `string`\
|
|
931
|
+
Allowed values: `visible` `hidden`\
|
|
932
|
+
Default: `visible`
|
|
933
|
+
|
|
934
|
+
Behavior for an element's overflow in the vertical direction.
|
|
935
|
+
|
|
936
|
+
##### overflow
|
|
937
|
+
|
|
938
|
+
Type: `string`\
|
|
939
|
+
Allowed values: `visible` `hidden`\
|
|
940
|
+
Default: `visible`
|
|
941
|
+
|
|
942
|
+
A shortcut for setting `overflowX` and `overflowY` at the same time.
|
|
943
|
+
|
|
944
|
+
#### Borders
|
|
945
|
+
|
|
946
|
+
##### borderStyle
|
|
947
|
+
|
|
948
|
+
Type: `string`\
|
|
949
|
+
Allowed values: `single` `double` `round` `bold` `singleDouble` `doubleSingle` `classic` | `BoxStyle`
|
|
950
|
+
|
|
951
|
+
Add a border with a specified style.
|
|
952
|
+
If `borderStyle` is `undefined` (the default), no border will be added.
|
|
953
|
+
Ink uses border styles from the [`cli-boxes`](https://github.com/sindresorhus/cli-boxes) module.
|
|
954
|
+
|
|
955
|
+
```jsx
|
|
956
|
+
<Box flexDirection="column">
|
|
957
|
+
<Box>
|
|
958
|
+
<Box borderStyle="single" marginRight={2}>
|
|
959
|
+
<Text>single</Text>
|
|
960
|
+
</Box>
|
|
961
|
+
|
|
962
|
+
<Box borderStyle="double" marginRight={2}>
|
|
963
|
+
<Text>double</Text>
|
|
964
|
+
</Box>
|
|
965
|
+
|
|
966
|
+
<Box borderStyle="round" marginRight={2}>
|
|
967
|
+
<Text>round</Text>
|
|
968
|
+
</Box>
|
|
969
|
+
|
|
970
|
+
<Box borderStyle="bold">
|
|
971
|
+
<Text>bold</Text>
|
|
972
|
+
</Box>
|
|
973
|
+
</Box>
|
|
974
|
+
|
|
975
|
+
<Box marginTop={1}>
|
|
976
|
+
<Box borderStyle="singleDouble" marginRight={2}>
|
|
977
|
+
<Text>singleDouble</Text>
|
|
978
|
+
</Box>
|
|
979
|
+
|
|
980
|
+
<Box borderStyle="doubleSingle" marginRight={2}>
|
|
981
|
+
<Text>doubleSingle</Text>
|
|
982
|
+
</Box>
|
|
983
|
+
|
|
984
|
+
<Box borderStyle="classic">
|
|
985
|
+
<Text>classic</Text>
|
|
986
|
+
</Box>
|
|
987
|
+
</Box>
|
|
988
|
+
</Box>
|
|
989
|
+
```
|
|
990
|
+
|
|
991
|
+
<img src="media/box-borderStyle.jpg" width="521">
|
|
992
|
+
|
|
993
|
+
Alternatively, pass a custom border style like so:
|
|
994
|
+
|
|
995
|
+
```jsx
|
|
996
|
+
<Box
|
|
997
|
+
borderStyle={{
|
|
998
|
+
topLeft: '↘',
|
|
999
|
+
top: '↓',
|
|
1000
|
+
topRight: '↙',
|
|
1001
|
+
left: '→',
|
|
1002
|
+
bottomLeft: '↗',
|
|
1003
|
+
bottom: '↑',
|
|
1004
|
+
bottomRight: '↖',
|
|
1005
|
+
right: '←'
|
|
1006
|
+
}}
|
|
1007
|
+
>
|
|
1008
|
+
<Text>Custom</Text>
|
|
1009
|
+
</Box>
|
|
1010
|
+
```
|
|
1011
|
+
|
|
1012
|
+
See example in [examples/borders](examples/borders/borders.tsx).
|
|
1013
|
+
|
|
1014
|
+
##### borderColor
|
|
1015
|
+
|
|
1016
|
+
Type: `string`
|
|
1017
|
+
|
|
1018
|
+
Change border color.
|
|
1019
|
+
A shorthand for setting `borderTopColor`, `borderRightColor`, `borderBottomColor`, and `borderLeftColor`.
|
|
1020
|
+
|
|
1021
|
+
```jsx
|
|
1022
|
+
<Box borderStyle="round" borderColor="green">
|
|
1023
|
+
<Text>Green Rounded Box</Text>
|
|
1024
|
+
</Box>
|
|
1025
|
+
```
|
|
1026
|
+
|
|
1027
|
+
<img src="media/box-borderColor.jpg" width="228">
|
|
1028
|
+
|
|
1029
|
+
##### borderTopColor
|
|
1030
|
+
|
|
1031
|
+
Type: `string`
|
|
1032
|
+
|
|
1033
|
+
Change top border color.
|
|
1034
|
+
Accepts the same values as [`color`](#color) in `<Text>` component.
|
|
1035
|
+
|
|
1036
|
+
```jsx
|
|
1037
|
+
<Box borderStyle="round" borderTopColor="green">
|
|
1038
|
+
<Text>Hello world</Text>
|
|
1039
|
+
</Box>
|
|
1040
|
+
```
|
|
1041
|
+
|
|
1042
|
+
##### borderRightColor
|
|
1043
|
+
|
|
1044
|
+
Type: `string`
|
|
1045
|
+
|
|
1046
|
+
Change the right border color.
|
|
1047
|
+
Accepts the same values as [`color`](#color) in `<Text>` component.
|
|
1048
|
+
|
|
1049
|
+
```jsx
|
|
1050
|
+
<Box borderStyle="round" borderRightColor="green">
|
|
1051
|
+
<Text>Hello world</Text>
|
|
1052
|
+
</Box>
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
##### borderBottomColor
|
|
1056
|
+
|
|
1057
|
+
Type: `string`
|
|
1058
|
+
|
|
1059
|
+
Change the bottom border color.
|
|
1060
|
+
Accepts the same values as [`color`](#color) in `<Text>` component.
|
|
1061
|
+
|
|
1062
|
+
```jsx
|
|
1063
|
+
<Box borderStyle="round" borderBottomColor="green">
|
|
1064
|
+
<Text>Hello world</Text>
|
|
1065
|
+
</Box>
|
|
1066
|
+
```
|
|
1067
|
+
|
|
1068
|
+
##### borderLeftColor
|
|
1069
|
+
|
|
1070
|
+
Type: `string`
|
|
1071
|
+
|
|
1072
|
+
Change the left border color.
|
|
1073
|
+
Accepts the same values as [`color`](#color) in `<Text>` component.
|
|
1074
|
+
|
|
1075
|
+
```jsx
|
|
1076
|
+
<Box borderStyle="round" borderLeftColor="green">
|
|
1077
|
+
<Text>Hello world</Text>
|
|
1078
|
+
</Box>
|
|
1079
|
+
```
|
|
1080
|
+
|
|
1081
|
+
##### borderDimColor
|
|
1082
|
+
|
|
1083
|
+
Type: `boolean`\
|
|
1084
|
+
Default: `false`
|
|
1085
|
+
|
|
1086
|
+
Dim the border color.
|
|
1087
|
+
A shorthand for setting `borderTopDimColor`, `borderBottomDimColor`, `borderLeftDimColor`, and `borderRightDimColor`.
|
|
1088
|
+
|
|
1089
|
+
```jsx
|
|
1090
|
+
<Box borderStyle="round" borderDimColor>
|
|
1091
|
+
<Text>Hello world</Text>
|
|
1092
|
+
</Box>
|
|
1093
|
+
```
|
|
1094
|
+
|
|
1095
|
+
##### borderTopDimColor
|
|
1096
|
+
|
|
1097
|
+
Type: `boolean`\
|
|
1098
|
+
Default: `false`
|
|
1099
|
+
|
|
1100
|
+
Dim the top border color.
|
|
1101
|
+
|
|
1102
|
+
```jsx
|
|
1103
|
+
<Box borderStyle="round" borderTopDimColor>
|
|
1104
|
+
<Text>Hello world</Text>
|
|
1105
|
+
</Box>
|
|
1106
|
+
```
|
|
1107
|
+
|
|
1108
|
+
##### borderBottomDimColor
|
|
1109
|
+
|
|
1110
|
+
Type: `boolean`\
|
|
1111
|
+
Default: `false`
|
|
1112
|
+
|
|
1113
|
+
Dim the bottom border color.
|
|
1114
|
+
|
|
1115
|
+
```jsx
|
|
1116
|
+
<Box borderStyle="round" borderBottomDimColor>
|
|
1117
|
+
<Text>Hello world</Text>
|
|
1118
|
+
</Box>
|
|
1119
|
+
```
|
|
1120
|
+
|
|
1121
|
+
##### borderLeftDimColor
|
|
1122
|
+
|
|
1123
|
+
Type: `boolean`\
|
|
1124
|
+
Default: `false`
|
|
1125
|
+
|
|
1126
|
+
Dim the left border color.
|
|
1127
|
+
|
|
1128
|
+
```jsx
|
|
1129
|
+
<Box borderStyle="round" borderLeftDimColor>
|
|
1130
|
+
<Text>Hello world</Text>
|
|
1131
|
+
</Box>
|
|
1132
|
+
```
|
|
1133
|
+
|
|
1134
|
+
##### borderRightDimColor
|
|
1135
|
+
|
|
1136
|
+
Type: `boolean`\
|
|
1137
|
+
Default: `false`
|
|
1138
|
+
|
|
1139
|
+
Dim the right border color.
|
|
1140
|
+
|
|
1141
|
+
```jsx
|
|
1142
|
+
<Box borderStyle="round" borderRightDimColor>
|
|
1143
|
+
<Text>Hello world</Text>
|
|
1144
|
+
</Box>
|
|
1145
|
+
```
|
|
1146
|
+
|
|
1147
|
+
##### borderTop
|
|
1148
|
+
|
|
1149
|
+
Type: `boolean`\
|
|
1150
|
+
Default: `true`
|
|
1151
|
+
|
|
1152
|
+
Determines whether the top border is visible.
|
|
1153
|
+
|
|
1154
|
+
##### borderRight
|
|
1155
|
+
|
|
1156
|
+
Type: `boolean`\
|
|
1157
|
+
Default: `true`
|
|
1158
|
+
|
|
1159
|
+
Determines whether the right border is visible.
|
|
1160
|
+
|
|
1161
|
+
##### borderBottom
|
|
1162
|
+
|
|
1163
|
+
Type: `boolean`\
|
|
1164
|
+
Default: `true`
|
|
1165
|
+
|
|
1166
|
+
Determines whether the bottom border is visible.
|
|
1167
|
+
|
|
1168
|
+
##### borderLeft
|
|
1169
|
+
|
|
1170
|
+
Type: `boolean`\
|
|
1171
|
+
Default: `true`
|
|
1172
|
+
|
|
1173
|
+
Determines whether the left border is visible.
|
|
1174
|
+
|
|
1175
|
+
#### Background
|
|
1176
|
+
|
|
1177
|
+
##### backgroundColor
|
|
1178
|
+
|
|
1179
|
+
Type: `string`
|
|
1180
|
+
|
|
1181
|
+
Background color for the element.
|
|
1182
|
+
|
|
1183
|
+
Accepts the same values as [`color`](#color) in the `<Text>` component.
|
|
1184
|
+
|
|
1185
|
+
```jsx
|
|
1186
|
+
<Box flexDirection="column">
|
|
1187
|
+
<Box backgroundColor="red" width={20} height={5} alignSelf="flex-start">
|
|
1188
|
+
<Text>Red background</Text>
|
|
1189
|
+
</Box>
|
|
1190
|
+
|
|
1191
|
+
<Box backgroundColor="#FF8800" width={20} height={3} marginTop={1} alignSelf="flex-start">
|
|
1192
|
+
<Text>Orange background</Text>
|
|
1193
|
+
</Box>
|
|
1194
|
+
|
|
1195
|
+
<Box backgroundColor="rgb(0, 255, 0)" width={20} height={3} marginTop={1} alignSelf="flex-start">
|
|
1196
|
+
<Text>Green background</Text>
|
|
1197
|
+
</Box>
|
|
1198
|
+
</Box>
|
|
1199
|
+
```
|
|
1200
|
+
|
|
1201
|
+
The background color fills the entire `<Box>` area and is inherited by child `<Text>` components unless they specify their own `backgroundColor`.
|
|
1202
|
+
|
|
1203
|
+
```jsx
|
|
1204
|
+
<Box backgroundColor="blue" alignSelf="flex-start">
|
|
1205
|
+
<Text>Blue inherited </Text>
|
|
1206
|
+
<Text backgroundColor="yellow">Yellow override </Text>
|
|
1207
|
+
<Text>Blue inherited again</Text>
|
|
1208
|
+
</Box>
|
|
1209
|
+
```
|
|
1210
|
+
|
|
1211
|
+
Background colors work with borders and padding:
|
|
1212
|
+
|
|
1213
|
+
```jsx
|
|
1214
|
+
<Box backgroundColor="cyan" borderStyle="round" padding={1} alignSelf="flex-start">
|
|
1215
|
+
<Text>Background with border and padding</Text>
|
|
1216
|
+
</Box>
|
|
1217
|
+
```
|
|
1218
|
+
|
|
1219
|
+
See example in [examples/box-backgrounds](examples/box-backgrounds/box-backgrounds.tsx).
|
|
1220
|
+
|
|
1221
|
+
### `<Newline>`
|
|
1222
|
+
|
|
1223
|
+
Adds one or more newline (`\n`) characters.
|
|
1224
|
+
Must be used within `<Text>` components.
|
|
1225
|
+
|
|
1226
|
+
#### count
|
|
1227
|
+
|
|
1228
|
+
Type: `number`\
|
|
1229
|
+
Default: `1`
|
|
1230
|
+
|
|
1231
|
+
Number of newlines to insert.
|
|
1232
|
+
|
|
1233
|
+
```jsx
|
|
1234
|
+
import {render, Text, Newline} from 'ink';
|
|
1235
|
+
|
|
1236
|
+
const Example = () => (
|
|
1237
|
+
<Text>
|
|
1238
|
+
<Text color="green">Hello</Text>
|
|
1239
|
+
<Newline />
|
|
1240
|
+
<Text color="red">World</Text>
|
|
1241
|
+
</Text>
|
|
1242
|
+
);
|
|
1243
|
+
|
|
1244
|
+
render(<Example />);
|
|
1245
|
+
```
|
|
1246
|
+
|
|
1247
|
+
Output:
|
|
1248
|
+
|
|
1249
|
+
```
|
|
1250
|
+
Hello
|
|
1251
|
+
World
|
|
1252
|
+
```
|
|
1253
|
+
|
|
1254
|
+
### `<Spacer>`
|
|
1255
|
+
|
|
1256
|
+
A flexible space that expands along the major axis of its containing layout.
|
|
1257
|
+
It's useful as a shortcut for filling all the available space between elements.
|
|
1258
|
+
|
|
1259
|
+
For example, using `<Spacer>` in a `<Box>` with default flex direction (`row`) will position "Left" on the left side and will push "Right" to the right side.
|
|
1260
|
+
|
|
1261
|
+
```jsx
|
|
1262
|
+
import {render, Box, Text, Spacer} from 'ink';
|
|
1263
|
+
|
|
1264
|
+
const Example = () => (
|
|
1265
|
+
<Box>
|
|
1266
|
+
<Text>Left</Text>
|
|
1267
|
+
<Spacer />
|
|
1268
|
+
<Text>Right</Text>
|
|
1269
|
+
</Box>
|
|
1270
|
+
);
|
|
1271
|
+
|
|
1272
|
+
render(<Example />);
|
|
1273
|
+
```
|
|
1274
|
+
|
|
1275
|
+
In a vertical flex direction (`column`), it will position "Top" at the top of the container and push "Bottom" to the bottom.
|
|
1276
|
+
Note that the container needs to be tall enough to see this in effect.
|
|
1277
|
+
|
|
1278
|
+
```jsx
|
|
1279
|
+
import {render, Box, Text, Spacer} from 'ink';
|
|
1280
|
+
|
|
1281
|
+
const Example = () => (
|
|
1282
|
+
<Box flexDirection="column" height={10}>
|
|
1283
|
+
<Text>Top</Text>
|
|
1284
|
+
<Spacer />
|
|
1285
|
+
<Text>Bottom</Text>
|
|
1286
|
+
</Box>
|
|
1287
|
+
);
|
|
1288
|
+
|
|
1289
|
+
render(<Example />);
|
|
1290
|
+
```
|
|
1291
|
+
|
|
1292
|
+
### `<Static>`
|
|
1293
|
+
|
|
1294
|
+
`<Static>` component permanently renders its output above everything else.
|
|
1295
|
+
It's useful for displaying activity like completed tasks or logs - things that
|
|
1296
|
+
don't change after they're rendered (hence the name "Static").
|
|
1297
|
+
|
|
1298
|
+
It's preferred to use `<Static>` for use cases like these when you can't know
|
|
1299
|
+
or control the number of items that need to be rendered.
|
|
1300
|
+
|
|
1301
|
+
For example, [Tap](https://github.com/tapjs/node-tap) uses `<Static>` to display
|
|
1302
|
+
a list of completed tests. [Gatsby](https://github.com/gatsbyjs/gatsby) uses it
|
|
1303
|
+
to display a list of generated pages while still displaying a live progress bar.
|
|
1304
|
+
|
|
1305
|
+
```jsx
|
|
1306
|
+
import React, {useState, useEffect} from 'react';
|
|
1307
|
+
import {render, Static, Box, Text} from 'ink';
|
|
1308
|
+
|
|
1309
|
+
const Example = () => {
|
|
1310
|
+
const [tests, setTests] = useState([]);
|
|
1311
|
+
|
|
1312
|
+
useEffect(() => {
|
|
1313
|
+
let completedTests = 0;
|
|
1314
|
+
let timer;
|
|
1315
|
+
|
|
1316
|
+
const run = () => {
|
|
1317
|
+
// Fake 10 completed tests
|
|
1318
|
+
if (completedTests++ < 10) {
|
|
1319
|
+
setTests(previousTests => [
|
|
1320
|
+
...previousTests,
|
|
1321
|
+
{
|
|
1322
|
+
id: previousTests.length,
|
|
1323
|
+
title: `Test #${previousTests.length + 1}`
|
|
1324
|
+
}
|
|
1325
|
+
]);
|
|
1326
|
+
|
|
1327
|
+
timer = setTimeout(run, 100);
|
|
1328
|
+
}
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
run();
|
|
1332
|
+
|
|
1333
|
+
return () => {
|
|
1334
|
+
clearTimeout(timer);
|
|
1335
|
+
};
|
|
1336
|
+
}, []);
|
|
1337
|
+
|
|
1338
|
+
return (
|
|
1339
|
+
<>
|
|
1340
|
+
{/* This part will be rendered once to the terminal */}
|
|
1341
|
+
<Static items={tests}>
|
|
1342
|
+
{test => (
|
|
1343
|
+
<Box key={test.id}>
|
|
1344
|
+
<Text color="green">✔ {test.title}</Text>
|
|
1345
|
+
</Box>
|
|
1346
|
+
)}
|
|
1347
|
+
</Static>
|
|
1348
|
+
|
|
1349
|
+
{/* This part keeps updating as state changes */}
|
|
1350
|
+
<Box marginTop={1}>
|
|
1351
|
+
<Text dimColor>Completed tests: {tests.length}</Text>
|
|
1352
|
+
</Box>
|
|
1353
|
+
</>
|
|
1354
|
+
);
|
|
1355
|
+
};
|
|
1356
|
+
|
|
1357
|
+
render(<Example />);
|
|
1358
|
+
```
|
|
1359
|
+
|
|
1360
|
+
**Note:** `<Static>` only renders new items in the `items` prop and ignores items
|
|
1361
|
+
that were previously rendered. This means that when you add new items to the `items`
|
|
1362
|
+
array, changes you make to previous items will not trigger a rerender.
|
|
1363
|
+
|
|
1364
|
+
See [examples/static](examples/static/static.tsx) for an example usage of `<Static>` component.
|
|
1365
|
+
|
|
1366
|
+
#### items
|
|
1367
|
+
|
|
1368
|
+
Type: `Array`
|
|
1369
|
+
|
|
1370
|
+
Array of items of any type to render using the function you pass as a component child.
|
|
1371
|
+
|
|
1372
|
+
#### style
|
|
1373
|
+
|
|
1374
|
+
Type: `object`
|
|
1375
|
+
|
|
1376
|
+
Styles to apply to a container of child elements.
|
|
1377
|
+
See [`<Box>`](#box) for supported properties.
|
|
1378
|
+
|
|
1379
|
+
```jsx
|
|
1380
|
+
<Static items={...} style={{padding: 1}}>
|
|
1381
|
+
{...}
|
|
1382
|
+
</Static>
|
|
1383
|
+
```
|
|
1384
|
+
|
|
1385
|
+
#### children(item)
|
|
1386
|
+
|
|
1387
|
+
Type: `Function`
|
|
1388
|
+
|
|
1389
|
+
Function that is called to render every item in the `items` array.
|
|
1390
|
+
The first argument is the item itself, and the second argument is the index of that item in the
|
|
1391
|
+
`items` array.
|
|
1392
|
+
|
|
1393
|
+
Note that a `key` must be assigned to the root component.
|
|
1394
|
+
|
|
1395
|
+
```jsx
|
|
1396
|
+
<Static items={['a', 'b', 'c']}>
|
|
1397
|
+
{(item, index) => {
|
|
1398
|
+
// This function is called for every item in ['a', 'b', 'c']
|
|
1399
|
+
// `item` is 'a', 'b', 'c'
|
|
1400
|
+
// `index` is 0, 1, 2
|
|
1401
|
+
return (
|
|
1402
|
+
<Box key={index}>
|
|
1403
|
+
<Text>Item: {item}</Text>
|
|
1404
|
+
</Box>
|
|
1405
|
+
);
|
|
1406
|
+
}}
|
|
1407
|
+
</Static>
|
|
1408
|
+
```
|
|
1409
|
+
|
|
1410
|
+
### `<Transform>`
|
|
1411
|
+
|
|
1412
|
+
Transform a string representation of React components before they're written to output.
|
|
1413
|
+
For example, you might want to apply a [gradient to text](https://github.com/sindresorhus/ink-gradient), [add a clickable link](https://github.com/sindresorhus/ink-link), or [create some text effects](https://github.com/sindresorhus/ink-big-text).
|
|
1414
|
+
These use cases can't accept React nodes as input; they expect a string.
|
|
1415
|
+
That's what the `<Transform>` component does: it gives you an output string of its child components and lets you transform it in any way.
|
|
1416
|
+
|
|
1417
|
+
**Note:** `<Transform>` must be applied only to `<Text>` children components and shouldn't change the dimensions of the output; otherwise, the layout will be incorrect.
|
|
1418
|
+
|
|
1419
|
+
```jsx
|
|
1420
|
+
import {render, Transform} from 'ink';
|
|
1421
|
+
|
|
1422
|
+
const Example = () => (
|
|
1423
|
+
<Transform transform={output => output.toUpperCase()}>
|
|
1424
|
+
<Text>Hello World</Text>
|
|
1425
|
+
</Transform>
|
|
1426
|
+
);
|
|
1427
|
+
|
|
1428
|
+
render(<Example />);
|
|
1429
|
+
```
|
|
1430
|
+
|
|
1431
|
+
Since the `transform` function converts all characters to uppercase, the final output rendered to the terminal will be "HELLO WORLD", not "Hello World".
|
|
1432
|
+
|
|
1433
|
+
When the output wraps to multiple lines, it can be helpful to know which line is being processed.
|
|
1434
|
+
|
|
1435
|
+
For example, to implement a hanging indent component, you can indent all the lines except for the first.
|
|
1436
|
+
|
|
1437
|
+
```jsx
|
|
1438
|
+
import {render, Transform} from 'ink';
|
|
1439
|
+
|
|
1440
|
+
const HangingIndent = ({indent = 4, children}) => (
|
|
1441
|
+
<Transform
|
|
1442
|
+
transform={(line, index) =>
|
|
1443
|
+
index === 0 ? line : ' '.repeat(indent) + line
|
|
1444
|
+
}
|
|
1445
|
+
>
|
|
1446
|
+
{children}
|
|
1447
|
+
</Transform>
|
|
1448
|
+
);
|
|
1449
|
+
|
|
1450
|
+
const text =
|
|
1451
|
+
'WHEN I WROTE the following pages, or rather the bulk of them, ' +
|
|
1452
|
+
'I lived alone, in the woods, a mile from any neighbor, in a ' +
|
|
1453
|
+
'house which I had built myself, on the shore of Walden Pond, ' +
|
|
1454
|
+
'in Concord, Massachusetts, and earned my living by the labor ' +
|
|
1455
|
+
'of my hands only. I lived there two years and two months. At ' +
|
|
1456
|
+
'present I am a sojourner in civilized life again.';
|
|
1457
|
+
|
|
1458
|
+
render(
|
|
1459
|
+
<HangingIndent indent={4}>
|
|
1460
|
+
{text}
|
|
1461
|
+
</HangingIndent>
|
|
1462
|
+
);
|
|
1463
|
+
```
|
|
1464
|
+
|
|
1465
|
+
#### transform(outputLine, index)
|
|
1466
|
+
|
|
1467
|
+
Type: `Function`
|
|
1468
|
+
|
|
1469
|
+
Function that transforms children output.
|
|
1470
|
+
It accepts children and must return transformed children as well.
|
|
1471
|
+
|
|
1472
|
+
##### children
|
|
1473
|
+
|
|
1474
|
+
Type: `string`
|
|
1475
|
+
|
|
1476
|
+
Output of child components.
|
|
1477
|
+
|
|
1478
|
+
##### index
|
|
1479
|
+
|
|
1480
|
+
Type: `number`
|
|
1481
|
+
|
|
1482
|
+
The zero-indexed line number of the line that's currently being transformed.
|
|
1483
|
+
|
|
1484
|
+
## Hooks
|
|
1485
|
+
|
|
1486
|
+
### useInput(inputHandler, options?)
|
|
1487
|
+
|
|
1488
|
+
This hook is used for handling user input.
|
|
1489
|
+
It's a more convenient alternative to using `useStdin` and listening for `data` events.
|
|
1490
|
+
The callback you pass to `useInput` is called for each character when the user enters any input.
|
|
1491
|
+
However, if the user pastes text and it's more than one character, the callback will be called only once, and the whole string will be passed as `input`.
|
|
1492
|
+
You can find a full example of using `useInput` at [examples/use-input](examples/use-input/use-input.tsx).
|
|
1493
|
+
|
|
1494
|
+
```jsx
|
|
1495
|
+
import {useInput} from 'ink';
|
|
1496
|
+
|
|
1497
|
+
const UserInput = () => {
|
|
1498
|
+
useInput((input, key) => {
|
|
1499
|
+
if (input === 'q') {
|
|
1500
|
+
// Exit program
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
if (key.leftArrow) {
|
|
1504
|
+
// Left arrow key pressed
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
|
|
1508
|
+
return …
|
|
1509
|
+
};
|
|
1510
|
+
```
|
|
1511
|
+
|
|
1512
|
+
#### inputHandler(input, key)
|
|
1513
|
+
|
|
1514
|
+
Type: `Function`
|
|
1515
|
+
|
|
1516
|
+
The handler function that you pass to `useInput` receives two arguments:
|
|
1517
|
+
|
|
1518
|
+
##### input
|
|
1519
|
+
|
|
1520
|
+
Type: `string`
|
|
1521
|
+
|
|
1522
|
+
The input that the program received.
|
|
1523
|
+
|
|
1524
|
+
##### key
|
|
1525
|
+
|
|
1526
|
+
Type: `object`
|
|
1527
|
+
|
|
1528
|
+
Handy information about a key that was pressed.
|
|
1529
|
+
|
|
1530
|
+
###### key.leftArrow
|
|
1531
|
+
|
|
1532
|
+
###### key.rightArrow
|
|
1533
|
+
|
|
1534
|
+
###### key.upArrow
|
|
1535
|
+
|
|
1536
|
+
###### key.downArrow
|
|
1537
|
+
|
|
1538
|
+
Type: `boolean`\
|
|
1539
|
+
Default: `false`
|
|
1540
|
+
|
|
1541
|
+
If an arrow key was pressed, the corresponding property will be `true`.
|
|
1542
|
+
For example, if the user presses the left arrow key, `key.leftArrow` equals `true`.
|
|
1543
|
+
|
|
1544
|
+
###### key.return
|
|
1545
|
+
|
|
1546
|
+
Type: `boolean`\
|
|
1547
|
+
Default: `false`
|
|
1548
|
+
|
|
1549
|
+
Return (Enter) key was pressed.
|
|
1550
|
+
|
|
1551
|
+
###### key.escape
|
|
1552
|
+
|
|
1553
|
+
Type: `boolean`\
|
|
1554
|
+
Default: `false`
|
|
1555
|
+
|
|
1556
|
+
Escape key was pressed.
|
|
1557
|
+
|
|
1558
|
+
###### key.ctrl
|
|
1559
|
+
|
|
1560
|
+
Type: `boolean`\
|
|
1561
|
+
Default: `false`
|
|
1562
|
+
|
|
1563
|
+
Ctrl key was pressed.
|
|
1564
|
+
|
|
1565
|
+
###### key.shift
|
|
1566
|
+
|
|
1567
|
+
Type: `boolean`\
|
|
1568
|
+
Default: `false`
|
|
1569
|
+
|
|
1570
|
+
Shift key was pressed.
|
|
1571
|
+
|
|
1572
|
+
###### key.tab
|
|
1573
|
+
|
|
1574
|
+
Type: `boolean`\
|
|
1575
|
+
Default: `false`
|
|
1576
|
+
|
|
1577
|
+
Tab key was pressed.
|
|
1578
|
+
|
|
1579
|
+
###### key.backspace
|
|
1580
|
+
|
|
1581
|
+
Type: `boolean`\
|
|
1582
|
+
Default: `false`
|
|
1583
|
+
|
|
1584
|
+
Backspace key was pressed.
|
|
1585
|
+
|
|
1586
|
+
###### key.delete
|
|
1587
|
+
|
|
1588
|
+
Type: `boolean`\
|
|
1589
|
+
Default: `false`
|
|
1590
|
+
|
|
1591
|
+
Delete key was pressed.
|
|
1592
|
+
|
|
1593
|
+
###### key.pageDown
|
|
1594
|
+
|
|
1595
|
+
###### key.pageUp
|
|
1596
|
+
|
|
1597
|
+
Type: `boolean`\
|
|
1598
|
+
Default: `false`
|
|
1599
|
+
|
|
1600
|
+
If the Page Up or Page Down key was pressed, the corresponding property will be `true`.
|
|
1601
|
+
For example, if the user presses Page Down, `key.pageDown` equals `true`.
|
|
1602
|
+
|
|
1603
|
+
###### key.home
|
|
1604
|
+
|
|
1605
|
+
###### key.end
|
|
1606
|
+
|
|
1607
|
+
Type: `boolean`\
|
|
1608
|
+
Default: `false`
|
|
1609
|
+
|
|
1610
|
+
If the Home or End key was pressed, the corresponding property will be `true`.
|
|
1611
|
+
For example, if the user presses End, `key.end` equals `true`.
|
|
1612
|
+
|
|
1613
|
+
###### key.meta
|
|
1614
|
+
|
|
1615
|
+
Type: `boolean`\
|
|
1616
|
+
Default: `false`
|
|
1617
|
+
|
|
1618
|
+
[Meta key](https://en.wikipedia.org/wiki/Meta_key) was pressed.
|
|
1619
|
+
|
|
1620
|
+
###### key.super
|
|
1621
|
+
|
|
1622
|
+
Type: `boolean`\
|
|
1623
|
+
Default: `false`
|
|
1624
|
+
|
|
1625
|
+
Super key (Cmd on macOS, Win on Windows) was pressed. Requires [kitty keyboard protocol](#kittykeyboard).
|
|
1626
|
+
|
|
1627
|
+
###### key.hyper
|
|
1628
|
+
|
|
1629
|
+
Type: `boolean`\
|
|
1630
|
+
Default: `false`
|
|
1631
|
+
|
|
1632
|
+
Hyper key was pressed. Requires [kitty keyboard protocol](#kittykeyboard).
|
|
1633
|
+
|
|
1634
|
+
###### key.capsLock
|
|
1635
|
+
|
|
1636
|
+
Type: `boolean`\
|
|
1637
|
+
Default: `false`
|
|
1638
|
+
|
|
1639
|
+
Caps Lock was active. Requires [kitty keyboard protocol](#kittykeyboard).
|
|
1640
|
+
|
|
1641
|
+
###### key.numLock
|
|
1642
|
+
|
|
1643
|
+
Type: `boolean`\
|
|
1644
|
+
Default: `false`
|
|
1645
|
+
|
|
1646
|
+
Num Lock was active. Requires [kitty keyboard protocol](#kittykeyboard).
|
|
1647
|
+
|
|
1648
|
+
###### key.eventType
|
|
1649
|
+
|
|
1650
|
+
Type: `'press' | 'repeat' | 'release'`\
|
|
1651
|
+
Default: `undefined`
|
|
1652
|
+
|
|
1653
|
+
The type of key event. Only available with [kitty keyboard protocol](#kittykeyboard). Without the protocol, this property is `undefined`.
|
|
1654
|
+
|
|
1655
|
+
#### options
|
|
1656
|
+
|
|
1657
|
+
Type: `object`
|
|
1658
|
+
|
|
1659
|
+
##### isActive
|
|
1660
|
+
|
|
1661
|
+
Type: `boolean`\
|
|
1662
|
+
Default: `true`
|
|
1663
|
+
|
|
1664
|
+
Enable or disable capturing of user input.
|
|
1665
|
+
Useful when there are multiple `useInput` hooks used at once to avoid handling the same input several times.
|
|
1666
|
+
|
|
1667
|
+
### useApp()
|
|
1668
|
+
|
|
1669
|
+
`useApp` is a React hook that exposes a method to manually exit the app (unmount).
|
|
1670
|
+
|
|
1671
|
+
#### exit(errorOrResult?)
|
|
1672
|
+
|
|
1673
|
+
Type: `Function`
|
|
1674
|
+
|
|
1675
|
+
Exit (unmount) the whole Ink app.
|
|
1676
|
+
|
|
1677
|
+
##### errorOrResult
|
|
1678
|
+
|
|
1679
|
+
Type: `Error | unknown`
|
|
1680
|
+
|
|
1681
|
+
Optional value that controls how [`waitUntilExit`](waituntilexit) settles:
|
|
1682
|
+
- `exit()` resolves with `undefined`.
|
|
1683
|
+
- `exit(error)` rejects when `error` is an `Error`.
|
|
1684
|
+
- `exit(value)` resolves with `value`.
|
|
1685
|
+
|
|
1686
|
+
```js
|
|
1687
|
+
import {useApp} from 'ink';
|
|
1688
|
+
|
|
1689
|
+
const Example = () => {
|
|
1690
|
+
const {exit} = useApp();
|
|
1691
|
+
|
|
1692
|
+
// Exit the app after 5 seconds
|
|
1693
|
+
useEffect(() => {
|
|
1694
|
+
setTimeout(() => {
|
|
1695
|
+
exit();
|
|
1696
|
+
}, 5000);
|
|
1697
|
+
}, []);
|
|
1698
|
+
|
|
1699
|
+
return …
|
|
1700
|
+
};
|
|
1701
|
+
```
|
|
1702
|
+
|
|
1703
|
+
### useStdin()
|
|
1704
|
+
|
|
1705
|
+
`useStdin` is a React hook that exposes the stdin stream.
|
|
1706
|
+
|
|
1707
|
+
#### stdin
|
|
1708
|
+
|
|
1709
|
+
Type: `stream.Readable`\
|
|
1710
|
+
Default: `process.stdin`
|
|
1711
|
+
|
|
1712
|
+
The stdin stream passed to `render()` in `options.stdin`, or `process.stdin` by default.
|
|
1713
|
+
Useful if your app needs to handle user input.
|
|
1714
|
+
|
|
1715
|
+
```js
|
|
1716
|
+
import {useStdin} from 'ink';
|
|
1717
|
+
|
|
1718
|
+
const Example = () => {
|
|
1719
|
+
const {stdin} = useStdin();
|
|
1720
|
+
|
|
1721
|
+
return …
|
|
1722
|
+
};
|
|
1723
|
+
```
|
|
1724
|
+
|
|
1725
|
+
#### isRawModeSupported
|
|
1726
|
+
|
|
1727
|
+
Type: `boolean`
|
|
1728
|
+
|
|
1729
|
+
A boolean flag determining if the current `stdin` supports `setRawMode`.
|
|
1730
|
+
A component using `setRawMode` might want to use `isRawModeSupported` to nicely fall back in environments where raw mode is not supported.
|
|
1731
|
+
|
|
1732
|
+
```jsx
|
|
1733
|
+
import {useStdin} from 'ink';
|
|
1734
|
+
|
|
1735
|
+
const Example = () => {
|
|
1736
|
+
const {isRawModeSupported} = useStdin();
|
|
1737
|
+
|
|
1738
|
+
return isRawModeSupported ? (
|
|
1739
|
+
<MyInputComponent />
|
|
1740
|
+
) : (
|
|
1741
|
+
<MyComponentThatDoesntUseInput />
|
|
1742
|
+
);
|
|
1743
|
+
};
|
|
1744
|
+
```
|
|
1745
|
+
|
|
1746
|
+
#### setRawMode(isRawModeEnabled)
|
|
1747
|
+
|
|
1748
|
+
Type: `function`
|
|
1749
|
+
|
|
1750
|
+
##### isRawModeEnabled
|
|
1751
|
+
|
|
1752
|
+
Type: `boolean`
|
|
1753
|
+
|
|
1754
|
+
See [`setRawMode`](https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode).
|
|
1755
|
+
Ink exposes this function to be able to handle <kbd>Ctrl</kbd>+<kbd>C</kbd>, that's why you should use Ink's `setRawMode` instead of `process.stdin.setRawMode`.
|
|
1756
|
+
|
|
1757
|
+
**Warning:** This function will throw unless the current `stdin` supports `setRawMode`. Use [`isRawModeSupported`](#israwmodesupported) to detect `setRawMode` support.
|
|
1758
|
+
|
|
1759
|
+
```js
|
|
1760
|
+
import {useStdin} from 'ink';
|
|
1761
|
+
|
|
1762
|
+
const Example = () => {
|
|
1763
|
+
const {setRawMode} = useStdin();
|
|
1764
|
+
|
|
1765
|
+
useEffect(() => {
|
|
1766
|
+
setRawMode(true);
|
|
1767
|
+
|
|
1768
|
+
return () => {
|
|
1769
|
+
setRawMode(false);
|
|
1770
|
+
};
|
|
1771
|
+
});
|
|
1772
|
+
|
|
1773
|
+
return …
|
|
1774
|
+
};
|
|
1775
|
+
```
|
|
1776
|
+
|
|
1777
|
+
### useStdout()
|
|
1778
|
+
|
|
1779
|
+
`useStdout` is a React hook that exposes the stdout stream where Ink renders your app.
|
|
1780
|
+
|
|
1781
|
+
#### stdout
|
|
1782
|
+
|
|
1783
|
+
Type: `stream.Writable`\
|
|
1784
|
+
Default: `process.stdout`
|
|
1785
|
+
|
|
1786
|
+
```js
|
|
1787
|
+
import {useStdout} from 'ink';
|
|
1788
|
+
|
|
1789
|
+
const Example = () => {
|
|
1790
|
+
const {stdout} = useStdout();
|
|
1791
|
+
|
|
1792
|
+
return …
|
|
1793
|
+
};
|
|
1794
|
+
```
|
|
1795
|
+
|
|
1796
|
+
#### write(data)
|
|
1797
|
+
|
|
1798
|
+
Write any string to stdout while preserving Ink's output.
|
|
1799
|
+
It's useful when you want to display external information outside of Ink's rendering and ensure there's no conflict between the two.
|
|
1800
|
+
It's similar to `<Static>`, except it can't accept components; it only works with strings.
|
|
1801
|
+
|
|
1802
|
+
##### data
|
|
1803
|
+
|
|
1804
|
+
Type: `string`
|
|
1805
|
+
|
|
1806
|
+
Data to write to stdout.
|
|
1807
|
+
|
|
1808
|
+
```js
|
|
1809
|
+
import {useStdout} from 'ink';
|
|
1810
|
+
|
|
1811
|
+
const Example = () => {
|
|
1812
|
+
const {write} = useStdout();
|
|
1813
|
+
|
|
1814
|
+
useEffect(() => {
|
|
1815
|
+
// Write a single message to stdout, above Ink's output
|
|
1816
|
+
write('Hello from Ink to stdout\n');
|
|
1817
|
+
}, []);
|
|
1818
|
+
|
|
1819
|
+
return …
|
|
1820
|
+
};
|
|
1821
|
+
```
|
|
1822
|
+
|
|
1823
|
+
See additional usage example in [examples/use-stdout](examples/use-stdout/use-stdout.tsx).
|
|
1824
|
+
|
|
1825
|
+
### useStderr()
|
|
1826
|
+
|
|
1827
|
+
`useStderr` is a React hook that exposes the stderr stream.
|
|
1828
|
+
|
|
1829
|
+
#### stderr
|
|
1830
|
+
|
|
1831
|
+
Type: `stream.Writable`\
|
|
1832
|
+
Default: `process.stderr`
|
|
1833
|
+
|
|
1834
|
+
Stderr stream.
|
|
1835
|
+
|
|
1836
|
+
```js
|
|
1837
|
+
import {useStderr} from 'ink';
|
|
1838
|
+
|
|
1839
|
+
const Example = () => {
|
|
1840
|
+
const {stderr} = useStderr();
|
|
1841
|
+
|
|
1842
|
+
return …
|
|
1843
|
+
};
|
|
1844
|
+
```
|
|
1845
|
+
|
|
1846
|
+
#### write(data)
|
|
1847
|
+
|
|
1848
|
+
Write any string to stderr while preserving Ink's output.
|
|
1849
|
+
|
|
1850
|
+
It's useful when you want to display external information outside of Ink's rendering and ensure there's no conflict between the two.
|
|
1851
|
+
It's similar to `<Static>`, except it can't accept components; it only works with strings.
|
|
1852
|
+
|
|
1853
|
+
##### data
|
|
1854
|
+
|
|
1855
|
+
Type: `string`
|
|
1856
|
+
|
|
1857
|
+
Data to write to stderr.
|
|
1858
|
+
|
|
1859
|
+
```js
|
|
1860
|
+
import {useStderr} from 'ink';
|
|
1861
|
+
|
|
1862
|
+
const Example = () => {
|
|
1863
|
+
const {write} = useStderr();
|
|
1864
|
+
|
|
1865
|
+
useEffect(() => {
|
|
1866
|
+
// Write a single message to stderr, above Ink's output
|
|
1867
|
+
write('Hello from Ink to stderr\n');
|
|
1868
|
+
}, []);
|
|
1869
|
+
|
|
1870
|
+
return …
|
|
1871
|
+
};
|
|
1872
|
+
```
|
|
1873
|
+
|
|
1874
|
+
### useFocus(options?)
|
|
1875
|
+
|
|
1876
|
+
A component that uses the `useFocus` hook becomes "focusable" to Ink, so when the user presses <kbd>Tab</kbd>, Ink will switch focus to this component.
|
|
1877
|
+
If there are multiple components that execute the `useFocus` hook, focus will be given to them in the order in which these components are rendered.
|
|
1878
|
+
This hook returns an object with an `isFocused` boolean property, which determines whether this component is focused.
|
|
1879
|
+
|
|
1880
|
+
#### options
|
|
1881
|
+
|
|
1882
|
+
##### autoFocus
|
|
1883
|
+
|
|
1884
|
+
Type: `boolean`\
|
|
1885
|
+
Default: `false`
|
|
1886
|
+
|
|
1887
|
+
Auto-focus this component if there's no active (focused) component right now.
|
|
1888
|
+
|
|
1889
|
+
##### isActive
|
|
1890
|
+
|
|
1891
|
+
Type: `boolean`\
|
|
1892
|
+
Default: `true`
|
|
1893
|
+
|
|
1894
|
+
Enable or disable this component's focus, while still maintaining its position in the list of focusable components.
|
|
1895
|
+
This is useful for inputs that are temporarily disabled.
|
|
1896
|
+
|
|
1897
|
+
##### id
|
|
1898
|
+
|
|
1899
|
+
Type: `string`\
|
|
1900
|
+
Required: `false`
|
|
1901
|
+
|
|
1902
|
+
Set a component's focus ID, which can be used to programmatically focus the component. This is useful for large interfaces with many focusable elements to avoid having to cycle through all of them.
|
|
1903
|
+
|
|
1904
|
+
```jsx
|
|
1905
|
+
import {render, useFocus, Text} from 'ink';
|
|
1906
|
+
|
|
1907
|
+
const Example = () => {
|
|
1908
|
+
const {isFocused} = useFocus();
|
|
1909
|
+
|
|
1910
|
+
return <Text>{isFocused ? 'I am focused' : 'I am not focused'}</Text>;
|
|
1911
|
+
};
|
|
1912
|
+
|
|
1913
|
+
render(<Example />);
|
|
1914
|
+
```
|
|
1915
|
+
|
|
1916
|
+
See example in [examples/use-focus](examples/use-focus/use-focus.tsx) and [examples/use-focus-with-id](examples/use-focus-with-id/use-focus-with-id.tsx).
|
|
1917
|
+
|
|
1918
|
+
### useFocusManager()
|
|
1919
|
+
|
|
1920
|
+
This hook exposes methods to enable or disable focus management for all components or manually switch focus to the next or previous components.
|
|
1921
|
+
|
|
1922
|
+
#### enableFocus()
|
|
1923
|
+
|
|
1924
|
+
Enable focus management for all components.
|
|
1925
|
+
|
|
1926
|
+
**Note:** You don't need to call this method manually unless you've disabled focus management. Focus management is enabled by default.
|
|
1927
|
+
|
|
1928
|
+
```js
|
|
1929
|
+
import {useFocusManager} from 'ink';
|
|
1930
|
+
|
|
1931
|
+
const Example = () => {
|
|
1932
|
+
const {enableFocus} = useFocusManager();
|
|
1933
|
+
|
|
1934
|
+
useEffect(() => {
|
|
1935
|
+
enableFocus();
|
|
1936
|
+
}, []);
|
|
1937
|
+
|
|
1938
|
+
return …
|
|
1939
|
+
};
|
|
1940
|
+
```
|
|
1941
|
+
|
|
1942
|
+
#### disableFocus()
|
|
1943
|
+
|
|
1944
|
+
Disable focus management for all components.
|
|
1945
|
+
The currently active component (if there's one) will lose its focus.
|
|
1946
|
+
|
|
1947
|
+
```js
|
|
1948
|
+
import {useFocusManager} from 'ink';
|
|
1949
|
+
|
|
1950
|
+
const Example = () => {
|
|
1951
|
+
const {disableFocus} = useFocusManager();
|
|
1952
|
+
|
|
1953
|
+
useEffect(() => {
|
|
1954
|
+
disableFocus();
|
|
1955
|
+
}, []);
|
|
1956
|
+
|
|
1957
|
+
return …
|
|
1958
|
+
};
|
|
1959
|
+
```
|
|
1960
|
+
|
|
1961
|
+
#### focusNext()
|
|
1962
|
+
|
|
1963
|
+
Switch focus to the next focusable component.
|
|
1964
|
+
If there's no active component right now, focus will be given to the first focusable component.
|
|
1965
|
+
If the active component is the last in the list of focusable components, focus will be switched to the first focusable component.
|
|
1966
|
+
|
|
1967
|
+
**Note:** Ink calls this method when user presses <kbd>Tab</kbd>.
|
|
1968
|
+
|
|
1969
|
+
```js
|
|
1970
|
+
import {useFocusManager} from 'ink';
|
|
1971
|
+
|
|
1972
|
+
const Example = () => {
|
|
1973
|
+
const {focusNext} = useFocusManager();
|
|
1974
|
+
|
|
1975
|
+
useEffect(() => {
|
|
1976
|
+
focusNext();
|
|
1977
|
+
}, []);
|
|
1978
|
+
|
|
1979
|
+
return …
|
|
1980
|
+
};
|
|
1981
|
+
```
|
|
1982
|
+
|
|
1983
|
+
#### focusPrevious()
|
|
1984
|
+
|
|
1985
|
+
Switch focus to the previous focusable component.
|
|
1986
|
+
If there's no active component right now, focus will be given to the first focusable component.
|
|
1987
|
+
If the active component is the first in the list of focusable components, focus will be switched to the last focusable component.
|
|
1988
|
+
|
|
1989
|
+
**Note:** Ink calls this method when user presses <kbd>Shift</kbd>+<kbd>Tab</kbd>.
|
|
1990
|
+
|
|
1991
|
+
```js
|
|
1992
|
+
import {useFocusManager} from 'ink';
|
|
1993
|
+
|
|
1994
|
+
const Example = () => {
|
|
1995
|
+
const {focusPrevious} = useFocusManager();
|
|
1996
|
+
|
|
1997
|
+
useEffect(() => {
|
|
1998
|
+
focusPrevious();
|
|
1999
|
+
}, []);
|
|
2000
|
+
|
|
2001
|
+
return …
|
|
2002
|
+
};
|
|
2003
|
+
```
|
|
2004
|
+
|
|
2005
|
+
#### focus(id)
|
|
2006
|
+
|
|
2007
|
+
##### id
|
|
2008
|
+
|
|
2009
|
+
Type: `string`
|
|
2010
|
+
|
|
2011
|
+
Switch focus to the component with the given [`id`](#id).
|
|
2012
|
+
If there's no component with that ID, focus will be given to the next focusable component.
|
|
2013
|
+
|
|
2014
|
+
```js
|
|
2015
|
+
import {useFocusManager, useInput} from 'ink';
|
|
2016
|
+
|
|
2017
|
+
const Example = () => {
|
|
2018
|
+
const {focus} = useFocusManager();
|
|
2019
|
+
|
|
2020
|
+
useInput(input => {
|
|
2021
|
+
if (input === 's') {
|
|
2022
|
+
// Focus the component with focus ID 'someId'
|
|
2023
|
+
focus('someId');
|
|
2024
|
+
}
|
|
2025
|
+
});
|
|
2026
|
+
|
|
2027
|
+
return …
|
|
2028
|
+
};
|
|
2029
|
+
```
|
|
2030
|
+
|
|
2031
|
+
### useCursor()
|
|
2032
|
+
|
|
2033
|
+
`useCursor` lets you control the terminal cursor position after each render. This is essential for IME (Input Method Editor) support, where the composing character is displayed at the cursor location.
|
|
2034
|
+
|
|
2035
|
+
```jsx
|
|
2036
|
+
import {useState} from 'react';
|
|
2037
|
+
import {Box, Text, useCursor} from 'ink';
|
|
2038
|
+
import stringWidth from 'string-width';
|
|
2039
|
+
|
|
2040
|
+
const TextInput = () => {
|
|
2041
|
+
const [text, setText] = useState('');
|
|
2042
|
+
const {setCursorPosition} = useCursor();
|
|
2043
|
+
|
|
2044
|
+
const prompt = '> ';
|
|
2045
|
+
setCursorPosition({x: stringWidth(prompt + text), y: 1});
|
|
2046
|
+
|
|
2047
|
+
return (
|
|
2048
|
+
<Box flexDirection="column">
|
|
2049
|
+
<Text>Type here:</Text>
|
|
2050
|
+
<Text>{prompt}{text}</Text>
|
|
2051
|
+
</Box>
|
|
2052
|
+
);
|
|
2053
|
+
};
|
|
2054
|
+
```
|
|
2055
|
+
|
|
2056
|
+
#### setCursorPosition(position)
|
|
2057
|
+
|
|
2058
|
+
Set the cursor position relative to the Ink output. Pass `undefined` to hide the cursor.
|
|
2059
|
+
|
|
2060
|
+
##### position
|
|
2061
|
+
|
|
2062
|
+
Type: `object | undefined`
|
|
2063
|
+
|
|
2064
|
+
Use [`string-width`](https://github.com/sindresorhus/string-width) to calculate `x` for strings containing wide characters (CJK, emoji).
|
|
2065
|
+
|
|
2066
|
+
See a full example at [examples/cursor-ime](examples/cursor-ime/cursor-ime.tsx).
|
|
2067
|
+
|
|
2068
|
+
###### x
|
|
2069
|
+
|
|
2070
|
+
Type: `number`
|
|
2071
|
+
|
|
2072
|
+
Column position (0-based).
|
|
2073
|
+
|
|
2074
|
+
###### y
|
|
2075
|
+
|
|
2076
|
+
Type: `number`
|
|
2077
|
+
|
|
2078
|
+
Row position from the top of the Ink output (0 = first line).
|
|
2079
|
+
|
|
2080
|
+
### useIsScreenReaderEnabled()
|
|
2081
|
+
|
|
2082
|
+
Returns whether a screen reader is enabled. This is useful when you want to render different output for screen readers.
|
|
2083
|
+
|
|
2084
|
+
```jsx
|
|
2085
|
+
import {useIsScreenReaderEnabled, Text} from 'ink';
|
|
2086
|
+
|
|
2087
|
+
const Example = () => {
|
|
2088
|
+
const isScreenReaderEnabled = useIsScreenReaderEnabled();
|
|
2089
|
+
|
|
2090
|
+
return (
|
|
2091
|
+
<Text>
|
|
2092
|
+
{isScreenReaderEnabled
|
|
2093
|
+
? 'Screen reader is enabled'
|
|
2094
|
+
: 'Screen reader is disabled'}
|
|
2095
|
+
</Text>
|
|
2096
|
+
);
|
|
2097
|
+
};
|
|
2098
|
+
```
|
|
2099
|
+
|
|
2100
|
+
## API
|
|
2101
|
+
|
|
2102
|
+
#### render(tree, options?)
|
|
2103
|
+
|
|
2104
|
+
Returns: [`Instance`](#instance)
|
|
2105
|
+
|
|
2106
|
+
Mount a component and render the output.
|
|
2107
|
+
|
|
2108
|
+
##### tree
|
|
2109
|
+
|
|
2110
|
+
Type: `ReactNode`
|
|
2111
|
+
|
|
2112
|
+
##### options
|
|
2113
|
+
|
|
2114
|
+
Type: `object`
|
|
2115
|
+
|
|
2116
|
+
###### stdout
|
|
2117
|
+
|
|
2118
|
+
Type: `stream.Writable`\
|
|
2119
|
+
Default: `process.stdout`
|
|
2120
|
+
|
|
2121
|
+
Output stream where the app will be rendered.
|
|
2122
|
+
|
|
2123
|
+
###### stdin
|
|
2124
|
+
|
|
2125
|
+
Type: `stream.Readable`\
|
|
2126
|
+
Default: `process.stdin`
|
|
2127
|
+
|
|
2128
|
+
Input stream where app will listen for input.
|
|
2129
|
+
|
|
2130
|
+
###### stderr
|
|
2131
|
+
|
|
2132
|
+
Type: `stream.Writable`\
|
|
2133
|
+
Default: `process.stderr`
|
|
2134
|
+
|
|
2135
|
+
Error stream.
|
|
2136
|
+
|
|
2137
|
+
###### exitOnCtrlC
|
|
2138
|
+
|
|
2139
|
+
Type: `boolean`\
|
|
2140
|
+
Default: `true`
|
|
2141
|
+
|
|
2142
|
+
Configure whether Ink should listen for Ctrl+C keyboard input and exit the app.
|
|
2143
|
+
This is needed in case `process.stdin` is in [raw mode](https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode), because then Ctrl+C is ignored by default and the process is expected to handle it manually.
|
|
2144
|
+
|
|
2145
|
+
###### patchConsole
|
|
2146
|
+
|
|
2147
|
+
Type: `boolean`\
|
|
2148
|
+
Default: `true`
|
|
2149
|
+
|
|
2150
|
+
Patch console methods to ensure console output doesn't mix with Ink's output.
|
|
2151
|
+
When any of the `console.*` methods are called (like `console.log()`), Ink intercepts their output, clears the main output, renders output from the console method, and then rerenders the main output again.
|
|
2152
|
+
That way, both are visible and don't overlap each other.
|
|
2153
|
+
|
|
2154
|
+
This functionality is powered by [patch-console](https://github.com/vadimdemedes/patch-console), so if you need to disable Ink's interception of output but want to build something custom, you can use that.
|
|
2155
|
+
|
|
2156
|
+
###### onRender
|
|
2157
|
+
|
|
2158
|
+
Type: `({renderTime: number}) => void`\
|
|
2159
|
+
Default: `undefined`
|
|
2160
|
+
|
|
2161
|
+
Runs the given callback after each render and re-render with a metrics object.
|
|
2162
|
+
|
|
2163
|
+
###### isScreenReaderEnabled
|
|
2164
|
+
|
|
2165
|
+
Type: `boolean`\
|
|
2166
|
+
Default: `process.env['INK_SCREEN_READER'] === 'true'`
|
|
2167
|
+
|
|
2168
|
+
Enable screen reader support. See [Screen Reader Support](#screen-reader-support).
|
|
2169
|
+
|
|
2170
|
+
###### debug
|
|
2171
|
+
|
|
2172
|
+
Type: `boolean`\
|
|
2173
|
+
Default: `false`
|
|
2174
|
+
|
|
2175
|
+
If `true`, each update will be rendered as separate output, without replacing the previous one.
|
|
2176
|
+
|
|
2177
|
+
###### maxFps
|
|
2178
|
+
|
|
2179
|
+
Type: `number`\
|
|
2180
|
+
Default: `30`
|
|
2181
|
+
|
|
2182
|
+
Maximum frames per second for render updates.
|
|
2183
|
+
This controls how frequently the UI can update to prevent excessive re-rendering.
|
|
2184
|
+
Higher values allow more frequent updates but may impact performance.
|
|
2185
|
+
Setting it to a lower value may be useful for components that update very frequently, to reduce CPU usage.
|
|
2186
|
+
|
|
2187
|
+
###### incrementalRendering
|
|
2188
|
+
|
|
2189
|
+
Type: `boolean`\
|
|
2190
|
+
Default: `false`
|
|
2191
|
+
|
|
2192
|
+
Enable incremental rendering mode which only updates changed lines instead of redrawing the entire output.
|
|
2193
|
+
This can reduce flickering and improve performance for frequently updating UIs.
|
|
2194
|
+
|
|
2195
|
+
###### concurrent
|
|
2196
|
+
|
|
2197
|
+
Type: `boolean`\
|
|
2198
|
+
Default: `false`
|
|
2199
|
+
|
|
2200
|
+
Enable React Concurrent Rendering mode.
|
|
2201
|
+
|
|
2202
|
+
When enabled:
|
|
2203
|
+
- Suspense boundaries work correctly with async data fetching
|
|
2204
|
+
- `useTransition` and `useDeferredValue` hooks are fully functional
|
|
2205
|
+
- Updates can be interrupted for higher priority work
|
|
2206
|
+
|
|
2207
|
+
```jsx
|
|
2208
|
+
render(<MyApp />, {concurrent: true});
|
|
2209
|
+
```
|
|
2210
|
+
|
|
2211
|
+
**Note:** Concurrent mode changes the timing of renders. Some tests may need to use `act()` to properly await updates. The `concurrent` option only takes effect on the first render for a given stdout. If you need to change the rendering mode, call `unmount()` first.
|
|
2212
|
+
|
|
2213
|
+
###### kittyKeyboard
|
|
2214
|
+
|
|
2215
|
+
Type: `object`\
|
|
2216
|
+
Default: `undefined`
|
|
2217
|
+
|
|
2218
|
+
Enable the [kitty keyboard protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol/) for enhanced keyboard input handling. When enabled, terminals that support the protocol will report additional key information including `super`, `hyper`, `capsLock`, `numLock` modifiers and `eventType` (press/repeat/release).
|
|
2219
|
+
|
|
2220
|
+
```jsx
|
|
2221
|
+
import {render} from 'ink';
|
|
2222
|
+
|
|
2223
|
+
render(<MyApp />, {kittyKeyboard: {mode: 'auto'}});
|
|
2224
|
+
```
|
|
2225
|
+
|
|
2226
|
+
```jsx
|
|
2227
|
+
import {render} from 'ink';
|
|
2228
|
+
|
|
2229
|
+
render(<MyApp />, {
|
|
2230
|
+
kittyKeyboard: {
|
|
2231
|
+
mode: 'enabled',
|
|
2232
|
+
flags: ['disambiguateEscapeCodes', 'reportEventTypes'],
|
|
2233
|
+
},
|
|
2234
|
+
});
|
|
2235
|
+
```
|
|
2236
|
+
|
|
2237
|
+
**kittyKeyboard.mode**
|
|
2238
|
+
|
|
2239
|
+
Type: `'auto' | 'enabled' | 'disabled'`\
|
|
2240
|
+
Default: `'auto'`
|
|
2241
|
+
|
|
2242
|
+
- `'auto'`: Detect terminal support using a heuristic precheck (known terminals like kitty, WezTerm, Ghostty) followed by a protocol query confirmation (`CSI ? u`). The protocol is only enabled if the terminal responds to the query within a short timeout.
|
|
2243
|
+
- `'enabled'`: Force enable the protocol. Both stdin and stdout must be TTYs.
|
|
2244
|
+
- `'disabled'`: Never enable the protocol.
|
|
2245
|
+
|
|
2246
|
+
**kittyKeyboard.flags**
|
|
2247
|
+
|
|
2248
|
+
Type: `string[]`\
|
|
2249
|
+
Default: `['disambiguateEscapeCodes']`
|
|
2250
|
+
|
|
2251
|
+
Protocol flags to request from the terminal. Pass an array of flag name strings.
|
|
2252
|
+
|
|
2253
|
+
Available flags:
|
|
2254
|
+
- `'disambiguateEscapeCodes'` - Disambiguate escape codes
|
|
2255
|
+
- `'reportEventTypes'` - Report key press, repeat, and release events
|
|
2256
|
+
- `'reportAlternateKeys'` - Report alternate key encodings
|
|
2257
|
+
- `'reportAllKeysAsEscapeCodes'` - Report all keys as escape codes
|
|
2258
|
+
- `'reportAssociatedText'` - Report associated text with key events
|
|
2259
|
+
|
|
2260
|
+
**Behavior notes**
|
|
2261
|
+
|
|
2262
|
+
When the kitty keyboard protocol is enabled, input handling changes in several ways:
|
|
2263
|
+
|
|
2264
|
+
- **Non-printable keys produce empty input.** Keys like function keys (F1-F35), modifier-only keys (Shift, Control, Super), media keys, Caps Lock, Print Screen, and similar keys will not produce any text in the `input` parameter of `useInput`. They can still be detected via the `key` object properties.
|
|
2265
|
+
- **Ctrl+letter shortcuts work as expected.** When the terminal sends `Ctrl+letter` as codepoint 1-26 (the kitty CSI-u alternate form), `input` is set to the letter name (e.g. `'c'` for `Ctrl+C`) and `key.ctrl` is `true`. This ensures `exitOnCtrlC` and custom `Ctrl+letter` handlers continue to work regardless of which codepoint form the terminal uses.
|
|
2266
|
+
- **Key disambiguation.** The protocol allows the terminal to distinguish between keys that normally produce the same escape sequence. For example:
|
|
2267
|
+
- `Ctrl+I` vs `Tab` - without the protocol, both produce the same byte (`\x09`). With the protocol, they are reported as distinct keys.
|
|
2268
|
+
- `Shift+Enter` vs `Enter` - the shift modifier is correctly reported.
|
|
2269
|
+
- `Escape` key vs `Ctrl+[` - these are disambiguated.
|
|
2270
|
+
- **Event types.** With the `reportEventTypes` flag, key press, repeat, and release events are distinguished via `key.eventType`.
|
|
2271
|
+
|
|
2272
|
+
#### renderToString(tree, options?)
|
|
2273
|
+
|
|
2274
|
+
Returns: `string`
|
|
2275
|
+
|
|
2276
|
+
Render a React element to a string synchronously. Unlike `render()`, this function does not write to stdout, does not set up any terminal event listeners, and returns the rendered output as a string.
|
|
2277
|
+
|
|
2278
|
+
Useful for generating documentation, writing output to files, testing, or any scenario where you need the rendered output as a string without starting a persistent terminal application.
|
|
2279
|
+
|
|
2280
|
+
```jsx
|
|
2281
|
+
import {renderToString, Text, Box} from 'ink';
|
|
2282
|
+
|
|
2283
|
+
const output = renderToString(
|
|
2284
|
+
<Box padding={1}>
|
|
2285
|
+
<Text color="green">Hello World</Text>
|
|
2286
|
+
</Box>,
|
|
2287
|
+
);
|
|
2288
|
+
|
|
2289
|
+
console.log(output);
|
|
2290
|
+
```
|
|
2291
|
+
|
|
2292
|
+
**Notes:**
|
|
2293
|
+
|
|
2294
|
+
- Terminal-specific hooks (`useInput`, `useStdin`, `useStdout`, `useStderr`, `useApp`, `useFocus`, `useFocusManager`) return default no-op values since there is no terminal session. They will not throw, but they will not function as in a live terminal.
|
|
2295
|
+
- `useEffect` callbacks will execute during rendering (due to synchronous rendering mode), but state updates they trigger will not affect the returned output, which reflects the initial render.
|
|
2296
|
+
- `useLayoutEffect` callbacks fire synchronously during commit, so state updates they trigger **will** be reflected in the output.
|
|
2297
|
+
- The `<Static>` component is supported — its output is prepended to the dynamic output.
|
|
2298
|
+
- If a component throws during rendering, the error is propagated to the caller after cleanup.
|
|
2299
|
+
|
|
2300
|
+
##### tree
|
|
2301
|
+
|
|
2302
|
+
Type: `ReactNode`
|
|
2303
|
+
|
|
2304
|
+
##### options
|
|
2305
|
+
|
|
2306
|
+
Type: `object`
|
|
2307
|
+
|
|
2308
|
+
###### columns
|
|
2309
|
+
|
|
2310
|
+
Type: `number`\
|
|
2311
|
+
Default: `80`
|
|
2312
|
+
|
|
2313
|
+
Width of the virtual terminal in columns. Controls where text wrapping occurs.
|
|
2314
|
+
|
|
2315
|
+
```jsx
|
|
2316
|
+
const output = renderToString(<Text>{'A'.repeat(100)}</Text>, {
|
|
2317
|
+
columns: 40,
|
|
2318
|
+
});
|
|
2319
|
+
// Text wraps at 40 columns
|
|
2320
|
+
```
|
|
2321
|
+
|
|
2322
|
+
#### Instance
|
|
2323
|
+
|
|
2324
|
+
This is the object that `render()` returns.
|
|
2325
|
+
|
|
2326
|
+
##### rerender(tree)
|
|
2327
|
+
|
|
2328
|
+
Replace the previous root node with a new one or update the props of the current root node.
|
|
2329
|
+
|
|
2330
|
+
###### tree
|
|
2331
|
+
|
|
2332
|
+
Type: `ReactNode`
|
|
2333
|
+
|
|
2334
|
+
```jsx
|
|
2335
|
+
// Update props of the root node
|
|
2336
|
+
const {rerender} = render(<Counter count={1} />);
|
|
2337
|
+
rerender(<Counter count={2} />);
|
|
2338
|
+
|
|
2339
|
+
// Replace root node
|
|
2340
|
+
const {rerender} = render(<OldCounter />);
|
|
2341
|
+
rerender(<NewCounter />);
|
|
2342
|
+
```
|
|
2343
|
+
|
|
2344
|
+
##### unmount()
|
|
2345
|
+
|
|
2346
|
+
Manually unmount the whole Ink app.
|
|
2347
|
+
|
|
2348
|
+
```jsx
|
|
2349
|
+
const {unmount} = render(<MyApp />);
|
|
2350
|
+
unmount();
|
|
2351
|
+
```
|
|
2352
|
+
|
|
2353
|
+
##### waitUntilExit()
|
|
2354
|
+
|
|
2355
|
+
Returns a promise that settles when the app is unmounted.
|
|
2356
|
+
|
|
2357
|
+
It resolves with the value passed to `exit(value)` and rejects with the error passed to `exit(error)`.
|
|
2358
|
+
|
|
2359
|
+
```jsx
|
|
2360
|
+
const {unmount, waitUntilExit} = render(<MyApp />);
|
|
2361
|
+
|
|
2362
|
+
setTimeout(unmount, 1000);
|
|
2363
|
+
|
|
2364
|
+
await waitUntilExit(); // resolves after `unmount()` is called
|
|
2365
|
+
```
|
|
2366
|
+
|
|
2367
|
+
##### cleanup()
|
|
2368
|
+
|
|
2369
|
+
Delete the internal Ink instance associated with the current `stdout`.
|
|
2370
|
+
This is mostly useful for advanced cases (for example, tests) where you need `render()` to create a fresh instance for the same stream.
|
|
2371
|
+
This does not unmount the current app.
|
|
2372
|
+
|
|
2373
|
+
##### clear()
|
|
2374
|
+
|
|
2375
|
+
Clear output.
|
|
2376
|
+
|
|
2377
|
+
```jsx
|
|
2378
|
+
const {clear} = render(<MyApp />);
|
|
2379
|
+
clear();
|
|
2380
|
+
```
|
|
2381
|
+
|
|
2382
|
+
#### measureElement(ref)
|
|
2383
|
+
|
|
2384
|
+
Measure the dimensions of a particular `<Box>` element.
|
|
2385
|
+
Returns an object with `width` and `height` properties.
|
|
2386
|
+
This function is useful when your component needs to know the amount of available space it has. You can use it when you need to change the layout based on the length of its content.
|
|
2387
|
+
|
|
2388
|
+
**Note:** `measureElement()` returns correct results only after the initial render, when the layout has been calculated. Until then, `width` and `height` equal zero. It's recommended to call `measureElement()` in a `useEffect` hook, which fires after the component has rendered.
|
|
2389
|
+
|
|
2390
|
+
##### ref
|
|
2391
|
+
|
|
2392
|
+
Type: `MutableRef`
|
|
2393
|
+
|
|
2394
|
+
A reference to a `<Box>` element captured with the `ref` property.
|
|
2395
|
+
See [Refs](https://reactjs.org/docs/refs-and-the-dom.html) for more information on how to capture references.
|
|
2396
|
+
|
|
2397
|
+
```jsx
|
|
2398
|
+
import {render, measureElement, Box, Text} from 'ink';
|
|
2399
|
+
|
|
2400
|
+
const Example = () => {
|
|
2401
|
+
const ref = useRef();
|
|
2402
|
+
|
|
2403
|
+
useEffect(() => {
|
|
2404
|
+
const {width, height} = measureElement(ref.current);
|
|
2405
|
+
// width = 100, height = 1
|
|
2406
|
+
}, []);
|
|
2407
|
+
|
|
2408
|
+
return (
|
|
2409
|
+
<Box width={100}>
|
|
2410
|
+
<Box ref={ref}>
|
|
2411
|
+
<Text>This box will stretch to 100 width</Text>
|
|
2412
|
+
</Box>
|
|
2413
|
+
</Box>
|
|
2414
|
+
);
|
|
2415
|
+
};
|
|
2416
|
+
|
|
2417
|
+
render(<Example />);
|
|
2418
|
+
```
|
|
2419
|
+
|
|
2420
|
+
## Testing
|
|
2421
|
+
|
|
2422
|
+
Ink components are simple to test with [ink-testing-library](https://github.com/vadimdemedes/ink-testing-library).
|
|
2423
|
+
Here's a simple example that checks how the component is rendered:
|
|
2424
|
+
|
|
2425
|
+
```jsx
|
|
2426
|
+
import React from 'react';
|
|
2427
|
+
import {Text} from 'ink';
|
|
2428
|
+
import {render} from 'ink-testing-library';
|
|
2429
|
+
|
|
2430
|
+
const Test = () => <Text>Hello World</Text>;
|
|
2431
|
+
const {lastFrame} = render(<Test />);
|
|
2432
|
+
|
|
2433
|
+
lastFrame() === 'Hello World'; //=> true
|
|
2434
|
+
```
|
|
2435
|
+
|
|
2436
|
+
Check out [ink-testing-library](https://github.com/vadimdemedes/ink-testing-library) for more examples and full documentation.
|
|
2437
|
+
|
|
2438
|
+
## Using React Devtools
|
|
2439
|
+
|
|
2440
|
+

|
|
2441
|
+
|
|
2442
|
+
Ink supports [React Devtools](https://github.com/facebook/react/tree/master/packages/react-devtools) out of the box. To enable integration with React Devtools in your Ink-based CLI, first ensure you have installed the optional `react-devtools-core` dependency, and then run your app with the `DEV=true` environment variable:
|
|
2443
|
+
|
|
2444
|
+
```sh
|
|
2445
|
+
DEV=true my-cli
|
|
2446
|
+
```
|
|
2447
|
+
|
|
2448
|
+
Then, start React Devtools itself:
|
|
2449
|
+
|
|
2450
|
+
```sh
|
|
2451
|
+
npx react-devtools
|
|
2452
|
+
```
|
|
2453
|
+
|
|
2454
|
+
After it starts, you should see the component tree of your CLI.
|
|
2455
|
+
You can even inspect and change the props of components, and see the results immediately in the CLI, without restarting it.
|
|
2456
|
+
|
|
2457
|
+
**Note**: You must manually quit your CLI via <kbd>Ctrl</kbd>+<kbd>C</kbd> after you're done testing.
|
|
2458
|
+
|
|
2459
|
+
## Screen Reader Support
|
|
2460
|
+
|
|
2461
|
+
Ink has basic support for screen readers.
|
|
2462
|
+
|
|
2463
|
+
To enable it, you can either pass the `isScreenReaderEnabled` option to the `render` function or set the `INK_SCREEN_READER` environment variable to `true`.
|
|
2464
|
+
|
|
2465
|
+
Ink implements a small subset of functionality from the [ARIA specification](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA).
|
|
2466
|
+
|
|
2467
|
+
```jsx
|
|
2468
|
+
render(<MyApp />, {isScreenReaderEnabled: true});
|
|
2469
|
+
```
|
|
2470
|
+
|
|
2471
|
+
When screen reader support is enabled, Ink will try its best to generate a screen-reader-friendly output.
|
|
2472
|
+
|
|
2473
|
+
For example, for this code:
|
|
2474
|
+
|
|
2475
|
+
```jsx
|
|
2476
|
+
<Box aria-role="checkbox" aria-state={{checked: true}}>
|
|
2477
|
+
<Text>Accept terms and conditions</Text>
|
|
2478
|
+
</Box>
|
|
2479
|
+
```
|
|
2480
|
+
|
|
2481
|
+
Ink will generate the following output for screen readers:
|
|
2482
|
+
|
|
2483
|
+
```
|
|
2484
|
+
(checked) checkbox: Accept terms and conditions
|
|
2485
|
+
```
|
|
2486
|
+
|
|
2487
|
+
You can also provide a custom label for screen readers if you want to render something different for them.
|
|
2488
|
+
|
|
2489
|
+
For example, if you are building a progress bar, you can use `aria-label` to provide a more descriptive label for screen readers.
|
|
2490
|
+
|
|
2491
|
+
```jsx
|
|
2492
|
+
<Box>
|
|
2493
|
+
<Box width="50%" height={1} backgroundColor="green" />
|
|
2494
|
+
<Text aria-label="Progress: 50%">50%</Text>
|
|
2495
|
+
</Box>
|
|
2496
|
+
```
|
|
2497
|
+
|
|
2498
|
+
In the example above, the screen reader will read "Progress: 50%" instead of "50%".
|
|
2499
|
+
|
|
2500
|
+
### `aria-label`
|
|
2501
|
+
|
|
2502
|
+
Type: `string`
|
|
2503
|
+
|
|
2504
|
+
A label for the element for screen readers.
|
|
2505
|
+
|
|
2506
|
+
### `aria-hidden`
|
|
2507
|
+
|
|
2508
|
+
Type: `boolean`\
|
|
2509
|
+
Default: `false`
|
|
2510
|
+
|
|
2511
|
+
Hide the element from screen readers.
|
|
2512
|
+
|
|
2513
|
+
##### aria-role
|
|
2514
|
+
|
|
2515
|
+
Type: `string`
|
|
2516
|
+
|
|
2517
|
+
The role of the element.
|
|
2518
|
+
|
|
2519
|
+
Supported values:
|
|
2520
|
+
- `button`
|
|
2521
|
+
- `checkbox`
|
|
2522
|
+
- `radio`
|
|
2523
|
+
- `radiogroup`
|
|
2524
|
+
- `list`
|
|
2525
|
+
- `listitem`
|
|
2526
|
+
- `menu`
|
|
2527
|
+
- `menuitem`
|
|
2528
|
+
- `progressbar`
|
|
2529
|
+
- `tab`
|
|
2530
|
+
- `tablist`
|
|
2531
|
+
- `timer`
|
|
2532
|
+
- `toolbar`
|
|
2533
|
+
- `table`
|
|
2534
|
+
|
|
2535
|
+
##### aria-state
|
|
2536
|
+
|
|
2537
|
+
Type: `object`
|
|
2538
|
+
|
|
2539
|
+
The state of the element.
|
|
2540
|
+
|
|
2541
|
+
Supported values:
|
|
2542
|
+
- `checked` (boolean)
|
|
2543
|
+
- `disabled` (boolean)
|
|
2544
|
+
- `expanded` (boolean)
|
|
2545
|
+
- `selected` (boolean)
|
|
2546
|
+
|
|
2547
|
+
## Creating Components
|
|
2548
|
+
|
|
2549
|
+
When building custom components, it's important to keep accessibility in mind. While Ink provides the building blocks, ensuring your components are accessible will make your CLIs usable by a wider audience.
|
|
2550
|
+
|
|
2551
|
+
### General Principles
|
|
2552
|
+
|
|
2553
|
+
- **Provide screen reader-friendly output:** Use the `useIsScreenReaderEnabled` hook to detect if a screen reader is active. You can then render more descriptive output for screen reader users.
|
|
2554
|
+
- **Leverage ARIA props:** For components that have a specific role (e.g., a checkbox or button), use the `aria-role`, `aria-state`, and `aria-label` props on `<Box>` and `<Text>` to provide semantic meaning to screen readers.
|
|
2555
|
+
|
|
2556
|
+
For a practical example of building an accessible component, see the [ARIA example](/examples/aria/aria.tsx).
|
|
2557
|
+
|
|
2558
|
+
## Useful Components
|
|
2559
|
+
|
|
2560
|
+
- [ink-text-input](https://github.com/vadimdemedes/ink-text-input) - Text input.
|
|
2561
|
+
- [ink-spinner](https://github.com/vadimdemedes/ink-spinner) - Spinner.
|
|
2562
|
+
- [ink-select-input](https://github.com/vadimdemedes/ink-select-input) - Select (dropdown) input.
|
|
2563
|
+
- [ink-link](https://github.com/sindresorhus/ink-link) - Link.
|
|
2564
|
+
- [ink-gradient](https://github.com/sindresorhus/ink-gradient) - Gradient color.
|
|
2565
|
+
- [ink-big-text](https://github.com/sindresorhus/ink-big-text) - Awesome text.
|
|
2566
|
+
- [ink-picture](https://github.com/endernoke/ink-picture) - Display images.
|
|
2567
|
+
- [ink-tab](https://github.com/jdeniau/ink-tab) - Tab.
|
|
2568
|
+
- [ink-color-pipe](https://github.com/LitoMore/ink-color-pipe) - Create color text with simpler style strings.
|
|
2569
|
+
- [ink-multi-select](https://github.com/karaggeorge/ink-multi-select) - Select one or more values from a list
|
|
2570
|
+
- [ink-divider](https://github.com/JureSotosek/ink-divider) - A divider.
|
|
2571
|
+
- [ink-progress-bar](https://github.com/brigand/ink-progress-bar) - Progress bar.
|
|
2572
|
+
- [ink-table](https://github.com/maticzav/ink-table) - Table.
|
|
2573
|
+
- [ink-ascii](https://github.com/hexrcs/ink-ascii) - Awesome text component with more font choices, based on Figlet.
|
|
2574
|
+
- [ink-markdown](https://github.com/cameronhunter/ink-markdown) - Render syntax highlighted Markdown.
|
|
2575
|
+
- [ink-quicksearch-input](https://github.com/Eximchain/ink-quicksearch-input) - Select component with fast, quicksearch-like navigation.
|
|
2576
|
+
- [ink-confirm-input](https://github.com/kevva/ink-confirm-input) - Yes/No confirmation input.
|
|
2577
|
+
- [ink-syntax-highlight](https://github.com/vsashyn/ink-syntax-highlight) - Code syntax highlighting.
|
|
2578
|
+
- [ink-form](https://github.com/lukasbach/ink-form) - Form.
|
|
2579
|
+
- [ink-task-list](https://github.com/privatenumber/ink-task-list) - Task list.
|
|
2580
|
+
- [ink-spawn](https://github.com/kraenhansen/ink-spawn) - Spawn child processes.
|
|
2581
|
+
- [ink-titled-box](https://github.com/mishieck/ink-titled-box) - Box with a title.
|
|
2582
|
+
- [ink-chart](https://github.com/pppp606/ink-chart) - Sparkline and bar chart.
|
|
2583
|
+
- [ink-scroll-view](https://github.com/ByteLandTechnology/ink-scroll-view) - Scroll container.
|
|
2584
|
+
- [ink-scroll-list](https://github.com/ByteLandTechnology/ink-scroll-list) - Scrollable list.
|
|
2585
|
+
- [ink-stepper](https://github.com/archcorsair/ink-stepper) - Step-by-step wizard.
|
|
2586
|
+
- [ink-virtual-list](https://github.com/archcorsair/ink-virtual-list) - Virtualized list that renders only visible items for performance.
|
|
2587
|
+
- [ink-color-picker](https://github.com/sina-byn/ink-color-picker) - Color picker.
|
|
2588
|
+
|
|
2589
|
+
## Useful Hooks
|
|
2590
|
+
|
|
2591
|
+
- [ink-use-stdout-dimensions](https://github.com/cameronhunter/ink-monorepo/tree/master/packages/ink-use-stdout-dimensions) - Subscribe to stdout dimensions.
|
|
2592
|
+
|
|
2593
|
+
## Recipes
|
|
2594
|
+
|
|
2595
|
+
- [Routing with React Router](recipes/routing.md) - Navigate between routes using `MemoryRouter`.
|
|
2596
|
+
|
|
2597
|
+
## Examples
|
|
2598
|
+
|
|
2599
|
+
The [`examples`](/examples) directory contains a set of real examples. You can run them with:
|
|
2600
|
+
|
|
2601
|
+
```bash
|
|
2602
|
+
npm run example examples/[example name]
|
|
2603
|
+
# e.g. npm run example examples/borders
|
|
2604
|
+
```
|
|
2605
|
+
|
|
2606
|
+
- [Jest](examples/jest/jest.tsx) - Implementation of basic Jest UI.
|
|
2607
|
+
- [Counter](examples/counter/counter.tsx) - A simple counter that increments every 100ms.
|
|
2608
|
+
- [Form with validation](https://github.com/final-form/rff-cli-example) - Manage form state using [Final Form](https://github.com/final-form/final-form#-final-form).
|
|
2609
|
+
- [Borders](examples/borders/borders.tsx) - Add borders to the `<Box>` component.
|
|
2610
|
+
- [Suspense](examples/suspense/suspense.tsx) - Use React Suspense.
|
|
2611
|
+
- [Table](examples/table/table.tsx) - Renders a table with multiple columns and rows.
|
|
2612
|
+
- [Focus management](examples/use-focus/use-focus.tsx) - Use the `useFocus` hook to manage focus between components.
|
|
2613
|
+
- [User input](examples/use-input/use-input.tsx) - Listen for user input.
|
|
2614
|
+
- [Write to stdout](examples/use-stdout/use-stdout.tsx) - Write to stdout, bypassing main Ink output.
|
|
2615
|
+
- [Write to stderr](examples/use-stderr/use-stderr.tsx) - Write to stderr, bypassing main Ink output.
|
|
2616
|
+
- [Static](examples/static/static.tsx) - Use the `<Static>` component to render permanent output.
|
|
2617
|
+
- [Child process](examples/subprocess-output) - Renders output from a child process.
|
|
2618
|
+
- [Router](examples/router/router.tsx) - Navigate between routes using React Router's `MemoryRouter`.
|
|
2619
|
+
|
|
2620
|
+
## Continuous Integration
|
|
2621
|
+
|
|
2622
|
+
When running on CI (detected via the `CI` environment variable), Ink adapts its rendering:
|
|
2623
|
+
|
|
2624
|
+
- Only the last frame is rendered on exit, instead of continuously updating the terminal. This is because most CI environments don't support the ANSI escape sequences used to overwrite previous output.
|
|
2625
|
+
- Terminal resize events are not listened to.
|
|
2626
|
+
|
|
2627
|
+
If your CI environment supports full terminal rendering and you want to opt out of this behavior, set `CI=false`:
|
|
2628
|
+
|
|
2629
|
+
```sh
|
|
2630
|
+
CI=false node my-cli.js
|
|
2631
|
+
```
|
|
2632
|
+
|
|
2633
|
+
## Maintainers
|
|
2634
|
+
|
|
2635
|
+
- [Vadim Demedes](https://github.com/vadimdemedes)
|
|
2636
|
+
- [Sindre Sorhus](https://github.com/sindresorhus)
|