@inquirer/core 8.2.2 → 8.2.4
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 +4 -4
- package/dist/cjs/lib/Separator.js +2 -2
- package/dist/cjs/lib/create-prompt.js +4 -5
- package/dist/cjs/lib/hook-engine.js +6 -6
- package/dist/cjs/lib/make-theme.js +1 -2
- package/dist/cjs/lib/pagination/lines.js +1 -2
- package/dist/cjs/lib/pagination/position.js +2 -3
- package/dist/cjs/lib/pagination/use-pagination.js +1 -2
- package/dist/cjs/lib/theme.js +10 -10
- package/dist/cjs/lib/use-effect.js +1 -2
- package/dist/cjs/lib/use-keypress.js +1 -2
- package/dist/cjs/lib/use-memo.js +1 -2
- package/dist/cjs/lib/use-prefix.js +22 -10
- package/dist/cjs/lib/use-ref.js +1 -2
- package/dist/cjs/lib/use-state.js +1 -2
- package/dist/cjs/lib/utils.js +2 -3
- package/dist/cjs/types/lib/pagination/lines.d.ts +1 -1
- package/dist/cjs/types/lib/pagination/use-pagination.d.ts +1 -1
- package/dist/cjs/types/lib/read-line.type.d.ts +0 -2
- package/dist/cjs/types/lib/use-effect.d.ts +1 -1
- package/dist/cjs/types/lib/use-memo.d.ts +1 -1
- package/dist/esm/lib/Separator.mjs +2 -2
- package/dist/esm/lib/create-prompt.mjs +3 -3
- package/dist/esm/lib/theme.mjs +10 -10
- package/dist/esm/lib/use-prefix.mjs +21 -8
- package/dist/esm/types/lib/pagination/lines.d.mts +1 -1
- package/dist/esm/types/lib/pagination/use-pagination.d.mts +1 -1
- package/dist/esm/types/lib/read-line.type.d.mts +0 -2
- package/dist/esm/types/lib/use-effect.d.mts +1 -1
- package/dist/esm/types/lib/use-memo.d.mts +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ yarn add @inquirer/core
|
|
|
15
15
|
# Usage
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import
|
|
18
|
+
import pc from 'picocolors';
|
|
19
19
|
import {
|
|
20
20
|
createPrompt,
|
|
21
21
|
useState,
|
|
@@ -44,12 +44,12 @@ const confirm = createPrompt<boolean, { message: string; default?: boolean }>(
|
|
|
44
44
|
let formattedValue = value;
|
|
45
45
|
let defaultValue = '';
|
|
46
46
|
if (status === 'done') {
|
|
47
|
-
formattedValue =
|
|
47
|
+
formattedValue = pc.cyan(value);
|
|
48
48
|
} else {
|
|
49
|
-
defaultValue =
|
|
49
|
+
defaultValue = pc.dim(config.default === false ? ' (y/N)' : ' (Y/n)');
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
const message =
|
|
52
|
+
const message = pc.bold(config.message);
|
|
53
53
|
return `${prefix} ${message}${defaultValue} ${formattedValue}`;
|
|
54
54
|
},
|
|
55
55
|
);
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Separator = void 0;
|
|
7
|
-
const
|
|
7
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
8
8
|
const figures_1 = __importDefault(require("@inquirer/figures"));
|
|
9
9
|
/**
|
|
10
10
|
* Separator object
|
|
@@ -16,7 +16,7 @@ class Separator {
|
|
|
16
16
|
enumerable: true,
|
|
17
17
|
configurable: true,
|
|
18
18
|
writable: true,
|
|
19
|
-
value:
|
|
19
|
+
value: picocolors_1.default.dim(Array.from({ length: 15 }).join(figures_1.default.line))
|
|
20
20
|
});
|
|
21
21
|
Object.defineProperty(this, "type", {
|
|
22
22
|
enumerable: true,
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.createPrompt =
|
|
29
|
+
exports.createPrompt = createPrompt;
|
|
30
30
|
const readline = __importStar(require("node:readline"));
|
|
31
31
|
const type_1 = require("@inquirer/type");
|
|
32
32
|
const mute_stream_1 = __importDefault(require("mute-stream"));
|
|
@@ -89,9 +89,8 @@ function createPrompt(view) {
|
|
|
89
89
|
resolve(value);
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
-
function workLoop(
|
|
92
|
+
function workLoop() {
|
|
93
93
|
store.index = 0;
|
|
94
|
-
store.handleChange = () => workLoop(resolvedConfig);
|
|
95
94
|
try {
|
|
96
95
|
const nextView = view(config, done);
|
|
97
96
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
@@ -103,7 +102,8 @@ function createPrompt(view) {
|
|
|
103
102
|
reject(error);
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
|
-
workLoop(
|
|
105
|
+
store.handleChange = () => workLoop();
|
|
106
|
+
workLoop();
|
|
107
107
|
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
108
108
|
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
109
109
|
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
@@ -116,4 +116,3 @@ function createPrompt(view) {
|
|
|
116
116
|
};
|
|
117
117
|
return prompt;
|
|
118
118
|
}
|
|
119
|
-
exports.createPrompt = createPrompt;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint @typescript-eslint/no-explicit-any: ["off"] */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.effectScheduler =
|
|
4
|
+
exports.effectScheduler = void 0;
|
|
5
|
+
exports.withHooks = withHooks;
|
|
6
|
+
exports.readline = readline;
|
|
7
|
+
exports.withUpdates = withUpdates;
|
|
8
|
+
exports.withPointer = withPointer;
|
|
9
|
+
exports.handleChange = handleChange;
|
|
5
10
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
6
11
|
const errors_mjs_1 = require('./errors.js');
|
|
7
12
|
const hookStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
@@ -23,7 +28,6 @@ function withHooks(rl, cb) {
|
|
|
23
28
|
cb(store);
|
|
24
29
|
});
|
|
25
30
|
}
|
|
26
|
-
exports.withHooks = withHooks;
|
|
27
31
|
// Safe getStore utility that'll return the store or throw if undefined.
|
|
28
32
|
function getStore() {
|
|
29
33
|
const store = hookStorage.getStore();
|
|
@@ -35,7 +39,6 @@ function getStore() {
|
|
|
35
39
|
function readline() {
|
|
36
40
|
return getStore().rl;
|
|
37
41
|
}
|
|
38
|
-
exports.readline = readline;
|
|
39
42
|
// Merge state updates happening within the callback function to avoid multiple renders.
|
|
40
43
|
function withUpdates(fn) {
|
|
41
44
|
const wrapped = (...args) => {
|
|
@@ -54,7 +57,6 @@ function withUpdates(fn) {
|
|
|
54
57
|
};
|
|
55
58
|
return node_async_hooks_1.AsyncResource.bind(wrapped);
|
|
56
59
|
}
|
|
57
|
-
exports.withUpdates = withUpdates;
|
|
58
60
|
function withPointer(cb) {
|
|
59
61
|
const store = getStore();
|
|
60
62
|
const { index } = store;
|
|
@@ -71,11 +73,9 @@ function withPointer(cb) {
|
|
|
71
73
|
store.index++;
|
|
72
74
|
return returnValue;
|
|
73
75
|
}
|
|
74
|
-
exports.withPointer = withPointer;
|
|
75
76
|
function handleChange() {
|
|
76
77
|
getStore().handleChange();
|
|
77
78
|
}
|
|
78
|
-
exports.handleChange = handleChange;
|
|
79
79
|
exports.effectScheduler = {
|
|
80
80
|
queue(cb) {
|
|
81
81
|
const store = getStore();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeTheme =
|
|
3
|
+
exports.makeTheme = makeTheme;
|
|
4
4
|
const theme_mjs_1 = require('./theme.js');
|
|
5
5
|
function isPlainObject(value) {
|
|
6
6
|
if (typeof value !== 'object' || value === null)
|
|
@@ -31,4 +31,3 @@ function makeTheme(...themes) {
|
|
|
31
31
|
];
|
|
32
32
|
return deepMerge(...themesToMerge);
|
|
33
33
|
}
|
|
34
|
-
exports.makeTheme = makeTheme;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lines =
|
|
3
|
+
exports.lines = lines;
|
|
4
4
|
const utils_mjs_1 = require('../utils.js');
|
|
5
5
|
function split(content, width) {
|
|
6
6
|
return (0, utils_mjs_1.breakLines)(content, width).split('\n');
|
|
@@ -60,4 +60,3 @@ function lines({ items, width, renderItem, active, position: requested, pageSize
|
|
|
60
60
|
}
|
|
61
61
|
return pageBuffer.filter((line) => typeof line === 'string');
|
|
62
62
|
}
|
|
63
|
-
exports.lines = lines;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.finite = finite;
|
|
4
|
+
exports.infinite = infinite;
|
|
4
5
|
/**
|
|
5
6
|
* Creates the next position for the active item considering a finite list of
|
|
6
7
|
* items to be rendered on a page.
|
|
@@ -13,7 +14,6 @@ function finite({ active, pageSize, total, }) {
|
|
|
13
14
|
return active + pageSize - total;
|
|
14
15
|
return middle;
|
|
15
16
|
}
|
|
16
|
-
exports.finite = finite;
|
|
17
17
|
/**
|
|
18
18
|
* Creates the next position for the active item considering an infinitely
|
|
19
19
|
* looping list of items to be rendered on the page.
|
|
@@ -29,4 +29,3 @@ function infinite({ active, lastActive, total, pageSize, pointer, }) {
|
|
|
29
29
|
}
|
|
30
30
|
return pointer;
|
|
31
31
|
}
|
|
32
|
-
exports.infinite = infinite;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePagination =
|
|
3
|
+
exports.usePagination = usePagination;
|
|
4
4
|
const use_ref_mjs_1 = require('../use-ref.js');
|
|
5
5
|
const utils_mjs_1 = require('../utils.js');
|
|
6
6
|
const lines_mjs_1 = require('./lines.js');
|
|
@@ -31,4 +31,3 @@ function usePagination({ items, active, renderItem, pageSize, loop = true, }) {
|
|
|
31
31
|
pageSize,
|
|
32
32
|
}).join('\n');
|
|
33
33
|
}
|
|
34
|
-
exports.usePagination = usePagination;
|
package/dist/cjs/lib/theme.js
CHANGED
|
@@ -4,21 +4,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.defaultTheme = void 0;
|
|
7
|
-
const
|
|
7
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
8
8
|
const cli_spinners_1 = __importDefault(require("cli-spinners"));
|
|
9
9
|
exports.defaultTheme = {
|
|
10
|
-
prefix:
|
|
10
|
+
prefix: picocolors_1.default.green('?'),
|
|
11
11
|
spinner: {
|
|
12
12
|
interval: cli_spinners_1.default.dots.interval,
|
|
13
|
-
frames: cli_spinners_1.default.dots.frames.map((frame) =>
|
|
13
|
+
frames: cli_spinners_1.default.dots.frames.map((frame) => picocolors_1.default.yellow(frame)),
|
|
14
14
|
},
|
|
15
15
|
style: {
|
|
16
|
-
answer:
|
|
17
|
-
message:
|
|
18
|
-
error: (text) =>
|
|
19
|
-
defaultAnswer: (text) =>
|
|
20
|
-
help:
|
|
21
|
-
highlight:
|
|
22
|
-
key: (text) =>
|
|
16
|
+
answer: picocolors_1.default.cyan,
|
|
17
|
+
message: picocolors_1.default.bold,
|
|
18
|
+
error: (text) => picocolors_1.default.red(`> ${text}`),
|
|
19
|
+
defaultAnswer: (text) => picocolors_1.default.dim(`(${text})`),
|
|
20
|
+
help: picocolors_1.default.dim,
|
|
21
|
+
highlight: picocolors_1.default.cyan,
|
|
22
|
+
key: (text) => picocolors_1.default.cyan(picocolors_1.default.bold(`<${text}>`)),
|
|
23
23
|
},
|
|
24
24
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useEffect =
|
|
3
|
+
exports.useEffect = useEffect;
|
|
4
4
|
const hook_engine_mjs_1 = require('./hook-engine.js');
|
|
5
5
|
function useEffect(cb, depArray) {
|
|
6
6
|
(0, hook_engine_mjs_1.withPointer)((pointer) => {
|
|
@@ -12,4 +12,3 @@ function useEffect(cb, depArray) {
|
|
|
12
12
|
pointer.set(depArray);
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
-
exports.useEffect = useEffect;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useKeypress =
|
|
3
|
+
exports.useKeypress = useKeypress;
|
|
4
4
|
const use_ref_mjs_1 = require('./use-ref.js');
|
|
5
5
|
const use_effect_mjs_1 = require('./use-effect.js');
|
|
6
6
|
const hook_engine_mjs_1 = require('./hook-engine.js');
|
|
@@ -17,4 +17,3 @@ function useKeypress(userHandler) {
|
|
|
17
17
|
};
|
|
18
18
|
}, []);
|
|
19
19
|
}
|
|
20
|
-
exports.useKeypress = useKeypress;
|
package/dist/cjs/lib/use-memo.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useMemo =
|
|
3
|
+
exports.useMemo = useMemo;
|
|
4
4
|
const hook_engine_mjs_1 = require('./hook-engine.js');
|
|
5
5
|
function useMemo(fn, dependencies) {
|
|
6
6
|
return (0, hook_engine_mjs_1.withPointer)((pointer) => {
|
|
@@ -15,4 +15,3 @@ function useMemo(fn, dependencies) {
|
|
|
15
15
|
return prev.value;
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
exports.useMemo = useMemo;
|
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePrefix =
|
|
3
|
+
exports.usePrefix = usePrefix;
|
|
4
4
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
5
|
const use_state_mjs_1 = require('./use-state.js');
|
|
6
6
|
const use_effect_mjs_1 = require('./use-effect.js');
|
|
7
7
|
const make_theme_mjs_1 = require('./make-theme.js');
|
|
8
8
|
function usePrefix({ isLoading = false, theme, }) {
|
|
9
|
+
const [showLoader, setShowLoader] = (0, use_state_mjs_1.useState)(false);
|
|
9
10
|
const [tick, setTick] = (0, use_state_mjs_1.useState)(0);
|
|
10
11
|
const { prefix, spinner } = (0, make_theme_mjs_1.makeTheme)(theme);
|
|
11
12
|
(0, use_effect_mjs_1.useEffect)(() => {
|
|
12
13
|
if (isLoading) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
let tickInterval;
|
|
15
|
+
let inc = -1;
|
|
16
|
+
// Delay displaying spinner by 300ms, to avoid flickering
|
|
17
|
+
const delayTimeout = setTimeout(node_async_hooks_1.AsyncResource.bind(() => {
|
|
18
|
+
setShowLoader(true);
|
|
19
|
+
tickInterval = setInterval(node_async_hooks_1.AsyncResource.bind(() => {
|
|
20
|
+
inc = inc + 1;
|
|
21
|
+
setTick(inc % spinner.frames.length);
|
|
22
|
+
}), spinner.interval);
|
|
23
|
+
}), 300);
|
|
24
|
+
return () => {
|
|
25
|
+
clearTimeout(delayTimeout);
|
|
26
|
+
clearInterval(tickInterval);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
setShowLoader(false);
|
|
17
31
|
}
|
|
18
|
-
}, [isLoading
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
return spinner.frames[frame];
|
|
32
|
+
}, [isLoading]);
|
|
33
|
+
if (showLoader) {
|
|
34
|
+
return spinner.frames[tick];
|
|
22
35
|
}
|
|
23
36
|
return prefix;
|
|
24
37
|
}
|
|
25
|
-
exports.usePrefix = usePrefix;
|
package/dist/cjs/lib/use-ref.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useRef =
|
|
3
|
+
exports.useRef = useRef;
|
|
4
4
|
const use_state_mjs_1 = require('./use-state.js');
|
|
5
5
|
function useRef(val) {
|
|
6
6
|
return (0, use_state_mjs_1.useState)({ current: val })[0];
|
|
7
7
|
}
|
|
8
|
-
exports.useRef = useRef;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useState =
|
|
3
|
+
exports.useState = useState;
|
|
4
4
|
const hook_engine_mjs_1 = require('./hook-engine.js');
|
|
5
5
|
function useState(defaultValue) {
|
|
6
6
|
return (0, hook_engine_mjs_1.withPointer)((pointer) => {
|
|
@@ -20,4 +20,3 @@ function useState(defaultValue) {
|
|
|
20
20
|
return [value, setFn];
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
exports.useState = useState;
|
package/dist/cjs/lib/utils.js
CHANGED
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.breakLines = breakLines;
|
|
7
|
+
exports.readlineWidth = readlineWidth;
|
|
7
8
|
const cli_width_1 = __importDefault(require("cli-width"));
|
|
8
9
|
const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
|
|
9
10
|
const hook_engine_mjs_1 = require('./hook-engine.js');
|
|
@@ -22,7 +23,6 @@ function breakLines(content, width) {
|
|
|
22
23
|
.map((str) => str.trimEnd()))
|
|
23
24
|
.join('\n');
|
|
24
25
|
}
|
|
25
|
-
exports.breakLines = breakLines;
|
|
26
26
|
/**
|
|
27
27
|
* Returns the width of the active readline, or 80 as default value.
|
|
28
28
|
* @returns {number}
|
|
@@ -30,4 +30,3 @@ exports.breakLines = breakLines;
|
|
|
30
30
|
function readlineWidth() {
|
|
31
31
|
return (0, cli_width_1.default)({ defaultWidth: 80, output: (0, hook_engine_mjs_1.readline)().output });
|
|
32
32
|
}
|
|
33
|
-
exports.readlineWidth = readlineWidth;
|
|
@@ -12,7 +12,7 @@ export type Layout<T> = {
|
|
|
12
12
|
* of the active item get rendered as possible.
|
|
13
13
|
*/
|
|
14
14
|
export declare function lines<T>({ items, width, renderItem, active, position: requested, pageSize, }: {
|
|
15
|
-
items:
|
|
15
|
+
items: ReadonlyArray<T>;
|
|
16
16
|
/** The width of a rendered line in characters. */
|
|
17
17
|
width: number;
|
|
18
18
|
/** Renders an item as part of a page. */
|
|
@@ -2,7 +2,7 @@ import type { Prettify } from '@inquirer/type';
|
|
|
2
2
|
import { type Theme } from '../theme.js';
|
|
3
3
|
import { type Layout } from './lines.js';
|
|
4
4
|
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
|
|
5
|
-
items:
|
|
5
|
+
items: ReadonlyArray<T>;
|
|
6
6
|
/** The index of the active item. */
|
|
7
7
|
active: number;
|
|
8
8
|
/** Renders an item as part of a page. */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { InquirerReadline } from './read-line.type.js';
|
|
2
|
-
export declare function useEffect(cb: (rl: InquirerReadline) => void | (() => void), depArray: unknown
|
|
2
|
+
export declare function useEffect(cb: (rl: InquirerReadline) => void | (() => void), depArray: ReadonlyArray<unknown>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useMemo<Value>(fn: () => Value, dependencies: unknown
|
|
1
|
+
export declare function useMemo<Value>(fn: () => Value, dependencies: ReadonlyArray<unknown>): Value;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pc from 'picocolors';
|
|
2
2
|
import figures from '@inquirer/figures';
|
|
3
3
|
/**
|
|
4
4
|
* Separator object
|
|
5
5
|
* Used to space/separate choices group
|
|
6
6
|
*/
|
|
7
7
|
export class Separator {
|
|
8
|
-
separator =
|
|
8
|
+
separator = pc.dim(Array.from({ length: 15 }).join(figures.line));
|
|
9
9
|
type = 'separator';
|
|
10
10
|
constructor(separator) {
|
|
11
11
|
if (separator) {
|
|
@@ -59,9 +59,8 @@ export function createPrompt(view) {
|
|
|
59
59
|
resolve(value);
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
function workLoop(
|
|
62
|
+
function workLoop() {
|
|
63
63
|
store.index = 0;
|
|
64
|
-
store.handleChange = () => workLoop(resolvedConfig);
|
|
65
64
|
try {
|
|
66
65
|
const nextView = view(config, done);
|
|
67
66
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
@@ -73,7 +72,8 @@ export function createPrompt(view) {
|
|
|
73
72
|
reject(error);
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
|
-
workLoop(
|
|
75
|
+
store.handleChange = () => workLoop();
|
|
76
|
+
workLoop();
|
|
77
77
|
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
78
78
|
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
79
79
|
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
package/dist/esm/lib/theme.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pc from 'picocolors';
|
|
2
2
|
import spinners from 'cli-spinners';
|
|
3
3
|
export const defaultTheme = {
|
|
4
|
-
prefix:
|
|
4
|
+
prefix: pc.green('?'),
|
|
5
5
|
spinner: {
|
|
6
6
|
interval: spinners.dots.interval,
|
|
7
|
-
frames: spinners.dots.frames.map((frame) =>
|
|
7
|
+
frames: spinners.dots.frames.map((frame) => pc.yellow(frame)),
|
|
8
8
|
},
|
|
9
9
|
style: {
|
|
10
|
-
answer:
|
|
11
|
-
message:
|
|
12
|
-
error: (text) =>
|
|
13
|
-
defaultAnswer: (text) =>
|
|
14
|
-
help:
|
|
15
|
-
highlight:
|
|
16
|
-
key: (text) =>
|
|
10
|
+
answer: pc.cyan,
|
|
11
|
+
message: pc.bold,
|
|
12
|
+
error: (text) => pc.red(`> ${text}`),
|
|
13
|
+
defaultAnswer: (text) => pc.dim(`(${text})`),
|
|
14
|
+
help: pc.dim,
|
|
15
|
+
highlight: pc.cyan,
|
|
16
|
+
key: (text) => pc.cyan(pc.bold(`<${text}>`)),
|
|
17
17
|
},
|
|
18
18
|
};
|
|
@@ -3,19 +3,32 @@ import { useState } from './use-state.mjs';
|
|
|
3
3
|
import { useEffect } from './use-effect.mjs';
|
|
4
4
|
import { makeTheme } from './make-theme.mjs';
|
|
5
5
|
export function usePrefix({ isLoading = false, theme, }) {
|
|
6
|
+
const [showLoader, setShowLoader] = useState(false);
|
|
6
7
|
const [tick, setTick] = useState(0);
|
|
7
8
|
const { prefix, spinner } = makeTheme(theme);
|
|
8
9
|
useEffect(() => {
|
|
9
10
|
if (isLoading) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
let tickInterval;
|
|
12
|
+
let inc = -1;
|
|
13
|
+
// Delay displaying spinner by 300ms, to avoid flickering
|
|
14
|
+
const delayTimeout = setTimeout(AsyncResource.bind(() => {
|
|
15
|
+
setShowLoader(true);
|
|
16
|
+
tickInterval = setInterval(AsyncResource.bind(() => {
|
|
17
|
+
inc = inc + 1;
|
|
18
|
+
setTick(inc % spinner.frames.length);
|
|
19
|
+
}), spinner.interval);
|
|
20
|
+
}), 300);
|
|
21
|
+
return () => {
|
|
22
|
+
clearTimeout(delayTimeout);
|
|
23
|
+
clearInterval(tickInterval);
|
|
24
|
+
};
|
|
14
25
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
else {
|
|
27
|
+
setShowLoader(false);
|
|
28
|
+
}
|
|
29
|
+
}, [isLoading]);
|
|
30
|
+
if (showLoader) {
|
|
31
|
+
return spinner.frames[tick];
|
|
19
32
|
}
|
|
20
33
|
return prefix;
|
|
21
34
|
}
|
|
@@ -12,7 +12,7 @@ export type Layout<T> = {
|
|
|
12
12
|
* of the active item get rendered as possible.
|
|
13
13
|
*/
|
|
14
14
|
export declare function lines<T>({ items, width, renderItem, active, position: requested, pageSize, }: {
|
|
15
|
-
items:
|
|
15
|
+
items: ReadonlyArray<T>;
|
|
16
16
|
/** The width of a rendered line in characters. */
|
|
17
17
|
width: number;
|
|
18
18
|
/** Renders an item as part of a page. */
|
|
@@ -2,7 +2,7 @@ import type { Prettify } from '@inquirer/type';
|
|
|
2
2
|
import { type Theme } from '../theme.mjs';
|
|
3
3
|
import { type Layout } from './lines.mjs';
|
|
4
4
|
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
|
|
5
|
-
items:
|
|
5
|
+
items: ReadonlyArray<T>;
|
|
6
6
|
/** The index of the active item. */
|
|
7
7
|
active: number;
|
|
8
8
|
/** Renders an item as part of a page. */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { InquirerReadline } from './read-line.type.mjs';
|
|
2
|
-
export declare function useEffect(cb: (rl: InquirerReadline) => void | (() => void), depArray: unknown
|
|
2
|
+
export declare function useEffect(cb: (rl: InquirerReadline) => void | (() => void), depArray: ReadonlyArray<unknown>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useMemo<Value>(fn: () => Value, dependencies: unknown
|
|
1
|
+
export declare function useMemo<Value>(fn: () => Value, dependencies: ReadonlyArray<unknown>): Value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.4",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
@@ -60,19 +60,19 @@
|
|
|
60
60
|
"@inquirer/figures": "^1.0.3",
|
|
61
61
|
"@inquirer/type": "^1.3.3",
|
|
62
62
|
"@types/mute-stream": "^0.0.4",
|
|
63
|
-
"@types/node": "^20.
|
|
63
|
+
"@types/node": "^20.14.9",
|
|
64
64
|
"@types/wrap-ansi": "^3.0.0",
|
|
65
65
|
"ansi-escapes": "^4.3.2",
|
|
66
|
-
"chalk": "^4.1.2",
|
|
67
66
|
"cli-spinners": "^2.9.2",
|
|
68
67
|
"cli-width": "^4.1.0",
|
|
69
68
|
"mute-stream": "^1.0.0",
|
|
69
|
+
"picocolors": "^1.0.1",
|
|
70
70
|
"signal-exit": "^4.1.0",
|
|
71
71
|
"strip-ansi": "^6.0.1",
|
|
72
72
|
"wrap-ansi": "^6.2.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@inquirer/testing": "^2.1.
|
|
75
|
+
"@inquirer/testing": "^2.1.23"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
"sideEffects": false,
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "d5f62c6ee3e671f7d1b776b85d43781869d70918"
|
|
101
101
|
}
|