@inquirer/core 9.2.1 → 10.0.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/dist/{cjs → commonjs}/index.js +22 -22
- package/dist/{cjs → commonjs}/lib/Separator.js +2 -12
- package/dist/{cjs → commonjs}/lib/create-prompt.js +16 -17
- package/dist/commonjs/lib/errors.js +29 -0
- package/dist/{cjs → commonjs}/lib/hook-engine.js +5 -6
- package/dist/{cjs → commonjs}/lib/make-theme.js +2 -2
- package/dist/{cjs → commonjs}/lib/pagination/lines.js +2 -2
- package/dist/{cjs → commonjs}/lib/pagination/use-pagination.js +9 -9
- package/dist/{cjs → commonjs}/lib/screen-manager.js +11 -30
- package/dist/{cjs → commonjs}/lib/use-effect.js +3 -3
- package/dist/{cjs → commonjs}/lib/use-keypress.js +6 -6
- package/dist/{cjs → commonjs}/lib/use-memo.js +2 -2
- package/dist/{cjs → commonjs}/lib/use-prefix.js +7 -7
- package/dist/{cjs → commonjs}/lib/use-ref.js +2 -2
- package/dist/{cjs → commonjs}/lib/use-state.js +3 -3
- package/dist/{cjs → commonjs}/lib/utils.js +2 -2
- package/dist/commonjs/package.json +3 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/{types/index.d.ts → esm/index.js} +0 -1
- package/dist/esm/lib/{create-prompt.mjs → create-prompt.js} +4 -4
- package/dist/esm/lib/{hook-engine.mjs → hook-engine.js} +1 -1
- package/dist/esm/lib/{make-theme.mjs → make-theme.js} +1 -1
- package/dist/esm/lib/pagination/{lines.mjs → lines.js} +1 -1
- package/dist/esm/lib/pagination/{use-pagination.mjs → use-pagination.js} +4 -4
- package/dist/esm/lib/{screen-manager.mjs → screen-manager.js} +1 -1
- package/dist/esm/lib/{use-effect.mjs → use-effect.js} +1 -1
- package/dist/esm/{types/lib/use-keypress.d.mts → lib/use-keypress.d.ts} +1 -1
- package/dist/esm/lib/{use-keypress.mjs → use-keypress.js} +3 -3
- package/dist/esm/lib/{use-memo.mjs → use-memo.js} +1 -1
- package/dist/esm/{types/lib/use-prefix.d.mts → lib/use-prefix.d.ts} +1 -1
- package/dist/esm/lib/{use-prefix.mjs → use-prefix.js} +3 -3
- package/dist/esm/lib/{use-ref.mjs → use-ref.js} +1 -1
- package/dist/esm/lib/{use-state.mjs → use-state.js} +1 -1
- package/dist/esm/lib/{utils.mjs → utils.js} +1 -1
- package/dist/esm/package.json +3 -0
- package/package.json +52 -39
- package/dist/cjs/lib/errors.js +0 -76
- package/dist/esm/index.mjs +0 -12
- package/dist/esm/types/index.d.mts +0 -13
- package/dist/esm/types/lib/create-prompt.d.mts +0 -4
- package/dist/esm/types/lib/key.d.mts +0 -10
- package/dist/esm/types/lib/make-theme.d.mts +0 -3
- package/dist/esm/types/lib/pagination/lines.d.mts +0 -26
- package/dist/esm/types/lib/pagination/position.d.mts +0 -20
- package/dist/esm/types/lib/pagination/use-pagination.d.mts +0 -15
- package/dist/esm/types/lib/use-effect.d.mts +0 -2
- package/dist/esm/types/lib/use-memo.d.mts +0 -1
- package/dist/esm/types/lib/use-ref.d.mts +0 -6
- package/dist/esm/types/lib/utils.d.mts +0 -13
- package/dist/types/lib/Separator.d.ts +0 -10
- package/dist/types/lib/errors.d.ts +0 -9
- package/dist/types/lib/hook-engine.d.ts +0 -30
- package/dist/types/lib/pagination/lines.test.d.ts +0 -1
- package/dist/types/lib/screen-manager.d.ts +0 -13
- package/dist/types/lib/theme.d.ts +0 -20
- package/dist/types/lib/use-keypress.d.ts +0 -3
- package/dist/types/lib/use-prefix.d.ts +0 -5
- package/dist/types/lib/use-state.d.ts +0 -4
- /package/dist/{cjs/types → commonjs}/index.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/Separator.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/create-prompt.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/errors.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/hook-engine.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/key.d.ts +0 -0
- /package/dist/{cjs → commonjs}/lib/key.js +0 -0
- /package/dist/{cjs/types → commonjs}/lib/make-theme.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/pagination/lines.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/pagination/position.d.ts +0 -0
- /package/dist/{cjs → commonjs}/lib/pagination/position.js +0 -0
- /package/dist/{cjs/types → commonjs}/lib/pagination/use-pagination.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/promise-polyfill.d.ts +0 -0
- /package/dist/{cjs → commonjs}/lib/promise-polyfill.js +0 -0
- /package/dist/{cjs/types → commonjs}/lib/screen-manager.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/theme.d.ts +0 -0
- /package/dist/{cjs → commonjs}/lib/theme.js +0 -0
- /package/dist/{cjs/types → commonjs}/lib/use-effect.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/use-keypress.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/use-memo.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/use-prefix.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/use-ref.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/use-state.d.ts +0 -0
- /package/dist/{cjs/types → commonjs}/lib/utils.d.ts +0 -0
- /package/dist/esm/{types/lib/Separator.d.mts → lib/Separator.d.ts} +0 -0
- /package/dist/esm/lib/{Separator.mjs → Separator.js} +0 -0
- /package/dist/{types → esm}/lib/create-prompt.d.ts +0 -0
- /package/dist/esm/{types/lib/errors.d.mts → lib/errors.d.ts} +0 -0
- /package/dist/esm/lib/{errors.mjs → errors.js} +0 -0
- /package/dist/esm/{types/lib/hook-engine.d.mts → lib/hook-engine.d.ts} +0 -0
- /package/dist/{types → esm}/lib/key.d.ts +0 -0
- /package/dist/esm/lib/{key.mjs → key.js} +0 -0
- /package/dist/{types → esm}/lib/make-theme.d.ts +0 -0
- /package/dist/{types → esm}/lib/pagination/lines.d.ts +0 -0
- /package/dist/{types → esm}/lib/pagination/position.d.ts +0 -0
- /package/dist/esm/lib/pagination/{position.mjs → position.js} +0 -0
- /package/dist/{types → esm}/lib/pagination/use-pagination.d.ts +0 -0
- /package/dist/esm/{types/lib/promise-polyfill.d.mts → lib/promise-polyfill.d.ts} +0 -0
- /package/dist/esm/lib/{promise-polyfill.mjs → promise-polyfill.js} +0 -0
- /package/dist/esm/{types/lib/screen-manager.d.mts → lib/screen-manager.d.ts} +0 -0
- /package/dist/esm/{types/lib/theme.d.mts → lib/theme.d.ts} +0 -0
- /package/dist/esm/lib/{theme.mjs → theme.js} +0 -0
- /package/dist/{types → esm}/lib/use-effect.d.ts +0 -0
- /package/dist/{types → esm}/lib/use-memo.d.ts +0 -0
- /package/dist/{types → esm}/lib/use-ref.d.ts +0 -0
- /package/dist/esm/{types/lib/use-state.d.mts → lib/use-state.d.ts} +0 -0
- /package/dist/{types → esm}/lib/utils.d.ts +0 -0
|
@@ -15,25 +15,25 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.Separator = exports.createPrompt = exports.usePagination = exports.makeTheme = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = void 0;
|
|
18
|
-
__exportStar(require(
|
|
19
|
-
__exportStar(require(
|
|
20
|
-
var
|
|
21
|
-
Object.defineProperty(exports, "usePrefix", { enumerable: true, get: function () { return
|
|
22
|
-
var
|
|
23
|
-
Object.defineProperty(exports, "useState", { enumerable: true, get: function () { return
|
|
24
|
-
var
|
|
25
|
-
Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return
|
|
26
|
-
var
|
|
27
|
-
Object.defineProperty(exports, "useMemo", { enumerable: true, get: function () { return
|
|
28
|
-
var
|
|
29
|
-
Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return
|
|
30
|
-
var
|
|
31
|
-
Object.defineProperty(exports, "useKeypress", { enumerable: true, get: function () { return
|
|
32
|
-
var
|
|
33
|
-
Object.defineProperty(exports, "makeTheme", { enumerable: true, get: function () { return
|
|
34
|
-
var
|
|
35
|
-
Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return
|
|
36
|
-
var
|
|
37
|
-
Object.defineProperty(exports, "createPrompt", { enumerable: true, get: function () { return
|
|
38
|
-
var
|
|
39
|
-
Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return
|
|
18
|
+
__exportStar(require("./lib/key.js"), exports);
|
|
19
|
+
__exportStar(require("./lib/errors.js"), exports);
|
|
20
|
+
var use_prefix_js_1 = require("./lib/use-prefix.js");
|
|
21
|
+
Object.defineProperty(exports, "usePrefix", { enumerable: true, get: function () { return use_prefix_js_1.usePrefix; } });
|
|
22
|
+
var use_state_js_1 = require("./lib/use-state.js");
|
|
23
|
+
Object.defineProperty(exports, "useState", { enumerable: true, get: function () { return use_state_js_1.useState; } });
|
|
24
|
+
var use_effect_js_1 = require("./lib/use-effect.js");
|
|
25
|
+
Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return use_effect_js_1.useEffect; } });
|
|
26
|
+
var use_memo_js_1 = require("./lib/use-memo.js");
|
|
27
|
+
Object.defineProperty(exports, "useMemo", { enumerable: true, get: function () { return use_memo_js_1.useMemo; } });
|
|
28
|
+
var use_ref_js_1 = require("./lib/use-ref.js");
|
|
29
|
+
Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return use_ref_js_1.useRef; } });
|
|
30
|
+
var use_keypress_js_1 = require("./lib/use-keypress.js");
|
|
31
|
+
Object.defineProperty(exports, "useKeypress", { enumerable: true, get: function () { return use_keypress_js_1.useKeypress; } });
|
|
32
|
+
var make_theme_js_1 = require("./lib/make-theme.js");
|
|
33
|
+
Object.defineProperty(exports, "makeTheme", { enumerable: true, get: function () { return make_theme_js_1.makeTheme; } });
|
|
34
|
+
var use_pagination_js_1 = require("./lib/pagination/use-pagination.js");
|
|
35
|
+
Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return use_pagination_js_1.usePagination; } });
|
|
36
|
+
var create_prompt_js_1 = require("./lib/create-prompt.js");
|
|
37
|
+
Object.defineProperty(exports, "createPrompt", { enumerable: true, get: function () { return create_prompt_js_1.createPrompt; } });
|
|
38
|
+
var Separator_js_1 = require("./lib/Separator.js");
|
|
39
|
+
Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return Separator_js_1.Separator; } });
|
|
@@ -11,19 +11,9 @@ const figures_1 = __importDefault(require("@inquirer/figures"));
|
|
|
11
11
|
* Used to space/separate choices group
|
|
12
12
|
*/
|
|
13
13
|
class Separator {
|
|
14
|
+
separator = yoctocolors_cjs_1.default.dim(Array.from({ length: 15 }).join(figures_1.default.line));
|
|
15
|
+
type = 'separator';
|
|
14
16
|
constructor(separator) {
|
|
15
|
-
Object.defineProperty(this, "separator", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: yoctocolors_cjs_1.default.dim(Array.from({ length: 15 }).join(figures_1.default.line))
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(this, "type", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: 'separator'
|
|
26
|
-
});
|
|
27
17
|
if (separator) {
|
|
28
18
|
this.separator = separator;
|
|
29
19
|
}
|
|
@@ -31,30 +31,29 @@ const readline = __importStar(require("node:readline"));
|
|
|
31
31
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
32
32
|
const mute_stream_1 = __importDefault(require("mute-stream"));
|
|
33
33
|
const signal_exit_1 = require("signal-exit");
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
34
|
+
const screen_manager_js_1 = __importDefault(require("./screen-manager.js"));
|
|
35
|
+
const promise_polyfill_js_1 = require("./promise-polyfill.js");
|
|
36
|
+
const hook_engine_js_1 = require("./hook-engine.js");
|
|
37
|
+
const errors_js_1 = require("./errors.js");
|
|
38
38
|
function createPrompt(view) {
|
|
39
39
|
const prompt = (config, context = {}) => {
|
|
40
|
-
var _a;
|
|
41
40
|
// Default `input` to stdin
|
|
42
41
|
const { input = process.stdin, signal } = context;
|
|
43
42
|
const cleanups = new Set();
|
|
44
43
|
// Add mute capabilities to the output
|
|
45
44
|
const output = new mute_stream_1.default();
|
|
46
|
-
output.pipe(
|
|
45
|
+
output.pipe(context.output ?? process.stdout);
|
|
47
46
|
const rl = readline.createInterface({
|
|
48
47
|
terminal: true,
|
|
49
48
|
input,
|
|
50
49
|
output,
|
|
51
50
|
});
|
|
52
|
-
const screen = new
|
|
53
|
-
const { promise, resolve, reject } =
|
|
51
|
+
const screen = new screen_manager_js_1.default(rl);
|
|
52
|
+
const { promise, resolve, reject } = promise_polyfill_js_1.PromisePolyfill.withResolver();
|
|
54
53
|
/** @deprecated pass an AbortSignal in the context options instead. See {@link https://github.com/SBoudrias/Inquirer.js#canceling-prompt} */
|
|
55
|
-
const cancel = () => reject(new
|
|
54
|
+
const cancel = () => reject(new errors_js_1.CancelPromptError());
|
|
56
55
|
if (signal) {
|
|
57
|
-
const abort = () => reject(new
|
|
56
|
+
const abort = () => reject(new errors_js_1.AbortPromptError({ cause: signal.reason }));
|
|
58
57
|
if (signal.aborted) {
|
|
59
58
|
abort();
|
|
60
59
|
return Object.assign(promise, { cancel });
|
|
@@ -63,7 +62,7 @@ function createPrompt(view) {
|
|
|
63
62
|
cleanups.add(() => signal.removeEventListener('abort', abort));
|
|
64
63
|
}
|
|
65
64
|
cleanups.add((0, signal_exit_1.onExit)((code, signal) => {
|
|
66
|
-
reject(new
|
|
65
|
+
reject(new errors_js_1.ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
|
|
67
66
|
}));
|
|
68
67
|
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
69
68
|
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
@@ -72,11 +71,11 @@ function createPrompt(view) {
|
|
|
72
71
|
const checkCursorPos = () => screen.checkCursorPos();
|
|
73
72
|
rl.input.on('keypress', checkCursorPos);
|
|
74
73
|
cleanups.add(() => rl.input.removeListener('keypress', checkCursorPos));
|
|
75
|
-
return (0,
|
|
74
|
+
return (0, hook_engine_js_1.withHooks)(rl, (cycle) => {
|
|
76
75
|
// The close event triggers immediately when the user press ctrl+c. SignalExit on the other hand
|
|
77
76
|
// triggers after the process is done (which happens after timeouts are done triggering.)
|
|
78
77
|
// We triggers the hooks cleanup phase on rl `close` so active timeouts can be cleared.
|
|
79
|
-
const hooksCleanup = node_async_hooks_1.AsyncResource.bind(() =>
|
|
78
|
+
const hooksCleanup = node_async_hooks_1.AsyncResource.bind(() => hook_engine_js_1.effectScheduler.clearAll());
|
|
80
79
|
rl.on('close', hooksCleanup);
|
|
81
80
|
cleanups.add(() => rl.removeListener('close', hooksCleanup));
|
|
82
81
|
cycle(() => {
|
|
@@ -86,7 +85,7 @@ function createPrompt(view) {
|
|
|
86
85
|
});
|
|
87
86
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
88
87
|
screen.render(content, bottomContent);
|
|
89
|
-
|
|
88
|
+
hook_engine_js_1.effectScheduler.run();
|
|
90
89
|
}
|
|
91
90
|
catch (error) {
|
|
92
91
|
reject(error);
|
|
@@ -94,16 +93,16 @@ function createPrompt(view) {
|
|
|
94
93
|
});
|
|
95
94
|
return Object.assign(promise
|
|
96
95
|
.then((answer) => {
|
|
97
|
-
|
|
96
|
+
hook_engine_js_1.effectScheduler.clearAll();
|
|
98
97
|
return answer;
|
|
99
98
|
}, (error) => {
|
|
100
|
-
|
|
99
|
+
hook_engine_js_1.effectScheduler.clearAll();
|
|
101
100
|
throw error;
|
|
102
101
|
})
|
|
103
102
|
// Wait for the promise to settle, then cleanup.
|
|
104
103
|
.finally(() => {
|
|
105
104
|
cleanups.forEach((cleanup) => cleanup());
|
|
106
|
-
screen.done({ clearContent: Boolean(context
|
|
105
|
+
screen.done({ clearContent: Boolean(context?.clearPromptOnDone) });
|
|
107
106
|
output.end();
|
|
108
107
|
})
|
|
109
108
|
// Once cleanup is done, let the expose promise resolve/reject to the internal one.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationError = exports.HookError = exports.ExitPromptError = exports.CancelPromptError = exports.AbortPromptError = void 0;
|
|
4
|
+
class AbortPromptError extends Error {
|
|
5
|
+
name = 'AbortPromptError';
|
|
6
|
+
message = 'Prompt was aborted';
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super();
|
|
9
|
+
this.cause = options?.cause;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.AbortPromptError = AbortPromptError;
|
|
13
|
+
class CancelPromptError extends Error {
|
|
14
|
+
name = 'CancelPromptError';
|
|
15
|
+
message = 'Prompt was canceled';
|
|
16
|
+
}
|
|
17
|
+
exports.CancelPromptError = CancelPromptError;
|
|
18
|
+
class ExitPromptError extends Error {
|
|
19
|
+
name = 'ExitPromptError';
|
|
20
|
+
}
|
|
21
|
+
exports.ExitPromptError = ExitPromptError;
|
|
22
|
+
class HookError extends Error {
|
|
23
|
+
name = 'HookError';
|
|
24
|
+
}
|
|
25
|
+
exports.HookError = HookError;
|
|
26
|
+
class ValidationError extends Error {
|
|
27
|
+
name = 'ValidationError';
|
|
28
|
+
}
|
|
29
|
+
exports.ValidationError = ValidationError;
|
|
@@ -8,7 +8,7 @@ exports.withUpdates = withUpdates;
|
|
|
8
8
|
exports.withPointer = withPointer;
|
|
9
9
|
exports.handleChange = handleChange;
|
|
10
10
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
11
|
-
const
|
|
11
|
+
const errors_js_1 = require("./errors.js");
|
|
12
12
|
const hookStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
13
13
|
function createStore(rl) {
|
|
14
14
|
const store = {
|
|
@@ -39,7 +39,7 @@ function withHooks(rl, cb) {
|
|
|
39
39
|
function getStore() {
|
|
40
40
|
const store = hookStorage.getStore();
|
|
41
41
|
if (!store) {
|
|
42
|
-
throw new
|
|
42
|
+
throw new errors_js_1.HookError('[Inquirer] Hook functions can only be called from within a prompt');
|
|
43
43
|
}
|
|
44
44
|
return store;
|
|
45
45
|
}
|
|
@@ -88,11 +88,10 @@ exports.effectScheduler = {
|
|
|
88
88
|
const store = getStore();
|
|
89
89
|
const { index } = store;
|
|
90
90
|
store.hooksEffect.push(() => {
|
|
91
|
-
|
|
92
|
-
(_b = (_a = store.hooksCleanup)[index]) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
91
|
+
store.hooksCleanup[index]?.();
|
|
93
92
|
const cleanFn = cb(readline());
|
|
94
93
|
if (cleanFn != null && typeof cleanFn !== 'function') {
|
|
95
|
-
throw new
|
|
94
|
+
throw new errors_js_1.ValidationError('useEffect return value must be a cleanup function or nothing.');
|
|
96
95
|
}
|
|
97
96
|
store.hooksCleanup[index] = cleanFn;
|
|
98
97
|
});
|
|
@@ -111,7 +110,7 @@ exports.effectScheduler = {
|
|
|
111
110
|
clearAll() {
|
|
112
111
|
const store = getStore();
|
|
113
112
|
store.hooksCleanup.forEach((cleanFn) => {
|
|
114
|
-
cleanFn
|
|
113
|
+
cleanFn?.();
|
|
115
114
|
});
|
|
116
115
|
store.hooksEffect.length = 0;
|
|
117
116
|
store.hooksCleanup.length = 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeTheme = makeTheme;
|
|
4
|
-
const
|
|
4
|
+
const theme_js_1 = require("./theme.js");
|
|
5
5
|
function isPlainObject(value) {
|
|
6
6
|
if (typeof value !== 'object' || value === null)
|
|
7
7
|
return false;
|
|
@@ -26,7 +26,7 @@ function deepMerge(...objects) {
|
|
|
26
26
|
}
|
|
27
27
|
function makeTheme(...themes) {
|
|
28
28
|
const themesToMerge = [
|
|
29
|
-
|
|
29
|
+
theme_js_1.defaultTheme,
|
|
30
30
|
...themes.filter((theme) => theme != null),
|
|
31
31
|
];
|
|
32
32
|
return deepMerge(...themesToMerge);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.lines = lines;
|
|
4
|
-
const
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
5
|
function split(content, width) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, utils_js_1.breakLines)(content, width).split('\n');
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Rotates an array of items by an integer number of positions.
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.usePagination = usePagination;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
4
|
+
const use_ref_js_1 = require("../use-ref.js");
|
|
5
|
+
const utils_js_1 = require("../utils.js");
|
|
6
|
+
const lines_js_1 = require("./lines.js");
|
|
7
|
+
const position_js_1 = require("./position.js");
|
|
8
8
|
function usePagination({ items, active, renderItem, pageSize, loop = true, }) {
|
|
9
|
-
const state = (0,
|
|
9
|
+
const state = (0, use_ref_js_1.useRef)({ position: 0, lastActive: 0 });
|
|
10
10
|
const position = loop
|
|
11
|
-
? (0,
|
|
11
|
+
? (0, position_js_1.infinite)({
|
|
12
12
|
active,
|
|
13
13
|
lastActive: state.current.lastActive,
|
|
14
14
|
total: items.length,
|
|
15
15
|
pageSize,
|
|
16
16
|
pointer: state.current.position,
|
|
17
17
|
})
|
|
18
|
-
: (0,
|
|
18
|
+
: (0, position_js_1.finite)({
|
|
19
19
|
active,
|
|
20
20
|
total: items.length,
|
|
21
21
|
pageSize,
|
|
22
22
|
});
|
|
23
23
|
state.current.position = position;
|
|
24
24
|
state.current.lastActive = active;
|
|
25
|
-
return (0,
|
|
25
|
+
return (0, lines_js_1.lines)({
|
|
26
26
|
items,
|
|
27
|
-
width: (0,
|
|
27
|
+
width: (0, utils_js_1.readlineWidth)(),
|
|
28
28
|
renderItem,
|
|
29
29
|
active,
|
|
30
30
|
position,
|
|
@@ -5,39 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
7
7
|
const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
|
|
8
|
-
const
|
|
8
|
+
const utils_js_1 = require("./utils.js");
|
|
9
9
|
const height = (content) => content.split('\n').length;
|
|
10
|
-
const lastLine = (content) =>
|
|
10
|
+
const lastLine = (content) => content.split('\n').pop() ?? '';
|
|
11
11
|
function cursorDown(n) {
|
|
12
12
|
return n > 0 ? ansi_escapes_1.default.cursorDown(n) : '';
|
|
13
13
|
}
|
|
14
14
|
class ScreenManager {
|
|
15
|
+
rl;
|
|
16
|
+
// These variables are keeping information to allow correct prompt re-rendering
|
|
17
|
+
height = 0;
|
|
18
|
+
extraLinesUnderPrompt = 0;
|
|
19
|
+
cursorPos;
|
|
15
20
|
constructor(rl) {
|
|
16
|
-
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true,
|
|
20
|
-
value: rl
|
|
21
|
-
});
|
|
22
|
-
// These variables are keeping information to allow correct prompt re-rendering
|
|
23
|
-
Object.defineProperty(this, "height", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true,
|
|
27
|
-
value: 0
|
|
28
|
-
});
|
|
29
|
-
Object.defineProperty(this, "extraLinesUnderPrompt", {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
configurable: true,
|
|
32
|
-
writable: true,
|
|
33
|
-
value: 0
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(this, "cursorPos", {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
configurable: true,
|
|
38
|
-
writable: true,
|
|
39
|
-
value: void 0
|
|
40
|
-
});
|
|
21
|
+
this.rl = rl;
|
|
41
22
|
this.rl = rl;
|
|
42
23
|
this.cursorPos = rl.getCursorPos();
|
|
43
24
|
}
|
|
@@ -60,9 +41,9 @@ class ScreenManager {
|
|
|
60
41
|
this.rl.setPrompt(prompt);
|
|
61
42
|
// SetPrompt will change cursor position, now we can get correct value
|
|
62
43
|
this.cursorPos = this.rl.getCursorPos();
|
|
63
|
-
const width = (0,
|
|
64
|
-
content = (0,
|
|
65
|
-
bottomContent = (0,
|
|
44
|
+
const width = (0, utils_js_1.readlineWidth)();
|
|
45
|
+
content = (0, utils_js_1.breakLines)(content, width);
|
|
46
|
+
bottomContent = (0, utils_js_1.breakLines)(bottomContent, width);
|
|
66
47
|
// Manually insert an extra line if we're at the end of the line.
|
|
67
48
|
// This prevent the cursor from appearing at the beginning of the
|
|
68
49
|
// current line.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useEffect = useEffect;
|
|
4
|
-
const
|
|
4
|
+
const hook_engine_js_1 = require("./hook-engine.js");
|
|
5
5
|
function useEffect(cb, depArray) {
|
|
6
|
-
(0,
|
|
6
|
+
(0, hook_engine_js_1.withPointer)((pointer) => {
|
|
7
7
|
const oldDeps = pointer.get();
|
|
8
8
|
const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
|
|
9
9
|
if (hasChanged) {
|
|
10
|
-
|
|
10
|
+
hook_engine_js_1.effectScheduler.queue(cb);
|
|
11
11
|
}
|
|
12
12
|
pointer.set(depArray);
|
|
13
13
|
});
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useKeypress = useKeypress;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const use_ref_js_1 = require("./use-ref.js");
|
|
5
|
+
const use_effect_js_1 = require("./use-effect.js");
|
|
6
|
+
const hook_engine_js_1 = require("./hook-engine.js");
|
|
7
7
|
function useKeypress(userHandler) {
|
|
8
|
-
const signal = (0,
|
|
8
|
+
const signal = (0, use_ref_js_1.useRef)(userHandler);
|
|
9
9
|
signal.current = userHandler;
|
|
10
|
-
(0,
|
|
10
|
+
(0, use_effect_js_1.useEffect)((rl) => {
|
|
11
11
|
let ignore = false;
|
|
12
|
-
const handler = (0,
|
|
12
|
+
const handler = (0, hook_engine_js_1.withUpdates)((_input, event) => {
|
|
13
13
|
if (ignore)
|
|
14
14
|
return;
|
|
15
15
|
void signal.current(event, rl);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useMemo = useMemo;
|
|
4
|
-
const
|
|
4
|
+
const hook_engine_js_1 = require("./hook-engine.js");
|
|
5
5
|
function useMemo(fn, dependencies) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, hook_engine_js_1.withPointer)((pointer) => {
|
|
7
7
|
const prev = pointer.get();
|
|
8
8
|
if (!prev ||
|
|
9
9
|
prev.dependencies.length !== dependencies.length ||
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.usePrefix = usePrefix;
|
|
4
4
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const use_state_js_1 = require("./use-state.js");
|
|
6
|
+
const use_effect_js_1 = require("./use-effect.js");
|
|
7
|
+
const make_theme_js_1 = require("./make-theme.js");
|
|
8
8
|
function usePrefix({ status = 'idle', theme, }) {
|
|
9
|
-
const [showLoader, setShowLoader] = (0,
|
|
10
|
-
const [tick, setTick] = (0,
|
|
11
|
-
const { prefix, spinner } = (0,
|
|
12
|
-
(0,
|
|
9
|
+
const [showLoader, setShowLoader] = (0, use_state_js_1.useState)(false);
|
|
10
|
+
const [tick, setTick] = (0, use_state_js_1.useState)(0);
|
|
11
|
+
const { prefix, spinner } = (0, make_theme_js_1.makeTheme)(theme);
|
|
12
|
+
(0, use_effect_js_1.useEffect)(() => {
|
|
13
13
|
if (status === 'loading') {
|
|
14
14
|
let tickInterval;
|
|
15
15
|
let inc = -1;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useRef = useRef;
|
|
4
|
-
const
|
|
4
|
+
const use_state_js_1 = require("./use-state.js");
|
|
5
5
|
function useRef(val) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, use_state_js_1.useState)({ current: val })[0];
|
|
7
7
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useState = useState;
|
|
4
|
-
const
|
|
4
|
+
const hook_engine_js_1 = require("./hook-engine.js");
|
|
5
5
|
function useState(defaultValue) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, hook_engine_js_1.withPointer)((pointer) => {
|
|
7
7
|
const setFn = (newValue) => {
|
|
8
8
|
// Noop if the value is still the same.
|
|
9
9
|
if (pointer.get() !== newValue) {
|
|
10
10
|
pointer.set(newValue);
|
|
11
11
|
// Trigger re-render
|
|
12
|
-
(0,
|
|
12
|
+
(0, hook_engine_js_1.handleChange)();
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
if (pointer.initialized) {
|
|
@@ -7,7 +7,7 @@ exports.breakLines = breakLines;
|
|
|
7
7
|
exports.readlineWidth = readlineWidth;
|
|
8
8
|
const cli_width_1 = __importDefault(require("cli-width"));
|
|
9
9
|
const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
|
|
10
|
-
const
|
|
10
|
+
const hook_engine_js_1 = require("./hook-engine.js");
|
|
11
11
|
/**
|
|
12
12
|
* Force line returns at specific width. This function is ANSI code friendly and it'll
|
|
13
13
|
* ignore invisible codes during width calculation.
|
|
@@ -28,5 +28,5 @@ function breakLines(content, width) {
|
|
|
28
28
|
* @returns {number}
|
|
29
29
|
*/
|
|
30
30
|
function readlineWidth() {
|
|
31
|
-
return (0, cli_width_1.default)({ defaultWidth: 80, output: (0,
|
|
31
|
+
return (0, cli_width_1.default)({ defaultWidth: 80, output: (0, hook_engine_js_1.readline)().output });
|
|
32
32
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './lib/key.js';
|
|
2
|
+
export * from './lib/errors.js';
|
|
3
|
+
export { usePrefix } from './lib/use-prefix.js';
|
|
4
|
+
export { useState } from './lib/use-state.js';
|
|
5
|
+
export { useEffect } from './lib/use-effect.js';
|
|
6
|
+
export { useMemo } from './lib/use-memo.js';
|
|
7
|
+
export { useRef } from './lib/use-ref.js';
|
|
8
|
+
export { useKeypress } from './lib/use-keypress.js';
|
|
9
|
+
export { makeTheme } from './lib/make-theme.js';
|
|
10
|
+
export type { Theme, Status } from './lib/theme.js';
|
|
11
|
+
export { usePagination } from './lib/pagination/use-pagination.js';
|
|
12
|
+
export { createPrompt } from './lib/create-prompt.js';
|
|
13
|
+
export { Separator } from './lib/Separator.js';
|
|
@@ -7,7 +7,6 @@ export { useMemo } from './lib/use-memo.js';
|
|
|
7
7
|
export { useRef } from './lib/use-ref.js';
|
|
8
8
|
export { useKeypress } from './lib/use-keypress.js';
|
|
9
9
|
export { makeTheme } from './lib/make-theme.js';
|
|
10
|
-
export type { Theme } from './lib/theme.js';
|
|
11
10
|
export { usePagination } from './lib/pagination/use-pagination.js';
|
|
12
11
|
export { createPrompt } from './lib/create-prompt.js';
|
|
13
12
|
export { Separator } from './lib/Separator.js';
|
|
@@ -2,10 +2,10 @@ import * as readline from 'node:readline';
|
|
|
2
2
|
import { AsyncResource } from 'node:async_hooks';
|
|
3
3
|
import MuteStream from 'mute-stream';
|
|
4
4
|
import { onExit as onSignalExit } from 'signal-exit';
|
|
5
|
-
import ScreenManager from './screen-manager.
|
|
6
|
-
import { PromisePolyfill } from './promise-polyfill.
|
|
7
|
-
import { withHooks, effectScheduler } from './hook-engine.
|
|
8
|
-
import { AbortPromptError, CancelPromptError, ExitPromptError } from './errors.
|
|
5
|
+
import ScreenManager from './screen-manager.js';
|
|
6
|
+
import { PromisePolyfill } from './promise-polyfill.js';
|
|
7
|
+
import { withHooks, effectScheduler } from './hook-engine.js';
|
|
8
|
+
import { AbortPromptError, CancelPromptError, ExitPromptError } from './errors.js';
|
|
9
9
|
export function createPrompt(view) {
|
|
10
10
|
const prompt = (config, context = {}) => {
|
|
11
11
|
// Default `input` to stdin
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-explicit-any: ["off"] */
|
|
2
2
|
import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
|
|
3
|
-
import { HookError, ValidationError } from './errors.
|
|
3
|
+
import { HookError, ValidationError } from './errors.js';
|
|
4
4
|
const hookStorage = new AsyncLocalStorage();
|
|
5
5
|
function createStore(rl) {
|
|
6
6
|
const store = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useRef } from '../use-ref.
|
|
2
|
-
import { readlineWidth } from '../utils.
|
|
3
|
-
import { lines } from './lines.
|
|
4
|
-
import { finite, infinite } from './position.
|
|
1
|
+
import { useRef } from '../use-ref.js';
|
|
2
|
+
import { readlineWidth } from '../utils.js';
|
|
3
|
+
import { lines } from './lines.js';
|
|
4
|
+
import { finite, infinite } from './position.js';
|
|
5
5
|
export function usePagination({ items, active, renderItem, pageSize, loop = true, }) {
|
|
6
6
|
const state = useRef({ position: 0, lastActive: 0 });
|
|
7
7
|
const position = loop
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import stripAnsi from 'strip-ansi';
|
|
2
2
|
import ansiEscapes from 'ansi-escapes';
|
|
3
|
-
import { breakLines, readlineWidth } from './utils.
|
|
3
|
+
import { breakLines, readlineWidth } from './utils.js';
|
|
4
4
|
const height = (content) => content.split('\n').length;
|
|
5
5
|
const lastLine = (content) => content.split('\n').pop() ?? '';
|
|
6
6
|
function cursorDown(n) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type InquirerReadline } from '@inquirer/type';
|
|
2
|
-
import { type KeypressEvent } from './key.
|
|
2
|
+
import { type KeypressEvent } from './key.js';
|
|
3
3
|
export declare function useKeypress(userHandler: (event: KeypressEvent, rl: InquirerReadline) => void | Promise<void>): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useRef } from './use-ref.
|
|
2
|
-
import { useEffect } from './use-effect.
|
|
3
|
-
import { withUpdates } from './hook-engine.
|
|
1
|
+
import { useRef } from './use-ref.js';
|
|
2
|
+
import { useEffect } from './use-effect.js';
|
|
3
|
+
import { withUpdates } from './hook-engine.js';
|
|
4
4
|
export function useKeypress(userHandler) {
|
|
5
5
|
const signal = useRef(userHandler);
|
|
6
6
|
signal.current = userHandler;
|