first commit
This commit is contained in:
22
node_modules/@inquirer/select/LICENSE
generated
vendored
Normal file
22
node_modules/@inquirer/select/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2025 Simon Boudrias
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
191
node_modules/@inquirer/select/README.md
generated
vendored
Normal file
191
node_modules/@inquirer/select/README.md
generated
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
# `@inquirer/select`
|
||||
|
||||
Simple interactive command line prompt to display a list of choices (single select.)
|
||||
|
||||

|
||||
|
||||
# Special Thanks
|
||||
|
||||
<div align="center" markdown="1">
|
||||
|
||||
[](https://graphite.dev/?utm_source=npmjs&utm_medium=repo&utm_campaign=inquirerjs)<br>
|
||||
|
||||
### [Graphite is the AI developer productivity platform helping teams on GitHub ship higher quality software, faster](https://graphite.dev/?utm_source=npmjs&utm_medium=repo&utm_campaign=inquirerjs)
|
||||
|
||||
</div>
|
||||
|
||||
# Installation
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>npm</th>
|
||||
<th>yarn</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
```sh
|
||||
npm install @inquirer/prompts
|
||||
```
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
```sh
|
||||
yarn add @inquirer/prompts
|
||||
```
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colSpan="2" align="center">Or</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
```sh
|
||||
npm install @inquirer/select
|
||||
```
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
```sh
|
||||
yarn add @inquirer/select
|
||||
```
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
# Usage
|
||||
|
||||
```js
|
||||
import { select, Separator } from '@inquirer/prompts';
|
||||
// Or
|
||||
// import select, { Separator } from '@inquirer/select';
|
||||
|
||||
const answer = await select({
|
||||
message: 'Select a package manager',
|
||||
choices: [
|
||||
{
|
||||
name: 'npm',
|
||||
value: 'npm',
|
||||
description: 'npm is the most popular package manager',
|
||||
},
|
||||
{
|
||||
name: 'yarn',
|
||||
value: 'yarn',
|
||||
description: 'yarn is an awesome package manager',
|
||||
},
|
||||
new Separator(),
|
||||
{
|
||||
name: 'jspm',
|
||||
value: 'jspm',
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
name: 'pnpm',
|
||||
value: 'pnpm',
|
||||
disabled: '(pnpm is not available)',
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
| Property | Type | Required | Description |
|
||||
| -------- | ----------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| message | `string` | yes | The question to ask |
|
||||
| choices | `Choice[]` | yes | List of the available choices. |
|
||||
| default | `string` | no | Defines in front of which item the cursor will initially appear. When omitted, the cursor will appear on the first selectable item. |
|
||||
| pageSize | `number` | no | By default, lists of choice longer than 7 will be paginated. Use this option to control how many choices will appear on the screen at once. |
|
||||
| loop | `boolean` | no | Defaults to `true`. When set to `false`, the cursor will be constrained to the top and bottom of the choice list without looping. |
|
||||
| theme | [See Theming](#Theming) | no | Customize look of the prompt. |
|
||||
|
||||
`Separator` objects can be used in the `choices` array to render non-selectable lines in the choice list. By default it'll render a line, but you can provide the text as argument (`new Separator('-- Dependencies --')`). This option is often used to add labels to groups within long list of options.
|
||||
|
||||
### `Choice` object
|
||||
|
||||
The `Choice` object is typed as
|
||||
|
||||
```ts
|
||||
type Choice<Value> = {
|
||||
value: Value;
|
||||
name?: string;
|
||||
description?: string;
|
||||
short?: string;
|
||||
disabled?: boolean | string;
|
||||
};
|
||||
```
|
||||
|
||||
Here's each property:
|
||||
|
||||
- `value`: The value is what will be returned by `await select()`.
|
||||
- `name`: This is the string displayed in the choice list.
|
||||
- `description`: Option for a longer description string that'll appear under the list when the cursor highlight a given choice.
|
||||
- `short`: Once the prompt is done (press enter), we'll use `short` if defined to render next to the question. By default we'll use `name`.
|
||||
- `disabled`: Disallow the option from being selected. If `disabled` is a string, it'll be used as a help tip explaining why the choice isn't available.
|
||||
|
||||
`choices` can also be an array of string, in which case the string will be used both as the `value` and the `name`.
|
||||
|
||||
## Theming
|
||||
|
||||
You can theme a prompt by passing a `theme` object option. The theme object only need to includes the keys you wish to modify, we'll fallback on the defaults for the rest.
|
||||
|
||||
```ts
|
||||
type Theme = {
|
||||
prefix: string | { idle: string; done: string };
|
||||
spinner: {
|
||||
interval: number;
|
||||
frames: string[];
|
||||
};
|
||||
style: {
|
||||
answer: (text: string) => string;
|
||||
message: (text: string, status: 'idle' | 'done' | 'loading') => string;
|
||||
error: (text: string) => string;
|
||||
help: (text: string) => string;
|
||||
highlight: (text: string) => string;
|
||||
description: (text: string) => string;
|
||||
disabled: (text: string) => string;
|
||||
keysHelpTip: (keys: [key: string, action: string][]) => string | undefined;
|
||||
};
|
||||
icon: {
|
||||
cursor: string;
|
||||
};
|
||||
indexMode: 'hidden' | 'number';
|
||||
};
|
||||
```
|
||||
|
||||
### `theme.style.keysHelpTip`
|
||||
|
||||
This function allows you to customize the keyboard shortcuts help tip displayed below the prompt. It receives an array of key-action pairs and should return a formatted string. You can also hook here to localize the labels to different languages.
|
||||
|
||||
It can also returns `undefined` to hide the help tip entirely. This is the replacement for the deprecated theme option `helpMode: 'never'`.
|
||||
|
||||
```js
|
||||
theme: {
|
||||
style: {
|
||||
keysHelpTip: (keys) => {
|
||||
// Return undefined to hide the help tip completely.
|
||||
return undefined;
|
||||
|
||||
// Or customize the formatting. Or localize the labels.
|
||||
return keys.map(([key, action]) => `${key}: ${action}`).join(' | ');
|
||||
};
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### `theme.indexMode`
|
||||
|
||||
Controls how indices are displayed before each choice:
|
||||
|
||||
- `hidden` (default): No indices are shown
|
||||
- `number`: Display a number before each choice (e.g. "1. Option A")
|
||||
|
||||
# License
|
||||
|
||||
Copyright (c) 2023 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))<br/>
|
||||
Licensed under the MIT license.
|
||||
40
node_modules/@inquirer/select/dist/commonjs/index.d.ts
generated
vendored
Normal file
40
node_modules/@inquirer/select/dist/commonjs/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Separator, type Theme, type Keybinding } from '@inquirer/core';
|
||||
import type { PartialDeep } from '@inquirer/type';
|
||||
type SelectTheme = {
|
||||
icon: {
|
||||
cursor: string;
|
||||
};
|
||||
style: {
|
||||
disabled: (text: string) => string;
|
||||
description: (text: string) => string;
|
||||
keysHelpTip: (keys: [key: string, action: string][]) => string | undefined;
|
||||
};
|
||||
/** @deprecated Use theme.style.keysHelpTip instead */
|
||||
helpMode: 'always' | 'never' | 'auto';
|
||||
indexMode: 'hidden' | 'number';
|
||||
keybindings: ReadonlyArray<Keybinding>;
|
||||
};
|
||||
type Choice<Value> = {
|
||||
value: Value;
|
||||
name?: string;
|
||||
description?: string;
|
||||
short?: string;
|
||||
disabled?: boolean | string;
|
||||
type?: never;
|
||||
};
|
||||
declare const _default: <Value>(config: {
|
||||
message: string;
|
||||
choices: readonly (string | Separator)[] | readonly (Separator | Choice<Value>)[];
|
||||
pageSize?: number | undefined;
|
||||
loop?: boolean | undefined;
|
||||
default?: unknown;
|
||||
instructions?: {
|
||||
navigation: string;
|
||||
pager: string;
|
||||
} | undefined;
|
||||
theme?: PartialDeep<Theme<SelectTheme>> | undefined;
|
||||
}, context?: import("@inquirer/type").Context) => Promise<Value> & {
|
||||
cancel: () => void;
|
||||
};
|
||||
export default _default;
|
||||
export { Separator } from '@inquirer/core';
|
||||
194
node_modules/@inquirer/select/dist/commonjs/index.js
generated
vendored
Normal file
194
node_modules/@inquirer/select/dist/commonjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Separator = void 0;
|
||||
const core_1 = require("@inquirer/core");
|
||||
const ansi_1 = require("@inquirer/ansi");
|
||||
const yoctocolors_cjs_1 = __importDefault(require("yoctocolors-cjs"));
|
||||
const figures_1 = __importDefault(require("@inquirer/figures"));
|
||||
const selectTheme = {
|
||||
icon: { cursor: figures_1.default.pointer },
|
||||
style: {
|
||||
disabled: (text) => yoctocolors_cjs_1.default.dim(`- ${text}`),
|
||||
description: (text) => yoctocolors_cjs_1.default.cyan(text),
|
||||
keysHelpTip: (keys) => keys
|
||||
.map(([key, action]) => `${yoctocolors_cjs_1.default.bold(key)} ${yoctocolors_cjs_1.default.dim(action)}`)
|
||||
.join(yoctocolors_cjs_1.default.dim(' • ')),
|
||||
},
|
||||
helpMode: 'always',
|
||||
indexMode: 'hidden',
|
||||
keybindings: [],
|
||||
};
|
||||
function isSelectable(item) {
|
||||
return !core_1.Separator.isSeparator(item) && !item.disabled;
|
||||
}
|
||||
function normalizeChoices(choices) {
|
||||
return choices.map((choice) => {
|
||||
if (core_1.Separator.isSeparator(choice))
|
||||
return choice;
|
||||
if (typeof choice === 'string') {
|
||||
return {
|
||||
value: choice,
|
||||
name: choice,
|
||||
short: choice,
|
||||
disabled: false,
|
||||
};
|
||||
}
|
||||
const name = choice.name ?? String(choice.value);
|
||||
const normalizedChoice = {
|
||||
value: choice.value,
|
||||
name,
|
||||
short: choice.short ?? name,
|
||||
disabled: choice.disabled ?? false,
|
||||
};
|
||||
if (choice.description) {
|
||||
normalizedChoice.description = choice.description;
|
||||
}
|
||||
return normalizedChoice;
|
||||
});
|
||||
}
|
||||
exports.default = (0, core_1.createPrompt)((config, done) => {
|
||||
const { loop = true, pageSize = 7 } = config;
|
||||
const theme = (0, core_1.makeTheme)(selectTheme, config.theme);
|
||||
const { keybindings } = theme;
|
||||
const [status, setStatus] = (0, core_1.useState)('idle');
|
||||
const prefix = (0, core_1.usePrefix)({ status, theme });
|
||||
const searchTimeoutRef = (0, core_1.useRef)();
|
||||
// Vim keybindings (j/k) conflict with typing those letters in search,
|
||||
// so search must be disabled when vim bindings are enabled
|
||||
const searchEnabled = !keybindings.includes('vim');
|
||||
const items = (0, core_1.useMemo)(() => normalizeChoices(config.choices), [config.choices]);
|
||||
const bounds = (0, core_1.useMemo)(() => {
|
||||
const first = items.findIndex(isSelectable);
|
||||
const last = items.findLastIndex(isSelectable);
|
||||
if (first === -1) {
|
||||
throw new core_1.ValidationError('[select prompt] No selectable choices. All choices are disabled.');
|
||||
}
|
||||
return { first, last };
|
||||
}, [items]);
|
||||
const defaultItemIndex = (0, core_1.useMemo)(() => {
|
||||
if (!('default' in config))
|
||||
return -1;
|
||||
return items.findIndex((item) => isSelectable(item) && item.value === config.default);
|
||||
}, [config.default, items]);
|
||||
const [active, setActive] = (0, core_1.useState)(defaultItemIndex === -1 ? bounds.first : defaultItemIndex);
|
||||
// Safe to assume the cursor position always point to a Choice.
|
||||
const selectedChoice = items[active];
|
||||
(0, core_1.useKeypress)((key, rl) => {
|
||||
clearTimeout(searchTimeoutRef.current);
|
||||
if ((0, core_1.isEnterKey)(key)) {
|
||||
setStatus('done');
|
||||
done(selectedChoice.value);
|
||||
}
|
||||
else if ((0, core_1.isUpKey)(key, keybindings) || (0, core_1.isDownKey)(key, keybindings)) {
|
||||
rl.clearLine(0);
|
||||
if (loop ||
|
||||
((0, core_1.isUpKey)(key, keybindings) && active !== bounds.first) ||
|
||||
((0, core_1.isDownKey)(key, keybindings) && active !== bounds.last)) {
|
||||
const offset = (0, core_1.isUpKey)(key, keybindings) ? -1 : 1;
|
||||
let next = active;
|
||||
do {
|
||||
next = (next + offset + items.length) % items.length;
|
||||
} while (!isSelectable(items[next]));
|
||||
setActive(next);
|
||||
}
|
||||
}
|
||||
else if ((0, core_1.isNumberKey)(key) && !Number.isNaN(Number(rl.line))) {
|
||||
const selectedIndex = Number(rl.line) - 1;
|
||||
// Find the nth item (ignoring separators)
|
||||
let selectableIndex = -1;
|
||||
const position = items.findIndex((item) => {
|
||||
if (core_1.Separator.isSeparator(item))
|
||||
return false;
|
||||
selectableIndex++;
|
||||
return selectableIndex === selectedIndex;
|
||||
});
|
||||
const item = items[position];
|
||||
if (item != null && isSelectable(item)) {
|
||||
setActive(position);
|
||||
}
|
||||
searchTimeoutRef.current = setTimeout(() => {
|
||||
rl.clearLine(0);
|
||||
}, 700);
|
||||
}
|
||||
else if ((0, core_1.isBackspaceKey)(key)) {
|
||||
rl.clearLine(0);
|
||||
}
|
||||
else if (searchEnabled) {
|
||||
const searchTerm = rl.line.toLowerCase();
|
||||
const matchIndex = items.findIndex((item) => {
|
||||
if (core_1.Separator.isSeparator(item) || !isSelectable(item))
|
||||
return false;
|
||||
return item.name.toLowerCase().startsWith(searchTerm);
|
||||
});
|
||||
if (matchIndex !== -1) {
|
||||
setActive(matchIndex);
|
||||
}
|
||||
searchTimeoutRef.current = setTimeout(() => {
|
||||
rl.clearLine(0);
|
||||
}, 700);
|
||||
}
|
||||
});
|
||||
(0, core_1.useEffect)(() => () => {
|
||||
clearTimeout(searchTimeoutRef.current);
|
||||
}, []);
|
||||
const message = theme.style.message(config.message, status);
|
||||
let helpLine;
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
if (theme.helpMode !== 'never') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
if (config.instructions) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
const { pager, navigation } = config.instructions;
|
||||
helpLine = theme.style.help(items.length > pageSize ? pager : navigation);
|
||||
}
|
||||
else {
|
||||
helpLine = theme.style.keysHelpTip([
|
||||
['↑↓', 'navigate'],
|
||||
['⏎', 'select'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
let separatorCount = 0;
|
||||
const page = (0, core_1.usePagination)({
|
||||
items,
|
||||
active,
|
||||
renderItem({ item, isActive, index }) {
|
||||
if (core_1.Separator.isSeparator(item)) {
|
||||
separatorCount++;
|
||||
return ` ${item.separator}`;
|
||||
}
|
||||
const indexLabel = theme.indexMode === 'number' ? `${index + 1 - separatorCount}. ` : '';
|
||||
if (item.disabled) {
|
||||
const disabledLabel = typeof item.disabled === 'string' ? item.disabled : '(disabled)';
|
||||
return theme.style.disabled(`${indexLabel}${item.name} ${disabledLabel}`);
|
||||
}
|
||||
const color = isActive ? theme.style.highlight : (x) => x;
|
||||
const cursor = isActive ? theme.icon.cursor : ` `;
|
||||
return color(`${cursor} ${indexLabel}${item.name}`);
|
||||
},
|
||||
pageSize,
|
||||
loop,
|
||||
});
|
||||
if (status === 'done') {
|
||||
return [prefix, message, theme.style.answer(selectedChoice.short)]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
}
|
||||
const { description } = selectedChoice;
|
||||
const lines = [
|
||||
[prefix, message].filter(Boolean).join(' '),
|
||||
page,
|
||||
' ',
|
||||
description ? theme.style.description(description) : '',
|
||||
helpLine,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('\n')
|
||||
.trimEnd();
|
||||
return `${lines}${ansi_1.cursorHide}`;
|
||||
});
|
||||
var core_2 = require("@inquirer/core");
|
||||
Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return core_2.Separator; } });
|
||||
3
node_modules/@inquirer/select/dist/commonjs/package.json
generated
vendored
Normal file
3
node_modules/@inquirer/select/dist/commonjs/package.json
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
40
node_modules/@inquirer/select/dist/esm/index.d.ts
generated
vendored
Normal file
40
node_modules/@inquirer/select/dist/esm/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Separator, type Theme, type Keybinding } from '@inquirer/core';
|
||||
import type { PartialDeep } from '@inquirer/type';
|
||||
type SelectTheme = {
|
||||
icon: {
|
||||
cursor: string;
|
||||
};
|
||||
style: {
|
||||
disabled: (text: string) => string;
|
||||
description: (text: string) => string;
|
||||
keysHelpTip: (keys: [key: string, action: string][]) => string | undefined;
|
||||
};
|
||||
/** @deprecated Use theme.style.keysHelpTip instead */
|
||||
helpMode: 'always' | 'never' | 'auto';
|
||||
indexMode: 'hidden' | 'number';
|
||||
keybindings: ReadonlyArray<Keybinding>;
|
||||
};
|
||||
type Choice<Value> = {
|
||||
value: Value;
|
||||
name?: string;
|
||||
description?: string;
|
||||
short?: string;
|
||||
disabled?: boolean | string;
|
||||
type?: never;
|
||||
};
|
||||
declare const _default: <Value>(config: {
|
||||
message: string;
|
||||
choices: readonly (string | Separator)[] | readonly (Separator | Choice<Value>)[];
|
||||
pageSize?: number | undefined;
|
||||
loop?: boolean | undefined;
|
||||
default?: unknown;
|
||||
instructions?: {
|
||||
navigation: string;
|
||||
pager: string;
|
||||
} | undefined;
|
||||
theme?: PartialDeep<Theme<SelectTheme>> | undefined;
|
||||
}, context?: import("@inquirer/type").Context) => Promise<Value> & {
|
||||
cancel: () => void;
|
||||
};
|
||||
export default _default;
|
||||
export { Separator } from '@inquirer/core';
|
||||
187
node_modules/@inquirer/select/dist/esm/index.js
generated
vendored
Normal file
187
node_modules/@inquirer/select/dist/esm/index.js
generated
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
import { createPrompt, useState, useKeypress, usePrefix, usePagination, useRef, useMemo, useEffect, isBackspaceKey, isEnterKey, isUpKey, isDownKey, isNumberKey, Separator, ValidationError, makeTheme, } from '@inquirer/core';
|
||||
import { cursorHide } from '@inquirer/ansi';
|
||||
import colors from 'yoctocolors-cjs';
|
||||
import figures from '@inquirer/figures';
|
||||
const selectTheme = {
|
||||
icon: { cursor: figures.pointer },
|
||||
style: {
|
||||
disabled: (text) => colors.dim(`- ${text}`),
|
||||
description: (text) => colors.cyan(text),
|
||||
keysHelpTip: (keys) => keys
|
||||
.map(([key, action]) => `${colors.bold(key)} ${colors.dim(action)}`)
|
||||
.join(colors.dim(' • ')),
|
||||
},
|
||||
helpMode: 'always',
|
||||
indexMode: 'hidden',
|
||||
keybindings: [],
|
||||
};
|
||||
function isSelectable(item) {
|
||||
return !Separator.isSeparator(item) && !item.disabled;
|
||||
}
|
||||
function normalizeChoices(choices) {
|
||||
return choices.map((choice) => {
|
||||
if (Separator.isSeparator(choice))
|
||||
return choice;
|
||||
if (typeof choice === 'string') {
|
||||
return {
|
||||
value: choice,
|
||||
name: choice,
|
||||
short: choice,
|
||||
disabled: false,
|
||||
};
|
||||
}
|
||||
const name = choice.name ?? String(choice.value);
|
||||
const normalizedChoice = {
|
||||
value: choice.value,
|
||||
name,
|
||||
short: choice.short ?? name,
|
||||
disabled: choice.disabled ?? false,
|
||||
};
|
||||
if (choice.description) {
|
||||
normalizedChoice.description = choice.description;
|
||||
}
|
||||
return normalizedChoice;
|
||||
});
|
||||
}
|
||||
export default createPrompt((config, done) => {
|
||||
const { loop = true, pageSize = 7 } = config;
|
||||
const theme = makeTheme(selectTheme, config.theme);
|
||||
const { keybindings } = theme;
|
||||
const [status, setStatus] = useState('idle');
|
||||
const prefix = usePrefix({ status, theme });
|
||||
const searchTimeoutRef = useRef();
|
||||
// Vim keybindings (j/k) conflict with typing those letters in search,
|
||||
// so search must be disabled when vim bindings are enabled
|
||||
const searchEnabled = !keybindings.includes('vim');
|
||||
const items = useMemo(() => normalizeChoices(config.choices), [config.choices]);
|
||||
const bounds = useMemo(() => {
|
||||
const first = items.findIndex(isSelectable);
|
||||
const last = items.findLastIndex(isSelectable);
|
||||
if (first === -1) {
|
||||
throw new ValidationError('[select prompt] No selectable choices. All choices are disabled.');
|
||||
}
|
||||
return { first, last };
|
||||
}, [items]);
|
||||
const defaultItemIndex = useMemo(() => {
|
||||
if (!('default' in config))
|
||||
return -1;
|
||||
return items.findIndex((item) => isSelectable(item) && item.value === config.default);
|
||||
}, [config.default, items]);
|
||||
const [active, setActive] = useState(defaultItemIndex === -1 ? bounds.first : defaultItemIndex);
|
||||
// Safe to assume the cursor position always point to a Choice.
|
||||
const selectedChoice = items[active];
|
||||
useKeypress((key, rl) => {
|
||||
clearTimeout(searchTimeoutRef.current);
|
||||
if (isEnterKey(key)) {
|
||||
setStatus('done');
|
||||
done(selectedChoice.value);
|
||||
}
|
||||
else if (isUpKey(key, keybindings) || isDownKey(key, keybindings)) {
|
||||
rl.clearLine(0);
|
||||
if (loop ||
|
||||
(isUpKey(key, keybindings) && active !== bounds.first) ||
|
||||
(isDownKey(key, keybindings) && active !== bounds.last)) {
|
||||
const offset = isUpKey(key, keybindings) ? -1 : 1;
|
||||
let next = active;
|
||||
do {
|
||||
next = (next + offset + items.length) % items.length;
|
||||
} while (!isSelectable(items[next]));
|
||||
setActive(next);
|
||||
}
|
||||
}
|
||||
else if (isNumberKey(key) && !Number.isNaN(Number(rl.line))) {
|
||||
const selectedIndex = Number(rl.line) - 1;
|
||||
// Find the nth item (ignoring separators)
|
||||
let selectableIndex = -1;
|
||||
const position = items.findIndex((item) => {
|
||||
if (Separator.isSeparator(item))
|
||||
return false;
|
||||
selectableIndex++;
|
||||
return selectableIndex === selectedIndex;
|
||||
});
|
||||
const item = items[position];
|
||||
if (item != null && isSelectable(item)) {
|
||||
setActive(position);
|
||||
}
|
||||
searchTimeoutRef.current = setTimeout(() => {
|
||||
rl.clearLine(0);
|
||||
}, 700);
|
||||
}
|
||||
else if (isBackspaceKey(key)) {
|
||||
rl.clearLine(0);
|
||||
}
|
||||
else if (searchEnabled) {
|
||||
const searchTerm = rl.line.toLowerCase();
|
||||
const matchIndex = items.findIndex((item) => {
|
||||
if (Separator.isSeparator(item) || !isSelectable(item))
|
||||
return false;
|
||||
return item.name.toLowerCase().startsWith(searchTerm);
|
||||
});
|
||||
if (matchIndex !== -1) {
|
||||
setActive(matchIndex);
|
||||
}
|
||||
searchTimeoutRef.current = setTimeout(() => {
|
||||
rl.clearLine(0);
|
||||
}, 700);
|
||||
}
|
||||
});
|
||||
useEffect(() => () => {
|
||||
clearTimeout(searchTimeoutRef.current);
|
||||
}, []);
|
||||
const message = theme.style.message(config.message, status);
|
||||
let helpLine;
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
if (theme.helpMode !== 'never') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
if (config.instructions) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
const { pager, navigation } = config.instructions;
|
||||
helpLine = theme.style.help(items.length > pageSize ? pager : navigation);
|
||||
}
|
||||
else {
|
||||
helpLine = theme.style.keysHelpTip([
|
||||
['↑↓', 'navigate'],
|
||||
['⏎', 'select'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
let separatorCount = 0;
|
||||
const page = usePagination({
|
||||
items,
|
||||
active,
|
||||
renderItem({ item, isActive, index }) {
|
||||
if (Separator.isSeparator(item)) {
|
||||
separatorCount++;
|
||||
return ` ${item.separator}`;
|
||||
}
|
||||
const indexLabel = theme.indexMode === 'number' ? `${index + 1 - separatorCount}. ` : '';
|
||||
if (item.disabled) {
|
||||
const disabledLabel = typeof item.disabled === 'string' ? item.disabled : '(disabled)';
|
||||
return theme.style.disabled(`${indexLabel}${item.name} ${disabledLabel}`);
|
||||
}
|
||||
const color = isActive ? theme.style.highlight : (x) => x;
|
||||
const cursor = isActive ? theme.icon.cursor : ` `;
|
||||
return color(`${cursor} ${indexLabel}${item.name}`);
|
||||
},
|
||||
pageSize,
|
||||
loop,
|
||||
});
|
||||
if (status === 'done') {
|
||||
return [prefix, message, theme.style.answer(selectedChoice.short)]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
}
|
||||
const { description } = selectedChoice;
|
||||
const lines = [
|
||||
[prefix, message].filter(Boolean).join(' '),
|
||||
page,
|
||||
' ',
|
||||
description ? theme.style.description(description) : '',
|
||||
helpLine,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('\n')
|
||||
.trimEnd();
|
||||
return `${lines}${cursorHide}`;
|
||||
});
|
||||
export { Separator } from '@inquirer/core';
|
||||
3
node_modules/@inquirer/select/dist/esm/package.json
generated
vendored
Normal file
3
node_modules/@inquirer/select/dist/esm/package.json
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
112
node_modules/@inquirer/select/package.json
generated
vendored
Normal file
112
node_modules/@inquirer/select/package.json
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
{
|
||||
"name": "@inquirer/select",
|
||||
"version": "4.4.0",
|
||||
"description": "Inquirer select/list prompt",
|
||||
"keywords": [
|
||||
"answer",
|
||||
"answers",
|
||||
"ask",
|
||||
"base",
|
||||
"cli",
|
||||
"command",
|
||||
"command-line",
|
||||
"confirm",
|
||||
"enquirer",
|
||||
"generate",
|
||||
"generator",
|
||||
"hyper",
|
||||
"input",
|
||||
"inquire",
|
||||
"inquirer",
|
||||
"interface",
|
||||
"iterm",
|
||||
"javascript",
|
||||
"menu",
|
||||
"node",
|
||||
"nodejs",
|
||||
"prompt",
|
||||
"promptly",
|
||||
"prompts",
|
||||
"question",
|
||||
"readline",
|
||||
"scaffold",
|
||||
"scaffolder",
|
||||
"scaffolding",
|
||||
"stdin",
|
||||
"stdout",
|
||||
"terminal",
|
||||
"tty",
|
||||
"ui",
|
||||
"yeoman",
|
||||
"yo",
|
||||
"zsh"
|
||||
],
|
||||
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/main/packages/select/README.md",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/SBoudrias/Inquirer.js.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "Simon Boudrias <admin@simonboudrias.com>",
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"main": "./dist/commonjs/index.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"attw": "attw --pack",
|
||||
"tsc": "tshy"
|
||||
},
|
||||
"dependencies": {
|
||||
"@inquirer/ansi": "^1.0.1",
|
||||
"@inquirer/core": "^10.3.0",
|
||||
"@inquirer/figures": "^1.0.14",
|
||||
"@inquirer/type": "^3.0.9",
|
||||
"yoctocolors-cjs": "^2.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@arethetypeswrong/cli": "^0.18.2",
|
||||
"@inquirer/testing": "^2.1.51",
|
||||
"tshy": "^3.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"tshy": {
|
||||
"exclude": [
|
||||
"src/**/*.test.ts"
|
||||
],
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": "./src/index.ts"
|
||||
}
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/node": ">=18"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/node": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"gitHead": "87cb01e67a25983bdaf0d74a7685915c0afb5f23"
|
||||
}
|
||||
Reference in New Issue
Block a user