@reliverse/rempts 1.7.65 → 2.2.7
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/LICENSE +21 -21
- package/README.md +1534 -1431
- package/cleanup.mjs +33 -0
- package/dist/cancel.d.ts +31 -0
- package/dist/cancel.js +28 -0
- package/dist/ffi.d.ts +1 -0
- package/dist/ffi.js +165 -0
- package/dist/group.d.ts +16 -0
- package/dist/group.js +22 -0
- package/dist/launcher/command.d.ts +8 -0
- package/dist/launcher/command.js +10 -0
- package/dist/launcher/discovery.d.ts +3 -0
- package/dist/launcher/discovery.js +207 -0
- package/dist/launcher/errors.d.ts +15 -0
- package/dist/launcher/errors.js +31 -0
- package/dist/launcher/help.d.ts +3 -0
- package/dist/launcher/help.js +145 -0
- package/dist/launcher/mod.d.ts +12 -0
- package/dist/launcher/mod.js +222 -0
- package/dist/launcher/parser.d.ts +14 -0
- package/dist/launcher/parser.js +255 -0
- package/dist/launcher/registry.d.ts +10 -0
- package/dist/launcher/registry.js +42 -0
- package/dist/launcher/types.d.ts +78 -0
- package/dist/launcher/validator.d.ts +3 -0
- package/dist/launcher/validator.js +39 -0
- package/dist/mod.d.ts +6 -0
- package/dist/mod.js +6 -0
- package/dist/prompt.d.ts +13 -0
- package/dist/prompt.js +53 -0
- package/dist/selection.d.ts +92 -0
- package/dist/selection.js +191 -0
- package/dist/spinner.d.ts +26 -0
- package/dist/spinner.js +141 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +11 -0
- package/package.json +41 -47
- package/bin/libs/animate/animate-mod.ts.txt +0 -78
- package/bin/libs/anykey/anykey-mod.d.ts +0 -12
- package/bin/libs/anykey/anykey-mod.js +0 -125
- package/bin/libs/cancel/cancel.d.ts +0 -45
- package/bin/libs/cancel/cancel.js +0 -72
- package/bin/libs/confirm/confirm-alias.d.ts +0 -2
- package/bin/libs/confirm/confirm-alias.js +0 -2
- package/bin/libs/confirm/confirm-mod.d.ts +0 -5
- package/bin/libs/confirm/confirm-mod.js +0 -179
- package/bin/libs/date/date.d.ts +0 -2
- package/bin/libs/date/date.js +0 -254
- package/bin/libs/editor/editor-mod.d.ts +0 -25
- package/bin/libs/editor/editor-mod.js +0 -1133
- package/bin/libs/figures/figures-mod.d.ts +0 -461
- package/bin/libs/figures/figures-mod.js +0 -285
- package/bin/libs/group/group-mod.d.ts +0 -33
- package/bin/libs/group/group-mod.js +0 -89
- package/bin/libs/input/input-alias.d.ts +0 -5
- package/bin/libs/input/input-alias.js +0 -4
- package/bin/libs/input/input-mod.d.ts +0 -16
- package/bin/libs/input/input-mod.js +0 -370
- package/bin/libs/intro/intro-alias.d.ts +0 -3
- package/bin/libs/intro/intro-alias.js +0 -3
- package/bin/libs/intro/intro-mod.d.ts +0 -19
- package/bin/libs/intro/intro-mod.js +0 -71
- package/bin/libs/launcher/command-runner.d.ts +0 -31
- package/bin/libs/launcher/command-runner.js +0 -229
- package/bin/libs/launcher/launcher-alias.d.ts +0 -2
- package/bin/libs/launcher/launcher-alias.js +0 -2
- package/bin/libs/launcher/launcher-mod.d.ts +0 -66
- package/bin/libs/launcher/launcher-mod.js +0 -1037
- package/bin/libs/launcher/launcher-types.d.ts +0 -176
- package/bin/libs/launcher/launcher-types.js +0 -0
- package/bin/libs/log/log-alias.d.ts +0 -1
- package/bin/libs/log/log-alias.js +0 -2
- package/bin/libs/msg-fmt/colors.d.ts +0 -30
- package/bin/libs/msg-fmt/colors.js +0 -42
- package/bin/libs/msg-fmt/mapping.d.ts +0 -3
- package/bin/libs/msg-fmt/mapping.js +0 -41
- package/bin/libs/msg-fmt/messages.d.ts +0 -35
- package/bin/libs/msg-fmt/messages.js +0 -305
- package/bin/libs/msg-fmt/terminal.d.ts +0 -15
- package/bin/libs/msg-fmt/terminal.js +0 -60
- package/bin/libs/msg-fmt/variants.d.ts +0 -11
- package/bin/libs/msg-fmt/variants.js +0 -52
- package/bin/libs/multiselect/multiselect-alias.d.ts +0 -2
- package/bin/libs/multiselect/multiselect-alias.js +0 -2
- package/bin/libs/multiselect/multiselect-prompt.d.ts +0 -2
- package/bin/libs/multiselect/multiselect-prompt.js +0 -340
- package/bin/libs/next-steps/next-steps.d.ts +0 -13
- package/bin/libs/next-steps/next-steps.js +0 -24
- package/bin/libs/number/number-mod.d.ts +0 -28
- package/bin/libs/number/number-mod.js +0 -234
- package/bin/libs/outro/outro-alias.d.ts +0 -3
- package/bin/libs/outro/outro-alias.js +0 -3
- package/bin/libs/outro/outro-mod.d.ts +0 -7
- package/bin/libs/outro/outro-mod.js +0 -49
- package/bin/libs/reliarg/reliarg-mod.d.ts +0 -76
- package/bin/libs/reliarg/reliarg-mod.js +0 -276
- package/bin/libs/results/results.d.ts +0 -7
- package/bin/libs/results/results.js +0 -27
- package/bin/libs/select/nummultiselect-prompt.d.ts +0 -6
- package/bin/libs/select/nummultiselect-prompt.js +0 -141
- package/bin/libs/select/numselect-prompt.d.ts +0 -7
- package/bin/libs/select/numselect-prompt.js +0 -111
- package/bin/libs/select/select-alias.d.ts +0 -9
- package/bin/libs/select/select-alias.js +0 -9
- package/bin/libs/select/select-prompt.d.ts +0 -5
- package/bin/libs/select/select-prompt.js +0 -311
- package/bin/libs/select/toggle-prompt.d.ts +0 -5
- package/bin/libs/select/toggle-prompt.js +0 -207
- package/bin/libs/spinner/spinner-impl.d.ts +0 -70
- package/bin/libs/spinner/spinner-impl.js +0 -336
- package/bin/libs/spinner/spinner-mod.d.ts +0 -167
- package/bin/libs/spinner/spinner-mod.js +0 -447
- package/bin/libs/utils/colorize.d.ts +0 -2
- package/bin/libs/utils/colorize.js +0 -122
- package/bin/libs/utils/errors.d.ts +0 -1
- package/bin/libs/utils/errors.js +0 -17
- package/bin/libs/utils/prevent.d.ts +0 -8
- package/bin/libs/utils/prevent.js +0 -62
- package/bin/libs/utils/prompt-end.d.ts +0 -8
- package/bin/libs/utils/prompt-end.js +0 -36
- package/bin/libs/utils/stream-text.d.ts +0 -18
- package/bin/libs/utils/stream-text.js +0 -138
- package/bin/libs/utils/system.d.ts +0 -6
- package/bin/libs/utils/system.js +0 -7
- package/bin/libs/utils/validate.d.ts +0 -21
- package/bin/libs/utils/validate.js +0 -17
- package/bin/libs/visual/visual-mod.ts.txt +0 -19
- package/bin/mod.d.ts +0 -50
- package/bin/mod.js +0 -127
- package/bin/types.d.ts +0 -372
- /package/{bin → dist/launcher}/types.js +0 -0
package/dist/spinner.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
const DEFAULT_FRAMES = ["\u25D2", "\u25D0", "\u25D3", "\u25D1"];
|
|
2
|
+
const DEFAULT_DELAY = 80;
|
|
3
|
+
function hideCursor() {
|
|
4
|
+
process.stdout.write("\x1B[?25l");
|
|
5
|
+
}
|
|
6
|
+
function showCursor() {
|
|
7
|
+
process.stdout.write("\x1B[?25h");
|
|
8
|
+
}
|
|
9
|
+
function clearLine() {
|
|
10
|
+
process.stdout.write("\r\x1B[K");
|
|
11
|
+
}
|
|
12
|
+
function formatTime(seconds) {
|
|
13
|
+
if (seconds < 60) {
|
|
14
|
+
return `${seconds}s`;
|
|
15
|
+
}
|
|
16
|
+
const mins = Math.floor(seconds / 60);
|
|
17
|
+
const secs = seconds % 60;
|
|
18
|
+
return `${mins}m ${secs}s`;
|
|
19
|
+
}
|
|
20
|
+
export function spinnerPrompt(options = {}) {
|
|
21
|
+
return createSpinner(options);
|
|
22
|
+
}
|
|
23
|
+
export function createSpinner(options = {}) {
|
|
24
|
+
const {
|
|
25
|
+
text = "",
|
|
26
|
+
indicator = "dots",
|
|
27
|
+
frames = DEFAULT_FRAMES,
|
|
28
|
+
delay = DEFAULT_DELAY,
|
|
29
|
+
onCancel,
|
|
30
|
+
cancelMessage = "Operation cancelled by user",
|
|
31
|
+
errorMessage = "Operation failed",
|
|
32
|
+
successText,
|
|
33
|
+
failText,
|
|
34
|
+
prefixText,
|
|
35
|
+
hideCursor: shouldHideCursor = true,
|
|
36
|
+
silent = false,
|
|
37
|
+
signal
|
|
38
|
+
} = options;
|
|
39
|
+
let frameIndex = 0;
|
|
40
|
+
let intervalId = null;
|
|
41
|
+
let startTime = null;
|
|
42
|
+
let isRunning = false;
|
|
43
|
+
let currentText = text;
|
|
44
|
+
const render = () => {
|
|
45
|
+
if (silent || !isRunning) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
clearLine();
|
|
49
|
+
const frame = frames[frameIndex % frames.length];
|
|
50
|
+
let output = `${frame} ${currentText}`;
|
|
51
|
+
if (indicator === "timer" && startTime !== null) {
|
|
52
|
+
const elapsed = Math.floor((Date.now() - startTime) / 1e3);
|
|
53
|
+
output += ` [${formatTime(elapsed)}]`;
|
|
54
|
+
}
|
|
55
|
+
if (prefixText) {
|
|
56
|
+
output = `${prefixText}${output}`;
|
|
57
|
+
}
|
|
58
|
+
process.stdout.write(output);
|
|
59
|
+
frameIndex += 1;
|
|
60
|
+
};
|
|
61
|
+
const start = () => {
|
|
62
|
+
if (isRunning) {
|
|
63
|
+
return spinner;
|
|
64
|
+
}
|
|
65
|
+
isRunning = true;
|
|
66
|
+
startTime = Date.now();
|
|
67
|
+
if (shouldHideCursor && !silent) {
|
|
68
|
+
hideCursor();
|
|
69
|
+
}
|
|
70
|
+
if (signal) {
|
|
71
|
+
signal.addEventListener("abort", () => {
|
|
72
|
+
stop();
|
|
73
|
+
if (onCancel) {
|
|
74
|
+
onCancel();
|
|
75
|
+
}
|
|
76
|
+
if (!silent) {
|
|
77
|
+
clearLine();
|
|
78
|
+
process.stdout.write(`\u2717 ${cancelMessage}
|
|
79
|
+
`);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (!silent) {
|
|
84
|
+
render();
|
|
85
|
+
intervalId = setInterval(() => {
|
|
86
|
+
render();
|
|
87
|
+
}, delay);
|
|
88
|
+
}
|
|
89
|
+
return spinner;
|
|
90
|
+
};
|
|
91
|
+
const stop = () => {
|
|
92
|
+
if (!isRunning) {
|
|
93
|
+
return spinner;
|
|
94
|
+
}
|
|
95
|
+
isRunning = false;
|
|
96
|
+
if (intervalId !== null) {
|
|
97
|
+
clearInterval(intervalId);
|
|
98
|
+
intervalId = null;
|
|
99
|
+
}
|
|
100
|
+
if (shouldHideCursor && !silent) {
|
|
101
|
+
showCursor();
|
|
102
|
+
}
|
|
103
|
+
if (!silent) {
|
|
104
|
+
clearLine();
|
|
105
|
+
}
|
|
106
|
+
return spinner;
|
|
107
|
+
};
|
|
108
|
+
const succeed = (customText) => {
|
|
109
|
+
stop();
|
|
110
|
+
if (!silent) {
|
|
111
|
+
const displayText = customText ?? successText ?? currentText;
|
|
112
|
+
process.stdout.write(`\u2713 ${displayText}
|
|
113
|
+
`);
|
|
114
|
+
}
|
|
115
|
+
return spinner;
|
|
116
|
+
};
|
|
117
|
+
const fail = (customText) => {
|
|
118
|
+
stop();
|
|
119
|
+
if (!silent) {
|
|
120
|
+
const displayText = customText ?? failText ?? errorMessage;
|
|
121
|
+
process.stdout.write(`\u2717 ${displayText}
|
|
122
|
+
`);
|
|
123
|
+
}
|
|
124
|
+
return spinner;
|
|
125
|
+
};
|
|
126
|
+
const updateText = (newText) => {
|
|
127
|
+
currentText = newText;
|
|
128
|
+
if (isRunning && !silent) {
|
|
129
|
+
render();
|
|
130
|
+
}
|
|
131
|
+
return spinner;
|
|
132
|
+
};
|
|
133
|
+
const spinner = {
|
|
134
|
+
start,
|
|
135
|
+
stop,
|
|
136
|
+
succeed,
|
|
137
|
+
fail,
|
|
138
|
+
updateText
|
|
139
|
+
};
|
|
140
|
+
return spinner;
|
|
141
|
+
}
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CString } from "bun:ffi";
|
|
2
|
+
import { symbols } from "./ffi.js";
|
|
3
|
+
const utf8e = new TextEncoder();
|
|
4
|
+
export function encode(data) {
|
|
5
|
+
return utf8e.encode(`${data}\0`);
|
|
6
|
+
}
|
|
7
|
+
export function toStringFromPtr(ptrValue) {
|
|
8
|
+
const str = new CString(ptrValue);
|
|
9
|
+
symbols.FreeString(str.ptr);
|
|
10
|
+
return str.toString();
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,57 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
"dependencies": {
|
|
3
|
-
"@reliverse/relico": "^1.4.0",
|
|
4
|
-
"@reliverse/relinka": "^1.6.1",
|
|
5
|
-
"@reliverse/reltime": "^1.1.1",
|
|
6
|
-
"ansi-escapes": "^7.1.0",
|
|
7
|
-
"cli-cursor": "^5.0.0",
|
|
8
|
-
"cli-spinners": "^3.2.0",
|
|
9
|
-
"gradient-string": "^3.0.0",
|
|
10
|
-
"is-interactive": "^2.0.0",
|
|
11
|
-
"is-unicode-supported": "^2.1.0",
|
|
12
|
-
"log-update": "^6.1.0",
|
|
13
|
-
"pkg-types": "^2.3.0",
|
|
14
|
-
"pretty-bytes": "^7.0.1",
|
|
15
|
-
"pretty-ms": "^9.2.0",
|
|
16
|
-
"sisteransi": "^1.0.5",
|
|
17
|
-
"stdin-discarder": "^0.2.2",
|
|
18
|
-
"string-width": "^8.1.0",
|
|
19
|
-
"strip-ansi": "^7.1.2",
|
|
20
|
-
"terminal-size": "^4.0.0",
|
|
21
|
-
"ts-regex-builder": "^1.8.2",
|
|
22
|
-
"wrap-ansi": "^9.0.2"
|
|
23
|
-
},
|
|
24
|
-
"description": "@reliverse/rempts is a modern, type-safe toolkit for building delightful cli experiences. it's fast, flexible, and made for developer happiness. file-based commands keep things simple.",
|
|
25
|
-
"homepage": "https://docs.reliverse.org/cli",
|
|
26
|
-
"license": "MIT",
|
|
27
2
|
"name": "@reliverse/rempts",
|
|
3
|
+
"version": "2.2.7",
|
|
4
|
+
"private": false,
|
|
28
5
|
"type": "module",
|
|
29
|
-
"version": "1.7.65",
|
|
30
|
-
"author": "reliverse",
|
|
31
|
-
"bugs": {
|
|
32
|
-
"email": "blefnk@gmail.com",
|
|
33
|
-
"url": "https://github.com/reliverse/rempts/issues"
|
|
34
|
-
},
|
|
35
|
-
"keywords": [
|
|
36
|
-
"reliverse"
|
|
37
|
-
],
|
|
38
|
-
"repository": {
|
|
39
|
-
"type": "git",
|
|
40
|
-
"url": "git+https://github.com/reliverse/rempts.git"
|
|
41
|
-
},
|
|
42
|
-
"devDependencies": {},
|
|
43
6
|
"exports": {
|
|
44
|
-
".":
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/mod.d.ts",
|
|
9
|
+
"default": "./dist/mod.js"
|
|
10
|
+
}
|
|
45
11
|
},
|
|
12
|
+
"description": "",
|
|
46
13
|
"files": [
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
14
|
+
"dist",
|
|
15
|
+
"release",
|
|
16
|
+
"cleanup.mjs",
|
|
17
|
+
"package.json"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"bun"
|
|
51
21
|
],
|
|
52
|
-
"main": "./bin/mod.js",
|
|
53
|
-
"module": "./bin/mod.js",
|
|
54
22
|
"publishConfig": {
|
|
55
23
|
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"homepage": "https://github.com/reliverse/dler/tree/main/packages/prompt#readme",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/reliverse/dler.git",
|
|
30
|
+
"directory": "packages/prompt"
|
|
31
|
+
},
|
|
32
|
+
"bugs": "https://github.com/reliverse/dler/issues",
|
|
33
|
+
"author": "Nazar Kornienko <blefnk@gmail.com>",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"log-update": "^7.0.2",
|
|
36
|
+
"sisteransi": "^1.0.5",
|
|
37
|
+
"cli-cursor": "^5.0.0",
|
|
38
|
+
"cli-spinners": "^3.3.0",
|
|
39
|
+
"is-interactive": "^2.0.0",
|
|
40
|
+
"is-unicode-supported": "^2.1.0",
|
|
41
|
+
"stdin-discarder": "^0.3.0",
|
|
42
|
+
"string-width": "^8.1.0",
|
|
43
|
+
"strip-ansi": "^7.1.2",
|
|
44
|
+
"pretty-bytes": "^7.1.0",
|
|
45
|
+
"pretty-ms": "^9.3.0",
|
|
46
|
+
"@reliverse/relico": "2.2.7",
|
|
47
|
+
"@reliverse/relinka": "2.2.7",
|
|
48
|
+
"@reliverse/mapkit": "2.2.7",
|
|
49
|
+
"@reliverse/helpers": "2.2.8"
|
|
56
50
|
}
|
|
57
|
-
}
|
|
51
|
+
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { type Animation, type AnimationName, ChalkAnimation } from "@figliolia/chalk-animation";
|
|
2
|
-
import { relinka } from "@reliverse/relinka";
|
|
3
|
-
import type { BorderColorName, ColorName, MsgType, TypographyName } from "../../types";
|
|
4
|
-
import { msg } from "../msg-fmt/messages";
|
|
5
|
-
import { deleteLastLine, getTerminalWidth } from "../msg-fmt/terminal";
|
|
6
|
-
|
|
7
|
-
export const animationMap: Record<AnimationName, (text: string) => Animation> = {
|
|
8
|
-
rainbow: ChalkAnimation.rainbow,
|
|
9
|
-
pulse: ChalkAnimation.pulse,
|
|
10
|
-
glitch: ChalkAnimation.glitch,
|
|
11
|
-
radar: ChalkAnimation.radar,
|
|
12
|
-
neon: ChalkAnimation.neon,
|
|
13
|
-
karaoke: ChalkAnimation.karaoke,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
function calculateDelay(text: string): number {
|
|
17
|
-
const baseDelay = 1000;
|
|
18
|
-
const delayPerCharacter = 50;
|
|
19
|
-
return baseDelay + text.length * delayPerCharacter;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function animateText({
|
|
23
|
-
title = "",
|
|
24
|
-
anim,
|
|
25
|
-
delay,
|
|
26
|
-
type = "M_INFO",
|
|
27
|
-
titleColor = "cyan",
|
|
28
|
-
titleTypography = "none",
|
|
29
|
-
border = true,
|
|
30
|
-
borderColor = "dim",
|
|
31
|
-
horizontalLineLength = 0,
|
|
32
|
-
}: {
|
|
33
|
-
title: string;
|
|
34
|
-
anim: AnimationName;
|
|
35
|
-
delay?: number;
|
|
36
|
-
type?: MsgType;
|
|
37
|
-
titleColor?: ColorName;
|
|
38
|
-
titleTypography?: TypographyName;
|
|
39
|
-
borderColor?: BorderColorName;
|
|
40
|
-
border?: boolean;
|
|
41
|
-
horizontalLineLength?: number;
|
|
42
|
-
}) {
|
|
43
|
-
if (horizontalLineLength === 0) {
|
|
44
|
-
horizontalLineLength = getTerminalWidth() - 5;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const finalDelay = delay ?? calculateDelay(title);
|
|
48
|
-
const animation = animationMap[anim](title);
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
await new Promise<void>((resolve) => {
|
|
52
|
-
setTimeout(() => {
|
|
53
|
-
animation.stop();
|
|
54
|
-
deleteLastLine();
|
|
55
|
-
|
|
56
|
-
if (title.includes("│ ")) {
|
|
57
|
-
title = title.replace("│ ", "");
|
|
58
|
-
} else if (title.includes("ℹ ")) {
|
|
59
|
-
title = title.replace("ℹ ", "");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
msg({
|
|
63
|
-
type,
|
|
64
|
-
title: title,
|
|
65
|
-
titleColor,
|
|
66
|
-
titleTypography,
|
|
67
|
-
content: "",
|
|
68
|
-
borderColor,
|
|
69
|
-
border,
|
|
70
|
-
horizontalLineLength,
|
|
71
|
-
});
|
|
72
|
-
resolve();
|
|
73
|
-
}, finalDelay);
|
|
74
|
-
});
|
|
75
|
-
} catch (error) {
|
|
76
|
-
relinka("error", "Animation failed to complete.", error);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ColorName } from "../../types";
|
|
2
|
-
interface Options {
|
|
3
|
-
ctrlC?: number | false | "reject";
|
|
4
|
-
preserveLog?: boolean;
|
|
5
|
-
hideMessage?: boolean;
|
|
6
|
-
shouldStream?: boolean;
|
|
7
|
-
streamDelay?: number;
|
|
8
|
-
color?: ColorName;
|
|
9
|
-
placeholderColor?: ColorName;
|
|
10
|
-
}
|
|
11
|
-
export declare function anykeyPrompt(message?: string, options?: Options): Promise<void>;
|
|
12
|
-
export {};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import logUpdate from "log-update";
|
|
2
|
-
import { cursor } from "sisteransi";
|
|
3
|
-
import { fmt } from "../msg-fmt/messages.js";
|
|
4
|
-
import { outroPrompt } from "../outro/outro-mod.js";
|
|
5
|
-
import { streamText } from "../utils/stream-text.js";
|
|
6
|
-
const DEFAULT_MESSAGE = "Press any key to continue...";
|
|
7
|
-
const CTRL_C_CODE = 3;
|
|
8
|
-
const terminal = {
|
|
9
|
-
/**
|
|
10
|
-
* Move cursor to start of line
|
|
11
|
-
*/
|
|
12
|
-
moveToStart: () => process.stdout.write("\r"),
|
|
13
|
-
/**
|
|
14
|
-
* Clear current line and move cursor up
|
|
15
|
-
*/
|
|
16
|
-
clearLineAndMoveUp: () => process.stdout.write("\x1B[1A\x1B[2K"),
|
|
17
|
-
/**
|
|
18
|
-
* Clear multiple lines above current position
|
|
19
|
-
*/
|
|
20
|
-
clearLines: (count) => {
|
|
21
|
-
terminal.moveToStart();
|
|
22
|
-
process.stdout.write("\x1B[2K");
|
|
23
|
-
for (let i = 0; i < count; i++) {
|
|
24
|
-
terminal.clearLineAndMoveUp();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
export async function anykeyPrompt(message = DEFAULT_MESSAGE, options = {}) {
|
|
29
|
-
const {
|
|
30
|
-
ctrlC = 1,
|
|
31
|
-
preserveLog = false,
|
|
32
|
-
hideMessage = false,
|
|
33
|
-
shouldStream = false,
|
|
34
|
-
streamDelay = 20,
|
|
35
|
-
color = "dim",
|
|
36
|
-
placeholderColor = "gray"
|
|
37
|
-
} = options;
|
|
38
|
-
if (message) {
|
|
39
|
-
if (!shouldStream) {
|
|
40
|
-
const { text } = fmt({
|
|
41
|
-
hintPlaceholderColor: placeholderColor,
|
|
42
|
-
type: "M_GENERAL",
|
|
43
|
-
title: message,
|
|
44
|
-
titleColor: color,
|
|
45
|
-
dontRemoveBar: true
|
|
46
|
-
});
|
|
47
|
-
message = text;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (message && !hideMessage) {
|
|
51
|
-
if (shouldStream) {
|
|
52
|
-
await streamText({
|
|
53
|
-
text: `\u25C6 ${message}`,
|
|
54
|
-
delay: streamDelay,
|
|
55
|
-
newline: false,
|
|
56
|
-
clearLine: true,
|
|
57
|
-
color
|
|
58
|
-
});
|
|
59
|
-
const lineCount = message.split("\n").length;
|
|
60
|
-
terminal.clearLines(lineCount);
|
|
61
|
-
const { text } = fmt({
|
|
62
|
-
hintPlaceholderColor: placeholderColor,
|
|
63
|
-
type: "M_GENERAL",
|
|
64
|
-
title: message,
|
|
65
|
-
titleColor: color,
|
|
66
|
-
dontRemoveBar: true
|
|
67
|
-
});
|
|
68
|
-
terminal.moveToStart();
|
|
69
|
-
logUpdate(text);
|
|
70
|
-
} else {
|
|
71
|
-
logUpdate(message);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return new Promise((resolve, reject) => {
|
|
75
|
-
const cleanup = () => {
|
|
76
|
-
process.stdin.removeListener("data", handler);
|
|
77
|
-
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
78
|
-
process.stdin.setRawMode(false);
|
|
79
|
-
}
|
|
80
|
-
process.stdin.pause();
|
|
81
|
-
process.stdout.write(cursor.show);
|
|
82
|
-
};
|
|
83
|
-
const handleCtrlC = () => {
|
|
84
|
-
cleanup();
|
|
85
|
-
void outroPrompt({
|
|
86
|
-
title: "\u270B User pressed Ctrl+C, exiting...",
|
|
87
|
-
titleAnimation: "pulse",
|
|
88
|
-
titleColor: "redBright",
|
|
89
|
-
titleTypography: "bold",
|
|
90
|
-
endTitleColor: "redBright",
|
|
91
|
-
titleAnimationDelay: 400
|
|
92
|
-
}).then(() => {
|
|
93
|
-
if (ctrlC === "reject") {
|
|
94
|
-
reject(new Error("User pressed CTRL+C"));
|
|
95
|
-
} else if (ctrlC === false) {
|
|
96
|
-
resolve();
|
|
97
|
-
} else if (typeof ctrlC === "number") {
|
|
98
|
-
process.exit(0);
|
|
99
|
-
} else {
|
|
100
|
-
throw new TypeError("Invalid ctrlC option");
|
|
101
|
-
}
|
|
102
|
-
}).catch(reject);
|
|
103
|
-
};
|
|
104
|
-
const handler = (buffer) => {
|
|
105
|
-
cleanup();
|
|
106
|
-
if (message && !preserveLog) {
|
|
107
|
-
logUpdate.clear();
|
|
108
|
-
} else {
|
|
109
|
-
logUpdate.done();
|
|
110
|
-
process.stdout.write("\n");
|
|
111
|
-
}
|
|
112
|
-
const [firstByte] = buffer;
|
|
113
|
-
if (firstByte === CTRL_C_CODE) {
|
|
114
|
-
handleCtrlC();
|
|
115
|
-
} else {
|
|
116
|
-
resolve();
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
process.stdin.resume();
|
|
120
|
-
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
121
|
-
process.stdin.setRawMode(true);
|
|
122
|
-
}
|
|
123
|
-
process.stdin.once("data", handler);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { Readable, Writable } from "node:stream";
|
|
2
|
-
/**
|
|
3
|
-
* Special value that indicates a cancelled operation
|
|
4
|
-
*/
|
|
5
|
-
export declare const CANCEL: unique symbol;
|
|
6
|
-
/**
|
|
7
|
-
* Type for the cancel value
|
|
8
|
-
*/
|
|
9
|
-
export type CancelValue = typeof CANCEL;
|
|
10
|
-
export declare const isWindows: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Sets raw mode on input stream
|
|
13
|
-
*/
|
|
14
|
-
export declare function setRawMode(input: Readable, value: boolean): void;
|
|
15
|
-
/**
|
|
16
|
-
* Gets the number of columns in the terminal
|
|
17
|
-
*/
|
|
18
|
-
export declare function getColumns(output: Writable): number;
|
|
19
|
-
interface BlockOptions {
|
|
20
|
-
input?: Readable;
|
|
21
|
-
output?: Writable;
|
|
22
|
-
overwrite?: boolean;
|
|
23
|
-
hideCursor?: boolean;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Creates a block for handling input with proper cursor and cleanup
|
|
27
|
-
*/
|
|
28
|
-
export declare function block({ input, output, overwrite, hideCursor, }?: BlockOptions): () => void;
|
|
29
|
-
/**
|
|
30
|
-
* Checks if a value represents a cancelled operation
|
|
31
|
-
* @param value - The value to check
|
|
32
|
-
* @returns true if the value represents a cancelled operation
|
|
33
|
-
*/
|
|
34
|
-
export declare function isCancel(value: unknown): value is CancelValue;
|
|
35
|
-
/**
|
|
36
|
-
* Handles cancellation of an operation
|
|
37
|
-
* @param message - Optional message to display before exiting
|
|
38
|
-
*/
|
|
39
|
-
export declare function cancel(message?: string): never;
|
|
40
|
-
/**
|
|
41
|
-
* Creates a cancel value that can be returned from operations
|
|
42
|
-
* @returns The cancel value
|
|
43
|
-
*/
|
|
44
|
-
export declare function createCancel(): CancelValue;
|
|
45
|
-
export {};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { stdin, stdout } from "node:process";
|
|
2
|
-
import * as readline from "node:readline";
|
|
3
|
-
import { ReadStream, WriteStream } from "node:tty";
|
|
4
|
-
import { cursor } from "sisteransi";
|
|
5
|
-
export const CANCEL = Symbol("CANCEL");
|
|
6
|
-
export const isWindows = globalThis.process.platform.startsWith("win");
|
|
7
|
-
export function setRawMode(input, value) {
|
|
8
|
-
const i = input;
|
|
9
|
-
if (i.isTTY) i.setRawMode(value);
|
|
10
|
-
}
|
|
11
|
-
export function getColumns(output) {
|
|
12
|
-
if (output instanceof WriteStream && output.columns) {
|
|
13
|
-
return output.columns;
|
|
14
|
-
}
|
|
15
|
-
return 80;
|
|
16
|
-
}
|
|
17
|
-
export function block({
|
|
18
|
-
input = stdin,
|
|
19
|
-
output = stdout,
|
|
20
|
-
overwrite = true,
|
|
21
|
-
hideCursor = true
|
|
22
|
-
} = {}) {
|
|
23
|
-
const rl = readline.createInterface({
|
|
24
|
-
input,
|
|
25
|
-
output,
|
|
26
|
-
prompt: "",
|
|
27
|
-
tabSize: 1
|
|
28
|
-
});
|
|
29
|
-
readline.emitKeypressEvents(input, rl);
|
|
30
|
-
if (input instanceof ReadStream && input.isTTY) {
|
|
31
|
-
input.setRawMode(true);
|
|
32
|
-
}
|
|
33
|
-
const clear = (data, { name, sequence }) => {
|
|
34
|
-
const str = String(data);
|
|
35
|
-
if (str === "" || name === "c" && sequence === "") {
|
|
36
|
-
if (hideCursor) output.write(cursor.show);
|
|
37
|
-
process.exit(0);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (!overwrite) return;
|
|
41
|
-
const dx = name === "return" ? 0 : -1;
|
|
42
|
-
const dy = name === "return" ? -1 : 0;
|
|
43
|
-
readline.moveCursor(output, dx, dy, () => {
|
|
44
|
-
readline.clearLine(output, 1, () => {
|
|
45
|
-
input.once("keypress", clear);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
if (hideCursor) output.write(cursor.hide);
|
|
50
|
-
input.once("keypress", clear);
|
|
51
|
-
return () => {
|
|
52
|
-
input.off("keypress", clear);
|
|
53
|
-
if (hideCursor) output.write(cursor.show);
|
|
54
|
-
if (input instanceof ReadStream && input.isTTY && !isWindows) {
|
|
55
|
-
input.setRawMode(false);
|
|
56
|
-
}
|
|
57
|
-
rl.terminal = false;
|
|
58
|
-
rl.close();
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
export function isCancel(value) {
|
|
62
|
-
return value === CANCEL;
|
|
63
|
-
}
|
|
64
|
-
export function cancel(message) {
|
|
65
|
-
if (message) {
|
|
66
|
-
console.log(message);
|
|
67
|
-
}
|
|
68
|
-
process.exit(0);
|
|
69
|
-
}
|
|
70
|
-
export function createCancel() {
|
|
71
|
-
return CANCEL;
|
|
72
|
-
}
|