@reliverse/relinka 1.1.7 → 1.1.9
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 +187 -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,92 +1,66 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from
|
|
10
|
-
|
|
11
|
-
const isFn = (a) => typeof a === 'function';
|
|
12
|
-
|
|
2
|
+
createPrompt,
|
|
3
|
+
useState,
|
|
4
|
+
useKeypress,
|
|
5
|
+
usePrefix,
|
|
6
|
+
isEnterKey,
|
|
7
|
+
isBackspaceKey,
|
|
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
|
-
|
|
25
|
-
useKeypress(async (key, rl) => {
|
|
26
|
-
if (status !== 'idle') {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (isEnterKey(key)) {
|
|
31
|
-
const answer = value || defaultValue;
|
|
32
|
-
setStatus('loading');
|
|
33
|
-
const isValid = required && !answer ? 'You must provide a value' : await validate(answer);
|
|
34
|
-
|
|
35
|
-
if (isValid) {
|
|
36
|
-
setValue(answer);
|
|
37
|
-
setStatus('done');
|
|
38
|
-
done(answer);
|
|
39
|
-
} else {
|
|
40
|
-
rl.write(value);
|
|
41
|
-
setError(isValid || 'You must provide a valid value');
|
|
42
|
-
setStatus('idle');
|
|
43
|
-
}
|
|
44
|
-
} else if (isBackspaceKey(key) && !value) {
|
|
45
|
-
setDefaultValue(void 0);
|
|
46
|
-
} else if (key.name === 'tab' && !value) {
|
|
47
|
-
setDefaultValue(void 0);
|
|
48
|
-
rl.clearLine(0);
|
|
49
|
-
rl.write(defaultValue);
|
|
50
|
-
setValue(defaultValue);
|
|
51
|
-
} else {
|
|
52
|
-
setValue(rl.line);
|
|
53
|
-
setError(void 0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
const message = theme.style.message(config.message, status);
|
|
58
|
-
let formattedValue = value;
|
|
59
|
-
|
|
60
|
-
if (isFn(config.transformer)) {
|
|
61
|
-
formattedValue = config.transformer(value, {
|
|
62
|
-
isFinal: status === 'done',
|
|
63
|
-
});
|
|
64
|
-
} else if (status === 'done') {
|
|
65
|
-
formattedValue = theme.style.answer(value);
|
|
11
|
+
const { required, validate = () => true } = config;
|
|
12
|
+
const theme = makeTheme(config.theme);
|
|
13
|
+
const [status, setStatus] = useState("idle");
|
|
14
|
+
const [defaultValue = "", setDefaultValue] = useState(config.default);
|
|
15
|
+
const [errorMsg, setError] = useState();
|
|
16
|
+
const [value, setValue] = useState("");
|
|
17
|
+
const prefix = usePrefix({ status, theme });
|
|
18
|
+
useKeypress(async (key, rl) => {
|
|
19
|
+
if (status !== "idle") {
|
|
20
|
+
return;
|
|
66
21
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
22
|
+
if (isEnterKey(key)) {
|
|
23
|
+
const answer = value || defaultValue;
|
|
24
|
+
setStatus("loading");
|
|
25
|
+
const isValid = required && !answer ? "You must provide a value" : await validate(answer);
|
|
26
|
+
if (isValid === true) {
|
|
27
|
+
setValue(answer);
|
|
28
|
+
setStatus("done");
|
|
29
|
+
done(answer);
|
|
30
|
+
} else {
|
|
31
|
+
rl.write(value);
|
|
32
|
+
setError(isValid || "You must provide a valid value");
|
|
33
|
+
setStatus("idle");
|
|
34
|
+
}
|
|
35
|
+
} else if (isBackspaceKey(key) && !value) {
|
|
36
|
+
setDefaultValue(void 0);
|
|
37
|
+
} else if (key.name === "tab" && !value) {
|
|
38
|
+
setDefaultValue(void 0);
|
|
39
|
+
rl.clearLine(0);
|
|
40
|
+
rl.write(defaultValue);
|
|
41
|
+
setValue(defaultValue);
|
|
42
|
+
} else {
|
|
43
|
+
setValue(rl.line);
|
|
44
|
+
setError(void 0);
|
|
73
45
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
]
|
|
46
|
+
});
|
|
47
|
+
const message = theme.style.message(config.message, status);
|
|
48
|
+
let formattedValue = value;
|
|
49
|
+
if (typeof config.transformer === "function") {
|
|
50
|
+
formattedValue = config.transformer(value, { isFinal: status === "done" });
|
|
51
|
+
} else if (status === "done") {
|
|
52
|
+
formattedValue = theme.style.answer(value);
|
|
53
|
+
}
|
|
54
|
+
let defaultStr;
|
|
55
|
+
if (defaultValue && status !== "done" && !value) {
|
|
56
|
+
defaultStr = theme.style.defaultAnswer(defaultValue);
|
|
57
|
+
}
|
|
58
|
+
let error = "";
|
|
59
|
+
if (errorMsg) {
|
|
60
|
+
error = theme.style.error(errorMsg);
|
|
61
|
+
}
|
|
62
|
+
return [
|
|
63
|
+
[prefix, message, defaultStr, formattedValue].filter((v) => v !== void 0).join(" "),
|
|
64
|
+
error
|
|
65
|
+
];
|
|
92
66
|
});
|
|
@@ -1,130 +1,103 @@
|
|
|
1
|
-
import {Value} from
|
|
1
|
+
import { Value } from "@sinclair/typebox/value";
|
|
2
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
3
|
+
import readline from "node:readline/promises";
|
|
4
|
+
import { fmt, msg } from "../../utils/messages.js";
|
|
2
5
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {fmt, msg} from '../../utils/messages.js';
|
|
8
|
-
import {
|
|
9
|
-
countLines,
|
|
10
|
-
deleteLastLine,
|
|
11
|
-
deleteLastLines,
|
|
12
|
-
} from '../../utils/terminal.js';
|
|
13
|
-
|
|
14
|
-
const isString = (a) => typeof a === 'string';
|
|
15
|
-
|
|
6
|
+
countLines,
|
|
7
|
+
deleteLastLine,
|
|
8
|
+
deleteLastLines
|
|
9
|
+
} from "../../utils/terminal.js";
|
|
16
10
|
export async function textPrompt(options) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
11
|
+
const {
|
|
12
|
+
title,
|
|
13
|
+
hint,
|
|
14
|
+
validate,
|
|
15
|
+
defaultValue = "",
|
|
16
|
+
schema,
|
|
17
|
+
titleColor = "cyanBright",
|
|
18
|
+
titleTypography = "bold",
|
|
19
|
+
titleVariant,
|
|
20
|
+
content,
|
|
21
|
+
contentColor,
|
|
22
|
+
contentTypography,
|
|
23
|
+
contentVariant,
|
|
24
|
+
borderColor = "viceGradient",
|
|
25
|
+
variantOptions,
|
|
26
|
+
placeholder
|
|
27
|
+
} = options;
|
|
28
|
+
const rl = readline.createInterface({ input, output });
|
|
29
|
+
let linesToDelete = 0;
|
|
30
|
+
let errorMessage = "";
|
|
31
|
+
let currentInput = "";
|
|
32
|
+
let showPlaceholder = true;
|
|
33
|
+
while (true) {
|
|
34
|
+
if (linesToDelete > 0) {
|
|
35
|
+
deleteLastLines(linesToDelete);
|
|
36
|
+
}
|
|
37
|
+
const question = fmt({
|
|
38
|
+
type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
|
|
39
|
+
title,
|
|
40
|
+
titleColor,
|
|
41
|
+
titleTypography,
|
|
42
|
+
titleVariant,
|
|
43
|
+
content,
|
|
44
|
+
contentColor,
|
|
45
|
+
contentTypography,
|
|
46
|
+
contentVariant,
|
|
47
|
+
borderColor,
|
|
48
|
+
hint,
|
|
49
|
+
placeholder: showPlaceholder ? placeholder : void 0,
|
|
50
|
+
variantOptions,
|
|
51
|
+
errorMessage
|
|
38
52
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
showPlaceholder = false;
|
|
72
|
-
deleteLastLine();
|
|
73
|
-
deleteLastLine();
|
|
74
|
-
msg({
|
|
75
|
-
type: 'M_MIDDLE',
|
|
76
|
-
title: ` ${currentInput}`,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
linesToDelete = questionLines + 1;
|
|
81
|
-
const answer = currentInput || defaultValue;
|
|
82
|
-
|
|
83
|
-
if (currentInput === '' && defaultValue !== '') {
|
|
84
|
-
deleteLastLine();
|
|
85
|
-
deleteLastLine();
|
|
86
|
-
const defaultMsg = fmt({
|
|
87
|
-
type: 'M_MIDDLE',
|
|
88
|
-
title: ` ${defaultValue}`,
|
|
89
|
-
borderColor,
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
linesToDelete += countLines(defaultMsg);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
let isValid = true;
|
|
96
|
-
|
|
97
|
-
errorMessage = '';
|
|
98
|
-
if (schema) {
|
|
99
|
-
isValid = Value.Check(schema, answer);
|
|
100
|
-
if (!isValid) {
|
|
101
|
-
const errors = Value.Errors(schema, answer);
|
|
102
|
-
|
|
103
|
-
if (errors.length > 0) {
|
|
104
|
-
errorMessage = errors[0]?.message ?? 'Invalid input.';
|
|
105
|
-
} else {
|
|
106
|
-
errorMessage = 'Invalid input.';
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (validate && isValid) {
|
|
112
|
-
const validation = await validate(answer);
|
|
113
|
-
|
|
114
|
-
if (!validation) {
|
|
115
|
-
isValid = false;
|
|
116
|
-
errorMessage = isString(validation) ? validation : 'Invalid input.';
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (isValid) {
|
|
121
|
-
msg({
|
|
122
|
-
type: 'M_NEWLINE',
|
|
123
|
-
});
|
|
124
|
-
rl.close();
|
|
125
|
-
return answer;
|
|
53
|
+
const questionLines = countLines(question);
|
|
54
|
+
const prompt = await rl.question(question);
|
|
55
|
+
currentInput = prompt.trim();
|
|
56
|
+
if (showPlaceholder && currentInput !== "") {
|
|
57
|
+
showPlaceholder = false;
|
|
58
|
+
deleteLastLine();
|
|
59
|
+
deleteLastLine();
|
|
60
|
+
msg({ type: "M_MIDDLE", title: ` ${currentInput}` });
|
|
61
|
+
}
|
|
62
|
+
linesToDelete = questionLines + 1;
|
|
63
|
+
const answer = currentInput || defaultValue;
|
|
64
|
+
if (currentInput === "" && defaultValue !== "") {
|
|
65
|
+
deleteLastLine();
|
|
66
|
+
deleteLastLine();
|
|
67
|
+
const defaultMsg = fmt({
|
|
68
|
+
type: "M_MIDDLE",
|
|
69
|
+
title: ` ${defaultValue}`,
|
|
70
|
+
borderColor
|
|
71
|
+
});
|
|
72
|
+
console.log(defaultMsg);
|
|
73
|
+
linesToDelete += countLines(defaultMsg);
|
|
74
|
+
}
|
|
75
|
+
let isValid = true;
|
|
76
|
+
errorMessage = "";
|
|
77
|
+
if (schema) {
|
|
78
|
+
isValid = Value.Check(schema, answer);
|
|
79
|
+
if (!isValid) {
|
|
80
|
+
const errors = [...Value.Errors(schema, answer)];
|
|
81
|
+
if (errors.length > 0) {
|
|
82
|
+
errorMessage = errors[0]?.message ?? "Invalid input.";
|
|
83
|
+
} else {
|
|
84
|
+
errorMessage = "Invalid input.";
|
|
126
85
|
}
|
|
127
|
-
|
|
128
|
-
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (validate && isValid) {
|
|
89
|
+
const validation = await validate(answer);
|
|
90
|
+
if (validation !== true) {
|
|
91
|
+
isValid = false;
|
|
92
|
+
errorMessage = typeof validation === "string" ? validation : "Invalid input.";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (isValid) {
|
|
96
|
+
msg({ type: "M_NEWLINE" });
|
|
97
|
+
rl.close();
|
|
98
|
+
return answer;
|
|
99
|
+
} else {
|
|
100
|
+
linesToDelete += 0;
|
|
129
101
|
}
|
|
102
|
+
}
|
|
130
103
|
}
|
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
import color from
|
|
2
|
-
import Prompt from
|
|
3
|
-
|
|
1
|
+
import color from "picocolors";
|
|
2
|
+
import Prompt from "../prompts/prompt.js";
|
|
4
3
|
export default class TextPrompt extends Prompt {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
4
|
+
valueWithCursor = "";
|
|
5
|
+
get cursor() {
|
|
6
|
+
return this._cursor;
|
|
7
|
+
}
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
super(opts);
|
|
10
|
+
this.on("finalize", () => {
|
|
11
|
+
if (!this.value) {
|
|
12
|
+
this.value = opts.defaultValue;
|
|
13
|
+
}
|
|
14
|
+
this.valueWithCursor = this.value;
|
|
15
|
+
});
|
|
16
|
+
this.on("value", () => {
|
|
17
|
+
if (this.cursor >= this.value.length) {
|
|
18
|
+
this.valueWithCursor = `${this.value}${color.inverse(color.hidden("_"))}`;
|
|
19
|
+
} else {
|
|
20
|
+
const s1 = this.value.slice(0, this.cursor);
|
|
21
|
+
const s2 = this.value.slice(this.cursor);
|
|
22
|
+
this.valueWithCursor = `${s1}${color.inverse(s2[0])}${s2.slice(1)}`;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
30
26
|
}
|
|
@@ -1,29 +1,21 @@
|
|
|
1
|
-
import {BasicReporter} from
|
|
2
|
-
import {createRelinka as _createRelinka} from
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export * from '../../components/instance/shared.js';
|
|
1
|
+
import { BasicReporter } from "../../components/instance/reporter/basic.js";
|
|
2
|
+
import { createRelinka as _createRelinka } from "../../components/prompts/relinka.js";
|
|
3
|
+
import { LogLevels } from "../../utils/constants.js";
|
|
4
|
+
export * from "../../components/instance/shared.js";
|
|
7
5
|
export function createRelinka(options = {}) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
reporters: options.reporters || [new BasicReporter()],
|
|
22
|
-
...options,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return relinka2;
|
|
6
|
+
let level = LogLevels.info;
|
|
7
|
+
if (process.env.RELINKA_LEVEL) {
|
|
8
|
+
level = Number.parseInt(process.env.RELINKA_LEVEL) ?? level;
|
|
9
|
+
}
|
|
10
|
+
const relinka2 = _createRelinka({
|
|
11
|
+
level,
|
|
12
|
+
defaults: { level },
|
|
13
|
+
stdout: process.stdout,
|
|
14
|
+
stderr: process.stderr,
|
|
15
|
+
reporters: options.reporters || [new BasicReporter()],
|
|
16
|
+
...options
|
|
17
|
+
});
|
|
18
|
+
return relinka2;
|
|
26
19
|
}
|
|
27
|
-
|
|
28
20
|
export const relinka = createRelinka();
|
|
29
21
|
export default relinka;
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import {BrowserReporter} from
|
|
2
|
-
import {createRelinka as _createRelinka} from
|
|
3
|
-
|
|
4
|
-
export * from '../../components/instance/shared.js';
|
|
1
|
+
import { BrowserReporter } from "../../components/instance/reporter/browser.js";
|
|
2
|
+
import { createRelinka as _createRelinka } from "../../components/prompts/relinka.js";
|
|
3
|
+
export * from "../../components/instance/shared.js";
|
|
5
4
|
export function createRelinka(options = {}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return relinka2;
|
|
5
|
+
const relinka2 = _createRelinka({
|
|
6
|
+
reporters: options.reporters || [new BrowserReporter({})],
|
|
7
|
+
prompt(message, options2 = {}) {
|
|
8
|
+
if (options2.type === "confirm") {
|
|
9
|
+
return Promise.resolve(confirm(message));
|
|
10
|
+
}
|
|
11
|
+
return Promise.resolve(prompt(message));
|
|
12
|
+
},
|
|
13
|
+
...options
|
|
14
|
+
});
|
|
15
|
+
return relinka2;
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
export const relinka = createRelinka();
|
|
22
18
|
export default relinka;
|
|
@@ -1,68 +1,49 @@
|
|
|
1
|
-
import {formatWithOptions} from
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const isString = (a) => typeof a === 'string';
|
|
7
|
-
const bracket = (x) => x ? `[${x}]` : '';
|
|
8
|
-
|
|
1
|
+
import { formatWithOptions } from "node:util";
|
|
2
|
+
import { parseStack } from "../../../utils/error.js";
|
|
3
|
+
import { writeStream } from "../../../utils/stream.js";
|
|
4
|
+
const bracket = (x) => x ? `[${x}]` : "";
|
|
9
5
|
export class BasicReporter {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
formatLogObj(logObj, opts) {
|
|
37
|
-
const message = this.formatArgs(logObj.args, opts);
|
|
38
|
-
|
|
39
|
-
if (logObj.type === 'box') {
|
|
40
|
-
return `
|
|
41
|
-
${[
|
|
42
|
-
bracket(logObj.tag),
|
|
43
|
-
logObj.title,
|
|
44
|
-
...message.split('\n'),
|
|
45
|
-
]
|
|
46
|
-
.filter(Boolean)
|
|
47
|
-
.map((l) => ` > ${l}`)
|
|
48
|
-
.join('\n')}
|
|
49
|
-
`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return this.filterAndJoin([
|
|
53
|
-
bracket(logObj.type),
|
|
54
|
-
bracket(logObj.tag),
|
|
55
|
-
message,
|
|
56
|
-
]);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
log(logObj, ctx) {
|
|
60
|
-
const line = this.formatLogObj(logObj, {
|
|
61
|
-
columns: ctx.options.stdout.columns || 0,
|
|
62
|
-
...ctx.options.formatOptions,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return writeStream(`${line}
|
|
66
|
-
`, logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout);
|
|
6
|
+
formatStack(stack, opts) {
|
|
7
|
+
return " " + parseStack(stack).join("\n ");
|
|
8
|
+
}
|
|
9
|
+
formatArgs(args, opts) {
|
|
10
|
+
const _args = args.map((arg) => {
|
|
11
|
+
if (arg && typeof arg.stack === "string") {
|
|
12
|
+
return arg.message + "\n" + this.formatStack(arg.stack, opts);
|
|
13
|
+
}
|
|
14
|
+
return arg;
|
|
15
|
+
});
|
|
16
|
+
return formatWithOptions(opts, ..._args);
|
|
17
|
+
}
|
|
18
|
+
formatDate(date, opts) {
|
|
19
|
+
return opts.date ? date.toLocaleTimeString() : "";
|
|
20
|
+
}
|
|
21
|
+
filterAndJoin(arr) {
|
|
22
|
+
return arr.filter(Boolean).join(" ");
|
|
23
|
+
}
|
|
24
|
+
formatLogObj(logObj, opts) {
|
|
25
|
+
const message = this.formatArgs(logObj.args, opts);
|
|
26
|
+
if (logObj.type === "box") {
|
|
27
|
+
return "\n" + [
|
|
28
|
+
bracket(logObj.tag),
|
|
29
|
+
logObj.title && logObj.title,
|
|
30
|
+
...message.split("\n")
|
|
31
|
+
].filter(Boolean).map((l) => " > " + l).join("\n") + "\n";
|
|
67
32
|
}
|
|
33
|
+
return this.filterAndJoin([
|
|
34
|
+
bracket(logObj.type),
|
|
35
|
+
bracket(logObj.tag),
|
|
36
|
+
message
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
log(logObj, ctx) {
|
|
40
|
+
const line = this.formatLogObj(logObj, {
|
|
41
|
+
columns: ctx.options.stdout.columns || 0,
|
|
42
|
+
...ctx.options.formatOptions
|
|
43
|
+
});
|
|
44
|
+
return writeStream(
|
|
45
|
+
line + "\n",
|
|
46
|
+
logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout
|
|
47
|
+
);
|
|
48
|
+
}
|
|
68
49
|
}
|