@inquirer/expand 1.1.16 → 2.0.1
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 +22 -0
- package/dist/cjs/index.js +7 -6
- package/dist/cjs/types/index.d.ts +10 -6
- package/dist/esm/index.mjs +8 -7
- package/dist/esm/types/index.d.mts +10 -6
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -54,6 +54,28 @@ const answer = await expand({
|
|
|
54
54
|
| choices | `Array<{ key: string, name: string, value?: string }>` | yes | Array of the different allowed choices. The `h`/help option is always provided by default |
|
|
55
55
|
| default | `string` | no | Default choices to be selected. (value must be one of the choices `key`) |
|
|
56
56
|
| expanded | `boolean` | no | Expand the choices by default |
|
|
57
|
+
| theme | [See Theming](#Theming) | no | Customize look of the prompt. |
|
|
58
|
+
|
|
59
|
+
## Theming
|
|
60
|
+
|
|
61
|
+
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.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
type Theme = {
|
|
65
|
+
prefix: string;
|
|
66
|
+
spinner: {
|
|
67
|
+
interval: number;
|
|
68
|
+
frames: string[];
|
|
69
|
+
};
|
|
70
|
+
style: {
|
|
71
|
+
answer: (text: string) => string;
|
|
72
|
+
message: (text: string) => string;
|
|
73
|
+
error: (text: string) => string;
|
|
74
|
+
defaultAnswer: (text: string) => string;
|
|
75
|
+
highlight: (text: string) => string;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
```
|
|
57
79
|
|
|
58
80
|
# License
|
|
59
81
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -26,7 +26,8 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
26
26
|
const [value, setValue] = (0, core_1.useState)('');
|
|
27
27
|
const [expanded, setExpanded] = (0, core_1.useState)(defaultExpandState);
|
|
28
28
|
const [errorMsg, setError] = (0, core_1.useState)(undefined);
|
|
29
|
-
const
|
|
29
|
+
const theme = (0, core_1.makeTheme)(config.theme);
|
|
30
|
+
const prefix = (0, core_1.usePrefix)({ theme });
|
|
30
31
|
(0, core_1.useKeypress)((event, rl) => {
|
|
31
32
|
if ((0, core_1.isEnterKey)(event)) {
|
|
32
33
|
const answer = (value || defaultKey).toLowerCase();
|
|
@@ -54,10 +55,10 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
54
55
|
setError(undefined);
|
|
55
56
|
}
|
|
56
57
|
});
|
|
57
|
-
const message =
|
|
58
|
+
const message = theme.style.message(config.message);
|
|
58
59
|
if (status === 'done') {
|
|
59
60
|
// TODO: `value` should be the display name instead of the raw value.
|
|
60
|
-
return `${prefix} ${message} ${
|
|
61
|
+
return `${prefix} ${message} ${theme.style.answer(value)}`;
|
|
61
62
|
}
|
|
62
63
|
const allChoices = expanded ? choices : [...choices, helpChoice];
|
|
63
64
|
// Collapsed display style
|
|
@@ -70,7 +71,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
70
71
|
return choice.key;
|
|
71
72
|
})
|
|
72
73
|
.join('');
|
|
73
|
-
shortChoices =
|
|
74
|
+
shortChoices = ` ${theme.style.defaultAnswer(shortChoices)}`;
|
|
74
75
|
// Expanded display style
|
|
75
76
|
if (expanded) {
|
|
76
77
|
shortChoices = '';
|
|
@@ -78,7 +79,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
78
79
|
.map((choice) => {
|
|
79
80
|
const line = ` ${choice.key}) ${getChoiceKey(choice, 'name')}`;
|
|
80
81
|
if (choice.key === value.toLowerCase()) {
|
|
81
|
-
return
|
|
82
|
+
return theme.style.highlight(line);
|
|
82
83
|
}
|
|
83
84
|
return line;
|
|
84
85
|
})
|
|
@@ -91,7 +92,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
91
92
|
}
|
|
92
93
|
let error = '';
|
|
93
94
|
if (errorMsg) {
|
|
94
|
-
error =
|
|
95
|
+
error = theme.style.error(errorMsg);
|
|
95
96
|
}
|
|
96
97
|
return [
|
|
97
98
|
`${prefix} ${message}${shortChoices} ${value}`,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type Theme } from '@inquirer/core';
|
|
2
|
+
import type { PartialDeep } from '@inquirer/type';
|
|
1
3
|
type ExpandChoice = {
|
|
2
4
|
key: string;
|
|
3
5
|
name: string;
|
|
@@ -9,10 +11,12 @@ type ExpandChoice = {
|
|
|
9
11
|
name: string;
|
|
10
12
|
value: string;
|
|
11
13
|
};
|
|
12
|
-
|
|
13
|
-
message: string
|
|
14
|
-
choices:
|
|
15
|
-
default?: string
|
|
16
|
-
expanded?: boolean
|
|
17
|
-
|
|
14
|
+
type ExpandConfig = {
|
|
15
|
+
message: string;
|
|
16
|
+
choices: ReadonlyArray<ExpandChoice>;
|
|
17
|
+
default?: string;
|
|
18
|
+
expanded?: boolean;
|
|
19
|
+
theme?: PartialDeep<Theme>;
|
|
20
|
+
};
|
|
21
|
+
declare const _default: import("@inquirer/type").Prompt<string, ExpandConfig>;
|
|
18
22
|
export default _default;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, } from '@inquirer/core';
|
|
1
|
+
import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, makeTheme, } from '@inquirer/core';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
const helpChoice = {
|
|
4
4
|
key: 'h',
|
|
@@ -21,7 +21,8 @@ export default createPrompt((config, done) => {
|
|
|
21
21
|
const [value, setValue] = useState('');
|
|
22
22
|
const [expanded, setExpanded] = useState(defaultExpandState);
|
|
23
23
|
const [errorMsg, setError] = useState(undefined);
|
|
24
|
-
const
|
|
24
|
+
const theme = makeTheme(config.theme);
|
|
25
|
+
const prefix = usePrefix({ theme });
|
|
25
26
|
useKeypress((event, rl) => {
|
|
26
27
|
if (isEnterKey(event)) {
|
|
27
28
|
const answer = (value || defaultKey).toLowerCase();
|
|
@@ -49,10 +50,10 @@ export default createPrompt((config, done) => {
|
|
|
49
50
|
setError(undefined);
|
|
50
51
|
}
|
|
51
52
|
});
|
|
52
|
-
const message =
|
|
53
|
+
const message = theme.style.message(config.message);
|
|
53
54
|
if (status === 'done') {
|
|
54
55
|
// TODO: `value` should be the display name instead of the raw value.
|
|
55
|
-
return `${prefix} ${message} ${
|
|
56
|
+
return `${prefix} ${message} ${theme.style.answer(value)}`;
|
|
56
57
|
}
|
|
57
58
|
const allChoices = expanded ? choices : [...choices, helpChoice];
|
|
58
59
|
// Collapsed display style
|
|
@@ -65,7 +66,7 @@ export default createPrompt((config, done) => {
|
|
|
65
66
|
return choice.key;
|
|
66
67
|
})
|
|
67
68
|
.join('');
|
|
68
|
-
shortChoices =
|
|
69
|
+
shortChoices = ` ${theme.style.defaultAnswer(shortChoices)}`;
|
|
69
70
|
// Expanded display style
|
|
70
71
|
if (expanded) {
|
|
71
72
|
shortChoices = '';
|
|
@@ -73,7 +74,7 @@ export default createPrompt((config, done) => {
|
|
|
73
74
|
.map((choice) => {
|
|
74
75
|
const line = ` ${choice.key}) ${getChoiceKey(choice, 'name')}`;
|
|
75
76
|
if (choice.key === value.toLowerCase()) {
|
|
76
|
-
return
|
|
77
|
+
return theme.style.highlight(line);
|
|
77
78
|
}
|
|
78
79
|
return line;
|
|
79
80
|
})
|
|
@@ -86,7 +87,7 @@ export default createPrompt((config, done) => {
|
|
|
86
87
|
}
|
|
87
88
|
let error = '';
|
|
88
89
|
if (errorMsg) {
|
|
89
|
-
error =
|
|
90
|
+
error = theme.style.error(errorMsg);
|
|
90
91
|
}
|
|
91
92
|
return [
|
|
92
93
|
`${prefix} ${message}${shortChoices} ${value}`,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type Theme } from '@inquirer/core';
|
|
2
|
+
import type { PartialDeep } from '@inquirer/type';
|
|
1
3
|
type ExpandChoice = {
|
|
2
4
|
key: string;
|
|
3
5
|
name: string;
|
|
@@ -9,10 +11,12 @@ type ExpandChoice = {
|
|
|
9
11
|
name: string;
|
|
10
12
|
value: string;
|
|
11
13
|
};
|
|
12
|
-
|
|
13
|
-
message: string
|
|
14
|
-
choices:
|
|
15
|
-
default?: string
|
|
16
|
-
expanded?: boolean
|
|
17
|
-
|
|
14
|
+
type ExpandConfig = {
|
|
15
|
+
message: string;
|
|
16
|
+
choices: ReadonlyArray<ExpandChoice>;
|
|
17
|
+
default?: string;
|
|
18
|
+
expanded?: boolean;
|
|
19
|
+
theme?: PartialDeep<Theme>;
|
|
20
|
+
};
|
|
21
|
+
declare const _default: import("@inquirer/type").Prompt<string, ExpandConfig>;
|
|
18
22
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/expand",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Inquirer checkbox prompt",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"typings": "./dist/cjs/types/index.d.ts",
|
|
@@ -54,13 +54,13 @@
|
|
|
54
54
|
"license": "MIT",
|
|
55
55
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/expand/README.md",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@inquirer/core": "^
|
|
58
|
-
"@inquirer/type": "^1.
|
|
57
|
+
"@inquirer/core": "^7.0.1",
|
|
58
|
+
"@inquirer/type": "^1.2.0",
|
|
59
59
|
"chalk": "^4.1.2",
|
|
60
60
|
"figures": "^3.2.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@inquirer/testing": "^2.1.
|
|
63
|
+
"@inquirer/testing": "^2.1.12"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
73
|
"engines": {
|
|
74
|
-
"node": ">=
|
|
74
|
+
"node": ">=18"
|
|
75
75
|
},
|
|
76
76
|
"exports": {
|
|
77
77
|
".": {
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "c91196e66689cfc05e9237763e6f95f3eb5342a1"
|
|
89
89
|
}
|