terminal-pilot 0.0.30 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1375 -435
- package/dist/cli.js.map +4 -4
- package/dist/commands/close-session.js +485 -6
- package/dist/commands/close-session.js.map +4 -4
- package/dist/commands/create-session.js +485 -6
- package/dist/commands/create-session.js.map +4 -4
- package/dist/commands/fill.js +485 -6
- package/dist/commands/fill.js.map +4 -4
- package/dist/commands/get-session.js +485 -6
- package/dist/commands/get-session.js.map +4 -4
- package/dist/commands/index.js +626 -44
- package/dist/commands/index.js.map +4 -4
- package/dist/commands/install.js +622 -40
- package/dist/commands/install.js.map +4 -4
- package/dist/commands/installer.js +68 -17
- package/dist/commands/installer.js.map +4 -4
- package/dist/commands/list-sessions.js +485 -6
- package/dist/commands/list-sessions.js.map +4 -4
- package/dist/commands/press-key.js +485 -6
- package/dist/commands/press-key.js.map +4 -4
- package/dist/commands/read-history.js +485 -6
- package/dist/commands/read-history.js.map +4 -4
- package/dist/commands/read-screen.js +485 -6
- package/dist/commands/read-screen.js.map +4 -4
- package/dist/commands/resize.js +485 -6
- package/dist/commands/resize.js.map +4 -4
- package/dist/commands/screenshot.js +485 -6
- package/dist/commands/screenshot.js.map +4 -4
- package/dist/commands/send-signal.js +485 -6
- package/dist/commands/send-signal.js.map +4 -4
- package/dist/commands/type.js +485 -6
- package/dist/commands/type.js.map +4 -4
- package/dist/commands/uninstall.js +550 -20
- package/dist/commands/uninstall.js.map +4 -4
- package/dist/commands/wait-for-exit.js +485 -6
- package/dist/commands/wait-for-exit.js.map +4 -4
- package/dist/commands/wait-for.js +485 -6
- package/dist/commands/wait-for.js.map +4 -4
- package/dist/testing/cli-repl.js +1375 -435
- package/dist/testing/cli-repl.js.map +4 -4
- package/dist/testing/qa-cli.js +1385 -445
- package/dist/testing/qa-cli.js.map +4 -4
- package/node_modules/@poe-code/agent-defs/README.md +35 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/claude-code.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/claude-code.js +21 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/claude-desktop.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/claude-desktop.js +18 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/codex.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/codex.js +25 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/cursor.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/cursor.js +15 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/gemini-cli.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/gemini-cli.js +16 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/goose.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/goose.js +16 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/index.d.ts +9 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/index.js +9 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/kimi.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/kimi.js +16 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/opencode.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/opencode.js +20 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/poe-agent.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/poe-agent.js +14 -0
- package/node_modules/@poe-code/agent-defs/dist/index.d.ts +5 -0
- package/node_modules/@poe-code/agent-defs/dist/index.js +3 -0
- package/node_modules/@poe-code/agent-defs/dist/registry.d.ts +3 -0
- package/node_modules/@poe-code/agent-defs/dist/registry.js +45 -0
- package/node_modules/@poe-code/agent-defs/dist/specifier.d.ts +7 -0
- package/node_modules/@poe-code/agent-defs/dist/specifier.js +40 -0
- package/node_modules/@poe-code/agent-defs/dist/types.d.ts +28 -0
- package/node_modules/@poe-code/agent-defs/dist/types.js +1 -0
- package/node_modules/@poe-code/agent-defs/package.json +20 -0
- package/node_modules/@poe-code/agent-skill-config/dist/apply.js +2 -1
- package/node_modules/@poe-code/agent-skill-config/dist/bridge-active-skills.d.ts +1 -0
- package/node_modules/@poe-code/agent-skill-config/dist/bridge-active-skills.js +37 -18
- package/node_modules/@poe-code/agent-skill-config/dist/resolve-skill-reference.js +8 -4
- package/node_modules/@poe-code/agent-skill-config/package.json +1 -5
- package/node_modules/@poe-code/config-mutations/README.md +55 -0
- package/node_modules/@poe-code/config-mutations/dist/error-codes.d.ts +1 -0
- package/node_modules/@poe-code/config-mutations/dist/error-codes.js +6 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.d.ts +6 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.js +829 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.d.ts +17 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.js +64 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/run-mutations.d.ts +7 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/run-mutations.js +39 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/index.d.ts +13 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/index.js +49 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/json.d.ts +32 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/json.js +171 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/object.d.ts +4 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/object.js +27 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/toml.d.ts +2 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/toml.js +75 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/yaml.d.ts +2 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/yaml.js +76 -0
- package/node_modules/@poe-code/config-mutations/dist/fs-utils.d.ts +18 -0
- package/node_modules/@poe-code/config-mutations/dist/fs-utils.js +43 -0
- package/node_modules/@poe-code/config-mutations/dist/index.d.ts +8 -0
- package/node_modules/@poe-code/config-mutations/dist/index.js +8 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/config-mutation.d.ts +47 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/config-mutation.js +34 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/file-mutation.d.ts +62 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/file-mutation.js +55 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/template-mutation.d.ts +40 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/template-mutation.js +32 -0
- package/node_modules/@poe-code/config-mutations/dist/template/render.d.ts +6 -0
- package/node_modules/@poe-code/config-mutations/dist/template/render.js +8 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/format-utils.d.ts +7 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/format-utils.js +21 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/index.d.ts +3 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/index.js +2 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.d.ts +25 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.js +194 -0
- package/node_modules/@poe-code/config-mutations/dist/types.d.ts +168 -0
- package/node_modules/@poe-code/config-mutations/dist/types.js +6 -0
- package/node_modules/@poe-code/config-mutations/package.json +29 -0
- package/node_modules/@poe-code/frontmatter/README.md +35 -0
- package/node_modules/@poe-code/frontmatter/dist/fences.d.ts +25 -0
- package/node_modules/@poe-code/frontmatter/dist/fences.js +100 -0
- package/node_modules/@poe-code/frontmatter/dist/index.d.ts +3 -0
- package/node_modules/@poe-code/frontmatter/dist/index.js +3 -0
- package/node_modules/@poe-code/frontmatter/dist/parse.d.ts +20 -0
- package/node_modules/@poe-code/frontmatter/dist/parse.js +209 -0
- package/node_modules/@poe-code/frontmatter/dist/stringify.d.ts +1 -0
- package/node_modules/@poe-code/frontmatter/dist/stringify.js +48 -0
- package/node_modules/@poe-code/frontmatter/package.json +25 -0
- package/node_modules/toolcraft-design/README.md +160 -0
- package/node_modules/toolcraft-design/dist/acp/components.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/acp/components.js +137 -0
- package/node_modules/toolcraft-design/dist/acp/index.d.ts +3 -0
- package/node_modules/toolcraft-design/dist/acp/index.js +2 -0
- package/node_modules/toolcraft-design/dist/acp/writer.d.ts +13 -0
- package/node_modules/toolcraft-design/dist/acp/writer.js +21 -0
- package/node_modules/toolcraft-design/dist/components/browser.d.ts +15 -0
- package/node_modules/toolcraft-design/dist/components/browser.js +31 -0
- package/node_modules/toolcraft-design/dist/components/catalog.d.ts +26 -0
- package/node_modules/toolcraft-design/dist/components/catalog.js +95 -0
- package/node_modules/toolcraft-design/dist/components/color.d.ts +31 -0
- package/node_modules/toolcraft-design/dist/components/color.js +102 -0
- package/node_modules/toolcraft-design/dist/components/command-errors.d.ts +16 -0
- package/node_modules/toolcraft-design/dist/components/command-errors.js +23 -0
- package/node_modules/toolcraft-design/dist/components/detail-card.d.ts +22 -0
- package/node_modules/toolcraft-design/dist/components/detail-card.js +45 -0
- package/node_modules/toolcraft-design/dist/components/help-formatter-plain.d.ts +5 -0
- package/node_modules/toolcraft-design/dist/components/help-formatter-plain.js +132 -0
- package/node_modules/toolcraft-design/dist/components/help-formatter.d.ts +33 -0
- package/node_modules/toolcraft-design/dist/components/help-formatter.js +213 -0
- package/node_modules/toolcraft-design/dist/components/index.d.ts +16 -0
- package/node_modules/toolcraft-design/dist/components/index.js +10 -0
- package/node_modules/toolcraft-design/dist/components/logger.d.ts +11 -0
- package/node_modules/toolcraft-design/dist/components/logger.js +60 -0
- package/node_modules/toolcraft-design/dist/components/symbols.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/components/symbols.js +71 -0
- package/node_modules/toolcraft-design/dist/components/table.d.ts +15 -0
- package/node_modules/toolcraft-design/dist/components/table.js +302 -0
- package/node_modules/toolcraft-design/dist/components/template.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/components/template.js +437 -0
- package/node_modules/toolcraft-design/dist/components/text.d.ts +16 -0
- package/node_modules/toolcraft-design/dist/components/text.js +145 -0
- package/node_modules/toolcraft-design/dist/dashboard/ansi.d.ts +18 -0
- package/node_modules/toolcraft-design/dist/dashboard/ansi.js +343 -0
- package/node_modules/toolcraft-design/dist/dashboard/buffer.d.ts +25 -0
- package/node_modules/toolcraft-design/dist/dashboard/buffer.js +219 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/border.d.ts +9 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/border.js +123 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/footer.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/footer.js +56 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/output-pane.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/output-pane.js +268 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/stats-pane.d.ts +7 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/stats-pane.js +107 -0
- package/node_modules/toolcraft-design/dist/dashboard/dashboard.d.ts +20 -0
- package/node_modules/toolcraft-design/dist/dashboard/dashboard.js +167 -0
- package/node_modules/toolcraft-design/dist/dashboard/demo.d.ts +13 -0
- package/node_modules/toolcraft-design/dist/dashboard/demo.js +145 -0
- package/node_modules/toolcraft-design/dist/dashboard/index.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/dashboard/index.js +4 -0
- package/node_modules/toolcraft-design/dist/dashboard/keymap.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/dashboard/keymap.js +233 -0
- package/node_modules/toolcraft-design/dist/dashboard/layout.d.ts +25 -0
- package/node_modules/toolcraft-design/dist/dashboard/layout.js +79 -0
- package/node_modules/toolcraft-design/dist/dashboard/should-use-dashboard.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/dashboard/should-use-dashboard.js +7 -0
- package/node_modules/toolcraft-design/dist/dashboard/snapshot.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/dashboard/snapshot.js +68 -0
- package/node_modules/toolcraft-design/dist/dashboard/store.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/dashboard/store.js +51 -0
- package/node_modules/toolcraft-design/dist/dashboard/terminal-width.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/dashboard/terminal-width.js +71 -0
- package/node_modules/toolcraft-design/dist/dashboard/terminal.d.ts +37 -0
- package/node_modules/toolcraft-design/dist/dashboard/terminal.js +264 -0
- package/node_modules/toolcraft-design/dist/dashboard/types.d.ts +38 -0
- package/node_modules/toolcraft-design/dist/dashboard/types.js +1 -0
- package/node_modules/toolcraft-design/dist/explorer/actions.d.ts +16 -0
- package/node_modules/toolcraft-design/dist/explorer/actions.js +39 -0
- package/node_modules/toolcraft-design/dist/explorer/demo.d.ts +13 -0
- package/node_modules/toolcraft-design/dist/explorer/demo.js +297 -0
- package/node_modules/toolcraft-design/dist/explorer/events.d.ts +67 -0
- package/node_modules/toolcraft-design/dist/explorer/events.js +1 -0
- package/node_modules/toolcraft-design/dist/explorer/filter.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/explorer/filter.js +95 -0
- package/node_modules/toolcraft-design/dist/explorer/index.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/explorer/index.js +8 -0
- package/node_modules/toolcraft-design/dist/explorer/jobs.d.ts +7 -0
- package/node_modules/toolcraft-design/dist/explorer/jobs.js +59 -0
- package/node_modules/toolcraft-design/dist/explorer/keymap.d.ts +21 -0
- package/node_modules/toolcraft-design/dist/explorer/keymap.js +376 -0
- package/node_modules/toolcraft-design/dist/explorer/layout.d.ts +20 -0
- package/node_modules/toolcraft-design/dist/explorer/layout.js +73 -0
- package/node_modules/toolcraft-design/dist/explorer/reducer.d.ts +9 -0
- package/node_modules/toolcraft-design/dist/explorer/reducer.js +782 -0
- package/node_modules/toolcraft-design/dist/explorer/render/detail.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/explorer/render/detail.js +97 -0
- package/node_modules/toolcraft-design/dist/explorer/render/footer.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/explorer/render/footer.js +73 -0
- package/node_modules/toolcraft-design/dist/explorer/render/header.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/explorer/render/header.js +49 -0
- package/node_modules/toolcraft-design/dist/explorer/render/index.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/explorer/render/index.js +53 -0
- package/node_modules/toolcraft-design/dist/explorer/render/list.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/explorer/render/list.js +116 -0
- package/node_modules/toolcraft-design/dist/explorer/render/modal.d.ts +3 -0
- package/node_modules/toolcraft-design/dist/explorer/render/modal.js +87 -0
- package/node_modules/toolcraft-design/dist/explorer/render/test-fixtures.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/explorer/render/test-fixtures.js +156 -0
- package/node_modules/toolcraft-design/dist/explorer/render/text.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/explorer/render/text.js +81 -0
- package/node_modules/toolcraft-design/dist/explorer/runtime.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/explorer/runtime.js +340 -0
- package/node_modules/toolcraft-design/dist/explorer/runtime.test-helpers.d.ts +50 -0
- package/node_modules/toolcraft-design/dist/explorer/runtime.test-helpers.js +101 -0
- package/node_modules/toolcraft-design/dist/explorer/state.d.ts +137 -0
- package/node_modules/toolcraft-design/dist/explorer/state.js +86 -0
- package/node_modules/toolcraft-design/dist/explorer/theme.d.ts +27 -0
- package/node_modules/toolcraft-design/dist/explorer/theme.js +29 -0
- package/node_modules/toolcraft-design/dist/index.d.ts +50 -0
- package/node_modules/toolcraft-design/dist/index.js +43 -0
- package/node_modules/toolcraft-design/dist/internal/color-support.d.ts +9 -0
- package/node_modules/toolcraft-design/dist/internal/color-support.js +12 -0
- package/node_modules/toolcraft-design/dist/internal/output-format.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/internal/output-format.js +22 -0
- package/node_modules/toolcraft-design/dist/internal/strip-ansi.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/internal/strip-ansi.js +50 -0
- package/node_modules/toolcraft-design/dist/internal/theme-detect.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/internal/theme-detect.js +71 -0
- package/node_modules/toolcraft-design/dist/internal/theme-state.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/internal/theme-state.js +35 -0
- package/node_modules/toolcraft-design/dist/prompts/index.d.ts +91 -0
- package/node_modules/toolcraft-design/dist/prompts/index.js +137 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/cancel-symbol.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/cancel-symbol.js +4 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/confirm.d.ts +9 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/confirm.js +47 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/core.d.ts +55 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/core.js +274 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/glyphs.d.ts +20 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/glyphs.js +53 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/index.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/index.js +6 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/keys.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/keys.js +28 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/multiselect.d.ts +13 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/multiselect.js +131 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/pagination.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/pagination.js +52 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/password.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/password.js +55 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/select.d.ts +18 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/select.js +89 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/test-helpers.d.ts +21 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/test-helpers.js +32 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/text.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/text.js +60 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/wrap.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/wrap.js +18 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/cancel.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/cancel.js +9 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/intro.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/intro.js +16 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/log.d.ts +18 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/log.js +104 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/note.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/note.js +39 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/outro.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/outro.js +16 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/spinner.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/spinner.js +74 -0
- package/node_modules/toolcraft-design/dist/prompts/theme.d.ts +11 -0
- package/node_modules/toolcraft-design/dist/prompts/theme.js +15 -0
- package/node_modules/toolcraft-design/dist/static/index.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/static/index.js +2 -0
- package/node_modules/toolcraft-design/dist/static/menu.d.ts +11 -0
- package/node_modules/toolcraft-design/dist/static/menu.js +42 -0
- package/node_modules/toolcraft-design/dist/static/spinner.d.ts +14 -0
- package/node_modules/toolcraft-design/dist/static/spinner.js +52 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/ast.d.ts +92 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/ast.js +1 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/demo-content.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/demo-content.js +139 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/index.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/index.js +8 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/block.d.ts +7 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/block.js +1495 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/frontmatter.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/frontmatter.js +36 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/inline.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/inline.js +1190 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser.d.ts +5 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser.js +42 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/renderer.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/renderer.js +615 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/testing/theme-render-fixture.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/testing/theme-render-fixture.js +27 -0
- package/node_modules/toolcraft-design/dist/tokens/brand.d.ts +5 -0
- package/node_modules/toolcraft-design/dist/tokens/brand.js +5 -0
- package/node_modules/toolcraft-design/dist/tokens/colors.d.ts +37 -0
- package/node_modules/toolcraft-design/dist/tokens/colors.js +85 -0
- package/node_modules/toolcraft-design/dist/tokens/index.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/tokens/index.js +5 -0
- package/node_modules/toolcraft-design/dist/tokens/spacing.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/tokens/spacing.js +6 -0
- package/node_modules/toolcraft-design/dist/tokens/typography.d.ts +7 -0
- package/node_modules/toolcraft-design/dist/tokens/typography.js +8 -0
- package/node_modules/toolcraft-design/dist/tokens/widths.d.ts +5 -0
- package/node_modules/toolcraft-design/dist/tokens/widths.js +5 -0
- package/node_modules/toolcraft-design/package.json +44 -0
- package/package.json +15 -5
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ThemeConfig {
|
|
2
|
+
brand: string;
|
|
3
|
+
label: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function configureTheme(patch: {
|
|
6
|
+
brand?: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
}): void;
|
|
9
|
+
export declare function getThemeConfig(): ThemeConfig;
|
|
10
|
+
export declare function getThemeRevision(): number;
|
|
11
|
+
export declare function isThemeBrandConfigured(): boolean;
|
|
12
|
+
export declare function resetTheme(): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { brands } from "../tokens/brand.js";
|
|
2
|
+
const defaults = {
|
|
3
|
+
brand: "purple",
|
|
4
|
+
label: "Poe"
|
|
5
|
+
};
|
|
6
|
+
let config = { ...defaults };
|
|
7
|
+
let revision = 0;
|
|
8
|
+
let brandConfigured = false;
|
|
9
|
+
export function configureTheme(patch) {
|
|
10
|
+
if (patch.brand !== undefined && !Object.hasOwn(brands, patch.brand)) {
|
|
11
|
+
throw new Error(`Unknown brand: ${patch.brand}`);
|
|
12
|
+
}
|
|
13
|
+
config = {
|
|
14
|
+
brand: patch.brand ?? config.brand,
|
|
15
|
+
label: patch.label ?? config.label
|
|
16
|
+
};
|
|
17
|
+
if (patch.brand !== undefined) {
|
|
18
|
+
brandConfigured = true;
|
|
19
|
+
}
|
|
20
|
+
revision += 1;
|
|
21
|
+
}
|
|
22
|
+
export function getThemeConfig() {
|
|
23
|
+
return { ...config };
|
|
24
|
+
}
|
|
25
|
+
export function getThemeRevision() {
|
|
26
|
+
return revision;
|
|
27
|
+
}
|
|
28
|
+
export function isThemeBrandConfigured() {
|
|
29
|
+
return brandConfigured;
|
|
30
|
+
}
|
|
31
|
+
export function resetTheme() {
|
|
32
|
+
config = { ...defaults };
|
|
33
|
+
brandConfigured = false;
|
|
34
|
+
revision += 1;
|
|
35
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { CANCEL } from "./interactive/cancel-symbol.js";
|
|
2
|
+
import { type SelectOption } from "./interactive/select.js";
|
|
3
|
+
import { cancel, isCancel } from "./primitives/cancel.js";
|
|
4
|
+
import { intro } from "./primitives/intro.js";
|
|
5
|
+
import { log } from "./primitives/log.js";
|
|
6
|
+
import { note } from "./primitives/note.js";
|
|
7
|
+
import { outro } from "./primitives/outro.js";
|
|
8
|
+
import { spinner } from "./primitives/spinner.js";
|
|
9
|
+
export { isCancel, cancel, log };
|
|
10
|
+
export { intro, outro, note, spinner };
|
|
11
|
+
export declare function introPlain(title: string): void;
|
|
12
|
+
export interface SelectOptions<Value> {
|
|
13
|
+
message: string;
|
|
14
|
+
options: Array<SelectOption<Value>>;
|
|
15
|
+
initialValue?: Value;
|
|
16
|
+
maxItems?: number;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
input?: NodeJS.ReadableStream;
|
|
19
|
+
output?: NodeJS.WritableStream;
|
|
20
|
+
}
|
|
21
|
+
export declare function select<Value>(opts: SelectOptions<Value>): Promise<Value | typeof CANCEL>;
|
|
22
|
+
export interface MultiselectOptions<Value> {
|
|
23
|
+
message: string;
|
|
24
|
+
options: Array<SelectOption<Value>>;
|
|
25
|
+
initialValues?: Value[];
|
|
26
|
+
required?: boolean;
|
|
27
|
+
maxItems?: number;
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
input?: NodeJS.ReadableStream;
|
|
30
|
+
output?: NodeJS.WritableStream;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Prompts the user to select one or more values from a list.
|
|
34
|
+
*
|
|
35
|
+
* Returns the selected values as an array, or a cancellation symbol if the
|
|
36
|
+
* user cancels. Use `isCancel` to check for cancellation.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const result = await multiselect({
|
|
40
|
+
* message: "Pick workflows to run",
|
|
41
|
+
* options: [{ label: "Fix Vulnerabilities", value: "fix-vulnerabilities" }],
|
|
42
|
+
* required: true
|
|
43
|
+
* });
|
|
44
|
+
* if (!isCancel(result)) {
|
|
45
|
+
* // result is Value[]
|
|
46
|
+
* }
|
|
47
|
+
*/
|
|
48
|
+
export declare function multiselect<Value>(opts: MultiselectOptions<Value>): Promise<Value[] | typeof CANCEL>;
|
|
49
|
+
export interface TextOptions {
|
|
50
|
+
message: string;
|
|
51
|
+
placeholder?: string;
|
|
52
|
+
defaultValue?: string;
|
|
53
|
+
initialValue?: string;
|
|
54
|
+
validate?: (value: string) => string | Error | undefined;
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
input?: NodeJS.ReadableStream;
|
|
57
|
+
output?: NodeJS.WritableStream;
|
|
58
|
+
}
|
|
59
|
+
export declare function text(opts: TextOptions): Promise<string | typeof CANCEL>;
|
|
60
|
+
export interface ConfirmOptions {
|
|
61
|
+
message: string;
|
|
62
|
+
initialValue?: boolean;
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
input?: NodeJS.ReadableStream;
|
|
65
|
+
output?: NodeJS.WritableStream;
|
|
66
|
+
}
|
|
67
|
+
export declare function confirm(opts: ConfirmOptions): Promise<boolean | typeof CANCEL>;
|
|
68
|
+
export declare class PromptCancelledError extends Error {
|
|
69
|
+
constructor(message?: string);
|
|
70
|
+
}
|
|
71
|
+
export declare function confirmOrCancel(opts: ConfirmOptions): Promise<boolean>;
|
|
72
|
+
export interface PasswordOptions {
|
|
73
|
+
message: string;
|
|
74
|
+
validate?: (value: string) => string | Error | undefined;
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
input?: NodeJS.ReadableStream;
|
|
77
|
+
output?: NodeJS.WritableStream;
|
|
78
|
+
}
|
|
79
|
+
export declare function password(opts: PasswordOptions): Promise<string | typeof CANCEL>;
|
|
80
|
+
export type SpinnerOptions = {
|
|
81
|
+
start: (message?: string) => void;
|
|
82
|
+
stop: (message?: string, code?: number) => void;
|
|
83
|
+
message: (message?: string) => void;
|
|
84
|
+
};
|
|
85
|
+
export interface WithSpinnerOptions<T> {
|
|
86
|
+
message: string | (() => string);
|
|
87
|
+
fn: () => Promise<T>;
|
|
88
|
+
stopMessage?: (result: T) => string;
|
|
89
|
+
subtext?: (result: T) => string | undefined;
|
|
90
|
+
}
|
|
91
|
+
export declare function withSpinner<T>(options: WithSpinnerOptions<T>): Promise<T>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { color } from "../components/color.js";
|
|
2
|
+
import { resolveOutputFormat } from "../internal/output-format.js";
|
|
3
|
+
import { stripAnsi } from "../internal/strip-ansi.js";
|
|
4
|
+
import { confirmPrompt } from "./interactive/confirm.js";
|
|
5
|
+
import { multiselectPrompt } from "./interactive/multiselect.js";
|
|
6
|
+
import { passwordPrompt } from "./interactive/password.js";
|
|
7
|
+
import { selectPrompt } from "./interactive/select.js";
|
|
8
|
+
import { textPrompt } from "./interactive/text.js";
|
|
9
|
+
import { cancel, isCancel } from "./primitives/cancel.js";
|
|
10
|
+
import { intro } from "./primitives/intro.js";
|
|
11
|
+
import { log } from "./primitives/log.js";
|
|
12
|
+
import { note } from "./primitives/note.js";
|
|
13
|
+
import { outro } from "./primitives/outro.js";
|
|
14
|
+
import { spinner } from "./primitives/spinner.js";
|
|
15
|
+
export { isCancel, cancel, log };
|
|
16
|
+
export { intro, outro, note, spinner };
|
|
17
|
+
export function introPlain(title) {
|
|
18
|
+
const format = resolveOutputFormat();
|
|
19
|
+
if (format === "markdown") {
|
|
20
|
+
process.stdout.write(`# ${stripAnsi(title)}\n\n`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (format === "json") {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
process.stdout.write(`${color.gray("┌")} ${title}\n`);
|
|
27
|
+
}
|
|
28
|
+
export async function select(opts) {
|
|
29
|
+
return selectPrompt(opts);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Prompts the user to select one or more values from a list.
|
|
33
|
+
*
|
|
34
|
+
* Returns the selected values as an array, or a cancellation symbol if the
|
|
35
|
+
* user cancels. Use `isCancel` to check for cancellation.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const result = await multiselect({
|
|
39
|
+
* message: "Pick workflows to run",
|
|
40
|
+
* options: [{ label: "Fix Vulnerabilities", value: "fix-vulnerabilities" }],
|
|
41
|
+
* required: true
|
|
42
|
+
* });
|
|
43
|
+
* if (!isCancel(result)) {
|
|
44
|
+
* // result is Value[]
|
|
45
|
+
* }
|
|
46
|
+
*/
|
|
47
|
+
export async function multiselect(opts) {
|
|
48
|
+
return multiselectPrompt(opts);
|
|
49
|
+
}
|
|
50
|
+
export async function text(opts) {
|
|
51
|
+
return textPrompt(opts);
|
|
52
|
+
}
|
|
53
|
+
export async function confirm(opts) {
|
|
54
|
+
return confirmPrompt(opts);
|
|
55
|
+
}
|
|
56
|
+
export class PromptCancelledError extends Error {
|
|
57
|
+
constructor(message = "Operation cancelled.") {
|
|
58
|
+
super(message);
|
|
59
|
+
this.name = "PromptCancelledError";
|
|
60
|
+
if (Error.captureStackTrace) {
|
|
61
|
+
Error.captureStackTrace(this, this.constructor);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export async function confirmOrCancel(opts) {
|
|
66
|
+
const result = await confirm(opts);
|
|
67
|
+
if (isCancel(result)) {
|
|
68
|
+
cancel("Operation cancelled.");
|
|
69
|
+
throw new PromptCancelledError();
|
|
70
|
+
}
|
|
71
|
+
return result === true;
|
|
72
|
+
}
|
|
73
|
+
export async function password(opts) {
|
|
74
|
+
return passwordPrompt(opts);
|
|
75
|
+
}
|
|
76
|
+
function formatElapsed(ms) {
|
|
77
|
+
const totalSeconds = Math.floor(ms / 1000);
|
|
78
|
+
if (totalSeconds < 60) {
|
|
79
|
+
return `${totalSeconds}s`;
|
|
80
|
+
}
|
|
81
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
82
|
+
const seconds = totalSeconds % 60;
|
|
83
|
+
return `${minutes}m ${seconds}s`;
|
|
84
|
+
}
|
|
85
|
+
export async function withSpinner(options) {
|
|
86
|
+
const { message, fn, stopMessage, subtext } = options;
|
|
87
|
+
const readMessage = () => (typeof message === "function" ? message() : message);
|
|
88
|
+
if (resolveOutputFormat() === "json") {
|
|
89
|
+
const result = await fn();
|
|
90
|
+
const sub = subtext ? subtext(result) : undefined;
|
|
91
|
+
if (sub) {
|
|
92
|
+
process.stdout.write(sub + "\n");
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
const noSpinner = process.env.POE_NO_SPINNER === "1";
|
|
97
|
+
const isTTY = process.stdout.isTTY;
|
|
98
|
+
if (noSpinner || !isTTY) {
|
|
99
|
+
const result = await fn();
|
|
100
|
+
const msg = stopMessage ? stopMessage(result) : undefined;
|
|
101
|
+
if (msg) {
|
|
102
|
+
process.stdout.write(`${color.green("◆")} ${msg}\n`);
|
|
103
|
+
}
|
|
104
|
+
const sub = subtext ? subtext(result) : undefined;
|
|
105
|
+
if (sub) {
|
|
106
|
+
for (const line of sub.split("\n")) {
|
|
107
|
+
process.stdout.write(`${color.gray("│")} ${line}\n`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
const s = spinner();
|
|
113
|
+
const start = Date.now();
|
|
114
|
+
s.start(readMessage());
|
|
115
|
+
const timer = setInterval(() => {
|
|
116
|
+
s.message(`${readMessage()} [${formatElapsed(Date.now() - start)}]`);
|
|
117
|
+
}, 1000);
|
|
118
|
+
try {
|
|
119
|
+
const result = await fn();
|
|
120
|
+
clearInterval(timer);
|
|
121
|
+
const elapsed = formatElapsed(Date.now() - start);
|
|
122
|
+
const msg = stopMessage ? stopMessage(result) : undefined;
|
|
123
|
+
s.stop(msg ? `${msg} [${elapsed}]` : `Done [${elapsed}]`);
|
|
124
|
+
const sub = subtext ? subtext(result) : undefined;
|
|
125
|
+
if (sub) {
|
|
126
|
+
for (const line of sub.split("\n")) {
|
|
127
|
+
process.stdout.write(`${color.gray("│")} ${line}\n`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
clearInterval(timer);
|
|
134
|
+
s.stop("", 1);
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CANCEL } from "./cancel-symbol.js";
|
|
2
|
+
export interface ConfirmOptions {
|
|
3
|
+
message: string;
|
|
4
|
+
initialValue?: boolean;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
input?: NodeJS.ReadableStream;
|
|
7
|
+
output?: NodeJS.WritableStream;
|
|
8
|
+
}
|
|
9
|
+
export declare function confirmPrompt(opts: ConfirmOptions): Promise<boolean | typeof CANCEL>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { color } from "../../components/color.js";
|
|
2
|
+
import { GLYPHS, symbol, symbolBar } from "./glyphs.js";
|
|
3
|
+
import { Prompt } from "./core.js";
|
|
4
|
+
class ConfirmPrompt extends Prompt {
|
|
5
|
+
constructor(opts) {
|
|
6
|
+
super({
|
|
7
|
+
...opts,
|
|
8
|
+
initialValue: opts.initialValue ?? true,
|
|
9
|
+
render: (prompt) => renderConfirmPrompt(prompt, opts)
|
|
10
|
+
}, false);
|
|
11
|
+
this.on("confirm", (value) => {
|
|
12
|
+
this.setValue(value);
|
|
13
|
+
this.state = "submit";
|
|
14
|
+
this.emit("finalize");
|
|
15
|
+
this.render();
|
|
16
|
+
this.close();
|
|
17
|
+
});
|
|
18
|
+
this.on("cursor", (action) => {
|
|
19
|
+
if (action === "up" || action === "down" || action === "left" || action === "right") {
|
|
20
|
+
this.setValue(!this.value);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
promptNonTty() {
|
|
25
|
+
if (process.env.POE_NO_PROMPT === "1") {
|
|
26
|
+
return Promise.resolve(this.value ?? true);
|
|
27
|
+
}
|
|
28
|
+
return super.promptNonTty();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function choices(value) {
|
|
32
|
+
const yes = value ? `${color.green(GLYPHS.radioActive)} ${color.bold("Yes")}` : `${color.dim(GLYPHS.radioInactive)} ${color.dim("Yes")}`;
|
|
33
|
+
const no = value ? `${color.dim(GLYPHS.radioInactive)} ${color.dim("No")}` : `${color.green(GLYPHS.radioActive)} ${color.bold("No")}`;
|
|
34
|
+
return `${yes} ${color.dim("/")} ${no}`;
|
|
35
|
+
}
|
|
36
|
+
function renderConfirmPrompt(prompt, opts) {
|
|
37
|
+
if (prompt.state === "submit") {
|
|
38
|
+
return `${color.gray(GLYPHS.barStart)} ${symbol(prompt.state)} ${opts.message}\n${color.gray(GLYPHS.bar)} ${color.dim(prompt.value ? "Yes" : "No")}\n${color.green(GLYPHS.barEnd)}`;
|
|
39
|
+
}
|
|
40
|
+
if (prompt.state === "cancel") {
|
|
41
|
+
return `${color.gray(GLYPHS.barStart)} ${symbol(prompt.state)} ${opts.message}\n${color.gray(GLYPHS.bar)} ${color.dim.strikethrough(prompt.value ? "Yes" : "No")}\n${color.red(GLYPHS.barEnd)}`;
|
|
42
|
+
}
|
|
43
|
+
return `${color.gray(GLYPHS.barStart)} ${symbol(prompt.state)} ${opts.message}\n${symbolBar(prompt.state)} ${choices(prompt.value)}\n${color.cyan(GLYPHS.barEnd)}`;
|
|
44
|
+
}
|
|
45
|
+
export function confirmPrompt(opts) {
|
|
46
|
+
return new ConfirmPrompt(opts).prompt();
|
|
47
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { CANCEL } from "./cancel-symbol.js";
|
|
3
|
+
export type PromptStateName = "initial" | "active" | "submit" | "cancel" | "error";
|
|
4
|
+
export interface PromptState<Value> {
|
|
5
|
+
state: PromptStateName;
|
|
6
|
+
value: Value | undefined;
|
|
7
|
+
error: string;
|
|
8
|
+
cursor: number;
|
|
9
|
+
userInput: string;
|
|
10
|
+
}
|
|
11
|
+
export interface PromptOptions<Value> {
|
|
12
|
+
render: (state: Prompt<Value>) => string;
|
|
13
|
+
initialValue?: Value;
|
|
14
|
+
initialUserInput?: string;
|
|
15
|
+
validate?: (value: Value | undefined) => string | Error | undefined;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
input?: NodeJS.ReadableStream;
|
|
18
|
+
output?: NodeJS.WritableStream;
|
|
19
|
+
}
|
|
20
|
+
type InputStream = NodeJS.ReadableStream & {
|
|
21
|
+
isTTY?: boolean;
|
|
22
|
+
setRawMode?: (enabled: boolean) => void;
|
|
23
|
+
unpipe?: () => void;
|
|
24
|
+
};
|
|
25
|
+
export declare class Prompt<Value> extends EventEmitter {
|
|
26
|
+
state: PromptStateName;
|
|
27
|
+
value: Value | undefined;
|
|
28
|
+
error: string;
|
|
29
|
+
userInput: string;
|
|
30
|
+
protected _cursor: number;
|
|
31
|
+
protected input: InputStream;
|
|
32
|
+
protected output: NodeJS.WritableStream;
|
|
33
|
+
private readonly renderFrame;
|
|
34
|
+
private readonly validate?;
|
|
35
|
+
private readonly signal?;
|
|
36
|
+
private readonly trackValue;
|
|
37
|
+
private previousFrame;
|
|
38
|
+
private readlineInterface?;
|
|
39
|
+
private abortListener?;
|
|
40
|
+
private closed;
|
|
41
|
+
constructor(opts: PromptOptions<Value>, trackValue?: boolean);
|
|
42
|
+
get cursor(): number;
|
|
43
|
+
prompt(): Promise<Value | typeof CANCEL>;
|
|
44
|
+
protected promptNonTty(): Promise<Value | typeof CANCEL>;
|
|
45
|
+
protected readNonTtyLine(): Promise<string>;
|
|
46
|
+
protected setValue(value: Value | undefined): void;
|
|
47
|
+
protected setError(message: string): void;
|
|
48
|
+
protected setUserInput(value: string): void;
|
|
49
|
+
protected clearUserInput(): void;
|
|
50
|
+
private readonly onKeypress;
|
|
51
|
+
private updateTrackedInput;
|
|
52
|
+
protected readonly render: () => void;
|
|
53
|
+
protected close(): void;
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import * as readline from "node:readline";
|
|
3
|
+
import { CANCEL } from "./cancel-symbol.js";
|
|
4
|
+
import { mapKey } from "./keys.js";
|
|
5
|
+
import { wrapFrame } from "./wrap.js";
|
|
6
|
+
const cursor = {
|
|
7
|
+
hide: "\x1b[?25l",
|
|
8
|
+
show: "\x1b[?25h",
|
|
9
|
+
move: (x, y) => {
|
|
10
|
+
let output = "";
|
|
11
|
+
if (x < 0)
|
|
12
|
+
output += `\x1b[${-x}D`;
|
|
13
|
+
if (x > 0)
|
|
14
|
+
output += `\x1b[${x}C`;
|
|
15
|
+
if (y < 0)
|
|
16
|
+
output += `\x1b[${-y}A`;
|
|
17
|
+
if (y > 0)
|
|
18
|
+
output += `\x1b[${y}B`;
|
|
19
|
+
return output;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const erase = {
|
|
23
|
+
down: "\x1b[J"
|
|
24
|
+
};
|
|
25
|
+
export class Prompt extends EventEmitter {
|
|
26
|
+
state = "initial";
|
|
27
|
+
value;
|
|
28
|
+
error = "";
|
|
29
|
+
userInput = "";
|
|
30
|
+
_cursor = 0;
|
|
31
|
+
input;
|
|
32
|
+
output;
|
|
33
|
+
renderFrame;
|
|
34
|
+
validate;
|
|
35
|
+
signal;
|
|
36
|
+
trackValue;
|
|
37
|
+
previousFrame = "";
|
|
38
|
+
readlineInterface;
|
|
39
|
+
abortListener;
|
|
40
|
+
closed = false;
|
|
41
|
+
constructor(opts, trackValue = true) {
|
|
42
|
+
super();
|
|
43
|
+
this.input = (opts.input ?? process.stdin);
|
|
44
|
+
this.output = opts.output ?? process.stdout;
|
|
45
|
+
this.renderFrame = opts.render;
|
|
46
|
+
this.validate = opts.validate;
|
|
47
|
+
this.signal = opts.signal;
|
|
48
|
+
this.value = opts.initialValue;
|
|
49
|
+
this.trackValue = trackValue;
|
|
50
|
+
this.userInput = opts.initialUserInput ?? "";
|
|
51
|
+
this._cursor = this.userInput.length;
|
|
52
|
+
}
|
|
53
|
+
get cursor() {
|
|
54
|
+
return this._cursor;
|
|
55
|
+
}
|
|
56
|
+
prompt() {
|
|
57
|
+
if (this.signal?.aborted) {
|
|
58
|
+
this.state = "cancel";
|
|
59
|
+
return Promise.resolve(CANCEL);
|
|
60
|
+
}
|
|
61
|
+
if (this.input.isTTY !== true) {
|
|
62
|
+
return this.promptNonTty();
|
|
63
|
+
}
|
|
64
|
+
return new Promise((resolve) => {
|
|
65
|
+
const onSubmit = (value) => resolve(value);
|
|
66
|
+
const onCancel = () => resolve(CANCEL);
|
|
67
|
+
this.once("submit", onSubmit);
|
|
68
|
+
this.once("cancel", onCancel);
|
|
69
|
+
this.abortListener = () => {
|
|
70
|
+
this.state = "cancel";
|
|
71
|
+
this.emit("finalize");
|
|
72
|
+
this.render();
|
|
73
|
+
this.close();
|
|
74
|
+
};
|
|
75
|
+
this.signal?.addEventListener("abort", this.abortListener, { once: true });
|
|
76
|
+
this.readlineInterface = readline.createInterface({
|
|
77
|
+
input: this.input,
|
|
78
|
+
output: undefined,
|
|
79
|
+
tabSize: 2,
|
|
80
|
+
prompt: "",
|
|
81
|
+
escapeCodeTimeout: 50,
|
|
82
|
+
terminal: true
|
|
83
|
+
});
|
|
84
|
+
readline.emitKeypressEvents(this.input, this.readlineInterface);
|
|
85
|
+
this.readlineInterface.prompt();
|
|
86
|
+
this.input.on("keypress", this.onKeypress);
|
|
87
|
+
if (this.input.setRawMode) {
|
|
88
|
+
this.input.setRawMode(true);
|
|
89
|
+
}
|
|
90
|
+
this.output.on("resize", this.render);
|
|
91
|
+
this.render();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
promptNonTty() {
|
|
95
|
+
return Promise.reject(new Error("Interactive prompt requires a TTY. Set POE_NO_PROMPT=1 to accept defaults non-interactively."));
|
|
96
|
+
}
|
|
97
|
+
readNonTtyLine() {
|
|
98
|
+
return new Promise((resolve) => {
|
|
99
|
+
const rl = readline.createInterface({ input: this.input, terminal: false });
|
|
100
|
+
let settled = false;
|
|
101
|
+
const settle = (value) => {
|
|
102
|
+
if (settled) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
settled = true;
|
|
106
|
+
rl.close();
|
|
107
|
+
resolve(value);
|
|
108
|
+
};
|
|
109
|
+
rl.once("line", settle);
|
|
110
|
+
rl.once("close", () => settle(rl.line));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
setValue(value) {
|
|
114
|
+
this.value = value;
|
|
115
|
+
this.emit("value", value);
|
|
116
|
+
}
|
|
117
|
+
setError(message) {
|
|
118
|
+
this.error = message;
|
|
119
|
+
}
|
|
120
|
+
setUserInput(value) {
|
|
121
|
+
this.userInput = value;
|
|
122
|
+
this._cursor = Math.min(this._cursor, this.userInput.length);
|
|
123
|
+
this.emit("userInput", this.userInput);
|
|
124
|
+
}
|
|
125
|
+
clearUserInput() {
|
|
126
|
+
this.userInput = "";
|
|
127
|
+
this._cursor = 0;
|
|
128
|
+
this.emit("userInput", this.userInput);
|
|
129
|
+
}
|
|
130
|
+
onKeypress = (char, key = {}) => {
|
|
131
|
+
let action = mapKey(key.name, char);
|
|
132
|
+
if (this.trackValue && char && char >= " " && key.name !== "return" && key.name !== "enter" && key.name !== "escape") {
|
|
133
|
+
action = undefined;
|
|
134
|
+
}
|
|
135
|
+
if (this.trackValue && action !== "enter") {
|
|
136
|
+
this.updateTrackedInput(char, key, action);
|
|
137
|
+
}
|
|
138
|
+
if (this.state === "error") {
|
|
139
|
+
this.state = "active";
|
|
140
|
+
this.error = "";
|
|
141
|
+
}
|
|
142
|
+
if (!this.trackValue && action) {
|
|
143
|
+
this.emit("cursor", action);
|
|
144
|
+
}
|
|
145
|
+
else if (this.trackValue && action && action !== "enter") {
|
|
146
|
+
this.emit("cursor", action);
|
|
147
|
+
}
|
|
148
|
+
if (char && /^[yn]$/i.test(char)) {
|
|
149
|
+
this.emit("confirm", char.toLowerCase() === "y");
|
|
150
|
+
}
|
|
151
|
+
if (char) {
|
|
152
|
+
this.emit("key", char.toLowerCase(), key);
|
|
153
|
+
}
|
|
154
|
+
if (action === "enter") {
|
|
155
|
+
const error = this.validate?.(this.value);
|
|
156
|
+
if (error) {
|
|
157
|
+
this.error = error instanceof Error ? error.message : error;
|
|
158
|
+
this.state = "error";
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
this.state = "submit";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (action === "cancel") {
|
|
165
|
+
this.state = "cancel";
|
|
166
|
+
}
|
|
167
|
+
if (this.state === "submit" || this.state === "cancel") {
|
|
168
|
+
this.emit("finalize");
|
|
169
|
+
}
|
|
170
|
+
this.render();
|
|
171
|
+
if (this.state === "submit" || this.state === "cancel") {
|
|
172
|
+
this.close();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
updateTrackedInput(char, key, action) {
|
|
176
|
+
if (key.ctrl) {
|
|
177
|
+
if (key.name === "a") {
|
|
178
|
+
this._cursor = 0;
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (key.name === "e") {
|
|
182
|
+
this._cursor = this.userInput.length;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (key.name === "u") {
|
|
186
|
+
this.userInput = this.userInput.slice(this._cursor);
|
|
187
|
+
this._cursor = 0;
|
|
188
|
+
this.emit("userInput", this.userInput);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (key.name === "k") {
|
|
192
|
+
this.userInput = this.userInput.slice(0, this._cursor);
|
|
193
|
+
this.emit("userInput", this.userInput);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (action === "left") {
|
|
198
|
+
this._cursor = Math.max(0, this._cursor - 1);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (action === "right") {
|
|
202
|
+
this._cursor = Math.min(this.userInput.length, this._cursor + 1);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (action === "cancel" || action === "up" || action === "down" || action === "space") {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (key.name === "backspace" || char === "\b" || char === "\x7f") {
|
|
209
|
+
if (this._cursor > 0) {
|
|
210
|
+
this.userInput = `${this.userInput.slice(0, this._cursor - 1)}${this.userInput.slice(this._cursor)}`;
|
|
211
|
+
this._cursor -= 1;
|
|
212
|
+
this.emit("userInput", this.userInput);
|
|
213
|
+
}
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (key.name === "delete") {
|
|
217
|
+
if (this._cursor < this.userInput.length) {
|
|
218
|
+
this.userInput = `${this.userInput.slice(0, this._cursor)}${this.userInput.slice(this._cursor + 1)}`;
|
|
219
|
+
this.emit("userInput", this.userInput);
|
|
220
|
+
}
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (!char || char < " " || key.ctrl) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
this.userInput = `${this.userInput.slice(0, this._cursor)}${char}${this.userInput.slice(this._cursor)}`;
|
|
227
|
+
this._cursor += char.length;
|
|
228
|
+
this.emit("userInput", this.userInput);
|
|
229
|
+
}
|
|
230
|
+
render = () => {
|
|
231
|
+
if (this.closed) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const frame = wrapFrame(this.output, this.renderFrame(this) ?? "");
|
|
235
|
+
if (frame === this.previousFrame) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (!this.previousFrame) {
|
|
239
|
+
this.output.write(`${cursor.hide}${frame}`);
|
|
240
|
+
this.previousFrame = frame;
|
|
241
|
+
if (this.state === "initial") {
|
|
242
|
+
this.state = "active";
|
|
243
|
+
}
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const previousLineCount = this.previousFrame.split("\n").length - 1;
|
|
247
|
+
this.output.write(`${cursor.move(-999, -previousLineCount)}${erase.down}${frame}`);
|
|
248
|
+
this.previousFrame = frame;
|
|
249
|
+
};
|
|
250
|
+
close() {
|
|
251
|
+
if (this.closed) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
this.closed = true;
|
|
255
|
+
this.input.removeListener("keypress", this.onKeypress);
|
|
256
|
+
this.output.removeListener("resize", this.render);
|
|
257
|
+
if (this.abortListener) {
|
|
258
|
+
this.signal?.removeEventListener("abort", this.abortListener);
|
|
259
|
+
}
|
|
260
|
+
this.output.write(`${cursor.show}\n`);
|
|
261
|
+
if (!process.platform.startsWith("win") && this.input.setRawMode) {
|
|
262
|
+
this.input.setRawMode(false);
|
|
263
|
+
}
|
|
264
|
+
this.readlineInterface?.close();
|
|
265
|
+
this.input.unpipe?.();
|
|
266
|
+
if (this.state === "cancel") {
|
|
267
|
+
this.emit("cancel");
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
this.emit("submit", this.value);
|
|
271
|
+
}
|
|
272
|
+
this.removeAllListeners();
|
|
273
|
+
}
|
|
274
|
+
}
|