@inquirer/core 10.1.9 → 10.1.11
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 +10 -0
- package/dist/commonjs/index.d.ts +13 -13
- package/dist/commonjs/index.js +20 -20
- package/dist/commonjs/lib/Separator.d.ts +1 -1
- package/dist/commonjs/lib/create-prompt.js +21 -15
- package/dist/commonjs/lib/hook-engine.js +3 -3
- package/dist/commonjs/lib/make-theme.d.ts +1 -1
- package/dist/commonjs/lib/make-theme.js +2 -2
- package/dist/commonjs/lib/pagination/lines.js +2 -2
- package/dist/commonjs/lib/pagination/use-pagination.d.ts +2 -2
- package/dist/commonjs/lib/pagination/use-pagination.js +9 -9
- package/dist/commonjs/lib/screen-manager.js +4 -4
- package/dist/commonjs/lib/use-effect.js +3 -3
- package/dist/commonjs/lib/use-keypress.d.ts +1 -1
- package/dist/commonjs/lib/use-keypress.js +6 -6
- package/dist/commonjs/lib/use-memo.js +2 -2
- package/dist/commonjs/lib/use-prefix.d.ts +1 -1
- package/dist/commonjs/lib/use-prefix.js +7 -7
- package/dist/commonjs/lib/use-ref.js +2 -2
- package/dist/commonjs/lib/use-state.js +3 -3
- package/dist/commonjs/lib/utils.js +2 -2
- package/dist/esm/index.d.ts +13 -13
- package/dist/esm/index.js +12 -12
- package/dist/esm/lib/Separator.d.ts +1 -1
- package/dist/esm/lib/create-prompt.js +11 -5
- package/dist/esm/lib/hook-engine.js +1 -1
- package/dist/esm/lib/make-theme.d.ts +1 -1
- package/dist/esm/lib/make-theme.js +1 -1
- package/dist/esm/lib/pagination/lines.js +1 -1
- package/dist/esm/lib/pagination/use-pagination.d.ts +2 -2
- package/dist/esm/lib/pagination/use-pagination.js +4 -4
- package/dist/esm/lib/screen-manager.js +1 -1
- package/dist/esm/lib/use-effect.js +1 -1
- package/dist/esm/lib/use-keypress.d.ts +1 -1
- package/dist/esm/lib/use-keypress.js +3 -3
- package/dist/esm/lib/use-memo.js +1 -1
- package/dist/esm/lib/use-prefix.d.ts +1 -1
- package/dist/esm/lib/use-prefix.js +3 -3
- package/dist/esm/lib/use-ref.js +1 -1
- package/dist/esm/lib/use-state.js +1 -1
- package/dist/esm/lib/utils.js +1 -1
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -4,6 +4,16 @@ The `@inquirer/core` package is the library enabling the creation of Inquirer pr
|
|
|
4
4
|
|
|
5
5
|
It aims to implements a lightweight API similar to React hooks - but without JSX.
|
|
6
6
|
|
|
7
|
+
# Special Thanks
|
|
8
|
+
|
|
9
|
+
<div align="center" markdown="1">
|
|
10
|
+
|
|
11
|
+
[](https://graphite.dev/?utm_source=npmjs&utm_medium=repo&utm_campaign=inquirerjs)<br>
|
|
12
|
+
|
|
13
|
+
### [Graphite is the AI developer productivity platform helping teams on GitHub ship higher quality software, faster](https://graphite.dev/?utm_source=npmjs&utm_medium=repo&utm_campaign=inquirerjs)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
7
17
|
# Installation
|
|
8
18
|
|
|
9
19
|
<table>
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from './lib/key.
|
|
2
|
-
export * from './lib/errors.
|
|
3
|
-
export { usePrefix } from './lib/use-prefix.
|
|
4
|
-
export { useState } from './lib/use-state.
|
|
5
|
-
export { useEffect } from './lib/use-effect.
|
|
6
|
-
export { useMemo } from './lib/use-memo.
|
|
7
|
-
export { useRef } from './lib/use-ref.
|
|
8
|
-
export { useKeypress } from './lib/use-keypress.
|
|
9
|
-
export { makeTheme } from './lib/make-theme.
|
|
10
|
-
export type { Theme, Status } from './lib/theme.
|
|
11
|
-
export { usePagination } from './lib/pagination/use-pagination.
|
|
12
|
-
export { createPrompt } from './lib/create-prompt.
|
|
13
|
-
export { Separator } from './lib/Separator.
|
|
1
|
+
export * from './lib/key.ts';
|
|
2
|
+
export * from './lib/errors.ts';
|
|
3
|
+
export { usePrefix } from './lib/use-prefix.ts';
|
|
4
|
+
export { useState } from './lib/use-state.ts';
|
|
5
|
+
export { useEffect } from './lib/use-effect.ts';
|
|
6
|
+
export { useMemo } from './lib/use-memo.ts';
|
|
7
|
+
export { useRef } from './lib/use-ref.ts';
|
|
8
|
+
export { useKeypress } from './lib/use-keypress.ts';
|
|
9
|
+
export { makeTheme } from './lib/make-theme.ts';
|
|
10
|
+
export type { Theme, Status } from './lib/theme.ts';
|
|
11
|
+
export { usePagination } from './lib/pagination/use-pagination.ts';
|
|
12
|
+
export { createPrompt } from './lib/create-prompt.ts';
|
|
13
|
+
export { Separator } from './lib/Separator.ts';
|
package/dist/commonjs/index.js
CHANGED
|
@@ -17,23 +17,23 @@ 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
18
|
__exportStar(require("./lib/key.js"), exports);
|
|
19
19
|
__exportStar(require("./lib/errors.js"), exports);
|
|
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
|
|
20
|
+
var use_prefix_ts_1 = require("./lib/use-prefix.js");
|
|
21
|
+
Object.defineProperty(exports, "usePrefix", { enumerable: true, get: function () { return use_prefix_ts_1.usePrefix; } });
|
|
22
|
+
var use_state_ts_1 = require("./lib/use-state.js");
|
|
23
|
+
Object.defineProperty(exports, "useState", { enumerable: true, get: function () { return use_state_ts_1.useState; } });
|
|
24
|
+
var use_effect_ts_1 = require("./lib/use-effect.js");
|
|
25
|
+
Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return use_effect_ts_1.useEffect; } });
|
|
26
|
+
var use_memo_ts_1 = require("./lib/use-memo.js");
|
|
27
|
+
Object.defineProperty(exports, "useMemo", { enumerable: true, get: function () { return use_memo_ts_1.useMemo; } });
|
|
28
|
+
var use_ref_ts_1 = require("./lib/use-ref.js");
|
|
29
|
+
Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return use_ref_ts_1.useRef; } });
|
|
30
|
+
var use_keypress_ts_1 = require("./lib/use-keypress.js");
|
|
31
|
+
Object.defineProperty(exports, "useKeypress", { enumerable: true, get: function () { return use_keypress_ts_1.useKeypress; } });
|
|
32
|
+
var make_theme_ts_1 = require("./lib/make-theme.js");
|
|
33
|
+
Object.defineProperty(exports, "makeTheme", { enumerable: true, get: function () { return make_theme_ts_1.makeTheme; } });
|
|
34
|
+
var use_pagination_ts_1 = require("./lib/pagination/use-pagination.js");
|
|
35
|
+
Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return use_pagination_ts_1.usePagination; } });
|
|
36
|
+
var create_prompt_ts_1 = require("./lib/create-prompt.js");
|
|
37
|
+
Object.defineProperty(exports, "createPrompt", { enumerable: true, get: function () { return create_prompt_ts_1.createPrompt; } });
|
|
38
|
+
var Separator_ts_1 = require("./lib/Separator.js");
|
|
39
|
+
Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return Separator_ts_1.Separator; } });
|
|
@@ -41,10 +41,10 @@ const readline = __importStar(require("node:readline"));
|
|
|
41
41
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
42
42
|
const mute_stream_1 = __importDefault(require("mute-stream"));
|
|
43
43
|
const signal_exit_1 = require("signal-exit");
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
44
|
+
const screen_manager_ts_1 = __importDefault(require("./screen-manager.js"));
|
|
45
|
+
const promise_polyfill_ts_1 = require("./promise-polyfill.js");
|
|
46
|
+
const hook_engine_ts_1 = require("./hook-engine.js");
|
|
47
|
+
const errors_ts_1 = require("./errors.js");
|
|
48
48
|
function getCallSites() {
|
|
49
49
|
const _prepareStackTrace = Error.prepareStackTrace;
|
|
50
50
|
let result = [];
|
|
@@ -79,11 +79,11 @@ function createPrompt(view) {
|
|
|
79
79
|
input,
|
|
80
80
|
output,
|
|
81
81
|
});
|
|
82
|
-
const screen = new
|
|
83
|
-
const { promise, resolve, reject } =
|
|
84
|
-
const cancel = () => reject(new
|
|
82
|
+
const screen = new screen_manager_ts_1.default(rl);
|
|
83
|
+
const { promise, resolve, reject } = promise_polyfill_ts_1.PromisePolyfill.withResolver();
|
|
84
|
+
const cancel = () => reject(new errors_ts_1.CancelPromptError());
|
|
85
85
|
if (signal) {
|
|
86
|
-
const abort = () => reject(new
|
|
86
|
+
const abort = () => reject(new errors_ts_1.AbortPromptError({ cause: signal.reason }));
|
|
87
87
|
if (signal.aborted) {
|
|
88
88
|
abort();
|
|
89
89
|
return Object.assign(promise, { cancel });
|
|
@@ -92,8 +92,14 @@ function createPrompt(view) {
|
|
|
92
92
|
cleanups.add(() => signal.removeEventListener('abort', abort));
|
|
93
93
|
}
|
|
94
94
|
cleanups.add((0, signal_exit_1.onExit)((code, signal) => {
|
|
95
|
-
reject(new
|
|
95
|
+
reject(new errors_ts_1.ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
|
|
96
96
|
}));
|
|
97
|
+
// SIGINT must be explicitly handled by the prompt so the ExitPromptError can be handled.
|
|
98
|
+
// Otherwise, the prompt will stop and in some scenarios never resolve.
|
|
99
|
+
// Ref issue #1741
|
|
100
|
+
const sigint = () => reject(new errors_ts_1.ExitPromptError(`User force closed the prompt with SIGINT`));
|
|
101
|
+
rl.on('SIGINT', sigint);
|
|
102
|
+
cleanups.add(() => rl.removeListener('SIGINT', sigint));
|
|
97
103
|
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
98
104
|
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
99
105
|
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
@@ -101,11 +107,11 @@ function createPrompt(view) {
|
|
|
101
107
|
const checkCursorPos = () => screen.checkCursorPos();
|
|
102
108
|
rl.input.on('keypress', checkCursorPos);
|
|
103
109
|
cleanups.add(() => rl.input.removeListener('keypress', checkCursorPos));
|
|
104
|
-
return (0,
|
|
110
|
+
return (0, hook_engine_ts_1.withHooks)(rl, (cycle) => {
|
|
105
111
|
// The close event triggers immediately when the user press ctrl+c. SignalExit on the other hand
|
|
106
112
|
// triggers after the process is done (which happens after timeouts are done triggering.)
|
|
107
113
|
// We triggers the hooks cleanup phase on rl `close` so active timeouts can be cleared.
|
|
108
|
-
const hooksCleanup = node_async_hooks_1.AsyncResource.bind(() =>
|
|
114
|
+
const hooksCleanup = node_async_hooks_1.AsyncResource.bind(() => hook_engine_ts_1.effectScheduler.clearAll());
|
|
109
115
|
rl.on('close', hooksCleanup);
|
|
110
116
|
cleanups.add(() => rl.removeListener('close', hooksCleanup));
|
|
111
117
|
cycle(() => {
|
|
@@ -116,12 +122,12 @@ function createPrompt(view) {
|
|
|
116
122
|
// Typescript won't allow this, but not all users rely on typescript.
|
|
117
123
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
118
124
|
if (nextView === undefined) {
|
|
119
|
-
const callerFilename = callSites[1]?.getFileName
|
|
125
|
+
const callerFilename = callSites[1]?.getFileName();
|
|
120
126
|
throw new Error(`Prompt functions must return a string.\n at ${callerFilename}`);
|
|
121
127
|
}
|
|
122
128
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
123
129
|
screen.render(content, bottomContent);
|
|
124
|
-
|
|
130
|
+
hook_engine_ts_1.effectScheduler.run();
|
|
125
131
|
}
|
|
126
132
|
catch (error) {
|
|
127
133
|
reject(error);
|
|
@@ -129,10 +135,10 @@ function createPrompt(view) {
|
|
|
129
135
|
});
|
|
130
136
|
return Object.assign(promise
|
|
131
137
|
.then((answer) => {
|
|
132
|
-
|
|
138
|
+
hook_engine_ts_1.effectScheduler.clearAll();
|
|
133
139
|
return answer;
|
|
134
140
|
}, (error) => {
|
|
135
|
-
|
|
141
|
+
hook_engine_ts_1.effectScheduler.clearAll();
|
|
136
142
|
throw error;
|
|
137
143
|
})
|
|
138
144
|
// Wait for the promise to settle, then cleanup.
|
|
@@ -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_ts_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_ts_1.HookError('[Inquirer] Hook functions can only be called from within a prompt');
|
|
43
43
|
}
|
|
44
44
|
return store;
|
|
45
45
|
}
|
|
@@ -91,7 +91,7 @@ exports.effectScheduler = {
|
|
|
91
91
|
store.hooksCleanup[index]?.();
|
|
92
92
|
const cleanFn = cb(readline());
|
|
93
93
|
if (cleanFn != null && typeof cleanFn !== 'function') {
|
|
94
|
-
throw new
|
|
94
|
+
throw new errors_ts_1.ValidationError('useEffect return value must be a cleanup function or nothing.');
|
|
95
95
|
}
|
|
96
96
|
store.hooksCleanup[index] = cleanFn;
|
|
97
97
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Prettify, PartialDeep } from '@inquirer/type';
|
|
2
|
-
import { type Theme } from './theme.
|
|
2
|
+
import { type Theme } from './theme.ts';
|
|
3
3
|
export declare function makeTheme<SpecificTheme extends object>(...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>): Prettify<Theme<SpecificTheme>>;
|
|
@@ -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_ts_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_ts_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_ts_1 = require("../utils.js");
|
|
5
5
|
function split(content, width) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, utils_ts_1.breakLines)(content, width).split('\n');
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Rotates an array of items by an integer number of positions.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Prettify } from '@inquirer/type';
|
|
2
|
-
import { type Theme } from '../theme.
|
|
3
|
-
import { type Layout } from './lines.
|
|
2
|
+
import { type Theme } from '../theme.ts';
|
|
3
|
+
import { type Layout } from './lines.ts';
|
|
4
4
|
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
|
|
5
5
|
items: ReadonlyArray<T>;
|
|
6
6
|
/** The index of the active item. */
|
|
@@ -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_ts_1 = require("../use-ref.js");
|
|
5
|
+
const utils_ts_1 = require("../utils.js");
|
|
6
|
+
const lines_ts_1 = require("./lines.js");
|
|
7
|
+
const position_ts_1 = require("./position.js");
|
|
8
8
|
function usePagination({ items, active, renderItem, pageSize, loop = true, }) {
|
|
9
|
-
const state = (0,
|
|
9
|
+
const state = (0, use_ref_ts_1.useRef)({ position: 0, lastActive: 0 });
|
|
10
10
|
const position = loop
|
|
11
|
-
? (0,
|
|
11
|
+
? (0, position_ts_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_ts_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_ts_1.lines)({
|
|
26
26
|
items,
|
|
27
|
-
width: (0,
|
|
27
|
+
width: (0, utils_ts_1.readlineWidth)(),
|
|
28
28
|
renderItem,
|
|
29
29
|
active,
|
|
30
30
|
position,
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const node_util_1 = require("node:util");
|
|
7
7
|
const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
|
|
8
|
-
const
|
|
8
|
+
const utils_ts_1 = require("./utils.js");
|
|
9
9
|
const height = (content) => content.split('\n').length;
|
|
10
10
|
const lastLine = (content) => content.split('\n').pop() ?? '';
|
|
11
11
|
function cursorDown(n) {
|
|
@@ -40,9 +40,9 @@ class ScreenManager {
|
|
|
40
40
|
this.rl.setPrompt(prompt);
|
|
41
41
|
// SetPrompt will change cursor position, now we can get correct value
|
|
42
42
|
this.cursorPos = this.rl.getCursorPos();
|
|
43
|
-
const width = (0,
|
|
44
|
-
content = (0,
|
|
45
|
-
bottomContent = (0,
|
|
43
|
+
const width = (0, utils_ts_1.readlineWidth)();
|
|
44
|
+
content = (0, utils_ts_1.breakLines)(content, width);
|
|
45
|
+
bottomContent = (0, utils_ts_1.breakLines)(bottomContent, width);
|
|
46
46
|
// Manually insert an extra line if we're at the end of the line.
|
|
47
47
|
// This prevent the cursor from appearing at the beginning of the
|
|
48
48
|
// 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_ts_1 = require("./hook-engine.js");
|
|
5
5
|
function useEffect(cb, depArray) {
|
|
6
|
-
(0,
|
|
6
|
+
(0, hook_engine_ts_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_ts_1.effectScheduler.queue(cb);
|
|
11
11
|
}
|
|
12
12
|
pointer.set(depArray);
|
|
13
13
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type InquirerReadline } from '@inquirer/type';
|
|
2
|
-
import { type KeypressEvent } from './key.
|
|
2
|
+
import { type KeypressEvent } from './key.ts';
|
|
3
3
|
export declare function useKeypress(userHandler: (event: KeypressEvent, rl: InquirerReadline) => void | Promise<void>): void;
|
|
@@ -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_ts_1 = require("./use-ref.js");
|
|
5
|
+
const use_effect_ts_1 = require("./use-effect.js");
|
|
6
|
+
const hook_engine_ts_1 = require("./hook-engine.js");
|
|
7
7
|
function useKeypress(userHandler) {
|
|
8
|
-
const signal = (0,
|
|
8
|
+
const signal = (0, use_ref_ts_1.useRef)(userHandler);
|
|
9
9
|
signal.current = userHandler;
|
|
10
|
-
(0,
|
|
10
|
+
(0, use_effect_ts_1.useEffect)((rl) => {
|
|
11
11
|
let ignore = false;
|
|
12
|
-
const handler = (0,
|
|
12
|
+
const handler = (0, hook_engine_ts_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_ts_1 = require("./hook-engine.js");
|
|
5
5
|
function useMemo(fn, dependencies) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, hook_engine_ts_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_ts_1 = require("./use-state.js");
|
|
6
|
+
const use_effect_ts_1 = require("./use-effect.js");
|
|
7
|
+
const make_theme_ts_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_ts_1.useState)(false);
|
|
10
|
+
const [tick, setTick] = (0, use_state_ts_1.useState)(0);
|
|
11
|
+
const { prefix, spinner } = (0, make_theme_ts_1.makeTheme)(theme);
|
|
12
|
+
(0, use_effect_ts_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_ts_1 = require("./use-state.js");
|
|
5
5
|
function useRef(val) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, use_state_ts_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_ts_1 = require("./hook-engine.js");
|
|
5
5
|
function useState(defaultValue) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, hook_engine_ts_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_ts_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_ts_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_ts_1.readline)().output });
|
|
32
32
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from './lib/key.
|
|
2
|
-
export * from './lib/errors.
|
|
3
|
-
export { usePrefix } from './lib/use-prefix.
|
|
4
|
-
export { useState } from './lib/use-state.
|
|
5
|
-
export { useEffect } from './lib/use-effect.
|
|
6
|
-
export { useMemo } from './lib/use-memo.
|
|
7
|
-
export { useRef } from './lib/use-ref.
|
|
8
|
-
export { useKeypress } from './lib/use-keypress.
|
|
9
|
-
export { makeTheme } from './lib/make-theme.
|
|
10
|
-
export type { Theme, Status } from './lib/theme.
|
|
11
|
-
export { usePagination } from './lib/pagination/use-pagination.
|
|
12
|
-
export { createPrompt } from './lib/create-prompt.
|
|
13
|
-
export { Separator } from './lib/Separator.
|
|
1
|
+
export * from './lib/key.ts';
|
|
2
|
+
export * from './lib/errors.ts';
|
|
3
|
+
export { usePrefix } from './lib/use-prefix.ts';
|
|
4
|
+
export { useState } from './lib/use-state.ts';
|
|
5
|
+
export { useEffect } from './lib/use-effect.ts';
|
|
6
|
+
export { useMemo } from './lib/use-memo.ts';
|
|
7
|
+
export { useRef } from './lib/use-ref.ts';
|
|
8
|
+
export { useKeypress } from './lib/use-keypress.ts';
|
|
9
|
+
export { makeTheme } from './lib/make-theme.ts';
|
|
10
|
+
export type { Theme, Status } from './lib/theme.ts';
|
|
11
|
+
export { usePagination } from './lib/pagination/use-pagination.ts';
|
|
12
|
+
export { createPrompt } from './lib/create-prompt.ts';
|
|
13
|
+
export { Separator } from './lib/Separator.ts';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export { usePrefix } from
|
|
4
|
-
export { useState } from
|
|
5
|
-
export { useEffect } from
|
|
6
|
-
export { useMemo } from
|
|
7
|
-
export { useRef } from
|
|
8
|
-
export { useKeypress } from
|
|
9
|
-
export { makeTheme } from
|
|
10
|
-
export { usePagination } from
|
|
11
|
-
export { createPrompt } from
|
|
12
|
-
export { Separator } from
|
|
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 { usePagination } from "./lib/pagination/use-pagination.js";
|
|
11
|
+
export { createPrompt } from "./lib/create-prompt.js";
|
|
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
|
|
6
|
-
import { PromisePolyfill } from
|
|
7
|
-
import { withHooks, effectScheduler } from
|
|
8
|
-
import { AbortPromptError, CancelPromptError, ExitPromptError } from
|
|
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
|
function getCallSites() {
|
|
10
10
|
const _prepareStackTrace = Error.prepareStackTrace;
|
|
11
11
|
let result = [];
|
|
@@ -55,6 +55,12 @@ export function createPrompt(view) {
|
|
|
55
55
|
cleanups.add(onSignalExit((code, signal) => {
|
|
56
56
|
reject(new ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
|
|
57
57
|
}));
|
|
58
|
+
// SIGINT must be explicitly handled by the prompt so the ExitPromptError can be handled.
|
|
59
|
+
// Otherwise, the prompt will stop and in some scenarios never resolve.
|
|
60
|
+
// Ref issue #1741
|
|
61
|
+
const sigint = () => reject(new ExitPromptError(`User force closed the prompt with SIGINT`));
|
|
62
|
+
rl.on('SIGINT', sigint);
|
|
63
|
+
cleanups.add(() => rl.removeListener('SIGINT', sigint));
|
|
58
64
|
// Re-renders only happen when the state change; but the readline cursor could change position
|
|
59
65
|
// and that also requires a re-render (and a manual one because we mute the streams).
|
|
60
66
|
// We set the listener after the initial workLoop to avoid a double render if render triggered
|
|
@@ -77,7 +83,7 @@ export function createPrompt(view) {
|
|
|
77
83
|
// Typescript won't allow this, but not all users rely on typescript.
|
|
78
84
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
79
85
|
if (nextView === undefined) {
|
|
80
|
-
const callerFilename = callSites[1]?.getFileName
|
|
86
|
+
const callerFilename = callSites[1]?.getFileName();
|
|
81
87
|
throw new Error(`Prompt functions must return a string.\n at ${callerFilename}`);
|
|
82
88
|
}
|
|
83
89
|
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
|
|
@@ -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
|
|
3
|
+
import { HookError, ValidationError } from "./errors.js";
|
|
4
4
|
const hookStorage = new AsyncLocalStorage();
|
|
5
5
|
function createStore(rl) {
|
|
6
6
|
const store = {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Prettify, PartialDeep } from '@inquirer/type';
|
|
2
|
-
import { type Theme } from './theme.
|
|
2
|
+
import { type Theme } from './theme.ts';
|
|
3
3
|
export declare function makeTheme<SpecificTheme extends object>(...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>): Prettify<Theme<SpecificTheme>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Prettify } from '@inquirer/type';
|
|
2
|
-
import { type Theme } from '../theme.
|
|
3
|
-
import { type Layout } from './lines.
|
|
2
|
+
import { type Theme } from '../theme.ts';
|
|
3
|
+
import { type Layout } from './lines.ts';
|
|
4
4
|
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
|
|
5
5
|
items: ReadonlyArray<T>;
|
|
6
6
|
/** The index of the active item. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useRef } from
|
|
2
|
-
import { readlineWidth } from
|
|
3
|
-
import { lines } from
|
|
4
|
-
import { finite, infinite } from
|
|
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 { stripVTControlCharacters } from 'node:util';
|
|
2
2
|
import ansiEscapes from 'ansi-escapes';
|
|
3
|
-
import { breakLines, readlineWidth } from
|
|
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.ts';
|
|
3
3
|
export declare function useKeypress(userHandler: (event: KeypressEvent, rl: InquirerReadline) => void | Promise<void>): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useRef } from
|
|
2
|
-
import { useEffect } from
|
|
3
|
-
import { withUpdates } from
|
|
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;
|
package/dist/esm/lib/use-memo.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AsyncResource } from 'node:async_hooks';
|
|
2
|
-
import { useState } from
|
|
3
|
-
import { useEffect } from
|
|
4
|
-
import { makeTheme } from
|
|
2
|
+
import { useState } from "./use-state.js";
|
|
3
|
+
import { useEffect } from "./use-effect.js";
|
|
4
|
+
import { makeTheme } from "./make-theme.js";
|
|
5
5
|
export function usePrefix({ status = 'idle', theme, }) {
|
|
6
6
|
const [showLoader, setShowLoader] = useState(false);
|
|
7
7
|
const [tick, setTick] = useState(0);
|
package/dist/esm/lib/use-ref.js
CHANGED
package/dist/esm/lib/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cliWidth from 'cli-width';
|
|
2
2
|
import wrapAnsi from 'wrap-ansi';
|
|
3
|
-
import { readline } from
|
|
3
|
+
import { readline } from "./hook-engine.js";
|
|
4
4
|
/**
|
|
5
5
|
* Force line returns at specific width. This function is ANSI code friendly and it'll
|
|
6
6
|
* ignore invisible codes during width calculation.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.11",
|
|
4
4
|
"description": "Core Inquirer prompt API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@inquirer/figures": "^1.0.11",
|
|
78
|
-
"@inquirer/type": "^3.0.
|
|
78
|
+
"@inquirer/type": "^3.0.6",
|
|
79
79
|
"ansi-escapes": "^4.3.2",
|
|
80
80
|
"cli-width": "^4.1.0",
|
|
81
81
|
"mute-stream": "^2.0.0",
|
|
@@ -85,10 +85,9 @@
|
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@arethetypeswrong/cli": "^0.17.4",
|
|
88
|
-
"@inquirer/testing": "^2.1.
|
|
89
|
-
"@repo/tsconfig": "workspace:*",
|
|
88
|
+
"@inquirer/testing": "^2.1.46",
|
|
90
89
|
"@types/mute-stream": "^0.0.4",
|
|
91
|
-
"@types/node": "^22.
|
|
90
|
+
"@types/node": "^22.14.0",
|
|
92
91
|
"@types/wrap-ansi": "^3.0.0",
|
|
93
92
|
"tshy": "^3.0.2"
|
|
94
93
|
},
|
|
@@ -115,5 +114,5 @@
|
|
|
115
114
|
".": "./src/index.ts"
|
|
116
115
|
}
|
|
117
116
|
},
|
|
118
|
-
"gitHead": "
|
|
117
|
+
"gitHead": "50bac82683b9a8d8e06ec87972894d56b2883bcd"
|
|
119
118
|
}
|