@inquirer/core 3.1.0 → 3.1.2
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 +11 -5
- package/dist/cjs/index.js +28 -13
- package/dist/cjs/types/index.d.ts +1 -1
- package/dist/esm/index.mjs +15 -12
- package/dist/esm/types/index.d.mts +1 -1
- package/package.json +9 -10
package/README.md
CHANGED
|
@@ -108,6 +108,7 @@ Those hooks are matching the React hooks API:
|
|
|
108
108
|
And those are custom utilities from Inquirer:
|
|
109
109
|
|
|
110
110
|
- `useKeypress`
|
|
111
|
+
- `usePagination`
|
|
111
112
|
- `usePrefix`
|
|
112
113
|
|
|
113
114
|
### Key utilities
|
|
@@ -121,17 +122,22 @@ Listening for keypress events inside an inquirer prompt is a very common pattern
|
|
|
121
122
|
- `isDownKey()` - Note: this utility will handle vim and emacs keybindings (down, `j`, and `ctrl+n`)
|
|
122
123
|
- `isNumberKey()` one of 1, 2, 3, 4, 5, 6, 7, 8, 9, 0
|
|
123
124
|
|
|
124
|
-
### `
|
|
125
|
+
### `usePagination`
|
|
125
126
|
|
|
126
|
-
When looping through a long list of options (like in the `select` prompt), paginating the results appearing on the screen at once can be necessary. The `
|
|
127
|
+
When looping through a long list of options (like in the `select` prompt), paginating the results appearing on the screen at once can be necessary. The `usePagination` hook is the utility used within the `select` and `checkbox` prompt to cycle through the list of options.
|
|
127
128
|
|
|
128
129
|
```js
|
|
129
130
|
export default createPrompt((config, done) => {
|
|
130
|
-
const
|
|
131
|
+
const [cursorPosition, setCursorPosition] = useState(0);
|
|
131
132
|
|
|
132
|
-
const
|
|
133
|
+
const allChoices = config.choices.map((choice) => choice.name);
|
|
133
134
|
|
|
134
|
-
|
|
135
|
+
const windowedChoices = usePagination(allChoices, {
|
|
136
|
+
active: cursorPosition,
|
|
137
|
+
pageSize: config.pageSize,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return `... ${windowedChoices}`;
|
|
135
141
|
});
|
|
136
142
|
```
|
|
137
143
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -10,6 +10,18 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
13
25
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
27
|
};
|
|
@@ -18,7 +30,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
30
|
};
|
|
19
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
32
|
exports.createPrompt = exports.usePagination = exports.useRef = exports.useKeypress = exports.useEffect = exports.useState = exports.usePrefix = void 0;
|
|
21
|
-
const
|
|
33
|
+
const readline = __importStar(require("node:readline"));
|
|
22
34
|
const type_1 = require("@inquirer/type");
|
|
23
35
|
const chalk_1 = __importDefault(require("chalk"));
|
|
24
36
|
const cli_width_1 = __importDefault(require("cli-width"));
|
|
@@ -44,12 +56,6 @@ function resetHookState() {
|
|
|
44
56
|
handleChange = () => { };
|
|
45
57
|
sessionRl = undefined;
|
|
46
58
|
}
|
|
47
|
-
function cleanupHook(index) {
|
|
48
|
-
const cleanFn = hooksCleanup[index];
|
|
49
|
-
if (typeof cleanFn === 'function') {
|
|
50
|
-
cleanFn();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
59
|
function mergeStateUpdates(fn) {
|
|
54
60
|
const wrapped = (...args) => {
|
|
55
61
|
let shouldUpdate = false;
|
|
@@ -66,6 +72,17 @@ function mergeStateUpdates(fn) {
|
|
|
66
72
|
};
|
|
67
73
|
return wrapped;
|
|
68
74
|
}
|
|
75
|
+
function cleanupHook(index) {
|
|
76
|
+
const cleanFn = hooksCleanup[index];
|
|
77
|
+
if (typeof cleanFn === 'function') {
|
|
78
|
+
cleanFn();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const runEffects = mergeStateUpdates(() => {
|
|
82
|
+
for (const effect of hooksEffect) {
|
|
83
|
+
effect();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
69
86
|
function useState(defaultValue) {
|
|
70
87
|
const _idx = index;
|
|
71
88
|
index++;
|
|
@@ -103,14 +120,14 @@ function useEffect(cb, depArray) {
|
|
|
103
120
|
hasChanged = depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
|
|
104
121
|
}
|
|
105
122
|
if (hasChanged) {
|
|
106
|
-
hooksEffect.push(
|
|
123
|
+
hooksEffect.push(() => {
|
|
107
124
|
cleanupHook(_idx);
|
|
108
125
|
const cleanFn = cb(rl);
|
|
109
126
|
if (cleanFn != null && typeof cleanFn !== 'function') {
|
|
110
127
|
throw new Error('useEffect return value must be a cleanup function or nothing.');
|
|
111
128
|
}
|
|
112
129
|
hooksCleanup[_idx] = cleanFn;
|
|
113
|
-
})
|
|
130
|
+
});
|
|
114
131
|
}
|
|
115
132
|
hooks[_idx] = depArray;
|
|
116
133
|
}
|
|
@@ -175,7 +192,7 @@ function createPrompt(view) {
|
|
|
175
192
|
// Add mute capabilities to the output
|
|
176
193
|
const output = new mute_stream_1.default();
|
|
177
194
|
output.pipe((_b = context === null || context === void 0 ? void 0 : context.output) !== null && _b !== void 0 ? _b : process.stdout);
|
|
178
|
-
sessionRl =
|
|
195
|
+
sessionRl = readline.createInterface({
|
|
179
196
|
terminal: true,
|
|
180
197
|
input,
|
|
181
198
|
output,
|
|
@@ -235,11 +252,9 @@ function createPrompt(view) {
|
|
|
235
252
|
handleChange = () => workLoop(resolvedConfig);
|
|
236
253
|
try {
|
|
237
254
|
const nextView = view(resolvedConfig, done);
|
|
238
|
-
for (const effect of hooksEffect) {
|
|
239
|
-
effect();
|
|
240
|
-
}
|
|
241
255
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
242
256
|
screen.render(content, bottomContent);
|
|
257
|
+
runEffects();
|
|
243
258
|
}
|
|
244
259
|
catch (err) {
|
|
245
260
|
onExit();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import readline from 'node:readline';
|
|
3
|
+
import * as readline from 'node:readline';
|
|
4
4
|
import { type Prompt } from '@inquirer/type';
|
|
5
5
|
import MuteStream from 'mute-stream';
|
|
6
6
|
export { usePrefix } from './lib/prefix.js';
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import readline from 'node:readline';
|
|
1
|
+
import * as readline from 'node:readline';
|
|
2
2
|
import { CancelablePromise } from '@inquirer/type';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import cliWidth from 'cli-width';
|
|
@@ -23,12 +23,6 @@ function resetHookState() {
|
|
|
23
23
|
handleChange = () => { };
|
|
24
24
|
sessionRl = undefined;
|
|
25
25
|
}
|
|
26
|
-
function cleanupHook(index) {
|
|
27
|
-
const cleanFn = hooksCleanup[index];
|
|
28
|
-
if (typeof cleanFn === 'function') {
|
|
29
|
-
cleanFn();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
26
|
function mergeStateUpdates(fn) {
|
|
33
27
|
const wrapped = (...args) => {
|
|
34
28
|
let shouldUpdate = false;
|
|
@@ -45,6 +39,17 @@ function mergeStateUpdates(fn) {
|
|
|
45
39
|
};
|
|
46
40
|
return wrapped;
|
|
47
41
|
}
|
|
42
|
+
function cleanupHook(index) {
|
|
43
|
+
const cleanFn = hooksCleanup[index];
|
|
44
|
+
if (typeof cleanFn === 'function') {
|
|
45
|
+
cleanFn();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const runEffects = mergeStateUpdates(() => {
|
|
49
|
+
for (const effect of hooksEffect) {
|
|
50
|
+
effect();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
48
53
|
export function useState(defaultValue) {
|
|
49
54
|
const _idx = index;
|
|
50
55
|
index++;
|
|
@@ -81,14 +86,14 @@ export function useEffect(cb, depArray) {
|
|
|
81
86
|
hasChanged = depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
|
|
82
87
|
}
|
|
83
88
|
if (hasChanged) {
|
|
84
|
-
hooksEffect.push(
|
|
89
|
+
hooksEffect.push(() => {
|
|
85
90
|
cleanupHook(_idx);
|
|
86
91
|
const cleanFn = cb(rl);
|
|
87
92
|
if (cleanFn != null && typeof cleanFn !== 'function') {
|
|
88
93
|
throw new Error('useEffect return value must be a cleanup function or nothing.');
|
|
89
94
|
}
|
|
90
95
|
hooksCleanup[_idx] = cleanFn;
|
|
91
|
-
})
|
|
96
|
+
});
|
|
92
97
|
}
|
|
93
98
|
hooks[_idx] = depArray;
|
|
94
99
|
}
|
|
@@ -208,11 +213,9 @@ export function createPrompt(view) {
|
|
|
208
213
|
handleChange = () => workLoop(resolvedConfig);
|
|
209
214
|
try {
|
|
210
215
|
const nextView = view(resolvedConfig, done);
|
|
211
|
-
for (const effect of hooksEffect) {
|
|
212
|
-
effect();
|
|
213
|
-
}
|
|
214
216
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
215
217
|
screen.render(content, bottomContent);
|
|
218
|
+
runEffects();
|
|
216
219
|
}
|
|
217
220
|
catch (err) {
|
|
218
221
|
onExit();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import readline from 'node:readline';
|
|
3
|
+
import * as readline from 'node:readline';
|
|
4
4
|
import { type Prompt } from '@inquirer/type';
|
|
5
5
|
import MuteStream from 'mute-stream';
|
|
6
6
|
export { usePrefix } from './lib/prefix.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=14.18.0"
|
|
6
6
|
},
|
|
@@ -57,29 +57,28 @@
|
|
|
57
57
|
"license": "MIT",
|
|
58
58
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/core/README.md",
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@inquirer/type": "^1.1.
|
|
60
|
+
"@inquirer/type": "^1.1.2",
|
|
61
61
|
"@types/mute-stream": "^0.0.1",
|
|
62
|
-
"@types/node": "^20.4.
|
|
62
|
+
"@types/node": "^20.4.8",
|
|
63
63
|
"@types/wrap-ansi": "^3.0.0",
|
|
64
64
|
"ansi-escapes": "^4.3.2",
|
|
65
65
|
"chalk": "^4.1.2",
|
|
66
|
-
"cli-spinners": "^2.
|
|
67
|
-
"cli-width": "^4.
|
|
66
|
+
"cli-spinners": "^2.9.0",
|
|
67
|
+
"cli-width": "^4.1.0",
|
|
68
68
|
"figures": "^3.2.0",
|
|
69
69
|
"mute-stream": "^1.0.0",
|
|
70
70
|
"run-async": "^3.0.0",
|
|
71
71
|
"strip-ansi": "^6.0.1",
|
|
72
|
-
"wrap-ansi": "^6.0
|
|
72
|
+
"wrap-ansi": "^6.2.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@inquirer/testing": "^2.1.
|
|
75
|
+
"@inquirer/testing": "^2.1.3"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"tsc": "yarn run clean && yarn run tsc:esm && yarn run tsc:cjs",
|
|
79
79
|
"clean": "rm -rf dist",
|
|
80
80
|
"tsc:esm": "tsc -p ./tsconfig.json",
|
|
81
|
-
"tsc:cjs": "tsc -p ./tsconfig.cjs.json &&
|
|
82
|
-
"fix-ext": "node --no-warnings=ExperimentalWarning --loader=ts-node/esm ../../tools/fix-ext.mts"
|
|
81
|
+
"tsc:cjs": "tsc -p ./tsconfig.cjs.json && node ../../tools/fix-ext.mjs"
|
|
83
82
|
},
|
|
84
83
|
"publishConfig": {
|
|
85
84
|
"access": "public"
|
|
@@ -96,5 +95,5 @@
|
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
},
|
|
99
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "2b29f261c4c7d85a00c1a2305d97ee10e3c15b68"
|
|
100
99
|
}
|