@inquirer/select 4.0.9 → 4.1.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 +8 -0
- package/dist/commonjs/index.d.ts +1 -0
- package/dist/commonjs/index.js +10 -6
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +10 -6
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -144,6 +144,7 @@ type Theme = {
|
|
|
144
144
|
cursor: string;
|
|
145
145
|
};
|
|
146
146
|
helpMode: 'always' | 'never' | 'auto';
|
|
147
|
+
indexMode: 'hidden' | 'number';
|
|
147
148
|
};
|
|
148
149
|
```
|
|
149
150
|
|
|
@@ -153,6 +154,13 @@ type Theme = {
|
|
|
153
154
|
- `always`: The help tips will always show and never hide.
|
|
154
155
|
- `never`: The help tips will never show.
|
|
155
156
|
|
|
157
|
+
### `theme.indexMode`
|
|
158
|
+
|
|
159
|
+
Controls how indices are displayed before each choice:
|
|
160
|
+
|
|
161
|
+
- `hidden` (default): No indices are shown
|
|
162
|
+
- `number`: Display a number before each choice (e.g. "1. Option A")
|
|
163
|
+
|
|
156
164
|
# License
|
|
157
165
|
|
|
158
166
|
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;
|
|
@@ -84,13 +85,15 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
84
85
|
setActive(next);
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
|
-
else if ((0, core_1.isNumberKey)(key)) {
|
|
88
|
-
rl.
|
|
89
|
-
const position = Number(key.name) - 1;
|
|
88
|
+
else if ((0, core_1.isNumberKey)(key) && !Number.isNaN(Number(rl.line))) {
|
|
89
|
+
const position = Number(rl.line) - 1;
|
|
90
90
|
const item = items[position];
|
|
91
91
|
if (item != null && isSelectable(item)) {
|
|
92
92
|
setActive(position);
|
|
93
93
|
}
|
|
94
|
+
searchTimeoutRef.current = setTimeout(() => {
|
|
95
|
+
rl.clearLine(0);
|
|
96
|
+
}, 700);
|
|
94
97
|
}
|
|
95
98
|
else if ((0, core_1.isBackspaceKey)(key)) {
|
|
96
99
|
rl.clearLine(0);
|
|
@@ -130,17 +133,18 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
130
133
|
const page = (0, core_1.usePagination)({
|
|
131
134
|
items,
|
|
132
135
|
active,
|
|
133
|
-
renderItem({ item, isActive }) {
|
|
136
|
+
renderItem({ item, isActive, index }) {
|
|
134
137
|
if (core_1.Separator.isSeparator(item)) {
|
|
135
138
|
return ` ${item.separator}`;
|
|
136
139
|
}
|
|
140
|
+
const indexLabel = theme.indexMode === 'number' ? `${index + 1}. ` : '';
|
|
137
141
|
if (item.disabled) {
|
|
138
142
|
const disabledLabel = typeof item.disabled === 'string' ? item.disabled : '(disabled)';
|
|
139
|
-
return theme.style.disabled(`${item.name} ${disabledLabel}`);
|
|
143
|
+
return theme.style.disabled(`${indexLabel}${item.name} ${disabledLabel}`);
|
|
140
144
|
}
|
|
141
145
|
const color = isActive ? theme.style.highlight : (x) => x;
|
|
142
146
|
const cursor = isActive ? theme.icon.cursor : ` `;
|
|
143
|
-
return color(`${cursor} ${item.name}`);
|
|
147
|
+
return color(`${cursor} ${indexLabel}${item.name}`);
|
|
144
148
|
},
|
|
145
149
|
pageSize,
|
|
146
150
|
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;
|
|
@@ -78,13 +79,15 @@ export default createPrompt((config, done) => {
|
|
|
78
79
|
setActive(next);
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
|
-
else if (isNumberKey(key)) {
|
|
82
|
-
rl.
|
|
83
|
-
const position = Number(key.name) - 1;
|
|
82
|
+
else if (isNumberKey(key) && !Number.isNaN(Number(rl.line))) {
|
|
83
|
+
const position = Number(rl.line) - 1;
|
|
84
84
|
const item = items[position];
|
|
85
85
|
if (item != null && isSelectable(item)) {
|
|
86
86
|
setActive(position);
|
|
87
87
|
}
|
|
88
|
+
searchTimeoutRef.current = setTimeout(() => {
|
|
89
|
+
rl.clearLine(0);
|
|
90
|
+
}, 700);
|
|
88
91
|
}
|
|
89
92
|
else if (isBackspaceKey(key)) {
|
|
90
93
|
rl.clearLine(0);
|
|
@@ -124,17 +127,18 @@ export default createPrompt((config, done) => {
|
|
|
124
127
|
const page = usePagination({
|
|
125
128
|
items,
|
|
126
129
|
active,
|
|
127
|
-
renderItem({ item, isActive }) {
|
|
130
|
+
renderItem({ item, isActive, index }) {
|
|
128
131
|
if (Separator.isSeparator(item)) {
|
|
129
132
|
return ` ${item.separator}`;
|
|
130
133
|
}
|
|
134
|
+
const indexLabel = theme.indexMode === 'number' ? `${index + 1}. ` : '';
|
|
131
135
|
if (item.disabled) {
|
|
132
136
|
const disabledLabel = typeof item.disabled === 'string' ? item.disabled : '(disabled)';
|
|
133
|
-
return theme.style.disabled(`${item.name} ${disabledLabel}`);
|
|
137
|
+
return theme.style.disabled(`${indexLabel}${item.name} ${disabledLabel}`);
|
|
134
138
|
}
|
|
135
139
|
const color = isActive ? theme.style.highlight : (x) => x;
|
|
136
140
|
const cursor = isActive ? theme.icon.cursor : ` `;
|
|
137
|
-
return color(`${cursor} ${item.name}`);
|
|
141
|
+
return color(`${cursor} ${indexLabel}${item.name}`);
|
|
138
142
|
},
|
|
139
143
|
pageSize,
|
|
140
144
|
loop,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/select",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
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.
|
|
78
|
-
"@inquirer/figures": "^1.0.
|
|
79
|
-
"@inquirer/type": "^3.0.
|
|
77
|
+
"@inquirer/core": "^10.1.9",
|
|
78
|
+
"@inquirer/figures": "^1.0.11",
|
|
79
|
+
"@inquirer/type": "^3.0.5",
|
|
80
80
|
"ansi-escapes": "^4.3.2",
|
|
81
81
|
"yoctocolors-cjs": "^2.1.2"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
|
-
"@arethetypeswrong/cli": "^0.17.
|
|
85
|
-
"@inquirer/testing": "^2.1.
|
|
84
|
+
"@arethetypeswrong/cli": "^0.17.4",
|
|
85
|
+
"@inquirer/testing": "^2.1.45",
|
|
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": "83508f90ca65d26abc1408e4209e4f8fc73e43fe"
|
|
113
113
|
}
|