@inquirer/select 0.0.20-alpha.0 → 0.0.23-alpha.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.
@@ -0,0 +1,15 @@
1
+ import { AsyncPromptConfig } from '@inquirer/core';
2
+ declare type SelectConfig = AsyncPromptConfig & {
3
+ choices: {
4
+ value: string;
5
+ name?: string;
6
+ description?: string;
7
+ disabled?: boolean;
8
+ }[];
9
+ pageSize?: number;
10
+ };
11
+ declare const _default: (options: SelectConfig, stdio?: {
12
+ input?: NodeJS.ReadableStream | undefined;
13
+ output?: NodeJS.WritableStream | undefined;
14
+ } | undefined) => Promise<string>;
15
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ import { createPrompt, useState, useKeypress, useRef, usePrefix, isEnterKey, isUpKey, isDownKey, isNumberKey, Paginator, } from '@inquirer/core';
2
+ import chalk from 'chalk';
3
+ import figures from 'figures';
4
+ import ansiEscapes from 'ansi-escapes';
5
+ export default createPrompt((config, done) => {
6
+ const [status, setStatus] = useState('pending');
7
+ const [cursorPosition, setCursorPos] = useState(0);
8
+ const { choices, pageSize = 7 } = config;
9
+ const paginator = useRef(new Paginator()).current;
10
+ const prefix = usePrefix();
11
+ useKeypress((key) => {
12
+ if (isEnterKey(key)) {
13
+ setStatus('done');
14
+ done(choices[cursorPosition].value);
15
+ }
16
+ else if (isUpKey(key) || isDownKey(key)) {
17
+ let newCursorPosition = cursorPosition;
18
+ const offset = isUpKey(key) ? -1 : 1;
19
+ let selectedOption;
20
+ while (!selectedOption || selectedOption.disabled) {
21
+ newCursorPosition =
22
+ (newCursorPosition + offset + choices.length) % choices.length;
23
+ selectedOption = choices[newCursorPosition];
24
+ }
25
+ setCursorPos(newCursorPosition);
26
+ }
27
+ else if (isNumberKey(key)) {
28
+ // Adjust index to start at 1
29
+ const newCursorPosition = Number(key.name) - 1;
30
+ // Abort if the choice doesn't exists or if disabled
31
+ if (!choices[newCursorPosition] || choices[newCursorPosition].disabled) {
32
+ return;
33
+ }
34
+ setCursorPos(newCursorPosition);
35
+ }
36
+ });
37
+ const message = chalk.bold(config.message);
38
+ if (status === 'done') {
39
+ const choice = choices[cursorPosition];
40
+ return `${prefix} ${message} ${chalk.cyan(choice.name || choice.value)}`;
41
+ }
42
+ const allChoices = choices
43
+ .map(({ name, value, disabled }, index) => {
44
+ const line = name || value;
45
+ if (disabled) {
46
+ return chalk.dim(`- ${line} (disabled)`);
47
+ }
48
+ if (index === cursorPosition) {
49
+ return chalk.cyan(`${figures.pointer} ${line}`);
50
+ }
51
+ return ` ${line}`;
52
+ })
53
+ .join('\n');
54
+ const windowedChoices = paginator.paginate(allChoices, cursorPosition, pageSize);
55
+ const choice = choices[cursorPosition];
56
+ const choiceDescription = choice && choice.description ? `\n${choice.description}` : ``;
57
+ return `${prefix} ${message}\n${windowedChoices}${choiceDescription}${ansiEscapes.cursorHide}`;
58
+ });
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@inquirer/select",
3
- "version": "0.0.20-alpha.0",
3
+ "type": "module",
4
+ "version": "0.0.23-alpha.0",
4
5
  "description": "Inquirer select/list prompt",
5
- "main": "index.js",
6
+ "main": "dist/index.js",
7
+ "typings": "dist/index.d.ts",
8
+ "files": [
9
+ "dist/"
10
+ ],
6
11
  "repository": "SBoudrias/Inquirer.js",
7
12
  "keywords": [
8
13
  "cli",
@@ -14,12 +19,16 @@
14
19
  "license": "MIT",
15
20
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/select/README.md",
16
21
  "dependencies": {
17
- "@inquirer/core": "^0.0.20-alpha.0",
18
- "chalk": "^4.1.1",
19
- "figures": "^3.0.0"
22
+ "@inquirer/core": "^0.0.23-alpha.0",
23
+ "ansi-escapes": "^5.0.0",
24
+ "chalk": "^5.0.1",
25
+ "figures": "^4.0.1"
26
+ },
27
+ "scripts": {
28
+ "tsc": "tsc"
20
29
  },
21
30
  "publishConfig": {
22
31
  "access": "public"
23
32
  },
24
- "gitHead": "83b807522ca6e10ab90a6921eac9d9655e2dac38"
33
+ "gitHead": "a95b68efa6f407cefff63300e7e50da34c6b6693"
25
34
  }
