@inquirer/core 10.3.2 → 11.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/{esm/lib → lib}/Separator.js +2 -2
- package/dist/{esm/lib → lib}/create-prompt.js +1 -1
- package/dist/{commonjs/lib → lib}/theme.d.ts +16 -16
- package/dist/lib/theme.js +21 -0
- package/package.json +14 -37
- package/dist/commonjs/index.js +0 -46
- package/dist/commonjs/lib/Separator.js +0 -28
- package/dist/commonjs/lib/create-prompt.js +0 -156
- package/dist/commonjs/lib/errors.js +0 -29
- package/dist/commonjs/lib/hook-engine.js +0 -118
- package/dist/commonjs/lib/key.js +0 -29
- package/dist/commonjs/lib/make-theme.js +0 -33
- package/dist/commonjs/lib/pagination/use-pagination.js +0 -124
- package/dist/commonjs/lib/promise-polyfill.js +0 -18
- package/dist/commonjs/lib/screen-manager.js +0 -82
- package/dist/commonjs/lib/theme.js +0 -27
- package/dist/commonjs/lib/use-effect.js +0 -14
- package/dist/commonjs/lib/use-keypress.js +0 -23
- package/dist/commonjs/lib/use-memo.js +0 -17
- package/dist/commonjs/lib/use-prefix.js +0 -38
- package/dist/commonjs/lib/use-ref.js +0 -7
- package/dist/commonjs/lib/use-state.js +0 -23
- package/dist/commonjs/lib/utils.js +0 -32
- package/dist/commonjs/package.json +0 -3
- package/dist/esm/index.d.ts +0 -13
- package/dist/esm/lib/Separator.d.ts +0 -10
- package/dist/esm/lib/create-prompt.d.ts +0 -4
- package/dist/esm/lib/errors.d.ts +0 -20
- package/dist/esm/lib/hook-engine.d.ts +0 -23
- package/dist/esm/lib/key.d.ts +0 -12
- package/dist/esm/lib/make-theme.d.ts +0 -3
- package/dist/esm/lib/pagination/use-pagination.d.ts +0 -16
- package/dist/esm/lib/promise-polyfill.d.ts +0 -7
- package/dist/esm/lib/screen-manager.d.ts +0 -14
- package/dist/esm/lib/theme.d.ts +0 -155
- package/dist/esm/lib/theme.js +0 -21
- package/dist/esm/lib/use-effect.d.ts +0 -2
- package/dist/esm/lib/use-keypress.d.ts +0 -3
- package/dist/esm/lib/use-memo.d.ts +0 -1
- package/dist/esm/lib/use-prefix.d.ts +0 -5
- package/dist/esm/lib/use-ref.d.ts +0 -6
- package/dist/esm/lib/use-state.d.ts +0 -4
- package/dist/esm/lib/utils.d.ts +0 -13
- package/dist/esm/package.json +0 -3
- /package/dist/{commonjs/index.d.ts → index.d.ts} +0 -0
- /package/dist/{esm/index.js → index.js} +0 -0
- /package/dist/{commonjs/lib → lib}/Separator.d.ts +0 -0
- /package/dist/{commonjs/lib → lib}/create-prompt.d.ts +0 -0
- /package/dist/{commonjs/lib → lib}/errors.d.ts +0 -0
- /package/dist/{esm/lib → lib}/errors.js +0 -0
- /package/dist/{commonjs/lib → lib}/hook-engine.d.ts +0 -0
- /package/dist/{esm/lib → lib}/hook-engine.js +0 -0
- /package/dist/{commonjs/lib → lib}/key.d.ts +0 -0
- /package/dist/{esm/lib → lib}/key.js +0 -0
- /package/dist/{commonjs/lib → lib}/make-theme.d.ts +0 -0
- /package/dist/{esm/lib → lib}/make-theme.js +0 -0
- /package/dist/{commonjs/lib → lib}/pagination/use-pagination.d.ts +0 -0
- /package/dist/{esm/lib → lib}/pagination/use-pagination.js +0 -0
- /package/dist/{commonjs/lib → lib}/promise-polyfill.d.ts +0 -0
- /package/dist/{esm/lib → lib}/promise-polyfill.js +0 -0
- /package/dist/{commonjs/lib → lib}/screen-manager.d.ts +0 -0
- /package/dist/{esm/lib → lib}/screen-manager.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-effect.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-effect.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-keypress.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-keypress.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-memo.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-memo.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-prefix.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-prefix.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-ref.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-ref.js +0 -0
- /package/dist/{commonjs/lib → lib}/use-state.d.ts +0 -0
- /package/dist/{esm/lib → lib}/use-state.js +0 -0
- /package/dist/{commonjs/lib → lib}/utils.d.ts +0 -0
- /package/dist/{esm/lib → lib}/utils.js +0 -0
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeTheme = makeTheme;
|
|
4
|
-
const theme_ts_1 = require("./theme.js");
|
|
5
|
-
function isPlainObject(value) {
|
|
6
|
-
if (typeof value !== 'object' || value === null)
|
|
7
|
-
return false;
|
|
8
|
-
let proto = value;
|
|
9
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
10
|
-
proto = Object.getPrototypeOf(proto);
|
|
11
|
-
}
|
|
12
|
-
return Object.getPrototypeOf(value) === proto;
|
|
13
|
-
}
|
|
14
|
-
function deepMerge(...objects) {
|
|
15
|
-
const output = {};
|
|
16
|
-
for (const obj of objects) {
|
|
17
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
18
|
-
const prevValue = output[key];
|
|
19
|
-
output[key] =
|
|
20
|
-
isPlainObject(prevValue) && isPlainObject(value)
|
|
21
|
-
? deepMerge(prevValue, value)
|
|
22
|
-
: value;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return output;
|
|
26
|
-
}
|
|
27
|
-
function makeTheme(...themes) {
|
|
28
|
-
const themesToMerge = [
|
|
29
|
-
theme_ts_1.defaultTheme,
|
|
30
|
-
...themes.filter((theme) => theme != null),
|
|
31
|
-
];
|
|
32
|
-
return deepMerge(...themesToMerge);
|
|
33
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePagination = usePagination;
|
|
4
|
-
const use_ref_ts_1 = require("../use-ref.js");
|
|
5
|
-
const utils_ts_1 = require("../utils.js");
|
|
6
|
-
function usePointerPosition({ active, renderedItems, pageSize, loop, }) {
|
|
7
|
-
const state = (0, use_ref_ts_1.useRef)({
|
|
8
|
-
lastPointer: active,
|
|
9
|
-
lastActive: undefined,
|
|
10
|
-
});
|
|
11
|
-
const { lastPointer, lastActive } = state.current;
|
|
12
|
-
const middle = Math.floor(pageSize / 2);
|
|
13
|
-
const renderedLength = renderedItems.reduce((acc, item) => acc + item.length, 0);
|
|
14
|
-
const defaultPointerPosition = renderedItems
|
|
15
|
-
.slice(0, active)
|
|
16
|
-
.reduce((acc, item) => acc + item.length, 0);
|
|
17
|
-
let pointer = defaultPointerPosition;
|
|
18
|
-
if (renderedLength > pageSize) {
|
|
19
|
-
if (loop) {
|
|
20
|
-
/**
|
|
21
|
-
* Creates the next position for the pointer considering an infinitely
|
|
22
|
-
* looping list of items to be rendered on the page.
|
|
23
|
-
*
|
|
24
|
-
* The goal is to progressively move the cursor to the middle position as the user move down, and then keep
|
|
25
|
-
* the cursor there. When the user move up, maintain the cursor position.
|
|
26
|
-
*/
|
|
27
|
-
// By default, keep the cursor position as-is.
|
|
28
|
-
pointer = lastPointer;
|
|
29
|
-
if (
|
|
30
|
-
// First render, skip this logic.
|
|
31
|
-
lastActive != null &&
|
|
32
|
-
// Only move the pointer down when the user moves down.
|
|
33
|
-
lastActive < active &&
|
|
34
|
-
// Check user didn't move up across page boundary.
|
|
35
|
-
active - lastActive < pageSize) {
|
|
36
|
-
pointer = Math.min(
|
|
37
|
-
// Furthest allowed position for the pointer is the middle of the list
|
|
38
|
-
middle, Math.abs(active - lastActive) === 1
|
|
39
|
-
? Math.min(
|
|
40
|
-
// Move the pointer at most the height of the last active item.
|
|
41
|
-
lastPointer + (renderedItems[lastActive]?.length ?? 0),
|
|
42
|
-
// If the user moved by one item, move the pointer to the natural position of the active item as
|
|
43
|
-
// long as it doesn't move the cursor up.
|
|
44
|
-
Math.max(defaultPointerPosition, lastPointer))
|
|
45
|
-
: // Otherwise, move the pointer down by the difference between the active and last active item.
|
|
46
|
-
lastPointer + active - lastActive);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
/**
|
|
51
|
-
* Creates the next position for the pointer considering a finite list of
|
|
52
|
-
* items to be rendered on a page.
|
|
53
|
-
*
|
|
54
|
-
* The goal is to keep the pointer in the middle of the page whenever possible, until
|
|
55
|
-
* we reach the bounds of the list (top or bottom). In which case, the cursor moves progressively
|
|
56
|
-
* to the bottom or top of the list.
|
|
57
|
-
*/
|
|
58
|
-
const spaceUnderActive = renderedItems
|
|
59
|
-
.slice(active)
|
|
60
|
-
.reduce((acc, item) => acc + item.length, 0);
|
|
61
|
-
pointer =
|
|
62
|
-
spaceUnderActive < pageSize - middle
|
|
63
|
-
? // If the active item is near the end of the list, progressively move the cursor towards the end.
|
|
64
|
-
pageSize - spaceUnderActive
|
|
65
|
-
: // Otherwise, progressively move the pointer to the middle of the list.
|
|
66
|
-
Math.min(defaultPointerPosition, middle);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// Save state for the next render
|
|
70
|
-
state.current.lastPointer = pointer;
|
|
71
|
-
state.current.lastActive = active;
|
|
72
|
-
return pointer;
|
|
73
|
-
}
|
|
74
|
-
function usePagination({ items, active, renderItem, pageSize, loop = true, }) {
|
|
75
|
-
const width = (0, utils_ts_1.readlineWidth)();
|
|
76
|
-
const bound = (num) => ((num % items.length) + items.length) % items.length;
|
|
77
|
-
const renderedItems = items.map((item, index) => {
|
|
78
|
-
if (item == null)
|
|
79
|
-
return [];
|
|
80
|
-
return (0, utils_ts_1.breakLines)(renderItem({ item, index, isActive: index === active }), width).split('\n');
|
|
81
|
-
});
|
|
82
|
-
const renderedLength = renderedItems.reduce((acc, item) => acc + item.length, 0);
|
|
83
|
-
const renderItemAtIndex = (index) => renderedItems[index] ?? [];
|
|
84
|
-
const pointer = usePointerPosition({ active, renderedItems, pageSize, loop });
|
|
85
|
-
// Render the active item to decide the position.
|
|
86
|
-
// If the active item fits under the pointer, we render it there.
|
|
87
|
-
// Otherwise, we need to render it to fit at the bottom of the page; moving the pointer up.
|
|
88
|
-
const activeItem = renderItemAtIndex(active).slice(0, pageSize);
|
|
89
|
-
const activeItemPosition = pointer + activeItem.length <= pageSize ? pointer : pageSize - activeItem.length;
|
|
90
|
-
// Create an array of lines for the page, and add the lines of the active item into the page
|
|
91
|
-
const pageBuffer = Array.from({ length: pageSize });
|
|
92
|
-
pageBuffer.splice(activeItemPosition, activeItem.length, ...activeItem);
|
|
93
|
-
// Store to prevent rendering the same item twice
|
|
94
|
-
const itemVisited = new Set([active]);
|
|
95
|
-
// Fill the page under the active item
|
|
96
|
-
let bufferPointer = activeItemPosition + activeItem.length;
|
|
97
|
-
let itemPointer = bound(active + 1);
|
|
98
|
-
while (bufferPointer < pageSize &&
|
|
99
|
-
!itemVisited.has(itemPointer) &&
|
|
100
|
-
(loop && renderedLength > pageSize ? itemPointer !== active : itemPointer > active)) {
|
|
101
|
-
const lines = renderItemAtIndex(itemPointer);
|
|
102
|
-
const linesToAdd = lines.slice(0, pageSize - bufferPointer);
|
|
103
|
-
pageBuffer.splice(bufferPointer, linesToAdd.length, ...linesToAdd);
|
|
104
|
-
// Move pointers for next iteration
|
|
105
|
-
itemVisited.add(itemPointer);
|
|
106
|
-
bufferPointer += linesToAdd.length;
|
|
107
|
-
itemPointer = bound(itemPointer + 1);
|
|
108
|
-
}
|
|
109
|
-
// Fill the page over the active item
|
|
110
|
-
bufferPointer = activeItemPosition - 1;
|
|
111
|
-
itemPointer = bound(active - 1);
|
|
112
|
-
while (bufferPointer >= 0 &&
|
|
113
|
-
!itemVisited.has(itemPointer) &&
|
|
114
|
-
(loop && renderedLength > pageSize ? itemPointer !== active : itemPointer < active)) {
|
|
115
|
-
const lines = renderItemAtIndex(itemPointer);
|
|
116
|
-
const linesToAdd = lines.slice(Math.max(0, lines.length - bufferPointer - 1));
|
|
117
|
-
pageBuffer.splice(bufferPointer - linesToAdd.length + 1, linesToAdd.length, ...linesToAdd);
|
|
118
|
-
// Move pointers for next iteration
|
|
119
|
-
itemVisited.add(itemPointer);
|
|
120
|
-
bufferPointer -= linesToAdd.length;
|
|
121
|
-
itemPointer = bound(itemPointer - 1);
|
|
122
|
-
}
|
|
123
|
-
return pageBuffer.filter((line) => typeof line === 'string').join('\n');
|
|
124
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PromisePolyfill = void 0;
|
|
4
|
-
// TODO: Remove this class once Node 22 becomes the minimum supported version.
|
|
5
|
-
class PromisePolyfill extends Promise {
|
|
6
|
-
// Available starting from Node 22
|
|
7
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
|
|
8
|
-
static withResolver() {
|
|
9
|
-
let resolve;
|
|
10
|
-
let reject;
|
|
11
|
-
const promise = new Promise((res, rej) => {
|
|
12
|
-
resolve = res;
|
|
13
|
-
reject = rej;
|
|
14
|
-
});
|
|
15
|
-
return { promise, resolve: resolve, reject: reject };
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.PromisePolyfill = PromisePolyfill;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_util_1 = require("node:util");
|
|
4
|
-
const utils_ts_1 = require("./utils.js");
|
|
5
|
-
const ansi_1 = require("@inquirer/ansi");
|
|
6
|
-
const height = (content) => content.split('\n').length;
|
|
7
|
-
const lastLine = (content) => content.split('\n').pop() ?? '';
|
|
8
|
-
class ScreenManager {
|
|
9
|
-
// These variables are keeping information to allow correct prompt re-rendering
|
|
10
|
-
height = 0;
|
|
11
|
-
extraLinesUnderPrompt = 0;
|
|
12
|
-
cursorPos;
|
|
13
|
-
rl;
|
|
14
|
-
constructor(rl) {
|
|
15
|
-
this.rl = rl;
|
|
16
|
-
this.cursorPos = rl.getCursorPos();
|
|
17
|
-
}
|
|
18
|
-
write(content) {
|
|
19
|
-
this.rl.output.unmute();
|
|
20
|
-
this.rl.output.write(content);
|
|
21
|
-
this.rl.output.mute();
|
|
22
|
-
}
|
|
23
|
-
render(content, bottomContent = '') {
|
|
24
|
-
// Write message to screen and setPrompt to control backspace
|
|
25
|
-
const promptLine = lastLine(content);
|
|
26
|
-
const rawPromptLine = (0, node_util_1.stripVTControlCharacters)(promptLine);
|
|
27
|
-
// Remove the rl.line from our prompt. We can't rely on the content of
|
|
28
|
-
// rl.line (mainly because of the password prompt), so just rely on it's
|
|
29
|
-
// length.
|
|
30
|
-
let prompt = rawPromptLine;
|
|
31
|
-
if (this.rl.line.length > 0) {
|
|
32
|
-
prompt = prompt.slice(0, -this.rl.line.length);
|
|
33
|
-
}
|
|
34
|
-
this.rl.setPrompt(prompt);
|
|
35
|
-
// SetPrompt will change cursor position, now we can get correct value
|
|
36
|
-
this.cursorPos = this.rl.getCursorPos();
|
|
37
|
-
const width = (0, utils_ts_1.readlineWidth)();
|
|
38
|
-
content = (0, utils_ts_1.breakLines)(content, width);
|
|
39
|
-
bottomContent = (0, utils_ts_1.breakLines)(bottomContent, width);
|
|
40
|
-
// Manually insert an extra line if we're at the end of the line.
|
|
41
|
-
// This prevent the cursor from appearing at the beginning of the
|
|
42
|
-
// current line.
|
|
43
|
-
if (rawPromptLine.length % width === 0) {
|
|
44
|
-
content += '\n';
|
|
45
|
-
}
|
|
46
|
-
let output = content + (bottomContent ? '\n' + bottomContent : '');
|
|
47
|
-
/**
|
|
48
|
-
* Re-adjust the cursor at the correct position.
|
|
49
|
-
*/
|
|
50
|
-
// We need to consider parts of the prompt under the cursor as part of the bottom
|
|
51
|
-
// content in order to correctly cleanup and re-render.
|
|
52
|
-
const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - this.cursorPos.rows;
|
|
53
|
-
const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
|
|
54
|
-
// Return cursor to the input position (on top of the bottomContent)
|
|
55
|
-
if (bottomContentHeight > 0)
|
|
56
|
-
output += (0, ansi_1.cursorUp)(bottomContentHeight);
|
|
57
|
-
// Return cursor to the initial left offset.
|
|
58
|
-
output += (0, ansi_1.cursorTo)(this.cursorPos.cols);
|
|
59
|
-
/**
|
|
60
|
-
* Render and store state for future re-rendering
|
|
61
|
-
*/
|
|
62
|
-
this.write((0, ansi_1.cursorDown)(this.extraLinesUnderPrompt) + (0, ansi_1.eraseLines)(this.height) + output);
|
|
63
|
-
this.extraLinesUnderPrompt = bottomContentHeight;
|
|
64
|
-
this.height = height(output);
|
|
65
|
-
}
|
|
66
|
-
checkCursorPos() {
|
|
67
|
-
const cursorPos = this.rl.getCursorPos();
|
|
68
|
-
if (cursorPos.cols !== this.cursorPos.cols) {
|
|
69
|
-
this.write((0, ansi_1.cursorTo)(cursorPos.cols));
|
|
70
|
-
this.cursorPos = cursorPos;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
done({ clearContent }) {
|
|
74
|
-
this.rl.setPrompt('');
|
|
75
|
-
let output = (0, ansi_1.cursorDown)(this.extraLinesUnderPrompt);
|
|
76
|
-
output += clearContent ? (0, ansi_1.eraseLines)(this.height) : '\n';
|
|
77
|
-
output += ansi_1.cursorShow;
|
|
78
|
-
this.write(output);
|
|
79
|
-
this.rl.close();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.default = ScreenManager;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.defaultTheme = void 0;
|
|
7
|
-
const yoctocolors_cjs_1 = __importDefault(require("yoctocolors-cjs"));
|
|
8
|
-
const figures_1 = __importDefault(require("@inquirer/figures"));
|
|
9
|
-
exports.defaultTheme = {
|
|
10
|
-
prefix: {
|
|
11
|
-
idle: yoctocolors_cjs_1.default.blue('?'),
|
|
12
|
-
done: yoctocolors_cjs_1.default.green(figures_1.default.tick),
|
|
13
|
-
},
|
|
14
|
-
spinner: {
|
|
15
|
-
interval: 80,
|
|
16
|
-
frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'].map((frame) => yoctocolors_cjs_1.default.yellow(frame)),
|
|
17
|
-
},
|
|
18
|
-
style: {
|
|
19
|
-
answer: yoctocolors_cjs_1.default.cyan,
|
|
20
|
-
message: yoctocolors_cjs_1.default.bold,
|
|
21
|
-
error: (text) => yoctocolors_cjs_1.default.red(`> ${text}`),
|
|
22
|
-
defaultAnswer: (text) => yoctocolors_cjs_1.default.dim(`(${text})`),
|
|
23
|
-
help: yoctocolors_cjs_1.default.dim,
|
|
24
|
-
highlight: yoctocolors_cjs_1.default.cyan,
|
|
25
|
-
key: (text) => yoctocolors_cjs_1.default.cyan(yoctocolors_cjs_1.default.bold(`<${text}>`)),
|
|
26
|
-
},
|
|
27
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useEffect = useEffect;
|
|
4
|
-
const hook_engine_ts_1 = require("./hook-engine.js");
|
|
5
|
-
function useEffect(cb, depArray) {
|
|
6
|
-
(0, hook_engine_ts_1.withPointer)((pointer) => {
|
|
7
|
-
const oldDeps = pointer.get();
|
|
8
|
-
const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
|
|
9
|
-
if (hasChanged) {
|
|
10
|
-
hook_engine_ts_1.effectScheduler.queue(cb);
|
|
11
|
-
}
|
|
12
|
-
pointer.set(depArray);
|
|
13
|
-
});
|
|
14
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useKeypress = useKeypress;
|
|
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
|
-
function useKeypress(userHandler) {
|
|
8
|
-
const signal = (0, use_ref_ts_1.useRef)(userHandler);
|
|
9
|
-
signal.current = userHandler;
|
|
10
|
-
(0, use_effect_ts_1.useEffect)((rl) => {
|
|
11
|
-
let ignore = false;
|
|
12
|
-
const handler = (0, hook_engine_ts_1.withUpdates)((_input, event) => {
|
|
13
|
-
if (ignore)
|
|
14
|
-
return;
|
|
15
|
-
void signal.current(event, rl);
|
|
16
|
-
});
|
|
17
|
-
rl.input.on('keypress', handler);
|
|
18
|
-
return () => {
|
|
19
|
-
ignore = true;
|
|
20
|
-
rl.input.removeListener('keypress', handler);
|
|
21
|
-
};
|
|
22
|
-
}, []);
|
|
23
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useMemo = useMemo;
|
|
4
|
-
const hook_engine_ts_1 = require("./hook-engine.js");
|
|
5
|
-
function useMemo(fn, dependencies) {
|
|
6
|
-
return (0, hook_engine_ts_1.withPointer)((pointer) => {
|
|
7
|
-
const prev = pointer.get();
|
|
8
|
-
if (!prev ||
|
|
9
|
-
prev.dependencies.length !== dependencies.length ||
|
|
10
|
-
prev.dependencies.some((dep, i) => dep !== dependencies[i])) {
|
|
11
|
-
const value = fn();
|
|
12
|
-
pointer.set({ value, dependencies });
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
return prev.value;
|
|
16
|
-
});
|
|
17
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePrefix = usePrefix;
|
|
4
|
-
const use_state_ts_1 = require("./use-state.js");
|
|
5
|
-
const use_effect_ts_1 = require("./use-effect.js");
|
|
6
|
-
const make_theme_ts_1 = require("./make-theme.js");
|
|
7
|
-
function usePrefix({ status = 'idle', theme, }) {
|
|
8
|
-
const [showLoader, setShowLoader] = (0, use_state_ts_1.useState)(false);
|
|
9
|
-
const [tick, setTick] = (0, use_state_ts_1.useState)(0);
|
|
10
|
-
const { prefix, spinner } = (0, make_theme_ts_1.makeTheme)(theme);
|
|
11
|
-
(0, use_effect_ts_1.useEffect)(() => {
|
|
12
|
-
if (status === 'loading') {
|
|
13
|
-
let tickInterval;
|
|
14
|
-
let inc = -1;
|
|
15
|
-
// Delay displaying spinner by 300ms, to avoid flickering
|
|
16
|
-
const delayTimeout = setTimeout(() => {
|
|
17
|
-
setShowLoader(true);
|
|
18
|
-
tickInterval = setInterval(() => {
|
|
19
|
-
inc = inc + 1;
|
|
20
|
-
setTick(inc % spinner.frames.length);
|
|
21
|
-
}, spinner.interval);
|
|
22
|
-
}, 300);
|
|
23
|
-
return () => {
|
|
24
|
-
clearTimeout(delayTimeout);
|
|
25
|
-
clearInterval(tickInterval);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
setShowLoader(false);
|
|
30
|
-
}
|
|
31
|
-
}, [status]);
|
|
32
|
-
if (showLoader) {
|
|
33
|
-
return spinner.frames[tick];
|
|
34
|
-
}
|
|
35
|
-
// There's a delay before we show the loader. So we want to ignore `loading` here, and pass idle instead.
|
|
36
|
-
const iconName = status === 'loading' ? 'idle' : status;
|
|
37
|
-
return typeof prefix === 'string' ? prefix : (prefix[iconName] ?? prefix['idle']);
|
|
38
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useState = useState;
|
|
4
|
-
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
|
-
const hook_engine_ts_1 = require("./hook-engine.js");
|
|
6
|
-
function useState(defaultValue) {
|
|
7
|
-
return (0, hook_engine_ts_1.withPointer)((pointer) => {
|
|
8
|
-
const setState = node_async_hooks_1.AsyncResource.bind(function setState(newValue) {
|
|
9
|
-
// Noop if the value is still the same.
|
|
10
|
-
if (pointer.get() !== newValue) {
|
|
11
|
-
pointer.set(newValue);
|
|
12
|
-
// Trigger re-render
|
|
13
|
-
(0, hook_engine_ts_1.handleChange)();
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
if (pointer.initialized) {
|
|
17
|
-
return [pointer.get(), setState];
|
|
18
|
-
}
|
|
19
|
-
const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
|
|
20
|
-
pointer.set(value);
|
|
21
|
-
return [value, setState];
|
|
22
|
-
});
|
|
23
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.breakLines = breakLines;
|
|
7
|
-
exports.readlineWidth = readlineWidth;
|
|
8
|
-
const cli_width_1 = __importDefault(require("cli-width"));
|
|
9
|
-
const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
|
|
10
|
-
const hook_engine_ts_1 = require("./hook-engine.js");
|
|
11
|
-
/**
|
|
12
|
-
* Force line returns at specific width. This function is ANSI code friendly and it'll
|
|
13
|
-
* ignore invisible codes during width calculation.
|
|
14
|
-
* @param {string} content
|
|
15
|
-
* @param {number} width
|
|
16
|
-
* @return {string}
|
|
17
|
-
*/
|
|
18
|
-
function breakLines(content, width) {
|
|
19
|
-
return content
|
|
20
|
-
.split('\n')
|
|
21
|
-
.flatMap((line) => (0, wrap_ansi_1.default)(line, width, { trim: false, hard: true })
|
|
22
|
-
.split('\n')
|
|
23
|
-
.map((str) => str.trimEnd()))
|
|
24
|
-
.join('\n');
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Returns the width of the active readline, or 80 as default value.
|
|
28
|
-
* @returns {number}
|
|
29
|
-
*/
|
|
30
|
-
function readlineWidth() {
|
|
31
|
-
return (0, cli_width_1.default)({ defaultWidth: 80, output: (0, hook_engine_ts_1.readline)().output });
|
|
32
|
-
}
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { isUpKey, isDownKey, isSpaceKey, isBackspaceKey, isTabKey, isNumberKey, isEnterKey, type KeypressEvent, type Keybinding, } 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';
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type Prompt, type Prettify } from '@inquirer/type';
|
|
2
|
-
type ViewFunction<Value, Config> = (config: Prettify<Config>, done: (value: Value) => void) => string | [string, string | undefined];
|
|
3
|
-
export declare function createPrompt<Value, Config>(view: ViewFunction<Value, Config>): Prompt<Value, Config>;
|
|
4
|
-
export {};
|
package/dist/esm/lib/errors.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare class AbortPromptError extends Error {
|
|
2
|
-
name: string;
|
|
3
|
-
message: string;
|
|
4
|
-
constructor(options?: {
|
|
5
|
-
cause?: unknown;
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
export declare class CancelPromptError extends Error {
|
|
9
|
-
name: string;
|
|
10
|
-
message: string;
|
|
11
|
-
}
|
|
12
|
-
export declare class ExitPromptError extends Error {
|
|
13
|
-
name: string;
|
|
14
|
-
}
|
|
15
|
-
export declare class HookError extends Error {
|
|
16
|
-
name: string;
|
|
17
|
-
}
|
|
18
|
-
export declare class ValidationError extends Error {
|
|
19
|
-
name: string;
|
|
20
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { InquirerReadline } from '@inquirer/type';
|
|
2
|
-
export declare function withHooks<T>(rl: InquirerReadline, cb: (cycle: (render: () => void) => void) => T): T;
|
|
3
|
-
export declare function readline(): InquirerReadline;
|
|
4
|
-
export declare function withUpdates<Args extends unknown[], R>(fn: (...args: Args) => R): (...args: Args) => R;
|
|
5
|
-
type SetPointer<Value> = {
|
|
6
|
-
get(): Value;
|
|
7
|
-
set(value: Value): void;
|
|
8
|
-
initialized: true;
|
|
9
|
-
};
|
|
10
|
-
type UnsetPointer<Value> = {
|
|
11
|
-
get(): void;
|
|
12
|
-
set(value: Value): void;
|
|
13
|
-
initialized: false;
|
|
14
|
-
};
|
|
15
|
-
type Pointer<Value> = SetPointer<Value> | UnsetPointer<Value>;
|
|
16
|
-
export declare function withPointer<Value, ReturnValue>(cb: (pointer: Pointer<Value>) => ReturnValue): ReturnValue;
|
|
17
|
-
export declare function handleChange(): void;
|
|
18
|
-
export declare const effectScheduler: {
|
|
19
|
-
queue(cb: (readline: InquirerReadline) => void | (() => void)): void;
|
|
20
|
-
run(): void;
|
|
21
|
-
clearAll(): void;
|
|
22
|
-
};
|
|
23
|
-
export {};
|
package/dist/esm/lib/key.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type KeypressEvent = {
|
|
2
|
-
name: string;
|
|
3
|
-
ctrl: boolean;
|
|
4
|
-
};
|
|
5
|
-
export type Keybinding = 'emacs' | 'vim';
|
|
6
|
-
export declare const isUpKey: (key: KeypressEvent, keybindings?: ReadonlyArray<Keybinding>) => boolean;
|
|
7
|
-
export declare const isDownKey: (key: KeypressEvent, keybindings?: ReadonlyArray<Keybinding>) => boolean;
|
|
8
|
-
export declare const isSpaceKey: (key: KeypressEvent) => boolean;
|
|
9
|
-
export declare const isBackspaceKey: (key: KeypressEvent) => boolean;
|
|
10
|
-
export declare const isTabKey: (key: KeypressEvent) => boolean;
|
|
11
|
-
export declare const isNumberKey: (key: KeypressEvent) => boolean;
|
|
12
|
-
export declare const isEnterKey: (key: KeypressEvent) => boolean;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Prettify } from '@inquirer/type';
|
|
2
|
-
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
|
|
3
|
-
items: ReadonlyArray<T>;
|
|
4
|
-
/** The index of the active item. */
|
|
5
|
-
active: number;
|
|
6
|
-
/** Renders an item as part of a page. */
|
|
7
|
-
renderItem: (layout: Prettify<{
|
|
8
|
-
item: T;
|
|
9
|
-
index: number;
|
|
10
|
-
isActive: boolean;
|
|
11
|
-
}>) => string;
|
|
12
|
-
/** The size of the page. */
|
|
13
|
-
pageSize: number;
|
|
14
|
-
/** Allows creating an infinitely looping list. `true` if unspecified. */
|
|
15
|
-
loop?: boolean;
|
|
16
|
-
}): string;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { InquirerReadline } from '@inquirer/type';
|
|
2
|
-
export default class ScreenManager {
|
|
3
|
-
private height;
|
|
4
|
-
private extraLinesUnderPrompt;
|
|
5
|
-
private cursorPos;
|
|
6
|
-
private readonly rl;
|
|
7
|
-
constructor(rl: InquirerReadline);
|
|
8
|
-
write(content: string): void;
|
|
9
|
-
render(content: string, bottomContent?: string): void;
|
|
10
|
-
checkCursorPos(): void;
|
|
11
|
-
done({ clearContent }: {
|
|
12
|
-
clearContent: boolean;
|
|
13
|
-
}): void;
|
|
14
|
-
}
|