@inquirer/core 3.1.0 → 3.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 +11 -5
- package/dist/cjs/index.js +14 -2
- package/dist/cjs/types/index.d.ts +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/types/index.d.mts +1 -1
- package/package.json +7 -7
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"));
|
|
@@ -175,7 +187,7 @@ function createPrompt(view) {
|
|
|
175
187
|
// Add mute capabilities to the output
|
|
176
188
|
const output = new mute_stream_1.default();
|
|
177
189
|
output.pipe((_b = context === null || context === void 0 ? void 0 : context.output) !== null && _b !== void 0 ? _b : process.stdout);
|
|
178
|
-
sessionRl =
|
|
190
|
+
sessionRl = readline.createInterface({
|
|
179
191
|
terminal: true,
|
|
180
192
|
input,
|
|
181
193
|
output,
|
|
@@ -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,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.1",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=14.18.0"
|
|
6
6
|
},
|
|
@@ -59,20 +59,20 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@inquirer/type": "^1.1.1",
|
|
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.2"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"tsc": "yarn run clean && yarn run tsc:esm && yarn run tsc:cjs",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "dd31d57ed3b1d0771e24cc34bc72e5bedb63a1d7"
|
|
100
100
|
}
|