package/demo.js DELETED
@@ -1,52 +0,0 @@
1
- const select = require('.');
2
-
3
- (async () => {
4
- let answer;
5
-
6
- answer = await select({
7
- message: 'Select a package manager',
8
- choices: [
9
- {
10
- name: 'npm',
11
- value: 'npm',
12
- description: 'npm is the most popular package manager',
13
- },
14
- { name: 'yarn', value: 'yarn', description: 'yarn is an awesome package manager' },
15
- { name: 'jspm', value: 'jspm', disabled: true },
16
- ],
17
- });
18
- console.log('Answer:', answer);
19
-
20
- answer = await select({
21
- message: 'Select your favorite letter',
22
- choices: [
23
- { value: 'A' },
24
- { value: 'B' },
25
- { value: 'C' },
26
- { value: 'D' },
27
- { value: 'E' },
28
- { value: 'F' },
29
- { value: 'G' },
30
- { value: 'H' },
31
- { value: 'I' },
32
- { value: 'J' },
33
- { value: 'K' },
34
- { value: 'L' },
35
- { value: 'M' },
36
- { value: 'N' },
37
- { value: 'O', description: 'Letter O, not number 0' },
38
- { value: 'P' },
39
- { value: 'Q' },
40
- { value: 'R' },
41
- { value: 'S' },
42
- { value: 'T' },
43
- { value: 'U' },
44
- { value: 'V' },
45
- { value: 'W' },
46
- { value: 'X' },
47
- { value: 'Y' },
48
- { value: 'Z' },
49
- ],
50
- });
51
- console.log('Answer:', answer);
52
- })();
package/index.js DELETED
@@ -1,72 +0,0 @@
1
- const { createPrompt, useState, useKeypress, useRef } = require('@inquirer/core/hooks');
2
- const { usePrefix } = require('@inquirer/core/lib/prefix');
3
- const { isEnterKey, isUpKey, isDownKey, isNumberKey } = require('@inquirer/core/lib/key');
4
- const Paginator = require('@inquirer/core/lib/Paginator');
5
- const chalk = require('chalk');
6
- const figures = require('figures');
7
- const { cursorHide } = require('ansi-escapes');
8
-
9
- module.exports = createPrompt((config, done) => {
10
- const [status, setStatus] = useState('pending');
11
- const [cursorPosition, setCursorPos] = useState(0);
12
- const { choices, pageSize = 7 } = config;
13
- const paginator = useRef(new Paginator()).current;
14
- const prefix = usePrefix();
15
-
16
- useKeypress((key) => {
17
- if (isEnterKey(key)) {
18
- setStatus('done');
19
- done(choices[cursorPosition].value);
20
- } else if (isUpKey(key) || isDownKey(key)) {
21
- let newCursorPosition = cursorPosition;
22
- const offset = isUpKey(key) ? -1 : 1;
23
- let selectedOption;
24
-
25
- while (!selectedOption || selectedOption.disabled) {
26
- newCursorPosition =
27
- (newCursorPosition + offset + choices.length) % choices.length;
28
- selectedOption = choices[newCursorPosition];
29
- }
30
-
31
- setCursorPos(newCursorPosition);
32
- } else if (isNumberKey(key)) {
33
- // Adjust index to start at 1
34
- const newCursorPosition = Number(key.name) - 1;
35
-
36
- // Abort if the choice doesn't exists or if disabled
37
- if (!choices[newCursorPosition] || choices[newCursorPosition].disabled) {
38
- return;
39
- }
40
-
41
- setCursorPos(newCursorPosition);
42
- }
43
- });
44
-
45
- const message = chalk.bold(config.message);
46
-
47
- if (status === 'done') {
48
- const choice = choices[cursorPosition];
49
- return `${prefix} ${message} ${chalk.cyan(choice.name || choice.value)}`;
50
- }
51
-
52
- const allChoices = choices
53
- .map(({ name, value, disabled }, index) => {
54
- const line = name || value;
55
- if (disabled) {
56
- return chalk.dim(`- ${line} (disabled)`);
57
- }
58
-
59
- if (index === cursorPosition) {
60
- return chalk.cyan(`${figures.pointer} ${line}`);
61
- }
62
-
63
- return ` ${line}`;
64
- })
65
- .join('\n');
66
- const windowedChoices = paginator.paginate(allChoices, cursorPosition, pageSize);
67
-
68
- const choice = choices[cursorPosition];
69
- const choiceDescription = choice && choice.description ? `\n${choice.description}` : ``;
70
-
71
- return `${prefix} ${message}\n${windowedChoices}${choiceDescription}${cursorHide}`;
72
- });