@inquirer/select 4.0.10 → 4.1.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 +18 -0
- package/dist/commonjs/index.d.ts +1 -0
- package/dist/commonjs/index.js +15 -8
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +15 -8
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -4,6 +4,16 @@ Simple interactive command line prompt to display a list of choices (single sele
|
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
7
|
+
# Special Thanks
|
|
8
|
+
|
|
9
|
+
<div align="center" markdown="1">
|
|
10
|
+
|
|
11
|
+
[](https://graphite.dev/?utm_source=npmjs&utm_medium=repo&utm_campaign=inquirerjs)<br>
|
|
12
|
+
|
|
13
|
+
### [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)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
7
17
|
# Installation
|
|
8
18
|
|
|
9
19
|
<table>
|
|
@@ -144,6 +154,7 @@ type Theme = {
|
|
|
144
154
|
cursor: string;
|
|
145
155
|
};
|
|
146
156
|
helpMode: 'always' | 'never' | 'auto';
|
|
157
|
+
indexMode: 'hidden' | 'number';
|
|
147
158
|
};
|
|
148
159
|
```
|
|
149
160
|
|
|
@@ -153,6 +164,13 @@ type Theme = {
|
|
|
153
164
|
- `always`: The help tips will always show and never hide.
|
|
154
165
|
- `never`: The help tips will never show.
|
|
155
166
|
|
|
167
|
+
### `theme.indexMode`
|
|
168
|
+
|
|
169
|
+
Controls how indices are displayed before each choice:
|
|
170
|
+
|
|
171
|
+
- `hidden` (default): No indices are shown
|
|
172
|
+
- `number`: Display a number before each choice (e.g. "1. Option A")
|
|
173
|
+
|
|
156
174
|
# License
|
|
157
175
|
|
|
158
176
|
Copyright (c) 2023 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))<br/>
|
package/dist/commonjs/index.d.ts
CHANGED
package/dist/commonjs/index.js
CHANGED
|
@@ -15,6 +15,7 @@ const selectTheme = {
|
|
|
15
15
|
description: (text) => yoctocolors_cjs_1.default.cyan(text),
|
|
16
16
|
},
|
|
17
17
|
helpMode: 'auto',
|
|
18
|
+
indexMode: 'hidden',
|
|
18
19
|
};
|
|
19
20
|
function isSelectable(item) {
|
|
20
21
|
return !core_1.Separator.isSeparator(item) && !item.disabled;
|
|
@@ -32,13 +33,16 @@ function normalizeChoices(choices) {
|
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
const name = choice.name ?? String(choice.value);
|
|
35
|
-
|
|
36
|
+
const normalizedChoice = {
|
|
36
37
|
value: choice.value,
|
|
37
38
|
name,
|
|
38
|
-
description: choice.description,
|
|
39
39
|
short: choice.short ?? name,
|
|
40
40
|
disabled: choice.disabled ?? false,
|
|
41
41
|
};
|
|
42
|
+
if (choice.description) {
|
|
43
|
+
normalizedChoice.description = choice.description;
|
|
44
|
+
}
|
|
45
|
+
return normalizedChoice;
|
|
42
46
|
});
|
|
43
47
|
}
|
|
44
48
|
exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
@@ -84,13 +88,15 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
84
88
|
setActive(next);
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
|
-
else if ((0, core_1.isNumberKey)(key)) {
|
|
88
|
-
rl.
|
|
89
|
-
const position = Number(key.name) - 1;
|
|
91
|
+
else if ((0, core_1.isNumberKey)(key) && !Number.isNaN(Number(rl.line))) {
|
|
92
|
+
const position = Number(rl.line) - 1;
|
|
90
93
|
const item = items[position];
|
|
91
94
|
if (item != null && isSelectable(item)) {
|
|
92
95
|
setActive(position);
|
|
93
96
|
}
|
|
97
|
+
searchTimeoutRef.current = setTimeout(() => {
|
|
98
|
+
rl.clearLine(0);
|
|
99
|
+
}, 700);
|
|
94
100
|
}
|
|
95
101
|
else if ((0, core_1.isBackspaceKey)(key)) {
|
|
96
102
|
rl.clearLine(0);
|
|
@@ -130,17 +136,18 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
130
136
|
const page = (0, core_1.usePagination)({
|
|
131
137
|
items,
|
|
132
138
|
active,
|
|
133
|
-
renderItem({ item, isActive }) {
|
|
139
|
+
renderItem({ item, isActive, index }) {
|
|
134
140
|
if (core_1.Separator.isSeparator(item)) {
|
|
135
141
|
return ` ${item.separator}`;
|
|
136
142
|
}
|
|
143
|
+
const indexLabel = theme.indexMode === 'number' ? `${index + 1}. ` : '';
|
|
137
144
|
if (item.disabled) {
|
|
138
145
|
const disabledLabel = typeof item.disabled === 'string' ? item.disabled : '(disabled)';
|
|
139
|
-
return theme.style.disabled(`${item.name} ${disabledLabel}`);
|
|
146
|
+
return theme.style.disabled(`${indexLabel}${item.name} ${disabledLabel}`);
|
|
140
147
|
}
|
|
141
148
|
const color = isActive ? theme.style.highlight : (x) => x;
|
|
142
149
|
const cursor = isActive ? theme.icon.cursor : ` `;
|
|
143
|
-
return color(`${cursor} ${item.name}`);
|
|
150
|
+
return color(`${cursor} ${indexLabel}${item.name}`);
|
|
144
151
|
},
|
|
145
152
|
pageSize,
|
|
146
153
|
loop,
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const selectTheme = {
|
|
|
9
9
|
description: (text) => colors.cyan(text),
|
|
10
10
|
},
|
|
11
11
|
helpMode: 'auto',
|
|
12
|
+
indexMode: 'hidden',
|
|
12
13
|
};
|
|
13
14
|
function isSelectable(item) {
|
|
14
15
|
return !Separator.isSeparator(item) && !item.disabled;
|
|
@@ -26,13 +27,16 @@ function normalizeChoices(choices) {
|
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
const name = choice.name ?? String(choice.value);
|
|
29
|
-
|
|
30
|
+
const normalizedChoice = {
|
|
30
31
|
value: choice.value,
|
|
31
32
|
name,
|
|
32
|
-
description: choice.description,
|
|
33
33
|
short: choice.short ?? name,
|
|
34
34
|
disabled: choice.disabled ?? false,
|
|
35
35
|
};
|
|
36
|
+
if (choice.description) {
|
|
37
|
+
normalizedChoice.description = choice.description;
|
|
38
|
+
}
|
|
39
|
+
return normalizedChoice;
|
|
36
40
|
});
|
|
37
41
|
}
|
|
38
42
|
export default createPrompt((config, done) => {
|
|
@@ -78,13 +82,15 @@ export default createPrompt((config, done) => {
|
|
|
78
82
|
setActive(next);
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
|
-
else if (isNumberKey(key)) {
|
|
82
|
-
rl.
|
|
83
|
-
const position = Number(key.name) - 1;
|
|
85
|
+
else if (isNumberKey(key) && !Number.isNaN(Number(rl.line))) {
|
|
86
|
+
const position = Number(rl.line) - 1;
|
|
84
87
|
const item = items[position];
|
|
85
88
|
if (item != null && isSelectable(item)) {
|
|
86
89
|
setActive(position);
|
|
87
90
|
}
|
|
91
|
+
searchTimeoutRef.current = setTimeout(() => {
|
|
92
|
+
rl.clearLine(0);
|
|
93
|
+
}, 700);
|
|
88
94
|
}
|
|
89
95
|
else if (isBackspaceKey(key)) {
|
|
90
96
|
rl.clearLine(0);
|
|
@@ -124,17 +130,18 @@ export default createPrompt((config, done) => {
|
|
|
124
130
|
const page = usePagination({
|
|
125
131
|
items,
|
|
126
132
|
active,
|
|
127
|
-
renderItem({ item, isActive }) {
|
|
133
|
+
renderItem({ item, isActive, index }) {
|
|
128
134
|
if (Separator.isSeparator(item)) {
|
|
129
135
|
return ` ${item.separator}`;
|
|
130
136
|
}
|
|
137
|
+
const indexLabel = theme.indexMode === 'number' ? `${index + 1}. ` : '';
|
|
131
138
|
if (item.disabled) {
|
|
132
139
|
const disabledLabel = typeof item.disabled === 'string' ? item.disabled : '(disabled)';
|
|
133
|
-
return theme.style.disabled(`${item.name} ${disabledLabel}`);
|
|
140
|
+
return theme.style.disabled(`${indexLabel}${item.name} ${disabledLabel}`);
|
|
134
141
|
}
|
|
135
142
|
const color = isActive ? theme.style.highlight : (x) => x;
|
|
136
143
|
const cursor = isActive ? theme.icon.cursor : ` `;
|
|
137
|
-
return color(`${cursor} ${item.name}`);
|
|
144
|
+
return color(`${cursor} ${indexLabel}${item.name}`);
|
|
138
145
|
},
|
|
139
146
|
pageSize,
|
|
140
147
|
loop,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/select",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "Inquirer select/list prompt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -74,15 +74,15 @@
|
|
|
74
74
|
"tsc": "tshy"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@inquirer/core": "^10.1.
|
|
77
|
+
"@inquirer/core": "^10.1.10",
|
|
78
78
|
"@inquirer/figures": "^1.0.11",
|
|
79
|
-
"@inquirer/type": "^3.0.
|
|
79
|
+
"@inquirer/type": "^3.0.6",
|
|
80
80
|
"ansi-escapes": "^4.3.2",
|
|
81
81
|
"yoctocolors-cjs": "^2.1.2"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@arethetypeswrong/cli": "^0.17.4",
|
|
85
|
-
"@inquirer/testing": "^2.1.
|
|
85
|
+
"@inquirer/testing": "^2.1.46",
|
|
86
86
|
"@repo/tsconfig": "workspace:*",
|
|
87
87
|
"tshy": "^3.0.2"
|
|
88
88
|
},
|
|
@@ -109,5 +109,5 @@
|
|
|
109
109
|
"optional": true
|
|
110
110
|
}
|
|
111
111
|
},
|
|
112
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "d367155a8d64d8b3e93f9c763adccf708aedc8a8"
|
|
113
113
|
}
|