@inquirer/select 2.2.2 → 2.3.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 +7 -0
- package/dist/cjs/index.js +16 -9
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/esm/index.mjs +16 -9
- package/dist/esm/types/index.d.mts +1 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -80,9 +80,16 @@ type Theme = {
|
|
|
80
80
|
icon: {
|
|
81
81
|
cursor: string;
|
|
82
82
|
};
|
|
83
|
+
helpMode: 'always' | 'never' | 'auto';
|
|
83
84
|
};
|
|
84
85
|
```
|
|
85
86
|
|
|
87
|
+
### `theme.helpMode`
|
|
88
|
+
|
|
89
|
+
- `auto` (default): Hide the help tips after an interaction occurs.
|
|
90
|
+
- `always`: The help tips will always show and never hide.
|
|
91
|
+
- `never`: The help tips will never show.
|
|
92
|
+
|
|
86
93
|
# License
|
|
87
94
|
|
|
88
95
|
Copyright (c) 2023 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))<br/>
|
package/dist/cjs/index.js
CHANGED
|
@@ -7,11 +7,12 @@ exports.Separator = void 0;
|
|
|
7
7
|
const core_1 = require("@inquirer/core");
|
|
8
8
|
Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return core_1.Separator; } });
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
const figures_1 = __importDefault(require("figures"));
|
|
10
|
+
const figures_1 = __importDefault(require("@inquirer/figures"));
|
|
11
11
|
const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
|
|
12
12
|
const selectTheme = {
|
|
13
13
|
icon: { cursor: figures_1.default.pointer },
|
|
14
14
|
style: { disabled: (text) => chalk_1.default.dim(`- ${text}`) },
|
|
15
|
+
helpMode: 'auto',
|
|
15
16
|
};
|
|
16
17
|
function isSelectable(item) {
|
|
17
18
|
return !core_1.Separator.isSeparator(item) && !item.disabled;
|
|
@@ -25,10 +26,10 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
25
26
|
const searchTimeoutRef = (0, core_1.useRef)(undefined);
|
|
26
27
|
const bounds = (0, core_1.useMemo)(() => {
|
|
27
28
|
const first = items.findIndex(isSelectable);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (first < 0)
|
|
29
|
+
const last = items.findLastIndex(isSelectable);
|
|
30
|
+
if (first < 0) {
|
|
31
31
|
throw new core_1.ValidationError('[select prompt] No selectable choices. All choices are disabled.');
|
|
32
|
+
}
|
|
32
33
|
return { first, last };
|
|
33
34
|
}, [items]);
|
|
34
35
|
const defaultItemIndex = (0, core_1.useMemo)(() => {
|
|
@@ -88,10 +89,17 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
88
89
|
}
|
|
89
90
|
});
|
|
90
91
|
const message = theme.style.message(config.message);
|
|
91
|
-
let
|
|
92
|
-
|
|
92
|
+
let helpTipTop = '';
|
|
93
|
+
let helpTipBottom = '';
|
|
94
|
+
if (theme.helpMode === 'always' ||
|
|
95
|
+
(theme.helpMode === 'auto' && firstRender.current)) {
|
|
93
96
|
firstRender.current = false;
|
|
94
|
-
|
|
97
|
+
if (items.length > pageSize) {
|
|
98
|
+
helpTipBottom = `\n${theme.style.help('(Use arrow keys to reveal more choices)')}`;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
helpTipTop = theme.style.help('(Use arrow keys)');
|
|
102
|
+
}
|
|
95
103
|
}
|
|
96
104
|
const page = (0, core_1.usePagination)({
|
|
97
105
|
items,
|
|
@@ -111,7 +119,6 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
111
119
|
},
|
|
112
120
|
pageSize,
|
|
113
121
|
loop,
|
|
114
|
-
theme,
|
|
115
122
|
});
|
|
116
123
|
if (status === 'done') {
|
|
117
124
|
const answer = selectedChoice.name ||
|
|
@@ -122,5 +129,5 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
122
129
|
const choiceDescription = selectedChoice.description
|
|
123
130
|
? `\n${selectedChoice.description}`
|
|
124
131
|
: ``;
|
|
125
|
-
return `${[prefix, message,
|
|
132
|
+
return `${[prefix, message, helpTipTop].filter(Boolean).join(' ')}\n${page}${choiceDescription}${helpTipBottom}${ansi_escapes_1.default.cursorHide}`;
|
|
126
133
|
});
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createPrompt, useState, useKeypress, usePrefix, usePagination, useRef, useMemo, isBackspaceKey, isEnterKey, isUpKey, isDownKey, isNumberKey, Separator, ValidationError, makeTheme, } from '@inquirer/core';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import figures from 'figures';
|
|
3
|
+
import figures from '@inquirer/figures';
|
|
4
4
|
import ansiEscapes from 'ansi-escapes';
|
|
5
5
|
const selectTheme = {
|
|
6
6
|
icon: { cursor: figures.pointer },
|
|
7
7
|
style: { disabled: (text) => chalk.dim(`- ${text}`) },
|
|
8
|
+
helpMode: 'auto',
|
|
8
9
|
};
|
|
9
10
|
function isSelectable(item) {
|
|
10
11
|
return !Separator.isSeparator(item) && !item.disabled;
|
|
@@ -18,10 +19,10 @@ export default createPrompt((config, done) => {
|
|
|
18
19
|
const searchTimeoutRef = useRef(undefined);
|
|
19
20
|
const bounds = useMemo(() => {
|
|
20
21
|
const first = items.findIndex(isSelectable);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (first < 0)
|
|
22
|
+
const last = items.findLastIndex(isSelectable);
|
|
23
|
+
if (first < 0) {
|
|
24
24
|
throw new ValidationError('[select prompt] No selectable choices. All choices are disabled.');
|
|
25
|
+
}
|
|
25
26
|
return { first, last };
|
|
26
27
|
}, [items]);
|
|
27
28
|
const defaultItemIndex = useMemo(() => {
|
|
@@ -81,10 +82,17 @@ export default createPrompt((config, done) => {
|
|
|
81
82
|
}
|
|
82
83
|
});
|
|
83
84
|
const message = theme.style.message(config.message);
|
|
84
|
-
let
|
|
85
|
-
|
|
85
|
+
let helpTipTop = '';
|
|
86
|
+
let helpTipBottom = '';
|
|
87
|
+
if (theme.helpMode === 'always' ||
|
|
88
|
+
(theme.helpMode === 'auto' && firstRender.current)) {
|
|
86
89
|
firstRender.current = false;
|
|
87
|
-
|
|
90
|
+
if (items.length > pageSize) {
|
|
91
|
+
helpTipBottom = `\n${theme.style.help('(Use arrow keys to reveal more choices)')}`;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
helpTipTop = theme.style.help('(Use arrow keys)');
|
|
95
|
+
}
|
|
88
96
|
}
|
|
89
97
|
const page = usePagination({
|
|
90
98
|
items,
|
|
@@ -104,7 +112,6 @@ export default createPrompt((config, done) => {
|
|
|
104
112
|
},
|
|
105
113
|
pageSize,
|
|
106
114
|
loop,
|
|
107
|
-
theme,
|
|
108
115
|
});
|
|
109
116
|
if (status === 'done') {
|
|
110
117
|
const answer = selectedChoice.name ||
|
|
@@ -115,6 +122,6 @@ export default createPrompt((config, done) => {
|
|
|
115
122
|
const choiceDescription = selectedChoice.description
|
|
116
123
|
? `\n${selectedChoice.description}`
|
|
117
124
|
: ``;
|
|
118
|
-
return `${[prefix, message,
|
|
125
|
+
return `${[prefix, message, helpTipTop].filter(Boolean).join(' ')}\n${page}${choiceDescription}${helpTipBottom}${ansiEscapes.cursorHide}`;
|
|
119
126
|
});
|
|
120
127
|
export { Separator };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/select",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Inquirer select/list prompt",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"typings": "./dist/cjs/types/index.d.ts",
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
"license": "MIT",
|
|
55
55
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/select/README.md",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@inquirer/core": "^
|
|
58
|
-
"@inquirer/
|
|
57
|
+
"@inquirer/core": "^8.0.0",
|
|
58
|
+
"@inquirer/figures": "^1.0.0",
|
|
59
|
+
"@inquirer/type": "^1.3.0",
|
|
59
60
|
"ansi-escapes": "^4.3.2",
|
|
60
|
-
"chalk": "^4.1.2"
|
|
61
|
-
"figures": "^3.2.0"
|
|
61
|
+
"chalk": "^4.1.2"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@inquirer/testing": "^2.1.
|
|
64
|
+
"@inquirer/testing": "^2.1.17"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
67
|
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "bb5b6b857d227b0fe8fd55951784f03800cdf73c"
|
|
91
91
|
}
|