@reliverse/relinka 1.1.4 → 1.1.6
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 -86
- 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 -168
- 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 -86
- 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 -98
- 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 -98
- package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
- package/dist-npm/components/next-steps/next-steps.js +25 -24
- package/dist-npm/components/number/index.js +112 -78
- package/dist-npm/components/number/number-main.js +2 -96
- package/dist-npm/components/password/index.js +73 -54
- package/dist-npm/components/password/password-main.js +2 -120
- 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 -125
- 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 -95
- package/dist-npm/components/spinner/index.js +136 -107
- package/dist-npm/components/st-end/end.d.ts +1 -1
- package/dist-npm/components/st-end/end.js +26 -35
- package/dist-npm/components/st-end/start.d.ts +1 -1
- package/dist-npm/components/st-end/start.js +15 -30
- 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.d.ts +2 -1
- 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
package/dist-npm/utils/color.js
CHANGED
|
@@ -1,84 +1,93 @@
|
|
|
1
|
-
import * as tty from
|
|
1
|
+
import * as tty from 'node:tty';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
|
|
4
|
+
const isUndefined = (a) => typeof a === 'undefined';
|
|
5
|
+
|
|
2
6
|
const {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} =
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
7
|
+
env = {},
|
|
8
|
+
argv = [],
|
|
9
|
+
platform = '',
|
|
10
|
+
} = isUndefined(process) ? {} : process;
|
|
11
|
+
|
|
12
|
+
const isDisabled = 'NO_COLOR' in env || argv.includes('--no-color');
|
|
13
|
+
const isForced = 'FORCE_COLOR' in env || argv.includes('--color');
|
|
14
|
+
const isWindows = platform === 'win32';
|
|
15
|
+
const isDumbTerminal = env.TERM === 'dumb';
|
|
11
16
|
const isCompatibleTerminal = tty?.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
|
|
12
|
-
const isCI =
|
|
17
|
+
const isCI = 'CI' in env && ('GITHUB_ACTIONS' in env || 'GITLAB_CI' in env || 'CIRCLECI' in env);
|
|
13
18
|
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
19
|
+
|
|
14
20
|
function replaceClose(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
|
|
15
|
-
|
|
21
|
+
return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
16
22
|
}
|
|
23
|
+
|
|
17
24
|
function clearBleed(index, string, open, close, replace) {
|
|
18
|
-
|
|
25
|
+
return index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
|
19
26
|
}
|
|
27
|
+
|
|
20
28
|
function filterEmpty(open, close, replace = open, at = open.length + 1) {
|
|
21
|
-
|
|
22
|
-
("" + string).indexOf(close, at),
|
|
23
|
-
string,
|
|
24
|
-
open,
|
|
25
|
-
close,
|
|
26
|
-
replace
|
|
27
|
-
) : "";
|
|
29
|
+
return (string) => string || !(string === '' || string === void 0) ? clearBleed(String(string).indexOf(close, at), string, open, close, replace) : '';
|
|
28
30
|
}
|
|
31
|
+
|
|
29
32
|
function init(open, close, replace) {
|
|
30
|
-
|
|
33
|
+
return filterEmpty(`\x1B[${open}m`, `\x1B[${close}m`, replace);
|
|
31
34
|
}
|
|
35
|
+
|
|
32
36
|
const colorDefs = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
37
|
+
reset: init(0, 0),
|
|
38
|
+
bold: init(1, 22, '\x1B[22m\x1B[1m'),
|
|
39
|
+
dim: init(2, 22, '\x1B[22m\x1B[2m'),
|
|
40
|
+
italic: init(3, 23),
|
|
41
|
+
underline: init(4, 24),
|
|
42
|
+
inverse: init(7, 27),
|
|
43
|
+
hidden: init(8, 28),
|
|
44
|
+
strikethrough: init(9, 29),
|
|
45
|
+
black: init(30, 39),
|
|
46
|
+
red: init(31, 39),
|
|
47
|
+
green: init(32, 39),
|
|
48
|
+
yellow: init(33, 39),
|
|
49
|
+
blue: init(34, 39),
|
|
50
|
+
magenta: init(35, 39),
|
|
51
|
+
cyan: init(36, 39),
|
|
52
|
+
white: init(37, 39),
|
|
53
|
+
gray: init(90, 39),
|
|
54
|
+
bgBlack: init(40, 49),
|
|
55
|
+
bgRed: init(41, 49),
|
|
56
|
+
bgGreen: init(42, 49),
|
|
57
|
+
bgYellow: init(43, 49),
|
|
58
|
+
bgBlue: init(44, 49),
|
|
59
|
+
bgMagenta: init(45, 49),
|
|
60
|
+
bgCyan: init(46, 49),
|
|
61
|
+
bgWhite: init(47, 49),
|
|
62
|
+
blackBright: init(90, 39),
|
|
63
|
+
redBright: init(91, 39),
|
|
64
|
+
greenBright: init(92, 39),
|
|
65
|
+
yellowBright: init(93, 39),
|
|
66
|
+
blueBright: init(94, 39),
|
|
67
|
+
magentaBright: init(95, 39),
|
|
68
|
+
cyanBright: init(96, 39),
|
|
69
|
+
whiteBright: init(97, 39),
|
|
70
|
+
bgBlackBright: init(100, 49),
|
|
71
|
+
bgRedBright: init(101, 49),
|
|
72
|
+
bgGreenBright: init(102, 49),
|
|
73
|
+
bgYellowBright: init(103, 49),
|
|
74
|
+
bgBlueBright: init(104, 49),
|
|
75
|
+
bgMagentaBright: init(105, 49),
|
|
76
|
+
bgCyanBright: init(106, 49),
|
|
77
|
+
bgWhiteBright: init(107, 49),
|
|
74
78
|
};
|
|
79
|
+
|
|
75
80
|
function createColors(useColor = isColorSupported) {
|
|
76
|
-
|
|
81
|
+
return useColor ? colorDefs : Object.fromEntries(Object
|
|
82
|
+
.keys(colorDefs)
|
|
83
|
+
.map((key) => [key, String]));
|
|
77
84
|
}
|
|
85
|
+
|
|
78
86
|
export const colors = createColors();
|
|
79
|
-
export function getColor(color, fallback =
|
|
80
|
-
|
|
87
|
+
export function getColor(color, fallback = 'reset') {
|
|
88
|
+
return colors[color] || colors[fallback];
|
|
81
89
|
}
|
|
90
|
+
|
|
82
91
|
export function colorize(color, text) {
|
|
83
|
-
|
|
92
|
+
return getColor(color)(text);
|
|
84
93
|
}
|
|
@@ -1,130 +1,162 @@
|
|
|
1
1
|
import gradient, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from
|
|
2
|
+
cristal,
|
|
3
|
+
mind,
|
|
4
|
+
passion,
|
|
5
|
+
rainbow,
|
|
6
|
+
vice,
|
|
7
|
+
} from 'gradient-string';
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} from
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
case
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
case
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
case
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
case
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
case
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
9
|
+
red,
|
|
10
|
+
inverse,
|
|
11
|
+
dim,
|
|
12
|
+
black,
|
|
13
|
+
green,
|
|
14
|
+
yellow,
|
|
15
|
+
blue,
|
|
16
|
+
magenta,
|
|
17
|
+
cyan,
|
|
18
|
+
cyanBright,
|
|
19
|
+
bgCyan,
|
|
20
|
+
bgCyanBright,
|
|
21
|
+
white,
|
|
22
|
+
gray,
|
|
23
|
+
underline,
|
|
24
|
+
bold,
|
|
25
|
+
strikethrough,
|
|
26
|
+
italic,
|
|
27
|
+
} from 'picocolors';
|
|
28
|
+
|
|
29
|
+
export function colorize(result, colorName, typography) {
|
|
30
|
+
switch(colorName) {
|
|
31
|
+
case 'inverse':
|
|
32
|
+
result = inverse(` ${result} `);
|
|
33
|
+
break;
|
|
34
|
+
|
|
35
|
+
case 'dim':
|
|
36
|
+
result = dim(result);
|
|
37
|
+
break;
|
|
38
|
+
|
|
39
|
+
case 'black':
|
|
40
|
+
result = black(result);
|
|
41
|
+
break;
|
|
42
|
+
|
|
43
|
+
case 'red':
|
|
44
|
+
result = red(result);
|
|
45
|
+
break;
|
|
46
|
+
|
|
47
|
+
case 'green':
|
|
48
|
+
result = green(result);
|
|
49
|
+
break;
|
|
50
|
+
|
|
51
|
+
case 'yellow':
|
|
52
|
+
result = yellow(result);
|
|
53
|
+
break;
|
|
54
|
+
|
|
55
|
+
case 'blue':
|
|
56
|
+
result = blue(result);
|
|
57
|
+
break;
|
|
58
|
+
|
|
59
|
+
case 'magenta':
|
|
60
|
+
result = magenta(result);
|
|
61
|
+
break;
|
|
62
|
+
|
|
63
|
+
case 'cyan':
|
|
64
|
+
result = cyan(result);
|
|
65
|
+
break;
|
|
66
|
+
|
|
67
|
+
case 'cyanBright':
|
|
68
|
+
result = cyanBright(result);
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case 'bgCyan':
|
|
72
|
+
result = bgCyan(` ${result} `);
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case 'bgCyanBright':
|
|
76
|
+
result = bgCyanBright(` ${result} `);
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case 'white':
|
|
80
|
+
result = white(result);
|
|
81
|
+
break;
|
|
82
|
+
|
|
83
|
+
case 'gray':
|
|
84
|
+
result = gray(result);
|
|
85
|
+
break;
|
|
86
|
+
|
|
87
|
+
case 'gradientGradient':
|
|
88
|
+
result = gradient([
|
|
89
|
+
'red',
|
|
90
|
+
'yellow',
|
|
91
|
+
'green',
|
|
92
|
+
'cyan',
|
|
93
|
+
'blue',
|
|
94
|
+
'magenta',
|
|
95
|
+
])(result);
|
|
96
|
+
break;
|
|
97
|
+
|
|
98
|
+
case 'rainbowGradient':
|
|
99
|
+
result = rainbow(result);
|
|
100
|
+
break;
|
|
101
|
+
|
|
102
|
+
case 'cristalGradient':
|
|
103
|
+
result = cristal(result);
|
|
104
|
+
break;
|
|
105
|
+
|
|
106
|
+
case 'mindGradient':
|
|
107
|
+
result = mind(result);
|
|
108
|
+
break;
|
|
109
|
+
|
|
110
|
+
case 'passionGradient':
|
|
111
|
+
result = passion(result);
|
|
112
|
+
break;
|
|
113
|
+
|
|
114
|
+
case 'viceGradient':
|
|
115
|
+
result = vice(result);
|
|
116
|
+
break;
|
|
117
|
+
|
|
118
|
+
case 'none':
|
|
119
|
+
break;
|
|
120
|
+
|
|
95
121
|
default:
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
const gradientColors = [
|
|
99
|
-
"gradientGradient",
|
|
100
|
-
"cristalGradient",
|
|
101
|
-
"mindGradient",
|
|
102
|
-
"passionGradient",
|
|
103
|
-
"rainbowGradient",
|
|
104
|
-
"viceGradient"
|
|
105
|
-
];
|
|
106
|
-
if (gradientColors.includes(colorName ?? "") && typography) {
|
|
107
|
-
throw new Error(
|
|
108
|
-
"[colorize] Cannot apply typography to gradient color.\n\u2502 Use regular colorize()'s color or remove typography."
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
if (!gradientColors.includes(colorName ?? "") && typography) {
|
|
112
|
-
switch (typography) {
|
|
113
|
-
case "bold":
|
|
114
|
-
result = bold(result);
|
|
115
|
-
break;
|
|
116
|
-
case "strikethrough":
|
|
117
|
-
result = strikethrough(result);
|
|
118
|
-
break;
|
|
119
|
-
case "underline":
|
|
120
|
-
result = underline(result);
|
|
121
|
-
break;
|
|
122
|
-
case "italic":
|
|
123
|
-
result = italic(result);
|
|
124
|
-
break;
|
|
125
|
-
default:
|
|
126
122
|
break;
|
|
127
123
|
}
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
|
|
125
|
+
const gradientColors = [
|
|
126
|
+
'gradientGradient',
|
|
127
|
+
'cristalGradient',
|
|
128
|
+
'mindGradient',
|
|
129
|
+
'passionGradient',
|
|
130
|
+
'rainbowGradient',
|
|
131
|
+
'viceGradient',
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
if (gradientColors.includes(colorName ?? '') && typography) {
|
|
135
|
+
throw Error(`[colorize] Cannot apply typography to gradient color.\n│ Use regular colorize()'s color or remove typography.`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!gradientColors.includes(colorName ?? '') && typography) {
|
|
139
|
+
switch(typography) {
|
|
140
|
+
case 'bold':
|
|
141
|
+
result = bold(result);
|
|
142
|
+
break;
|
|
143
|
+
|
|
144
|
+
case 'strikethrough':
|
|
145
|
+
result = strikethrough(result);
|
|
146
|
+
break;
|
|
147
|
+
|
|
148
|
+
case 'underline':
|
|
149
|
+
result = underline(result);
|
|
150
|
+
break;
|
|
151
|
+
|
|
152
|
+
case 'italic':
|
|
153
|
+
result = italic(result);
|
|
154
|
+
break;
|
|
155
|
+
|
|
156
|
+
default:
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return result;
|
|
130
162
|
}
|