@reliverse/relinka 1.1.5 → 1.1.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/dist-npm/components/anykey/index.js +77 -57
- package/dist-npm/components/block/block.js +61 -48
- package/dist-npm/components/checkbox/index.js +211 -178
- package/dist-npm/components/confirm/confirm-main.js +122 -85
- package/dist-npm/components/confirm/confirm-three.js +27 -24
- package/dist-npm/components/confirm/index.js +45 -36
- package/dist-npm/components/core/Separator.js +17 -15
- package/dist-npm/components/core/create-prompt.js +124 -101
- package/dist-npm/components/core/errors.js +15 -19
- package/dist-npm/components/core/hook-engine.js +120 -91
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +6 -16
- package/dist-npm/components/core/lines.js +54 -45
- package/dist-npm/components/core/make-theme.js +30 -21
- package/dist-npm/components/core/position.js +23 -27
- package/dist-npm/components/core/promise-polyfill.js +14 -11
- package/dist-npm/components/core/screen-manager.js +74 -59
- package/dist-npm/components/core/theme.js +32 -22
- package/dist-npm/components/core/use-effect.js +15 -9
- package/dist-npm/components/core/use-keypress.js +23 -19
- package/dist-npm/components/core/use-memo.js +16 -10
- package/dist-npm/components/core/use-pagination.js +32 -33
- package/dist-npm/components/core/use-prefix.js +38 -40
- package/dist-npm/components/core/use-ref.js +5 -2
- package/dist-npm/components/core/use-state.js +23 -15
- package/dist-npm/components/core/useKeyPress.js +17 -14
- package/dist-npm/components/core/usePromptState.js +14 -8
- package/dist-npm/components/core/utils.js +16 -7
- package/dist-npm/components/date/date.js +204 -167
- package/dist-npm/components/editor/index.js +92 -71
- package/dist-npm/components/expand/index.js +124 -96
- package/dist-npm/components/figures/index.js +294 -283
- package/dist-npm/components/input/index.js +87 -61
- package/dist-npm/components/input/text-main.js +124 -97
- package/dist-npm/components/input/text.js +28 -24
- package/dist-npm/components/instance/basic.js +25 -17
- package/dist-npm/components/instance/browser.js +18 -14
- package/dist-npm/components/instance/reporter/basic.js +65 -46
- package/dist-npm/components/instance/reporter/browser.js +47 -44
- package/dist-npm/components/instance/reporter/fancy.js +96 -83
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +62 -52
- package/dist-npm/components/mono/monoTwo.js +49 -35
- package/dist-npm/components/multiselect/group-multiselect.js +71 -55
- package/dist-npm/components/multiselect/multi-select-two.js +130 -97
- package/dist-npm/components/multiselect/multi-select.js +49 -43
- package/dist-npm/components/multiselect/multiselect-main.js +146 -120
- package/dist-npm/components/multiselect/num-multi-select.js +130 -97
- package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
- package/dist-npm/components/next-steps/next-steps.js +25 -23
- package/dist-npm/components/number/index.js +112 -78
- package/dist-npm/components/number/number-main.js +2 -95
- package/dist-npm/components/password/index.js +73 -54
- package/dist-npm/components/password/password-main.js +2 -119
- package/dist-npm/components/password/password-three.js +30 -26
- package/dist-npm/components/progressbar/ProgressBar.js +64 -45
- package/dist-npm/components/progressbar/helper.js +40 -33
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +44 -29
- package/dist-npm/components/prompts/index.js +45 -45
- package/dist-npm/components/prompts/prompt.js +260 -211
- package/dist-npm/components/prompts/promptTwo.js +605 -561
- package/dist-npm/components/prompts/relinka.js +295 -237
- package/dist-npm/components/range/range.js +294 -247
- package/dist-npm/components/rawlist/index.js +107 -87
- package/dist-npm/components/results/results.js +37 -31
- package/dist-npm/components/search/index.js +193 -148
- package/dist-npm/components/select/index.js +186 -148
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +5 -124
- package/dist-npm/components/select/select-key.js +25 -24
- package/dist-npm/components/select/select-main.js +133 -109
- package/dist-npm/components/select/select-three.js +36 -32
- package/dist-npm/components/select/select-two.js +87 -94
- package/dist-npm/components/spinner/index.js +136 -107
- package/dist-npm/components/st-end/end.js +26 -34
- package/dist-npm/components/st-end/start.js +15 -29
- package/dist-npm/components/toggle/index.js +137 -113
- package/dist-npm/components/visual/animate/animate.js +10 -53
- package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
- package/dist-npm/mod.js +2 -1
- package/dist-npm/testing/index.js +83 -58
- package/dist-npm/types/general.js +1 -0
- package/dist-npm/types/index.js +3 -2
- package/dist-npm/types/keypress.js +36 -35
- package/dist-npm/types/readline.js +1 -0
- package/dist-npm/types/relinka.js +1 -0
- package/dist-npm/types/utils.js +1 -0
- package/dist-npm/utils/box.js +137 -135
- package/dist-npm/utils/color.js +74 -65
- package/dist-npm/utils/colorize.js +156 -124
- package/dist-npm/utils/component.js +657 -532
- package/dist-npm/utils/constants.js +63 -64
- package/dist-npm/utils/core.js +3 -2
- package/dist-npm/utils/decoder.js +223 -244
- package/dist-npm/utils/error.js +9 -4
- package/dist-npm/utils/errors.js +4 -14
- package/dist-npm/utils/format.js +24 -19
- package/dist-npm/utils/keypress.js +414 -316
- package/dist-npm/utils/log.js +15 -11
- package/dist-npm/utils/mapping.js +52 -45
- package/dist-npm/utils/messages.js +183 -183
- package/dist-npm/utils/platforms.js +20 -16
- package/dist-npm/utils/prompt-tmp.js +286 -235
- package/dist-npm/utils/prompt-two.js +286 -235
- package/dist-npm/utils/readline.js +7 -5
- package/dist-npm/utils/skeleton.js +170 -130
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +58 -44
- package/dist-npm/utils/terminal.js +34 -23
- package/dist-npm/utils/tree.js +41 -30
- package/dist-npm/utils/types.js +1 -0
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +44 -36
- package/package.json +20 -28
|
@@ -1,66 +1,92 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from
|
|
2
|
+
createPrompt,
|
|
3
|
+
useState,
|
|
4
|
+
useKeypress,
|
|
5
|
+
usePrefix,
|
|
6
|
+
isEnterKey,
|
|
7
|
+
isBackspaceKey,
|
|
8
|
+
makeTheme,
|
|
9
|
+
} from '../../components/core/index.js';
|
|
10
|
+
|
|
11
|
+
const isFn = (a) => typeof a === 'function';
|
|
12
|
+
|
|
10
13
|
export default createPrompt((config, done) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const {required, validate = () => true} = config;
|
|
15
|
+
const theme = makeTheme(config.theme);
|
|
16
|
+
const [status, setStatus] = useState('idle');
|
|
17
|
+
const [defaultValue = '', setDefaultValue] = useState(config.default);
|
|
18
|
+
const [errorMsg, setError] = useState();
|
|
19
|
+
const [value, setValue] = useState('');
|
|
20
|
+
const prefix = usePrefix({
|
|
21
|
+
status,
|
|
22
|
+
theme,
|
|
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);
|
|
21
66
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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);
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
let defaultStr;
|
|
70
|
+
|
|
71
|
+
if (defaultValue && status !== 'done' && !value) {
|
|
72
|
+
defaultStr = theme.style.defaultAnswer(defaultValue);
|
|
45
73
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
error
|
|
65
|
-
];
|
|
74
|
+
|
|
75
|
+
let error = '';
|
|
76
|
+
|
|
77
|
+
if (errorMsg) {
|
|
78
|
+
error = theme.style.error(errorMsg);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return [
|
|
82
|
+
[
|
|
83
|
+
prefix,
|
|
84
|
+
message,
|
|
85
|
+
defaultStr,
|
|
86
|
+
formattedValue,
|
|
87
|
+
]
|
|
88
|
+
.filter((v) => v !== void 0)
|
|
89
|
+
.join(' '),
|
|
90
|
+
error,
|
|
91
|
+
];
|
|
66
92
|
});
|
|
@@ -1,103 +1,130 @@
|
|
|
1
|
-
import {
|
|
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";
|
|
1
|
+
import {Value} from '@sinclair/typebox/value';
|
|
5
2
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
stdin as input,
|
|
4
|
+
stdout as output,
|
|
5
|
+
} from 'node:process';
|
|
6
|
+
import readline from 'node:readline/promises';
|
|
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
|
+
|
|
10
16
|
export async function textPrompt(options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
17
|
+
const {
|
|
18
|
+
title,
|
|
19
|
+
hint,
|
|
20
|
+
validate,
|
|
21
|
+
defaultValue = '',
|
|
22
|
+
schema,
|
|
23
|
+
titleColor = 'cyanBright',
|
|
24
|
+
titleTypography = 'bold',
|
|
25
|
+
titleVariant,
|
|
26
|
+
content,
|
|
27
|
+
contentColor,
|
|
28
|
+
contentTypography,
|
|
29
|
+
contentVariant,
|
|
30
|
+
borderColor = 'viceGradient',
|
|
31
|
+
variantOptions,
|
|
32
|
+
placeholder,
|
|
33
|
+
} = options;
|
|
34
|
+
|
|
35
|
+
const rl = readline.createInterface({
|
|
36
|
+
input,
|
|
37
|
+
output,
|
|
52
38
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
currentInput =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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.";
|
|
39
|
+
let linesToDelete = 0;
|
|
40
|
+
let errorMessage = '';
|
|
41
|
+
let currentInput = '';
|
|
42
|
+
let showPlaceholder = true;
|
|
43
|
+
|
|
44
|
+
while (true) {
|
|
45
|
+
if (linesToDelete > 0) {
|
|
46
|
+
deleteLastLines(linesToDelete);
|
|
85
47
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
48
|
+
|
|
49
|
+
const question = fmt({
|
|
50
|
+
type: errorMessage !== '' ? 'M_ERROR' : 'M_GENERAL',
|
|
51
|
+
title,
|
|
52
|
+
titleColor,
|
|
53
|
+
titleTypography,
|
|
54
|
+
titleVariant,
|
|
55
|
+
content,
|
|
56
|
+
contentColor,
|
|
57
|
+
contentTypography,
|
|
58
|
+
contentVariant,
|
|
59
|
+
borderColor,
|
|
60
|
+
hint,
|
|
61
|
+
placeholder: showPlaceholder ? placeholder : void 0,
|
|
62
|
+
variantOptions,
|
|
63
|
+
errorMessage,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const questionLines = countLines(question);
|
|
67
|
+
const prompt = await rl.question(question);
|
|
68
|
+
|
|
69
|
+
currentInput = prompt.trim();
|
|
70
|
+
if (showPlaceholder && currentInput !== '') {
|
|
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;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
linesToDelete += 0;
|
|
101
129
|
}
|
|
102
|
-
}
|
|
103
130
|
}
|
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
import color from
|
|
2
|
-
import Prompt from
|
|
1
|
+
import color from 'picocolors';
|
|
2
|
+
import Prompt from '../prompts/prompt.js';
|
|
3
|
+
|
|
3
4
|
export default class TextPrompt extends Prompt {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
valueWithCursor = '';
|
|
6
|
+
get cursor() {
|
|
7
|
+
return this._cursor;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
super(opts);
|
|
12
|
+
this.on('finalize', () => {
|
|
13
|
+
if (!this.value) {
|
|
14
|
+
this.value = opts.defaultValue;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
this.valueWithCursor = this.value;
|
|
18
|
+
});
|
|
19
|
+
this.on('value', () => {
|
|
20
|
+
if (this.cursor >= this.value.length) {
|
|
21
|
+
this.valueWithCursor = `${this.value}${color.inverse(color.hidden('_'))}`;
|
|
22
|
+
} else {
|
|
23
|
+
const s1 = this.value.slice(0, this.cursor);
|
|
24
|
+
const s2 = this.value.slice(this.cursor);
|
|
25
|
+
|
|
26
|
+
this.valueWithCursor = `${s1}${color.inverse(s2[0])}${s2.slice(1)}`;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
26
30
|
}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import {BasicReporter} from '../../components/instance/reporter/basic.js';
|
|
2
|
+
import {createRelinka as _createRelinka} from '../../components/prompts/relinka.js';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import {LogLevels} from '../../utils/constants.js';
|
|
5
|
+
|
|
6
|
+
export * from '../../components/instance/shared.js';
|
|
5
7
|
export function createRelinka(options = {}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
let level = LogLevels.info;
|
|
9
|
+
|
|
10
|
+
if (process.env.RELINKA_LEVEL) {
|
|
11
|
+
level = Number.parseInt(process.env.RELINKA_LEVEL) ?? level;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const relinka2 = _createRelinka({
|
|
15
|
+
level,
|
|
16
|
+
defaults: {
|
|
17
|
+
level,
|
|
18
|
+
},
|
|
19
|
+
stdout: process.stdout,
|
|
20
|
+
stderr: process.stderr,
|
|
21
|
+
reporters: options.reporters || [new BasicReporter()],
|
|
22
|
+
...options,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return relinka2;
|
|
19
26
|
}
|
|
27
|
+
|
|
20
28
|
export const relinka = createRelinka();
|
|
21
29
|
export default relinka;
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import {BrowserReporter} from '../../components/instance/reporter/browser.js';
|
|
2
|
+
import {createRelinka as _createRelinka} from '../../components/prompts/relinka.js';
|
|
3
|
+
|
|
4
|
+
export * from '../../components/instance/shared.js';
|
|
4
5
|
export function createRelinka(options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
const relinka2 = _createRelinka({
|
|
7
|
+
reporters: options.reporters || [new BrowserReporter({})],
|
|
8
|
+
prompt(message, options2 = {}) {
|
|
9
|
+
if (options2.type === 'confirm') {
|
|
10
|
+
return Promise.resolve(confirm(message));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return Promise.resolve(prompt(message));
|
|
14
|
+
},
|
|
15
|
+
...options,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return relinka2;
|
|
16
19
|
}
|
|
20
|
+
|
|
17
21
|
export const relinka = createRelinka();
|
|
18
22
|
export default relinka;
|
|
@@ -1,49 +1,68 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import {formatWithOptions} from 'node:util';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import {parseStack} from '../../../utils/error.js';
|
|
4
|
+
import {writeStream} from '../../../utils/stream.js';
|
|
5
|
+
|
|
6
|
+
const isString = (a) => typeof a === 'string';
|
|
7
|
+
const bracket = (x) => x ? `[${x}]` : '';
|
|
8
|
+
|
|
5
9
|
export class BasicReporter {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
10
|
+
formatStack(stack) {
|
|
11
|
+
return ' ' + parseStack(stack).join('\n ');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
formatArgs(args, opts) {
|
|
15
|
+
const _args = args.map((arg) => {
|
|
16
|
+
if (arg && isString(arg.stack)) {
|
|
17
|
+
return arg.message + '\n' + this.formatStack(arg.stack, opts);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return arg;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return formatWithOptions(opts, ..._args);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
formatDate(date, opts) {
|
|
27
|
+
return opts.date ? date.toLocaleTimeString() : '';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
filterAndJoin(arr) {
|
|
31
|
+
return arr
|
|
32
|
+
.filter(Boolean)
|
|
33
|
+
.join(' ');
|
|
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);
|
|
32
67
|
}
|
|
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
|
-
}
|
|
49
68
|
}
|