@inquirer/core 6.0.0 → 7.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 +71 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/lib/create-prompt.js +7 -26
- package/dist/cjs/lib/make-theme.js +10 -0
- package/dist/cjs/lib/pagination/use-pagination.js +4 -6
- package/dist/cjs/lib/theme.js +24 -0
- package/dist/cjs/lib/use-prefix.js +5 -9
- package/dist/cjs/types/index.d.ts +3 -1
- package/dist/cjs/types/lib/create-prompt.d.ts +2 -9
- package/dist/cjs/types/lib/make-theme.d.ts +3 -0
- package/dist/cjs/types/lib/pagination/use-pagination.d.ts +4 -2
- package/dist/cjs/types/lib/theme.d.ts +20 -0
- package/dist/cjs/types/lib/use-prefix.d.ts +5 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/lib/create-prompt.mjs +7 -18
- package/dist/esm/lib/make-theme.mjs +6 -0
- package/dist/esm/lib/pagination/use-pagination.mjs +4 -3
- package/dist/esm/lib/theme.mjs +18 -0
- package/dist/esm/lib/use-prefix.mjs +5 -6
- package/dist/esm/types/index.d.mts +3 -1
- package/dist/esm/types/lib/create-prompt.d.mts +2 -9
- package/dist/esm/types/lib/make-theme.d.mts +3 -0
- package/dist/esm/types/lib/pagination/use-pagination.d.mts +4 -2
- package/dist/esm/types/lib/theme.d.mts +20 -0
- package/dist/esm/types/lib/use-prefix.d.mts +5 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ const confirm = createPrompt<boolean, { message: string; default?: boolean }>(
|
|
|
28
28
|
(config, done) => {
|
|
29
29
|
const [status, setStatus] = useState('pending');
|
|
30
30
|
const [value, setValue] = useState('');
|
|
31
|
-
const prefix = usePrefix();
|
|
31
|
+
const prefix = usePrefix({});
|
|
32
32
|
|
|
33
33
|
useKeypress((key, rl) => {
|
|
34
34
|
if (isEnterKey(key)) {
|
|
@@ -141,12 +141,82 @@ export default createPrompt((config, done) => {
|
|
|
141
141
|
renderItem: ({ item, index, isActive }) => `${isActive ? ">" : " "}${index}. ${item.toString()}`
|
|
142
142
|
pageSize: config.pageSize,
|
|
143
143
|
loop: config.loop,
|
|
144
|
+
theme, config.theme,
|
|
144
145
|
});
|
|
145
146
|
|
|
146
147
|
return `... ${page}`;
|
|
147
148
|
});
|
|
148
149
|
```
|
|
149
150
|
|
|
151
|
+
### Theming
|
|
152
|
+
|
|
153
|
+
Theming utilities will allow you to expose customization of the prompt style. Inquirer also has a few standard theme values shared across all the official prompts.
|
|
154
|
+
|
|
155
|
+
To allow standard customization:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { createPrompt, usePrefix, makeTheme, type Theme } from '@inquirer/core';
|
|
159
|
+
import type { PartialDeep } from '@inquirer/type';
|
|
160
|
+
|
|
161
|
+
type PromptConfig = {
|
|
162
|
+
theme?: PartialDeep<Theme>;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export default createPrompt<string, PromptConfig>((config, done) => {
|
|
166
|
+
const theme = makeTheme(config.theme);
|
|
167
|
+
|
|
168
|
+
const prefix = usePrefix({ isLoading, theme });
|
|
169
|
+
|
|
170
|
+
return `${prefix} ${theme.style.highlight('hello')}`;
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
To setup a custom theme:
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { createPrompt, makeTheme, type Theme } from '@inquirer/core';
|
|
178
|
+
import type { PartialDeep } from '@inquirer/type';
|
|
179
|
+
|
|
180
|
+
type PromptTheme = {};
|
|
181
|
+
|
|
182
|
+
const promptTheme: PromptTheme = {
|
|
183
|
+
icon: '!',
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
type PromptConfig = {
|
|
187
|
+
theme?: PartialDeep<Theme<PromptTheme>>;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export default createPrompt<string, PromptConfig>((config, done) => {
|
|
191
|
+
const theme = makeTheme(promptTheme, config.theme);
|
|
192
|
+
|
|
193
|
+
const prefix = usePrefix({ isLoading, theme });
|
|
194
|
+
|
|
195
|
+
return `${prefix} ${theme.icon}`;
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
The [default theme keys cover](https://github.com/SBoudrias/Inquirer.js/blob/theme/packages/core/src/lib/theme.mts):
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
type DefaultTheme = {
|
|
203
|
+
prefix: string;
|
|
204
|
+
spinner: {
|
|
205
|
+
interval: number;
|
|
206
|
+
frames: string[];
|
|
207
|
+
};
|
|
208
|
+
style: {
|
|
209
|
+
answer: (text: string) => string;
|
|
210
|
+
message: (text: string) => string;
|
|
211
|
+
error: (text: string) => string;
|
|
212
|
+
defaultAnswer: (text: string) => string;
|
|
213
|
+
help: (text: string) => string;
|
|
214
|
+
highlight: (text: string) => string;
|
|
215
|
+
key: (text: string) => string;
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
```
|
|
219
|
+
|
|
150
220
|
# License
|
|
151
221
|
|
|
152
222
|
Copyright (c) 2023 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))<br/>
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Separator = exports.createPrompt = exports.usePagination = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = void 0;
|
|
17
|
+
exports.Separator = exports.createPrompt = exports.usePagination = exports.makeTheme = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = void 0;
|
|
18
18
|
__exportStar(require('./lib/key.js'), exports);
|
|
19
19
|
var use_prefix_mjs_1 = require('./lib/use-prefix.js');
|
|
20
20
|
Object.defineProperty(exports, "usePrefix", { enumerable: true, get: function () { return use_prefix_mjs_1.usePrefix; } });
|
|
@@ -28,6 +28,8 @@ var use_ref_mjs_1 = require('./lib/use-ref.js');
|
|
|
28
28
|
Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return use_ref_mjs_1.useRef; } });
|
|
29
29
|
var use_keypress_mjs_1 = require('./lib/use-keypress.js');
|
|
30
30
|
Object.defineProperty(exports, "useKeypress", { enumerable: true, get: function () { return use_keypress_mjs_1.useKeypress; } });
|
|
31
|
+
var make_theme_mjs_1 = require('./lib/make-theme.js');
|
|
32
|
+
Object.defineProperty(exports, "makeTheme", { enumerable: true, get: function () { return make_theme_mjs_1.makeTheme; } });
|
|
31
33
|
var use_pagination_mjs_1 = require('./lib/pagination/use-pagination.js');
|
|
32
34
|
Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return use_pagination_mjs_1.usePagination; } });
|
|
33
35
|
var create_prompt_mjs_1 = require('./lib/create-prompt.js');
|
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
@@ -42,13 +33,6 @@ const mute_stream_1 = __importDefault(require("mute-stream"));
|
|
|
42
33
|
const signal_exit_1 = require("signal-exit");
|
|
43
34
|
const screen_manager_mjs_1 = __importDefault(require('./screen-manager.js'));
|
|
44
35
|
const hook_engine_mjs_1 = require('./hook-engine.js');
|
|
45
|
-
// Take an AsyncPromptConfig and resolves all it's values.
|
|
46
|
-
function getPromptConfig(config) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const message = typeof config.message === 'function' ? config.message() : config.message;
|
|
49
|
-
return Object.assign(Object.assign({}, config), { message: yield message });
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
36
|
function createPrompt(view) {
|
|
53
37
|
const prompt = (config, context) => {
|
|
54
38
|
var _a, _b;
|
|
@@ -108,7 +92,7 @@ function createPrompt(view) {
|
|
|
108
92
|
store.index = 0;
|
|
109
93
|
store.handleChange = () => workLoop(resolvedConfig);
|
|
110
94
|
try {
|
|
111
|
-
const nextView = view(
|
|
95
|
+
const nextView = view(config, done);
|
|
112
96
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
113
97
|
screen.render(content, bottomContent);
|
|
114
98
|
hook_engine_mjs_1.effectScheduler.run();
|
|
@@ -118,15 +102,12 @@ function createPrompt(view) {
|
|
|
118
102
|
reject(err);
|
|
119
103
|
}
|
|
120
104
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// by a state change sets the cursor to the right position.
|
|
128
|
-
store.rl.input.on('keypress', checkCursorPos);
|
|
129
|
-
}, reject);
|
|
105
|
+
workLoop(config);
|
|
106
|
+
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
107
|
+
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
108
|
+
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
109
|
+
// by a state change sets the cursor to the right position.
|
|
110
|
+
store.rl.input.on('keypress', checkCursorPos);
|
|
130
111
|
});
|
|
131
112
|
});
|
|
132
113
|
answer.cancel = cancel;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeTheme = void 0;
|
|
4
|
+
const theme_mjs_1 = require('./theme.js');
|
|
5
|
+
function makeTheme(...themes) {
|
|
6
|
+
return Object.assign({}, theme_mjs_1.defaultTheme, ...themes, {
|
|
7
|
+
style: Object.assign({}, theme_mjs_1.defaultTheme.style, ...themes.map((theme) => theme === null || theme === void 0 ? void 0 : theme.style)),
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
exports.makeTheme = makeTheme;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.usePagination = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
4
|
const use_ref_mjs_1 = require('../use-ref.js');
|
|
9
5
|
const utils_mjs_1 = require('../utils.js');
|
|
6
|
+
const make_theme_mjs_1 = require('../make-theme.js');
|
|
10
7
|
const lines_mjs_1 = require('./lines.js');
|
|
11
8
|
const position_mjs_1 = require('./position.js');
|
|
12
|
-
function usePagination({ items, active, renderItem, pageSize, loop = true, }) {
|
|
9
|
+
function usePagination({ items, active, renderItem, pageSize, loop = true, theme: defaultTheme, }) {
|
|
13
10
|
const state = (0, use_ref_mjs_1.useRef)({ position: 0, lastActive: 0 });
|
|
11
|
+
const theme = (0, make_theme_mjs_1.makeTheme)(defaultTheme);
|
|
14
12
|
const position = loop
|
|
15
13
|
? (0, position_mjs_1.infinite)({
|
|
16
14
|
active,
|
|
@@ -35,7 +33,7 @@ function usePagination({ items, active, renderItem, pageSize, loop = true, }) {
|
|
|
35
33
|
pageSize,
|
|
36
34
|
}).join('\n');
|
|
37
35
|
if (items.length > pageSize) {
|
|
38
|
-
return `${visibleLines}\n${
|
|
36
|
+
return `${visibleLines}\n${theme.style.help('(Use arrow keys to reveal more choices)')}`;
|
|
39
37
|
}
|
|
40
38
|
return visibleLines;
|
|
41
39
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.defaultTheme = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const cli_spinners_1 = __importDefault(require("cli-spinners"));
|
|
9
|
+
exports.defaultTheme = {
|
|
10
|
+
prefix: chalk_1.default.green('?'),
|
|
11
|
+
spinner: {
|
|
12
|
+
interval: cli_spinners_1.default.dots.interval,
|
|
13
|
+
frames: cli_spinners_1.default.dots.frames.map(chalk_1.default.yellow),
|
|
14
|
+
},
|
|
15
|
+
style: {
|
|
16
|
+
answer: chalk_1.default.cyan,
|
|
17
|
+
message: chalk_1.default.bold,
|
|
18
|
+
error: (text) => chalk_1.default.red(`> ${text}`),
|
|
19
|
+
defaultAnswer: (text) => chalk_1.default.dim(`(${text})`),
|
|
20
|
+
help: chalk_1.default.dim,
|
|
21
|
+
highlight: chalk_1.default.cyan,
|
|
22
|
+
key: (text) => chalk_1.default.cyan.bold(`<${text}>`),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.usePrefix = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const cli_spinners_1 = __importDefault(require("cli-spinners"));
|
|
9
4
|
const use_state_mjs_1 = require('./use-state.js');
|
|
10
5
|
const use_effect_mjs_1 = require('./use-effect.js');
|
|
11
|
-
const
|
|
12
|
-
function usePrefix(isLoading = false) {
|
|
6
|
+
const make_theme_mjs_1 = require('./make-theme.js');
|
|
7
|
+
function usePrefix({ isLoading = false, theme, }) {
|
|
13
8
|
const [tick, setTick] = (0, use_state_mjs_1.useState)(0);
|
|
9
|
+
const { prefix, spinner } = (0, make_theme_mjs_1.makeTheme)(theme);
|
|
14
10
|
(0, use_effect_mjs_1.useEffect)(() => {
|
|
15
11
|
if (isLoading) {
|
|
16
12
|
const timeout = setTimeout(() => {
|
|
@@ -21,8 +17,8 @@ function usePrefix(isLoading = false) {
|
|
|
21
17
|
}, [isLoading, tick]);
|
|
22
18
|
if (isLoading) {
|
|
23
19
|
const frame = tick % spinner.frames.length;
|
|
24
|
-
return
|
|
20
|
+
return spinner.frames[frame];
|
|
25
21
|
}
|
|
26
|
-
return
|
|
22
|
+
return prefix;
|
|
27
23
|
}
|
|
28
24
|
exports.usePrefix = usePrefix;
|
|
@@ -5,7 +5,9 @@ export { useEffect } from './lib/use-effect.js';
|
|
|
5
5
|
export { useMemo } from './lib/use-memo.js';
|
|
6
6
|
export { useRef } from './lib/use-ref.js';
|
|
7
7
|
export { useKeypress } from './lib/use-keypress.js';
|
|
8
|
+
export { makeTheme } from './lib/make-theme.js';
|
|
9
|
+
export type { Theme } from './lib/theme.js';
|
|
8
10
|
export { usePagination } from './lib/pagination/use-pagination.js';
|
|
9
|
-
export { createPrompt
|
|
11
|
+
export { createPrompt } from './lib/create-prompt.js';
|
|
10
12
|
export { Separator } from './lib/Separator.js';
|
|
11
13
|
export { type InquirerReadline } from './lib/read-line.type.js';
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { type Prompt, type Prettify } from '@inquirer/type';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
export type PromptConfig<Config> = Prettify<AsyncPromptConfig & Config>;
|
|
6
|
-
type ResolvedPromptConfig = {
|
|
7
|
-
message: string;
|
|
8
|
-
};
|
|
9
|
-
type ViewFunction<Value, Config> = (config: Prettify<Config & ResolvedPromptConfig>, done: (value: Value) => void) => string | [string, string | undefined];
|
|
10
|
-
export declare function createPrompt<Value, Config extends AsyncPromptConfig>(view: ViewFunction<Value, Config>): Prompt<Value, Config>;
|
|
2
|
+
type ViewFunction<Value, Config> = (config: Prettify<Config>, done: (value: Value) => void) => string | [string, string | undefined];
|
|
3
|
+
export declare function createPrompt<Value, Config>(view: ViewFunction<Value, Config>): Prompt<Value, Config>;
|
|
11
4
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Prettify } from '@inquirer/type';
|
|
2
|
+
import { type Theme } from '../theme.js';
|
|
2
3
|
import { type Layout } from './lines.js';
|
|
3
|
-
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
|
|
4
|
+
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, theme: defaultTheme, }: {
|
|
4
5
|
items: readonly T[];
|
|
5
6
|
/** The index of the active item. */
|
|
6
7
|
active: number;
|
|
@@ -10,4 +11,5 @@ export declare function usePagination<T>({ items, active, renderItem, pageSize,
|
|
|
10
11
|
pageSize: number;
|
|
11
12
|
/** Allows creating an infinitely looping list. `true` if unspecified. */
|
|
12
13
|
loop?: boolean;
|
|
14
|
+
theme?: Theme;
|
|
13
15
|
}): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Prettify } from '@inquirer/type';
|
|
2
|
+
type DefaultTheme = {
|
|
3
|
+
prefix: string;
|
|
4
|
+
spinner: {
|
|
5
|
+
interval: number;
|
|
6
|
+
frames: string[];
|
|
7
|
+
};
|
|
8
|
+
style: {
|
|
9
|
+
answer: (text: string) => string;
|
|
10
|
+
message: (text: string) => string;
|
|
11
|
+
error: (text: string) => string;
|
|
12
|
+
defaultAnswer: (text: string) => string;
|
|
13
|
+
help: (text: string) => string;
|
|
14
|
+
highlight: (text: string) => string;
|
|
15
|
+
key: (text: string) => string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type Theme<Extension extends {} = {}> = Prettify<Extension & DefaultTheme>;
|
|
19
|
+
export declare const defaultTheme: DefaultTheme;
|
|
20
|
+
export {};
|
package/dist/esm/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ export { useEffect } from './lib/use-effect.mjs';
|
|
|
5
5
|
export { useMemo } from './lib/use-memo.mjs';
|
|
6
6
|
export { useRef } from './lib/use-ref.mjs';
|
|
7
7
|
export { useKeypress } from './lib/use-keypress.mjs';
|
|
8
|
+
export { makeTheme } from './lib/make-theme.mjs';
|
|
8
9
|
export { usePagination } from './lib/pagination/use-pagination.mjs';
|
|
9
|
-
export { createPrompt
|
|
10
|
+
export { createPrompt } from './lib/create-prompt.mjs';
|
|
10
11
|
export { Separator } from './lib/Separator.mjs';
|
|
@@ -4,14 +4,6 @@ import MuteStream from 'mute-stream';
|
|
|
4
4
|
import { onExit as onSignalExit } from 'signal-exit';
|
|
5
5
|
import ScreenManager from './screen-manager.mjs';
|
|
6
6
|
import { withHooks, effectScheduler } from './hook-engine.mjs';
|
|
7
|
-
// Take an AsyncPromptConfig and resolves all it's values.
|
|
8
|
-
async function getPromptConfig(config) {
|
|
9
|
-
const message = typeof config.message === 'function' ? config.message() : config.message;
|
|
10
|
-
return {
|
|
11
|
-
...config,
|
|
12
|
-
message: await message,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
7
|
export function createPrompt(view) {
|
|
16
8
|
const prompt = (config, context) => {
|
|
17
9
|
// Default `input` to stdin
|
|
@@ -70,7 +62,7 @@ export function createPrompt(view) {
|
|
|
70
62
|
store.index = 0;
|
|
71
63
|
store.handleChange = () => workLoop(resolvedConfig);
|
|
72
64
|
try {
|
|
73
|
-
const nextView = view(
|
|
65
|
+
const nextView = view(config, done);
|
|
74
66
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
75
67
|
screen.render(content, bottomContent);
|
|
76
68
|
effectScheduler.run();
|
|
@@ -80,15 +72,12 @@ export function createPrompt(view) {
|
|
|
80
72
|
reject(err);
|
|
81
73
|
}
|
|
82
74
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// by a state change sets the cursor to the right position.
|
|
90
|
-
store.rl.input.on('keypress', checkCursorPos);
|
|
91
|
-
}, reject);
|
|
75
|
+
workLoop(config);
|
|
76
|
+
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
77
|
+
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
78
|
+
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
79
|
+
// by a state change sets the cursor to the right position.
|
|
80
|
+
store.rl.input.on('keypress', checkCursorPos);
|
|
92
81
|
});
|
|
93
82
|
});
|
|
94
83
|
answer.cancel = cancel;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
1
|
import { useRef } from '../use-ref.mjs';
|
|
3
2
|
import { readlineWidth } from '../utils.mjs';
|
|
3
|
+
import { makeTheme } from '../make-theme.mjs';
|
|
4
4
|
import { lines } from './lines.mjs';
|
|
5
5
|
import { finite, infinite } from './position.mjs';
|
|
6
|
-
export function usePagination({ items, active, renderItem, pageSize, loop = true, }) {
|
|
6
|
+
export function usePagination({ items, active, renderItem, pageSize, loop = true, theme: defaultTheme, }) {
|
|
7
7
|
const state = useRef({ position: 0, lastActive: 0 });
|
|
8
|
+
const theme = makeTheme(defaultTheme);
|
|
8
9
|
const position = loop
|
|
9
10
|
? infinite({
|
|
10
11
|
active,
|
|
@@ -29,7 +30,7 @@ export function usePagination({ items, active, renderItem, pageSize, loop = true
|
|
|
29
30
|
pageSize,
|
|
30
31
|
}).join('\n');
|
|
31
32
|
if (items.length > pageSize) {
|
|
32
|
-
return `${visibleLines}\n${
|
|
33
|
+
return `${visibleLines}\n${theme.style.help('(Use arrow keys to reveal more choices)')}`;
|
|
33
34
|
}
|
|
34
35
|
return visibleLines;
|
|
35
36
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import spinners from 'cli-spinners';
|
|
3
|
+
export const defaultTheme = {
|
|
4
|
+
prefix: chalk.green('?'),
|
|
5
|
+
spinner: {
|
|
6
|
+
interval: spinners.dots.interval,
|
|
7
|
+
frames: spinners.dots.frames.map(chalk.yellow),
|
|
8
|
+
},
|
|
9
|
+
style: {
|
|
10
|
+
answer: chalk.cyan,
|
|
11
|
+
message: chalk.bold,
|
|
12
|
+
error: (text) => chalk.red(`> ${text}`),
|
|
13
|
+
defaultAnswer: (text) => chalk.dim(`(${text})`),
|
|
14
|
+
help: chalk.dim,
|
|
15
|
+
highlight: chalk.cyan,
|
|
16
|
+
key: (text) => chalk.cyan.bold(`<${text}>`),
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import spinners from 'cli-spinners';
|
|
3
1
|
import { useState } from './use-state.mjs';
|
|
4
2
|
import { useEffect } from './use-effect.mjs';
|
|
5
|
-
|
|
6
|
-
export function usePrefix(isLoading = false) {
|
|
3
|
+
import { makeTheme } from './make-theme.mjs';
|
|
4
|
+
export function usePrefix({ isLoading = false, theme, }) {
|
|
7
5
|
const [tick, setTick] = useState(0);
|
|
6
|
+
const { prefix, spinner } = makeTheme(theme);
|
|
8
7
|
useEffect(() => {
|
|
9
8
|
if (isLoading) {
|
|
10
9
|
const timeout = setTimeout(() => {
|
|
@@ -15,7 +14,7 @@ export function usePrefix(isLoading = false) {
|
|
|
15
14
|
}, [isLoading, tick]);
|
|
16
15
|
if (isLoading) {
|
|
17
16
|
const frame = tick % spinner.frames.length;
|
|
18
|
-
return
|
|
17
|
+
return spinner.frames[frame];
|
|
19
18
|
}
|
|
20
|
-
return
|
|
19
|
+
return prefix;
|
|
21
20
|
}
|
|
@@ -5,7 +5,9 @@ export { useEffect } from './lib/use-effect.mjs';
|
|
|
5
5
|
export { useMemo } from './lib/use-memo.mjs';
|
|
6
6
|
export { useRef } from './lib/use-ref.mjs';
|
|
7
7
|
export { useKeypress } from './lib/use-keypress.mjs';
|
|
8
|
+
export { makeTheme } from './lib/make-theme.mjs';
|
|
9
|
+
export type { Theme } from './lib/theme.mjs';
|
|
8
10
|
export { usePagination } from './lib/pagination/use-pagination.mjs';
|
|
9
|
-
export { createPrompt
|
|
11
|
+
export { createPrompt } from './lib/create-prompt.mjs';
|
|
10
12
|
export { Separator } from './lib/Separator.mjs';
|
|
11
13
|
export { type InquirerReadline } from './lib/read-line.type.mjs';
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { type Prompt, type Prettify } from '@inquirer/type';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
export type PromptConfig<Config> = Prettify<AsyncPromptConfig & Config>;
|
|
6
|
-
type ResolvedPromptConfig = {
|
|
7
|
-
message: string;
|
|
8
|
-
};
|
|
9
|
-
type ViewFunction<Value, Config> = (config: Prettify<Config & ResolvedPromptConfig>, done: (value: Value) => void) => string | [string, string | undefined];
|
|
10
|
-
export declare function createPrompt<Value, Config extends AsyncPromptConfig>(view: ViewFunction<Value, Config>): Prompt<Value, Config>;
|
|
2
|
+
type ViewFunction<Value, Config> = (config: Prettify<Config>, done: (value: Value) => void) => string | [string, string | undefined];
|
|
3
|
+
export declare function createPrompt<Value, Config>(view: ViewFunction<Value, Config>): Prompt<Value, Config>;
|
|
11
4
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Prettify } from '@inquirer/type';
|
|
2
|
+
import { type Theme } from '../theme.mjs';
|
|
2
3
|
import { type Layout } from './lines.mjs';
|
|
3
|
-
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
|
|
4
|
+
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, theme: defaultTheme, }: {
|
|
4
5
|
items: readonly T[];
|
|
5
6
|
/** The index of the active item. */
|
|
6
7
|
active: number;
|
|
@@ -10,4 +11,5 @@ export declare function usePagination<T>({ items, active, renderItem, pageSize,
|
|
|
10
11
|
pageSize: number;
|
|
11
12
|
/** Allows creating an infinitely looping list. `true` if unspecified. */
|
|
12
13
|
loop?: boolean;
|
|
14
|
+
theme?: Theme;
|
|
13
15
|
}): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Prettify } from '@inquirer/type';
|
|
2
|
+
type DefaultTheme = {
|
|
3
|
+
prefix: string;
|
|
4
|
+
spinner: {
|
|
5
|
+
interval: number;
|
|
6
|
+
frames: string[];
|
|
7
|
+
};
|
|
8
|
+
style: {
|
|
9
|
+
answer: (text: string) => string;
|
|
10
|
+
message: (text: string) => string;
|
|
11
|
+
error: (text: string) => string;
|
|
12
|
+
defaultAnswer: (text: string) => string;
|
|
13
|
+
help: (text: string) => string;
|
|
14
|
+
highlight: (text: string) => string;
|
|
15
|
+
key: (text: string) => string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type Theme<Extension extends {} = {}> = Prettify<Extension & DefaultTheme>;
|
|
19
|
+
export declare const defaultTheme: DefaultTheme;
|
|
20
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"engines": {
|
|
5
|
-
"node": ">=
|
|
5
|
+
"node": ">=18"
|
|
6
6
|
},
|
|
7
7
|
"description": "Core Inquirer prompt API",
|
|
8
8
|
"main": "./dist/cjs/index.js",
|
|
@@ -57,9 +57,9 @@
|
|
|
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.
|
|
60
|
+
"@inquirer/type": "^1.2.0",
|
|
61
61
|
"@types/mute-stream": "^0.0.4",
|
|
62
|
-
"@types/node": "^20.
|
|
62
|
+
"@types/node": "^20.11.25",
|
|
63
63
|
"@types/wrap-ansi": "^3.0.0",
|
|
64
64
|
"ansi-escapes": "^4.3.2",
|
|
65
65
|
"chalk": "^4.1.2",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"wrap-ansi": "^6.2.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@inquirer/testing": "^2.1.
|
|
76
|
+
"@inquirer/testing": "^2.1.12"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "c91196e66689cfc05e9237763e6f95f3eb5342a1"
|
|
99
99
|
}
|