@reliverse/relinka 1.1.7 → 1.1.8
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-npm/components/anykey/index.js +57 -77
- package/dist-npm/components/block/block.js +48 -61
- package/dist-npm/components/checkbox/index.js +178 -211
- package/dist-npm/components/confirm/confirm-main.js +85 -122
- package/dist-npm/components/confirm/confirm-three.js +24 -27
- package/dist-npm/components/confirm/index.js +36 -45
- package/dist-npm/components/core/Separator.js +15 -17
- package/dist-npm/components/core/create-prompt.js +101 -124
- package/dist-npm/components/core/errors.js +19 -15
- package/dist-npm/components/core/hook-engine.js +91 -120
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +16 -6
- package/dist-npm/components/core/lines.js +45 -54
- package/dist-npm/components/core/make-theme.js +21 -30
- package/dist-npm/components/core/position.js +27 -23
- package/dist-npm/components/core/promise-polyfill.js +11 -14
- package/dist-npm/components/core/screen-manager.js +59 -74
- package/dist-npm/components/core/theme.js +22 -32
- package/dist-npm/components/core/use-effect.js +9 -15
- package/dist-npm/components/core/use-keypress.js +19 -23
- package/dist-npm/components/core/use-memo.js +10 -16
- package/dist-npm/components/core/use-pagination.js +33 -32
- package/dist-npm/components/core/use-prefix.js +40 -38
- package/dist-npm/components/core/use-ref.js +2 -5
- package/dist-npm/components/core/use-state.js +15 -23
- package/dist-npm/components/core/useKeyPress.js +14 -17
- package/dist-npm/components/core/usePromptState.js +8 -14
- package/dist-npm/components/core/utils.js +7 -16
- package/dist-npm/components/date/date.js +173 -204
- package/dist-npm/components/editor/index.js +71 -92
- package/dist-npm/components/expand/index.js +96 -124
- package/dist-npm/components/figures/index.js +283 -294
- package/dist-npm/components/input/index.js +61 -87
- package/dist-npm/components/input/text-main.js +97 -124
- package/dist-npm/components/input/text.js +24 -28
- package/dist-npm/components/instance/basic.js +17 -25
- package/dist-npm/components/instance/browser.js +14 -18
- package/dist-npm/components/instance/reporter/basic.js +46 -65
- package/dist-npm/components/instance/reporter/browser.js +44 -47
- package/dist-npm/components/instance/reporter/fancy.js +83 -96
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +52 -62
- package/dist-npm/components/mono/monoTwo.js +35 -49
- package/dist-npm/components/multiselect/group-multiselect.js +55 -71
- package/dist-npm/components/multiselect/multi-select-two.js +97 -130
- package/dist-npm/components/multiselect/multi-select.js +43 -49
- package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
- package/dist-npm/components/multiselect/multiselect-main.js +158 -145
- package/dist-npm/components/multiselect/num-multi-select.js +97 -130
- package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
- package/dist-npm/components/next-steps/next-steps.js +23 -25
- package/dist-npm/components/number/index.js +78 -112
- package/dist-npm/components/number/number-main.js +95 -2
- package/dist-npm/components/password/index.js +54 -73
- package/dist-npm/components/password/password-main.js +119 -2
- package/dist-npm/components/password/password-three.js +26 -30
- package/dist-npm/components/progressbar/ProgressBar.js +45 -64
- package/dist-npm/components/progressbar/helper.js +33 -40
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +29 -44
- package/dist-npm/components/prompts/index.d.ts +1 -0
- package/dist-npm/components/prompts/index.js +46 -45
- package/dist-npm/components/prompts/prompt.js +211 -260
- package/dist-npm/components/prompts/promptTwo.js +561 -605
- package/dist-npm/components/prompts/relinka.js +237 -295
- package/dist-npm/components/range/range.js +247 -294
- package/dist-npm/components/rawlist/index.js +87 -107
- package/dist-npm/components/results/results.js +31 -37
- package/dist-npm/components/search/index.js +148 -193
- package/dist-npm/components/select/index.js +148 -186
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +124 -5
- package/dist-npm/components/select/select-key.js +24 -25
- package/dist-npm/components/select/select-main.d.ts +1 -0
- package/dist-npm/components/select/select-main.js +143 -133
- package/dist-npm/components/select/select-three.js +32 -36
- package/dist-npm/components/select/select-two.js +94 -87
- package/dist-npm/components/spinner/index.js +107 -136
- package/dist-npm/components/st-end/end.js +34 -26
- package/dist-npm/components/st-end/start.js +29 -15
- package/dist-npm/components/toggle/index.js +113 -137
- package/dist-npm/components/visual/animate/animate.js +53 -10
- package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
- package/dist-npm/main.js +1 -0
- package/dist-npm/testing/index.js +58 -83
- package/dist-npm/types/general.d.ts +1 -1
- package/dist-npm/types/general.js +0 -1
- package/dist-npm/types/index.js +2 -3
- package/dist-npm/types/keypress.js +35 -36
- package/dist-npm/types/readline.js +0 -1
- package/dist-npm/types/relinka.js +0 -1
- package/dist-npm/types/utils.js +0 -1
- package/dist-npm/utils/box.js +135 -137
- package/dist-npm/utils/color.js +65 -74
- package/dist-npm/utils/colorize.js +124 -156
- package/dist-npm/utils/component.js +532 -657
- package/dist-npm/utils/constants.js +64 -63
- package/dist-npm/utils/core.js +2 -3
- package/dist-npm/utils/decoder.js +244 -223
- package/dist-npm/utils/error.js +4 -9
- package/dist-npm/utils/errors.js +14 -4
- package/dist-npm/utils/format.js +19 -24
- package/dist-npm/utils/keypress.js +316 -414
- package/dist-npm/utils/log.js +11 -15
- package/dist-npm/utils/mapping.js +45 -52
- package/dist-npm/utils/messages.js +196 -183
- package/dist-npm/utils/platforms.js +16 -20
- package/dist-npm/utils/prompt-tmp.js +235 -286
- package/dist-npm/utils/prompt-two.js +235 -286
- package/dist-npm/utils/readline.js +5 -7
- package/dist-npm/utils/skeleton.js +130 -170
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +44 -58
- package/dist-npm/utils/terminal.js +23 -34
- package/dist-npm/utils/tree.js +30 -41
- package/dist-npm/utils/types.js +0 -1
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +36 -44
- package/package.json +14 -14
- package/dist-npm/mod.js +0 -2
- /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
|
@@ -1,78 +1,59 @@
|
|
|
1
|
-
import ansiEscapes from
|
|
1
|
+
import ansiEscapes from "ansi-escapes";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from
|
|
10
|
-
|
|
11
|
-
const isString = (a) => typeof a === 'string';
|
|
12
|
-
|
|
3
|
+
createPrompt,
|
|
4
|
+
useState,
|
|
5
|
+
useKeypress,
|
|
6
|
+
usePrefix,
|
|
7
|
+
isEnterKey,
|
|
8
|
+
makeTheme
|
|
9
|
+
} from "../../components/core/index.js";
|
|
13
10
|
export default createPrompt((config, done) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
useKeypress(async (key, rl) => {
|
|
25
|
-
if (status !== 'idle') {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (isEnterKey(key)) {
|
|
30
|
-
const answer = value;
|
|
31
|
-
setStatus('loading');
|
|
32
|
-
const isValid = await validate(answer);
|
|
33
|
-
|
|
34
|
-
if (isValid) {
|
|
35
|
-
setValue(answer);
|
|
36
|
-
setStatus('done');
|
|
37
|
-
done(answer);
|
|
38
|
-
} else {
|
|
39
|
-
rl.write(value);
|
|
40
|
-
setError(isValid || 'You must provide a valid value');
|
|
41
|
-
setStatus('idle');
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
setValue(rl.line);
|
|
45
|
-
setError(void 0);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
const message = theme.style.message(config.message, status);
|
|
49
|
-
let formattedValue = '';
|
|
50
|
-
let helpTip;
|
|
51
|
-
|
|
52
|
-
if (config.mask) {
|
|
53
|
-
const maskChar = isString(config.mask) ? config.mask : '*';
|
|
54
|
-
formattedValue = maskChar.repeat(value.length);
|
|
55
|
-
} else if (status !== 'done') {
|
|
56
|
-
helpTip = `${theme.style.help('[input is masked]')}${ansiEscapes.cursorHide}`;
|
|
11
|
+
const { validate = () => true } = config;
|
|
12
|
+
const theme = makeTheme(config.theme);
|
|
13
|
+
const [status, setStatus] = useState("idle");
|
|
14
|
+
const [errorMsg, setError] = useState();
|
|
15
|
+
const [value, setValue] = useState("");
|
|
16
|
+
const prefix = usePrefix({ status, theme });
|
|
17
|
+
useKeypress(async (key, rl) => {
|
|
18
|
+
if (status !== "idle") {
|
|
19
|
+
return;
|
|
57
20
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
21
|
+
if (isEnterKey(key)) {
|
|
22
|
+
const answer = value;
|
|
23
|
+
setStatus("loading");
|
|
24
|
+
const isValid = await validate(answer);
|
|
25
|
+
if (isValid === true) {
|
|
26
|
+
setValue(answer);
|
|
27
|
+
setStatus("done");
|
|
28
|
+
done(answer);
|
|
29
|
+
} else {
|
|
30
|
+
rl.write(value);
|
|
31
|
+
setError(isValid || "You must provide a valid value");
|
|
32
|
+
setStatus("idle");
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
setValue(rl.line);
|
|
36
|
+
setError(void 0);
|
|
62
37
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
38
|
+
});
|
|
39
|
+
const message = theme.style.message(config.message, status);
|
|
40
|
+
let formattedValue = "";
|
|
41
|
+
let helpTip;
|
|
42
|
+
if (config.mask) {
|
|
43
|
+
const maskChar = typeof config.mask === "string" ? config.mask : "*";
|
|
44
|
+
formattedValue = maskChar.repeat(value.length);
|
|
45
|
+
} else if (status !== "done") {
|
|
46
|
+
helpTip = `${theme.style.help("[input is masked]")}${ansiEscapes.cursorHide}`;
|
|
47
|
+
}
|
|
48
|
+
if (status === "done") {
|
|
49
|
+
formattedValue = theme.style.answer(formattedValue);
|
|
50
|
+
}
|
|
51
|
+
let error = "";
|
|
52
|
+
if (errorMsg) {
|
|
53
|
+
error = theme.style.error(errorMsg);
|
|
54
|
+
}
|
|
55
|
+
return [
|
|
56
|
+
[prefix, message, config.mask ? formattedValue : helpTip].join(" "),
|
|
57
|
+
error
|
|
58
|
+
];
|
|
78
59
|
});
|
|
@@ -1,2 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Value } from "@sinclair/typebox/value";
|
|
2
|
+
import { bar, fmt } from "../../utils/messages.js";
|
|
3
|
+
import {
|
|
4
|
+
countLines,
|
|
5
|
+
deleteLastLines
|
|
6
|
+
} from "../../utils/terminal.js";
|
|
7
|
+
export async function passwordPrompt(options) {
|
|
8
|
+
const {
|
|
9
|
+
title,
|
|
10
|
+
hint,
|
|
11
|
+
validate,
|
|
12
|
+
schema,
|
|
13
|
+
defaultValue,
|
|
14
|
+
titleColor = "cyanBright",
|
|
15
|
+
titleTypography = "bold",
|
|
16
|
+
titleVariant,
|
|
17
|
+
content,
|
|
18
|
+
contentColor,
|
|
19
|
+
contentTypography,
|
|
20
|
+
contentVariant,
|
|
21
|
+
borderColor = "viceGradient",
|
|
22
|
+
variantOptions
|
|
23
|
+
} = options;
|
|
24
|
+
let linesToDelete = 0;
|
|
25
|
+
let errorMessage = "";
|
|
26
|
+
while (true) {
|
|
27
|
+
const question = fmt({
|
|
28
|
+
type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
|
|
29
|
+
title: `${title}${defaultValue ? ` [Default: ****]` : ""}`,
|
|
30
|
+
titleColor,
|
|
31
|
+
titleTypography,
|
|
32
|
+
titleVariant,
|
|
33
|
+
content,
|
|
34
|
+
contentColor,
|
|
35
|
+
contentTypography,
|
|
36
|
+
contentVariant,
|
|
37
|
+
borderColor,
|
|
38
|
+
hint,
|
|
39
|
+
variantOptions,
|
|
40
|
+
errorMessage
|
|
41
|
+
});
|
|
42
|
+
const questionLines = countLines(question);
|
|
43
|
+
if (linesToDelete > 0) {
|
|
44
|
+
deleteLastLines(linesToDelete);
|
|
45
|
+
}
|
|
46
|
+
process.stdout.write(question);
|
|
47
|
+
const password = await readPassword(borderColor);
|
|
48
|
+
linesToDelete = questionLines + 1;
|
|
49
|
+
const formattedBar = bar({ borderColor });
|
|
50
|
+
if (!password.trim() && defaultValue !== void 0) {
|
|
51
|
+
deleteLastLines(2);
|
|
52
|
+
process.stdout.write(`${formattedBar} ****`);
|
|
53
|
+
console.log(`
|
|
54
|
+
${formattedBar}`);
|
|
55
|
+
return defaultValue;
|
|
56
|
+
}
|
|
57
|
+
let isValid = true;
|
|
58
|
+
errorMessage = "";
|
|
59
|
+
if (schema) {
|
|
60
|
+
isValid = Value.Check(schema, password);
|
|
61
|
+
if (!isValid) {
|
|
62
|
+
const errors = [...Value.Errors(schema, password)];
|
|
63
|
+
if (errors.length > 0) {
|
|
64
|
+
errorMessage = errors[0]?.message ?? "Invalid input.";
|
|
65
|
+
} else {
|
|
66
|
+
errorMessage = "Invalid input.";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (validate && isValid) {
|
|
71
|
+
const validation = await validate(password);
|
|
72
|
+
if (validation !== true) {
|
|
73
|
+
isValid = false;
|
|
74
|
+
errorMessage = typeof validation === "string" ? validation : "Invalid input.";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (isValid) {
|
|
78
|
+
process.stdout.write("\n");
|
|
79
|
+
return password;
|
|
80
|
+
} else {
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function readPassword(borderColor) {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const stdin = process.stdin;
|
|
87
|
+
let password = "";
|
|
88
|
+
const formattedBar = bar({ borderColor });
|
|
89
|
+
stdin.setRawMode(true);
|
|
90
|
+
stdin.resume();
|
|
91
|
+
stdin.setEncoding("utf8");
|
|
92
|
+
const onData = function(char) {
|
|
93
|
+
char = char.toString();
|
|
94
|
+
if (char === "\n" || char === "\r" || char === "") {
|
|
95
|
+
stdin.setRawMode(false);
|
|
96
|
+
stdin.pause();
|
|
97
|
+
stdin.removeListener("data", onData);
|
|
98
|
+
process.stdout.write(`
|
|
99
|
+
${formattedBar}`);
|
|
100
|
+
resolve(password.trim());
|
|
101
|
+
} else if (char === "") {
|
|
102
|
+
stdin.setRawMode(false);
|
|
103
|
+
stdin.pause();
|
|
104
|
+
stdin.removeListener("data", onData);
|
|
105
|
+
reject(new Error("User aborted."));
|
|
106
|
+
} else if (char === "\x7F" ||
|
|
107
|
+
char === "\b" || char === "\x7F" || char === "\b") {
|
|
108
|
+
if (password.length > 0) {
|
|
109
|
+
password = password.slice(0, -1);
|
|
110
|
+
process.stdout.write("\b \b");
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
password += char;
|
|
114
|
+
process.stdout.write("*");
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
stdin.on("data", onData);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
import color from
|
|
2
|
-
import Prompt from
|
|
3
|
-
|
|
1
|
+
import color from "picocolors";
|
|
2
|
+
import Prompt from "../../components/prompts/prompt.js";
|
|
4
3
|
export default class PasswordPrompt extends Prompt {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
4
|
+
valueWithCursor = "";
|
|
5
|
+
_mask = "\u2022";
|
|
6
|
+
get cursor() {
|
|
7
|
+
return this._cursor;
|
|
8
|
+
}
|
|
9
|
+
get masked() {
|
|
10
|
+
return this.value.replaceAll(/./g, this._mask);
|
|
11
|
+
}
|
|
12
|
+
constructor({ mask, ...opts }) {
|
|
13
|
+
super(opts);
|
|
14
|
+
this._mask = mask ?? "\u2022";
|
|
15
|
+
this.on("finalize", () => {
|
|
16
|
+
this.valueWithCursor = this.masked;
|
|
17
|
+
});
|
|
18
|
+
this.on("value", () => {
|
|
19
|
+
if (this.cursor >= this.value.length) {
|
|
20
|
+
this.valueWithCursor = `${this.masked}${color.inverse(color.hidden("_"))}`;
|
|
21
|
+
} else {
|
|
22
|
+
const s1 = this.masked.slice(0, this.cursor);
|
|
23
|
+
const s2 = this.masked.slice(this.cursor);
|
|
24
|
+
this.valueWithCursor = `${s1}${color.inverse(s2[0])}${s2.slice(1)}`;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
32
28
|
}
|
|
@@ -1,72 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
green,
|
|
3
|
-
greenBright,
|
|
4
|
-
red,
|
|
5
|
-
} from 'picocolors';
|
|
6
|
-
import process from 'node:process';
|
|
7
|
-
|
|
1
|
+
import { green, greenBright, red } from "picocolors";
|
|
8
2
|
export class ProgressBar {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
this.total = options.total;
|
|
23
|
-
this.current = 0;
|
|
24
|
-
this.width = options.width || 40;
|
|
25
|
-
this.completeChar = options.completeChar || '\u2588';
|
|
26
|
-
this.incompleteChar = options.incompleteChar || '\u2591';
|
|
27
|
-
this.startTime = Date.now();
|
|
28
|
-
this.format = options.format || 'Progress: [:bar] :percent% | Elapsed: :elapsed s';
|
|
29
|
-
this.colorize = options.colorize || false;
|
|
3
|
+
total;
|
|
4
|
+
current;
|
|
5
|
+
width;
|
|
6
|
+
completeChar;
|
|
7
|
+
incompleteChar;
|
|
8
|
+
startTime;
|
|
9
|
+
format;
|
|
10
|
+
colorize;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
if (options.total <= 0) {
|
|
13
|
+
throw new Error("Total must be a positive number");
|
|
30
14
|
}
|
|
31
|
-
|
|
15
|
+
this.total = options.total;
|
|
16
|
+
this.current = 0;
|
|
17
|
+
this.width = options.width || 40;
|
|
18
|
+
this.completeChar = options.completeChar || "\u2588";
|
|
19
|
+
this.incompleteChar = options.incompleteChar || "\u2591";
|
|
20
|
+
this.startTime = Date.now();
|
|
21
|
+
this.format = options.format || "Progress: [:bar] :percent% | Elapsed: :elapsed s";
|
|
22
|
+
this.colorize = options.colorize || false;
|
|
23
|
+
}
|
|
32
24
|
update(value) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.render();
|
|
38
|
-
}
|
|
25
|
+
const newValue = Math.min(value, this.total);
|
|
26
|
+
if (newValue !== this.current) {
|
|
27
|
+
this.current = newValue;
|
|
28
|
+
this.render();
|
|
39
29
|
}
|
|
40
|
-
|
|
30
|
+
}
|
|
41
31
|
increment(amount = 1) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
this.update(this.current + amount);
|
|
33
|
+
}
|
|
45
34
|
render() {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
.replace(':elapsed', elapsed)
|
|
63
|
-
.replace(':eta', eta);
|
|
64
|
-
|
|
65
|
-
process.stdout.clearLine(0);
|
|
66
|
-
process.stdout.cursorTo(0);
|
|
67
|
-
process.stdout.write(greenBright('\u25C6') + ' ' + output);
|
|
68
|
-
if (this.current >= this.total) {
|
|
69
|
-
process.stdout.write('\n');
|
|
70
|
-
}
|
|
35
|
+
const percent = this.current / this.total;
|
|
36
|
+
const filledLength = Math.round(this.width * percent);
|
|
37
|
+
const emptyLength = this.width - filledLength;
|
|
38
|
+
let bar = this.completeChar.repeat(filledLength) + this.incompleteChar.repeat(emptyLength);
|
|
39
|
+
if (this.colorize) {
|
|
40
|
+
bar = green(this.completeChar.repeat(filledLength)) + red(this.incompleteChar.repeat(emptyLength));
|
|
41
|
+
}
|
|
42
|
+
const percentage = (percent * 100).toFixed(2);
|
|
43
|
+
const elapsed = ((Date.now() - this.startTime) / 1e3).toFixed(2);
|
|
44
|
+
const eta = percent > 0 ? ((Date.now() - this.startTime) / percent / 1e3).toFixed(2) : "N/A";
|
|
45
|
+
const output = this.format.replace(":bar", bar).replace(":percent", percentage).replace(":elapsed", elapsed).replace(":eta", eta);
|
|
46
|
+
process.stdout.clearLine(0);
|
|
47
|
+
process.stdout.cursorTo(0);
|
|
48
|
+
process.stdout.write(greenBright("\u25C6") + " " + output);
|
|
49
|
+
if (this.current >= this.total) {
|
|
50
|
+
process.stdout.write("\n");
|
|
71
51
|
}
|
|
52
|
+
}
|
|
72
53
|
}
|
|
@@ -1,45 +1,38 @@
|
|
|
1
|
-
import {msg} from
|
|
2
|
-
import {ProgressBar} from
|
|
3
|
-
|
|
1
|
+
import { msg } from "../../utils/messages.js";
|
|
2
|
+
import { ProgressBar } from "./ProgressBar.js";
|
|
4
3
|
export async function progressbar(options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
const {
|
|
5
|
+
total,
|
|
6
|
+
increment = 1,
|
|
7
|
+
desiredTotalTime = 3e3,
|
|
8
|
+
...progressBarOptions
|
|
9
|
+
} = options;
|
|
10
|
+
if (increment <= 0) {
|
|
11
|
+
throw new Error("Increment must be a positive number");
|
|
12
|
+
}
|
|
13
|
+
const iterations = Math.ceil(total / increment) + 1;
|
|
14
|
+
const delay = desiredTotalTime / iterations;
|
|
15
|
+
const progressBar = new ProgressBar({
|
|
16
|
+
total,
|
|
17
|
+
...progressBarOptions
|
|
18
|
+
});
|
|
19
|
+
try {
|
|
20
|
+
for (let i = 0; i <= total; i += increment) {
|
|
21
|
+
progressBar.update(i);
|
|
22
|
+
await sleep(delay);
|
|
14
23
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
progressBar.update(i);
|
|
27
|
-
await sleep(delay);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (total % increment) {
|
|
31
|
-
progressBar.update(total);
|
|
32
|
-
}
|
|
33
|
-
} catch(error) {}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
msg({
|
|
37
|
-
type: 'M_MIDDLE',
|
|
38
|
-
title: '',
|
|
39
|
-
borderColor: 'viceGradient',
|
|
40
|
-
});
|
|
24
|
+
if (total % increment !== 0) {
|
|
25
|
+
progressBar.update(total);
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error("Progress bar encountered an error:", error);
|
|
29
|
+
}
|
|
30
|
+
msg({
|
|
31
|
+
type: "M_MIDDLE",
|
|
32
|
+
title: "",
|
|
33
|
+
borderColor: "viceGradient"
|
|
34
|
+
});
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
function sleep(ms) {
|
|
44
|
-
|
|
37
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
45
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {progressbar} from
|
|
1
|
+
export { progressbar } from "./helper.js";
|
|
@@ -1,50 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from
|
|
6
|
-
|
|
7
|
-
import {LogLevels} from '../../utils/constants.js';
|
|
8
|
-
import {BasicReporter} from '../instance/reporter/basic.js';
|
|
9
|
-
import {FancyReporter} from '../instance/reporter/fancy.js';
|
|
10
|
-
import {createRelinka as _createRelinka} from './relinka.js';
|
|
11
|
-
|
|
12
|
-
export * from '../instance/shared.js';
|
|
1
|
+
import { isDebug, isTest, isCI } from "std-env";
|
|
2
|
+
import { LogLevels } from "../../utils/constants.js";
|
|
3
|
+
import { BasicReporter } from "../instance/reporter/basic.js";
|
|
4
|
+
import { FancyReporter } from "../instance/reporter/fancy.js";
|
|
5
|
+
import { createRelinka as _createRelinka } from "./relinka.js";
|
|
6
|
+
export * from "../instance/shared.js";
|
|
13
7
|
export function createRelinka(options = {}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
],
|
|
31
|
-
...options,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
return relinka2;
|
|
8
|
+
let level = _getDefaultLogLevel();
|
|
9
|
+
if (process.env.RELINKA_LEVEL) {
|
|
10
|
+
level = Number.parseInt(process.env.RELINKA_LEVEL) ?? level;
|
|
11
|
+
}
|
|
12
|
+
const relinka2 = _createRelinka({
|
|
13
|
+
level,
|
|
14
|
+
defaults: { level },
|
|
15
|
+
stdout: process.stdout,
|
|
16
|
+
stderr: process.stderr,
|
|
17
|
+
prompt: (...args) => import("../../components/mono/monoTwo.js").then((m) => m.prompt(...args)),
|
|
18
|
+
reporters: options.reporters || [
|
|
19
|
+
options.fancy ?? !(isCI || isTest) ? new FancyReporter() : new BasicReporter()
|
|
20
|
+
],
|
|
21
|
+
...options
|
|
22
|
+
});
|
|
23
|
+
return relinka2;
|
|
35
24
|
}
|
|
36
|
-
|
|
37
25
|
function _getDefaultLogLevel() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return LogLevels.info;
|
|
26
|
+
if (isDebug) {
|
|
27
|
+
return LogLevels.debug;
|
|
28
|
+
}
|
|
29
|
+
if (isTest) {
|
|
30
|
+
return LogLevels.warn;
|
|
31
|
+
}
|
|
32
|
+
return LogLevels.info;
|
|
47
33
|
}
|
|
48
|
-
|
|
49
34
|
export const relinka = createRelinka();
|
|
50
35
|
export default relinka;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type { ColorName } from "../../types/general.js";
|
|
2
2
|
export type { ChoiceOptions } from "../../types/general.js";
|
|
3
3
|
export type { OptionalPromptOptions } from "../../types/general.js";
|
|
4
|
+
export { deleteLastLine, deleteLastLines, countLines, removeCursor, restoreCursor } from "../../utils/terminal.js";
|
|
4
5
|
export { colorize } from "../../utils/colorize.js";
|
|
5
6
|
export { fmt, msg } from "../../utils/messages.js";
|
|
6
7
|
export { errorHandler } from "../../utils/errors.js";
|