@inquirer/select 0.0.29-alpha.0 → 1.0.0
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
CHANGED
|
@@ -35,6 +35,11 @@ const answer = await select({
|
|
|
35
35
|
value: 'jspm',
|
|
36
36
|
disabled: true,
|
|
37
37
|
},
|
|
38
|
+
{
|
|
39
|
+
name: 'pnpm',
|
|
40
|
+
value: 'pnpm',
|
|
41
|
+
disabled: '(pnpm is not available)',
|
|
42
|
+
},
|
|
38
43
|
],
|
|
39
44
|
});
|
|
40
45
|
```
|
|
@@ -44,7 +49,7 @@ const answer = await select({
|
|
|
44
49
|
| Property | Type | Required | Description |
|
|
45
50
|
| -------- | --------- | -------- | ------------------------------ |
|
|
46
51
|
| message | `string` | yes | The question to ask |
|
|
47
|
-
| choices | `Array<{ value: string, name?: string, description?: string, disabled?: boolean }>` | yes | List of the available choices. The `value` will be returned as the answer, and used as display if no `name` is defined. Choices who're `disabled` will be displayed, but not selectable. The `description` will be displayed under the prompt when the cursor land over the choice. |
|
|
52
|
+
| choices | `Array<{ value: string, name?: string, description?: string, disabled?: boolean \| string }>` | yes | List of the available choices. The `value` will be returned as the answer, and used as display if no `name` is defined. Choices who're `disabled` will be displayed, but not selectable. The `description` will be displayed under the prompt when the cursor land over the choice. |
|
|
48
53
|
| 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. |
|
|
49
54
|
|
|
50
55
|
# License
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@inquirer/core");
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const figures_1 = __importDefault(require("figures"));
|
|
9
|
+
const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
|
|
10
|
+
exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
11
|
+
const { choices } = config;
|
|
12
|
+
const startIndex = Math.max(choices.findIndex(({ disabled }) => !disabled), 0);
|
|
13
|
+
const paginator = (0, core_1.useRef)(new core_1.Paginator()).current;
|
|
14
|
+
const firstRender = (0, core_1.useRef)(true);
|
|
15
|
+
const prefix = (0, core_1.usePrefix)();
|
|
16
|
+
const [status, setStatus] = (0, core_1.useState)('pending');
|
|
17
|
+
const [cursorPosition, setCursorPos] = (0, core_1.useState)(startIndex);
|
|
18
|
+
(0, core_1.useKeypress)((key) => {
|
|
19
|
+
if ((0, core_1.isEnterKey)(key)) {
|
|
20
|
+
setStatus('done');
|
|
21
|
+
done(choices[cursorPosition].value);
|
|
22
|
+
}
|
|
23
|
+
else if ((0, core_1.isUpKey)(key) || (0, core_1.isDownKey)(key)) {
|
|
24
|
+
let newCursorPosition = cursorPosition;
|
|
25
|
+
const offset = (0, core_1.isUpKey)(key) ? -1 : 1;
|
|
26
|
+
let selectedOption;
|
|
27
|
+
while (!selectedOption || selectedOption.disabled) {
|
|
28
|
+
newCursorPosition =
|
|
29
|
+
(newCursorPosition + offset + choices.length) % choices.length;
|
|
30
|
+
selectedOption = choices[newCursorPosition];
|
|
31
|
+
}
|
|
32
|
+
setCursorPos(newCursorPosition);
|
|
33
|
+
}
|
|
34
|
+
else if ((0, core_1.isNumberKey)(key)) {
|
|
35
|
+
// Adjust index to start at 1
|
|
36
|
+
const newCursorPosition = Number(key.name) - 1;
|
|
37
|
+
// Abort if the choice doesn't exists or if disabled
|
|
38
|
+
if (!choices[newCursorPosition] || choices[newCursorPosition].disabled) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setCursorPos(newCursorPosition);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
let message = chalk_1.default.bold(config.message);
|
|
45
|
+
if (firstRender.current) {
|
|
46
|
+
message += chalk_1.default.dim(' (Use arrow keys)');
|
|
47
|
+
firstRender.current = false;
|
|
48
|
+
}
|
|
49
|
+
if (status === 'done') {
|
|
50
|
+
const choice = choices[cursorPosition];
|
|
51
|
+
return `${prefix} ${message} ${chalk_1.default.cyan(choice.name || choice.value)}`;
|
|
52
|
+
}
|
|
53
|
+
const allChoices = choices
|
|
54
|
+
.map(({ name, value, disabled }, index) => {
|
|
55
|
+
const line = name || value;
|
|
56
|
+
if (disabled) {
|
|
57
|
+
return chalk_1.default.dim(`- ${line} ${typeof disabled === 'string' ? disabled : '(disabled)'}`);
|
|
58
|
+
}
|
|
59
|
+
if (index === cursorPosition) {
|
|
60
|
+
return chalk_1.default.cyan(`${figures_1.default.pointer} ${line}`);
|
|
61
|
+
}
|
|
62
|
+
return ` ${line}`;
|
|
63
|
+
})
|
|
64
|
+
.join('\n');
|
|
65
|
+
const windowedChoices = paginator.paginate(allChoices, cursorPosition, config.pageSize);
|
|
66
|
+
const choice = choices[cursorPosition];
|
|
67
|
+
const choiceDescription = choice && choice.description ? `\n${choice.description}` : ``;
|
|
68
|
+
return `${prefix} ${message}\n${windowedChoices}${choiceDescription}${ansi_escapes_1.default.cursorHide}`;
|
|
69
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AsyncPromptConfig } from '@inquirer/core';
|
|
2
|
-
|
|
2
|
+
type SelectConfig = AsyncPromptConfig & {
|
|
3
3
|
choices: {
|
|
4
4
|
value: string;
|
|
5
5
|
name?: string;
|
|
6
6
|
description?: string;
|
|
7
|
-
disabled?: boolean;
|
|
7
|
+
disabled?: boolean | string;
|
|
8
8
|
}[];
|
|
9
9
|
pageSize?: number;
|
|
10
10
|
};
|
|
@@ -49,7 +49,7 @@ export default createPrompt((config, done) => {
|
|
|
49
49
|
.map(({ name, value, disabled }, index) => {
|
|
50
50
|
const line = name || value;
|
|
51
51
|
if (disabled) {
|
|
52
|
-
return chalk.dim(`- ${line} (disabled)`);
|
|
52
|
+
return chalk.dim(`- ${line} ${typeof disabled === 'string' ? disabled : '(disabled)'}`);
|
|
53
53
|
}
|
|
54
54
|
if (index === cursorPosition) {
|
|
55
55
|
return chalk.cyan(`${figures.pointer} ${line}`);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AsyncPromptConfig } from '@inquirer/core';
|
|
2
|
+
type SelectConfig = AsyncPromptConfig & {
|
|
3
|
+
choices: {
|
|
4
|
+
value: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
disabled?: boolean | string;
|
|
8
|
+
}[];
|
|
9
|
+
pageSize?: number;
|
|
10
|
+
};
|
|
11
|
+
declare const _default: import("@inquirer/type").Prompt<string, SelectConfig>;
|
|
12
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/select",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.0.29-alpha.0",
|
|
3
|
+
"version": "1.0.0",
|
|
5
4
|
"description": "Inquirer select/list prompt",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"typings": "dist/index.d.
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"typings": "./dist/cjs/types/index.d.mts",
|
|
8
7
|
"files": [
|
|
9
|
-
"dist
|
|
8
|
+
"dist/**/*"
|
|
10
9
|
],
|
|
11
|
-
"repository":
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/SBoudrias/Inquirer.js.git"
|
|
13
|
+
},
|
|
12
14
|
"keywords": [
|
|
13
15
|
"answer",
|
|
14
16
|
"answers",
|
|
15
17
|
"ask",
|
|
16
18
|
"base",
|
|
17
19
|
"cli",
|
|
18
|
-
"cli",
|
|
19
20
|
"command",
|
|
20
21
|
"command-line",
|
|
21
22
|
"confirm",
|
|
@@ -49,20 +50,40 @@
|
|
|
49
50
|
"yo",
|
|
50
51
|
"zsh"
|
|
51
52
|
],
|
|
52
|
-
"author": "Simon Boudrias",
|
|
53
|
+
"author": "Simon Boudrias <admin@simonboudrias.com>",
|
|
53
54
|
"license": "MIT",
|
|
54
55
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/select/README.md",
|
|
55
56
|
"dependencies": {
|
|
56
|
-
"@inquirer/core": "^
|
|
57
|
+
"@inquirer/core": "^1.0.1",
|
|
58
|
+
"@inquirer/type": "^1.0.0",
|
|
57
59
|
"ansi-escapes": "^6.0.0",
|
|
58
|
-
"chalk": "^5.
|
|
60
|
+
"chalk": "^5.2.0",
|
|
59
61
|
"figures": "^5.0.0"
|
|
60
62
|
},
|
|
61
63
|
"scripts": {
|
|
62
|
-
"tsc": "tsc"
|
|
64
|
+
"tsc": "yarn run clean && yarn run tsc:esm && yarn run tsc:cjs",
|
|
65
|
+
"clean": "rm -rf dist",
|
|
66
|
+
"tsc:esm": "tsc -p ./tsconfig.esm.json",
|
|
67
|
+
"tsc:cjs": "tsc -p ./tsconfig.cjs.json && yarn run fix-ext",
|
|
68
|
+
"fix-ext": "ts-node ../../tools/rename-ext.ts"
|
|
63
69
|
},
|
|
64
70
|
"publishConfig": {
|
|
65
71
|
"access": "public"
|
|
66
72
|
},
|
|
67
|
-
"
|
|
73
|
+
"engines": {
|
|
74
|
+
"node": ">=14.18.0"
|
|
75
|
+
},
|
|
76
|
+
"exports": {
|
|
77
|
+
".": {
|
|
78
|
+
"import": {
|
|
79
|
+
"types": "./dist/esm/types/index.d.mts",
|
|
80
|
+
"default": "./dist/esm/index.mjs"
|
|
81
|
+
},
|
|
82
|
+
"require": {
|
|
83
|
+
"types": "./dist/cjs/types/index.d.mts",
|
|
84
|
+
"default": "./dist/cjs/index.js"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"gitHead": "e93c4cb14f0c35ebd1efb065776b90f48899b075"
|
|
68
89
|
}
|