@voidzero-dev/vite-plus-prompts 1.0.0-rc.1 → 1.1.0
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/README.md +58 -0
- package/dist/index.d.mts +132 -21
- package/dist/index.mjs +579 -500
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,71 +1,166 @@
|
|
|
1
|
-
import { AutocompletePrompt, ConfirmPrompt, GroupMultiSelectPrompt, MultiSelectPrompt, PasswordPrompt, SelectKeyPrompt, SelectPrompt, TextPrompt, block, getColumns, getRows, isCancel, isCancel as isCancel$1, settings, settings as settings$1, updateSettings,
|
|
1
|
+
import { AutocompletePrompt, CANCEL_SYMBOL, ConfirmPrompt, GroupMultiSelectPrompt, MultiSelectPrompt, PasswordPrompt, SelectKeyPrompt, SelectPrompt, TextPrompt, block, getColumns, getRows, isAccessible, isCancel, isCancel as isCancel$1, runValidation, settings, settings as settings$1, updateSettings, updateSettings as updateSettings$1 } from "@clack/core";
|
|
2
2
|
import color from "picocolors";
|
|
3
3
|
import process$1 from "node:process";
|
|
4
|
+
import { stripVTControlCharacters } from "node:util";
|
|
4
5
|
import { randomBytes } from "node:crypto";
|
|
5
6
|
import { existsSync, lstatSync, readdirSync } from "node:fs";
|
|
6
7
|
import { dirname, join } from "node:path";
|
|
7
8
|
import { cursor, erase } from "sisteransi";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
//#region ../../node_modules/.pnpm/fast-string-truncated-width@1.2.1/node_modules/fast-string-truncated-width/dist/utils.js
|
|
10
|
+
const isAmbiguous = (x) => {
|
|
11
|
+
return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
|
|
12
|
+
};
|
|
13
|
+
const isFullWidth$1 = (x) => {
|
|
14
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
15
|
+
};
|
|
16
|
+
const isWide = (x) => {
|
|
17
|
+
return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9800 && x <= 9811 || x === 9855 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 19968 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x === 94192 || x === 94193 || x >= 94208 && x <= 100343 || x >= 100352 && x <= 101589 || x >= 101632 && x <= 101640 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128727 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129672 || x >= 129680 && x <= 129725 || x >= 129727 && x <= 129733 || x >= 129742 && x <= 129755 || x >= 129760 && x <= 129768 || x >= 129776 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
18
|
+
};
|
|
14
19
|
//#endregion
|
|
15
|
-
//#region
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
+
//#region ../../node_modules/.pnpm/fast-string-truncated-width@1.2.1/node_modules/fast-string-truncated-width/dist/index.js
|
|
21
|
+
const ANSI_RE$1 = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
|
|
22
|
+
const CONTROL_RE$1 = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
23
|
+
const TAB_RE$1 = /\t{1,1000}/y;
|
|
24
|
+
const EMOJI_RE$1 = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy;
|
|
25
|
+
const LATIN_RE$1 = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
26
|
+
const MODIFIER_RE$1 = /\p{M}+/gu;
|
|
27
|
+
const NO_TRUNCATION$3 = {
|
|
28
|
+
limit: Infinity,
|
|
29
|
+
ellipsis: ""
|
|
20
30
|
};
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
31
|
+
const getStringTruncatedWidth$1 = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
32
|
+
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
33
|
+
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
34
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth$1(ELLIPSIS, NO_TRUNCATION$3, widthOptions).width : 0);
|
|
35
|
+
const ANSI_WIDTH = widthOptions.ansiWidth ?? 0;
|
|
36
|
+
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
37
|
+
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
38
|
+
const AMBIGUOUS_WIDTH = widthOptions.ambiguousWidth ?? 1;
|
|
39
|
+
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
40
|
+
const FULL_WIDTH_WIDTH = widthOptions.fullWidthWidth ?? 2;
|
|
41
|
+
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
42
|
+
const WIDE_WIDTH = widthOptions.wideWidth ?? 2;
|
|
43
|
+
let indexPrev = 0;
|
|
44
|
+
let index = 0;
|
|
45
|
+
let length = input.length;
|
|
46
|
+
let lengthExtra = 0;
|
|
47
|
+
let truncationEnabled = false;
|
|
48
|
+
let truncationIndex = length;
|
|
49
|
+
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
50
|
+
let unmatchedStart = 0;
|
|
51
|
+
let unmatchedEnd = 0;
|
|
52
|
+
let width = 0;
|
|
53
|
+
let widthExtra = 0;
|
|
54
|
+
outer: while (true) {
|
|
55
|
+
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
56
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
57
|
+
lengthExtra = 0;
|
|
58
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE$1, "")) {
|
|
59
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
60
|
+
if (isFullWidth$1(codePoint)) widthExtra = FULL_WIDTH_WIDTH;
|
|
61
|
+
else if (isWide(codePoint)) widthExtra = WIDE_WIDTH;
|
|
62
|
+
else if (AMBIGUOUS_WIDTH !== REGULAR_WIDTH && isAmbiguous(codePoint)) widthExtra = AMBIGUOUS_WIDTH;
|
|
63
|
+
else widthExtra = REGULAR_WIDTH;
|
|
64
|
+
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
65
|
+
if (width + widthExtra > LIMIT) {
|
|
66
|
+
truncationEnabled = true;
|
|
67
|
+
break outer;
|
|
68
|
+
}
|
|
69
|
+
lengthExtra += char.length;
|
|
70
|
+
width += widthExtra;
|
|
71
|
+
}
|
|
72
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
73
|
+
}
|
|
74
|
+
if (index >= length) break;
|
|
75
|
+
LATIN_RE$1.lastIndex = index;
|
|
76
|
+
if (LATIN_RE$1.test(input)) {
|
|
77
|
+
lengthExtra = LATIN_RE$1.lastIndex - index;
|
|
78
|
+
widthExtra = lengthExtra * REGULAR_WIDTH;
|
|
79
|
+
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / REGULAR_WIDTH));
|
|
80
|
+
if (width + widthExtra > LIMIT) {
|
|
81
|
+
truncationEnabled = true;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
width += widthExtra;
|
|
85
|
+
unmatchedStart = indexPrev;
|
|
86
|
+
unmatchedEnd = index;
|
|
87
|
+
index = indexPrev = LATIN_RE$1.lastIndex;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
ANSI_RE$1.lastIndex = index;
|
|
91
|
+
if (ANSI_RE$1.test(input)) {
|
|
92
|
+
if (width + ANSI_WIDTH > truncationLimit) truncationIndex = Math.min(truncationIndex, index);
|
|
93
|
+
if (width + ANSI_WIDTH > LIMIT) {
|
|
94
|
+
truncationEnabled = true;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
width += ANSI_WIDTH;
|
|
98
|
+
unmatchedStart = indexPrev;
|
|
99
|
+
unmatchedEnd = index;
|
|
100
|
+
index = indexPrev = ANSI_RE$1.lastIndex;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
CONTROL_RE$1.lastIndex = index;
|
|
104
|
+
if (CONTROL_RE$1.test(input)) {
|
|
105
|
+
lengthExtra = CONTROL_RE$1.lastIndex - index;
|
|
106
|
+
widthExtra = lengthExtra * CONTROL_WIDTH;
|
|
107
|
+
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / CONTROL_WIDTH));
|
|
108
|
+
if (width + widthExtra > LIMIT) {
|
|
109
|
+
truncationEnabled = true;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
width += widthExtra;
|
|
113
|
+
unmatchedStart = indexPrev;
|
|
114
|
+
unmatchedEnd = index;
|
|
115
|
+
index = indexPrev = CONTROL_RE$1.lastIndex;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
TAB_RE$1.lastIndex = index;
|
|
119
|
+
if (TAB_RE$1.test(input)) {
|
|
120
|
+
lengthExtra = TAB_RE$1.lastIndex - index;
|
|
121
|
+
widthExtra = lengthExtra * TAB_WIDTH;
|
|
122
|
+
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / TAB_WIDTH));
|
|
123
|
+
if (width + widthExtra > LIMIT) {
|
|
124
|
+
truncationEnabled = true;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
width += widthExtra;
|
|
128
|
+
unmatchedStart = indexPrev;
|
|
129
|
+
unmatchedEnd = index;
|
|
130
|
+
index = indexPrev = TAB_RE$1.lastIndex;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
EMOJI_RE$1.lastIndex = index;
|
|
134
|
+
if (EMOJI_RE$1.test(input)) {
|
|
135
|
+
if (width + EMOJI_WIDTH > truncationLimit) truncationIndex = Math.min(truncationIndex, index);
|
|
136
|
+
if (width + EMOJI_WIDTH > LIMIT) {
|
|
137
|
+
truncationEnabled = true;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
width += EMOJI_WIDTH;
|
|
141
|
+
unmatchedStart = indexPrev;
|
|
142
|
+
unmatchedEnd = index;
|
|
143
|
+
index = indexPrev = EMOJI_RE$1.lastIndex;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
index += 1;
|
|
58
147
|
}
|
|
148
|
+
return {
|
|
149
|
+
width: truncationEnabled ? truncationLimit : width,
|
|
150
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
151
|
+
truncated: truncationEnabled,
|
|
152
|
+
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
153
|
+
};
|
|
59
154
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region ../../node_modules/.pnpm/fast-string-width@1.1.0/node_modules/fast-string-width/dist/index.js
|
|
157
|
+
const NO_TRUNCATION$2 = {
|
|
158
|
+
limit: Infinity,
|
|
159
|
+
ellipsis: "",
|
|
160
|
+
ellipsisWidth: 0
|
|
161
|
+
};
|
|
162
|
+
const fastStringWidth$1 = (input, options = {}) => {
|
|
163
|
+
return getStringTruncatedWidth$1(input, NO_TRUNCATION$2, options).width;
|
|
69
164
|
};
|
|
70
165
|
//#endregion
|
|
71
166
|
//#region ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
|
|
@@ -78,7 +173,7 @@ const getCodePointsLength = (() => {
|
|
|
78
173
|
return input.length - surrogatePairsNr;
|
|
79
174
|
};
|
|
80
175
|
})();
|
|
81
|
-
const isFullWidth
|
|
176
|
+
const isFullWidth = (x) => {
|
|
82
177
|
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
83
178
|
};
|
|
84
179
|
const isWideNotCJKTNotEmoji = (x) => {
|
|
@@ -86,21 +181,21 @@ const isWideNotCJKTNotEmoji = (x) => {
|
|
|
86
181
|
};
|
|
87
182
|
//#endregion
|
|
88
183
|
//#region ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/index.js
|
|
89
|
-
const ANSI_RE
|
|
90
|
-
const CONTROL_RE
|
|
184
|
+
const ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
|
|
185
|
+
const CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
91
186
|
const CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy;
|
|
92
|
-
const TAB_RE
|
|
93
|
-
const EMOJI_RE
|
|
94
|
-
const LATIN_RE
|
|
95
|
-
const MODIFIER_RE
|
|
96
|
-
const NO_TRUNCATION$
|
|
187
|
+
const TAB_RE = /\t{1,1000}/y;
|
|
188
|
+
const EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy;
|
|
189
|
+
const LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
190
|
+
const MODIFIER_RE = /\p{M}+/gu;
|
|
191
|
+
const NO_TRUNCATION$1 = {
|
|
97
192
|
limit: Infinity,
|
|
98
193
|
ellipsis: ""
|
|
99
194
|
};
|
|
100
|
-
const getStringTruncatedWidth
|
|
195
|
+
const getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
101
196
|
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
102
197
|
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
103
|
-
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth
|
|
198
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION$1, widthOptions).width : 0);
|
|
104
199
|
const ANSI_WIDTH = 0;
|
|
105
200
|
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
106
201
|
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
@@ -109,11 +204,11 @@ const getStringTruncatedWidth$1 = (input, truncationOptions = {}, widthOptions =
|
|
|
109
204
|
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
110
205
|
const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
|
|
111
206
|
const PARSE_BLOCKS = [
|
|
112
|
-
[LATIN_RE
|
|
113
|
-
[ANSI_RE
|
|
114
|
-
[CONTROL_RE
|
|
115
|
-
[TAB_RE
|
|
116
|
-
[EMOJI_RE
|
|
207
|
+
[LATIN_RE, REGULAR_WIDTH],
|
|
208
|
+
[ANSI_RE, ANSI_WIDTH],
|
|
209
|
+
[CONTROL_RE, CONTROL_WIDTH],
|
|
210
|
+
[TAB_RE, TAB_WIDTH],
|
|
211
|
+
[EMOJI_RE, EMOJI_WIDTH],
|
|
117
212
|
[CJKT_WIDE_RE, WIDE_WIDTH]
|
|
118
213
|
];
|
|
119
214
|
let indexPrev = 0;
|
|
@@ -131,9 +226,9 @@ const getStringTruncatedWidth$1 = (input, truncationOptions = {}, widthOptions =
|
|
|
131
226
|
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
132
227
|
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
133
228
|
lengthExtra = 0;
|
|
134
|
-
for (const char of unmatched.replaceAll(MODIFIER_RE
|
|
229
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
135
230
|
const codePoint = char.codePointAt(0) || 0;
|
|
136
|
-
if (isFullWidth
|
|
231
|
+
if (isFullWidth(codePoint)) widthExtra = FULL_WIDTH_WIDTH;
|
|
137
232
|
else if (isWideNotCJKTNotEmoji(codePoint)) widthExtra = WIDE_WIDTH;
|
|
138
233
|
else widthExtra = REGULAR_WIDTH;
|
|
139
234
|
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
@@ -151,7 +246,7 @@ const getStringTruncatedWidth$1 = (input, truncationOptions = {}, widthOptions =
|
|
|
151
246
|
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
|
|
152
247
|
BLOCK_RE.lastIndex = index;
|
|
153
248
|
if (BLOCK_RE.test(input)) {
|
|
154
|
-
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE
|
|
249
|
+
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
155
250
|
widthExtra = lengthExtra * BLOCK_WIDTH;
|
|
156
251
|
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
|
|
157
252
|
if (width + widthExtra > LIMIT) {
|
|
@@ -176,13 +271,13 @@ const getStringTruncatedWidth$1 = (input, truncationOptions = {}, widthOptions =
|
|
|
176
271
|
};
|
|
177
272
|
//#endregion
|
|
178
273
|
//#region ../../node_modules/.pnpm/fast-string-width@3.0.2/node_modules/fast-string-width/dist/index.js
|
|
179
|
-
const NO_TRUNCATION
|
|
274
|
+
const NO_TRUNCATION = {
|
|
180
275
|
limit: Infinity,
|
|
181
276
|
ellipsis: "",
|
|
182
277
|
ellipsisWidth: 0
|
|
183
278
|
};
|
|
184
|
-
const fastStringWidth
|
|
185
|
-
return getStringTruncatedWidth
|
|
279
|
+
const fastStringWidth = (input, options = {}) => {
|
|
280
|
+
return getStringTruncatedWidth(input, NO_TRUNCATION, options).width;
|
|
186
281
|
};
|
|
187
282
|
//#endregion
|
|
188
283
|
//#region ../../node_modules/.pnpm/fast-wrap-ansi@0.2.0/node_modules/fast-wrap-ansi/lib/main.js
|
|
@@ -215,13 +310,13 @@ const wrapWord = (rows, word, columns) => {
|
|
|
215
310
|
let isInsideEscape = false;
|
|
216
311
|
let isInsideLinkEscape = false;
|
|
217
312
|
let lastRow = rows.at(-1);
|
|
218
|
-
let visible = lastRow === void 0 ? 0 : fastStringWidth
|
|
313
|
+
let visible = lastRow === void 0 ? 0 : fastStringWidth(lastRow);
|
|
219
314
|
let currentCharacter = characters.next();
|
|
220
315
|
let nextCharacter = characters.next();
|
|
221
316
|
let rawCharacterIndex = 0;
|
|
222
317
|
while (!currentCharacter.done) {
|
|
223
318
|
const character = currentCharacter.value;
|
|
224
|
-
const characterLength = fastStringWidth
|
|
319
|
+
const characterLength = fastStringWidth(character);
|
|
225
320
|
if (visible + characterLength <= columns) rows[rows.length - 1] += character;
|
|
226
321
|
else {
|
|
227
322
|
rows.push(character);
|
|
@@ -256,7 +351,7 @@ const stringVisibleTrimSpacesRight = (string) => {
|
|
|
256
351
|
const words = string.split(" ");
|
|
257
352
|
let last = words.length;
|
|
258
353
|
while (last) {
|
|
259
|
-
if (fastStringWidth
|
|
354
|
+
if (fastStringWidth(words[last - 1])) break;
|
|
260
355
|
last--;
|
|
261
356
|
}
|
|
262
357
|
if (last === words.length) return string;
|
|
@@ -277,7 +372,7 @@ const exec = (string, columns, options = {}) => {
|
|
|
277
372
|
const trimmed = row.trimStart();
|
|
278
373
|
if (row.length !== trimmed.length) {
|
|
279
374
|
rows[rows.length - 1] = trimmed;
|
|
280
|
-
rowLength = fastStringWidth
|
|
375
|
+
rowLength = fastStringWidth(trimmed);
|
|
281
376
|
}
|
|
282
377
|
}
|
|
283
378
|
if (index !== 0) {
|
|
@@ -290,19 +385,19 @@ const exec = (string, columns, options = {}) => {
|
|
|
290
385
|
rowLength++;
|
|
291
386
|
}
|
|
292
387
|
}
|
|
293
|
-
const wordLength = fastStringWidth
|
|
388
|
+
const wordLength = fastStringWidth(word);
|
|
294
389
|
if (options.hard && wordLength > columns) {
|
|
295
390
|
const remainingColumns = columns - rowLength;
|
|
296
391
|
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
297
392
|
if (Math.floor((wordLength - 1) / columns) < breaksStartingThisLine) rows.push("");
|
|
298
393
|
wrapWord(rows, word, columns);
|
|
299
|
-
rowLength = fastStringWidth
|
|
394
|
+
rowLength = fastStringWidth(rows.at(-1) ?? "");
|
|
300
395
|
continue;
|
|
301
396
|
}
|
|
302
397
|
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
303
398
|
if (options.wordWrap === false && rowLength < columns) {
|
|
304
399
|
wrapWord(rows, word, columns);
|
|
305
|
-
rowLength = fastStringWidth
|
|
400
|
+
rowLength = fastStringWidth(rows.at(-1) ?? "");
|
|
306
401
|
continue;
|
|
307
402
|
}
|
|
308
403
|
rows.push("");
|
|
@@ -310,7 +405,7 @@ const exec = (string, columns, options = {}) => {
|
|
|
310
405
|
}
|
|
311
406
|
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
312
407
|
wrapWord(rows, word, columns);
|
|
313
|
-
rowLength = fastStringWidth
|
|
408
|
+
rowLength = fastStringWidth(rows.at(-1) ?? "");
|
|
314
409
|
continue;
|
|
315
410
|
}
|
|
316
411
|
rows[rows.length - 1] += word;
|
|
@@ -350,13 +445,113 @@ function wrapAnsi(string, columns, options) {
|
|
|
350
445
|
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join("\n");
|
|
351
446
|
}
|
|
352
447
|
//#endregion
|
|
448
|
+
//#region ../../node_modules/.pnpm/is-unicode-supported@1.3.0/node_modules/is-unicode-supported/index.js
|
|
449
|
+
function isUnicodeSupported() {
|
|
450
|
+
if (process$1.platform !== "win32") return process$1.env.TERM !== "linux";
|
|
451
|
+
return Boolean(process$1.env.CI) || Boolean(process$1.env.WT_SESSION) || Boolean(process$1.env.TERMINUS_SUBLIME) || process$1.env.ConEmuTask === "{cmd::Cmder}" || process$1.env.TERM_PROGRAM === "Terminus-Sublime" || process$1.env.TERM_PROGRAM === "vscode" || process$1.env.TERM === "xterm-256color" || process$1.env.TERM === "alacritty" || process$1.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
452
|
+
}
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/common.ts
|
|
455
|
+
updateSettings$1({ withGuide: false });
|
|
456
|
+
/** Wrap using visible columns rather than the length of ANSI escape sequences. */
|
|
457
|
+
const wrapTextWithPrefix = (output, text, prefix, startPrefix = prefix) => {
|
|
458
|
+
return wrapAnsi(text, Math.max(1, getColumns(output ?? process.stdout) - Math.max(fastStringWidth$1(prefix), fastStringWidth$1(startPrefix))), {
|
|
459
|
+
hard: true,
|
|
460
|
+
trim: false
|
|
461
|
+
}).split("\n").map((line, index) => `${index === 0 ? startPrefix : prefix}${line}`).join("\n");
|
|
462
|
+
};
|
|
463
|
+
const getGuide = (opts) => opts?.withGuide ?? settings$1.withGuide;
|
|
464
|
+
const promptTitle = (message, state, opts) => {
|
|
465
|
+
if (!message.trim()) return "";
|
|
466
|
+
const hasGuide = getGuide(opts);
|
|
467
|
+
return `${hasGuide ? `${color.gray(S_BAR)}\n` : ""}${wrapTextWithPrefix(opts.output, message, hasGuide ? `${symbolBar(state)} ` : " ", `${symbol(state)} `)}\n`;
|
|
468
|
+
};
|
|
469
|
+
const optionText = (output, marker, label, format, suffix = "") => {
|
|
470
|
+
const continuation = " ".repeat(fastStringWidth$1(marker));
|
|
471
|
+
const width = Math.max(1, getColumns(output ?? process.stdout) - 2 - fastStringWidth$1(marker));
|
|
472
|
+
const [first, ...rest] = label.split("\n");
|
|
473
|
+
return wrapAnsi([format(first) + suffix, ...rest.map(format)].join("\n"), width, {
|
|
474
|
+
hard: true,
|
|
475
|
+
trim: false
|
|
476
|
+
}).split("\n").map((line, index) => `${index === 0 ? marker : continuation}${line}`).join("\n");
|
|
477
|
+
};
|
|
478
|
+
const SELECT_INSTRUCTIONS = ["↑/↓ navigate", "Enter confirm"];
|
|
479
|
+
const MULTISELECT_INSTRUCTIONS = [
|
|
480
|
+
"↑/↓ navigate",
|
|
481
|
+
"Space select",
|
|
482
|
+
"Enter confirm"
|
|
483
|
+
];
|
|
484
|
+
const formatInstructionFooter = (instructions, hasGuide, output) => wrapTextWithPrefix(output, color.dim(instructions.join(" · ")), hasGuide ? `${color.blue(S_BAR)} ` : " ").split("\n");
|
|
485
|
+
const unicode = isUnicodeSupported();
|
|
486
|
+
const isCI = () => process.env.CI === "true";
|
|
487
|
+
const isTTY = (output) => {
|
|
488
|
+
return output.isTTY === true;
|
|
489
|
+
};
|
|
490
|
+
const unicodeOr = (c, fallback) => unicode ? c : fallback;
|
|
491
|
+
const S_POINTER_ACTIVE = unicodeOr("›", ">");
|
|
492
|
+
const S_POINTER_INACTIVE = " ";
|
|
493
|
+
const S_STEP_ACTIVE = S_POINTER_ACTIVE;
|
|
494
|
+
const S_STEP_CANCEL = unicodeOr("■", "x");
|
|
495
|
+
const S_STEP_ERROR = unicodeOr("▲", "x");
|
|
496
|
+
const S_STEP_SUBMIT = unicodeOr("◇", "o");
|
|
497
|
+
const S_BAR_START = unicodeOr("┌", "T");
|
|
498
|
+
const S_BAR = unicodeOr("│", "|");
|
|
499
|
+
const S_BAR_END = unicodeOr("└", "—");
|
|
500
|
+
const S_BAR_START_RIGHT = unicodeOr("┐", "T");
|
|
501
|
+
const S_BAR_END_RIGHT = unicodeOr("┘", "—");
|
|
502
|
+
const S_RADIO_ACTIVE = S_POINTER_ACTIVE;
|
|
503
|
+
const S_RADIO_INACTIVE = " ";
|
|
504
|
+
const S_CHECKBOX_ACTIVE = unicodeOr("◻", "[•]");
|
|
505
|
+
const S_CHECKBOX_SELECTED = unicodeOr("◼", "[+]");
|
|
506
|
+
const S_CHECKBOX_INACTIVE = unicodeOr("◻", "[ ]");
|
|
507
|
+
const S_PASSWORD_MASK = unicodeOr("▪", "•");
|
|
508
|
+
const S_BAR_H = unicodeOr("─", "-");
|
|
509
|
+
const S_CORNER_TOP_RIGHT = unicodeOr("╮", "+");
|
|
510
|
+
const S_CONNECT_LEFT = unicodeOr("├", "+");
|
|
511
|
+
const S_CORNER_BOTTOM_RIGHT = unicodeOr("╯", "+");
|
|
512
|
+
const S_CORNER_BOTTOM_LEFT = unicodeOr("╰", "+");
|
|
513
|
+
const S_CORNER_TOP_LEFT = unicodeOr("╭", "+");
|
|
514
|
+
const S_INFO = unicodeOr("●", "•");
|
|
515
|
+
const S_SUCCESS = unicodeOr("◆", "*");
|
|
516
|
+
const S_WARN = unicodeOr("▲", "!");
|
|
517
|
+
const S_ERROR = unicodeOr("■", "x");
|
|
518
|
+
const completeColor = (value) => color.gray(value);
|
|
519
|
+
const symbol = (state) => {
|
|
520
|
+
switch (state) {
|
|
521
|
+
case "initial":
|
|
522
|
+
case "active": return color.blue(S_STEP_ACTIVE);
|
|
523
|
+
case "cancel": return color.red(S_STEP_CANCEL);
|
|
524
|
+
case "error": return color.yellow(S_STEP_ERROR);
|
|
525
|
+
case "validating": return color.dim(S_STEP_ACTIVE);
|
|
526
|
+
case "submit": return completeColor(S_STEP_SUBMIT);
|
|
527
|
+
default: return color.blue(S_STEP_ACTIVE);
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
const symbolBar = (state) => {
|
|
531
|
+
switch (state) {
|
|
532
|
+
case "initial":
|
|
533
|
+
case "active": return color.blue(S_BAR);
|
|
534
|
+
case "cancel": return color.red(S_BAR);
|
|
535
|
+
case "error": return color.yellow(S_BAR);
|
|
536
|
+
case "validating": return color.dim(S_BAR);
|
|
537
|
+
case "submit": return completeColor(S_BAR);
|
|
538
|
+
default: return color.blue(S_BAR);
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
//#endregion
|
|
353
542
|
//#region src/limit-options.ts
|
|
354
|
-
const trimLines = (groups, initialLineCount, startIndex, endIndex, maxLines) => {
|
|
543
|
+
const trimLines = (groups, initialLineCount, startIndex, endIndex, maxLines, fromEnd = false) => {
|
|
355
544
|
let lineCount = initialLineCount;
|
|
356
545
|
let removals = 0;
|
|
357
|
-
for (let i =
|
|
546
|
+
if (fromEnd) for (let i = endIndex - 1; i >= startIndex; i--) {
|
|
547
|
+
const group = groups[i];
|
|
548
|
+
if (group) lineCount -= group.length;
|
|
549
|
+
removals++;
|
|
550
|
+
if (lineCount <= maxLines) break;
|
|
551
|
+
}
|
|
552
|
+
else for (let i = startIndex; i < endIndex; i++) {
|
|
358
553
|
const group = groups[i];
|
|
359
|
-
|
|
554
|
+
if (group) lineCount -= group.length;
|
|
360
555
|
removals++;
|
|
361
556
|
if (lineCount <= maxLines) break;
|
|
362
557
|
}
|
|
@@ -365,23 +560,41 @@ const trimLines = (groups, initialLineCount, startIndex, endIndex, maxLines) =>
|
|
|
365
560
|
removals
|
|
366
561
|
};
|
|
367
562
|
};
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
563
|
+
/**
|
|
564
|
+
* Trims an option list to what fits the terminal, while keeping the active
|
|
565
|
+
* option (cursor) visible using a Clack style sliding window.
|
|
566
|
+
*
|
|
567
|
+
* @returns The lines to render.
|
|
568
|
+
*
|
|
569
|
+
* @see https://bomb.sh/docs/clack/packages/prompts/#limitoptions
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* ```ts
|
|
573
|
+
* import { limitOptions } from '@voidzero-dev/vite-plus-prompts';
|
|
574
|
+
* import color from 'picocolors';
|
|
575
|
+
*
|
|
576
|
+
* const options = ['apple', 'banana', 'cherry', 'date'];
|
|
577
|
+
* const lines = limitOptions({
|
|
578
|
+
* options,
|
|
579
|
+
* cursor: 2,
|
|
580
|
+
* maxItems: 8,
|
|
581
|
+
* style: (opt, active) =>
|
|
582
|
+
* active ? color.blue(opt) : color.dim(opt),
|
|
583
|
+
* });
|
|
584
|
+
* ```
|
|
585
|
+
*/
|
|
586
|
+
const limitOptions = ({ cursor, options, style, output = process.stdout, maxItems = Number.POSITIVE_INFINITY, columnPadding = 0, rowPadding = 4 }) => {
|
|
371
587
|
const columns = getColumns(output);
|
|
372
|
-
const
|
|
373
|
-
const rowPadding = params.rowPadding ?? 4;
|
|
374
|
-
const maxWidth = columns - columnPadding;
|
|
588
|
+
const maxWidth = Math.max(1, columns - columnPadding);
|
|
375
589
|
const rows = getRows(output);
|
|
376
590
|
const overflowFormat = color.dim("...");
|
|
377
|
-
const paramMaxItems = params.maxItems ?? Number.POSITIVE_INFINITY;
|
|
378
591
|
const outputMaxItems = Math.max(rows - rowPadding, 0);
|
|
379
|
-
const
|
|
592
|
+
const computedMaxItems = Math.max(Math.min(maxItems, outputMaxItems), 5);
|
|
380
593
|
let slidingWindowLocation = 0;
|
|
381
|
-
if (cursor >=
|
|
382
|
-
let shouldRenderTopEllipsis =
|
|
383
|
-
let shouldRenderBottomEllipsis =
|
|
384
|
-
const slidingWindowLocationEnd = Math.min(slidingWindowLocation +
|
|
594
|
+
if (cursor >= computedMaxItems - 3) slidingWindowLocation = Math.max(Math.min(cursor - computedMaxItems + 3, options.length - computedMaxItems), 0);
|
|
595
|
+
let shouldRenderTopEllipsis = computedMaxItems < options.length && slidingWindowLocation > 0;
|
|
596
|
+
let shouldRenderBottomEllipsis = computedMaxItems < options.length && slidingWindowLocation + computedMaxItems < options.length;
|
|
597
|
+
const slidingWindowLocationEnd = Math.min(slidingWindowLocation + computedMaxItems, options.length);
|
|
385
598
|
const lineGroups = [];
|
|
386
599
|
let lineCount = 0;
|
|
387
600
|
if (shouldRenderTopEllipsis) lineCount++;
|
|
@@ -389,7 +602,8 @@ const limitOptions = (params) => {
|
|
|
389
602
|
const slidingWindowLocationWithEllipsis = slidingWindowLocation + (shouldRenderTopEllipsis ? 1 : 0);
|
|
390
603
|
const slidingWindowLocationEndWithEllipsis = slidingWindowLocationEnd - (shouldRenderBottomEllipsis ? 1 : 0);
|
|
391
604
|
for (let i = slidingWindowLocationWithEllipsis; i < slidingWindowLocationEndWithEllipsis; i++) {
|
|
392
|
-
const
|
|
605
|
+
const option = options[i];
|
|
606
|
+
const wrappedLines = wrapAnsi(option === void 0 ? "" : style(option, i === cursor), maxWidth, {
|
|
393
607
|
hard: true,
|
|
394
608
|
trim: false
|
|
395
609
|
}).split("\n");
|
|
@@ -401,13 +615,22 @@ const limitOptions = (params) => {
|
|
|
401
615
|
let followingRemovals = 0;
|
|
402
616
|
let newLineCount = lineCount;
|
|
403
617
|
const cursorGroupIndex = cursor - slidingWindowLocationWithEllipsis;
|
|
404
|
-
|
|
618
|
+
let adjustedMax = outputMaxItems;
|
|
619
|
+
const trimPreceding = () => trimLines(lineGroups, newLineCount, 0, cursorGroupIndex, adjustedMax);
|
|
620
|
+
const trimFollowing = () => trimLines(lineGroups, newLineCount, cursorGroupIndex + 1, lineGroups.length, adjustedMax, true);
|
|
405
621
|
if (shouldRenderTopEllipsis) {
|
|
406
|
-
({lineCount: newLineCount, removals: precedingRemovals} =
|
|
407
|
-
if (newLineCount >
|
|
622
|
+
({lineCount: newLineCount, removals: precedingRemovals} = trimPreceding());
|
|
623
|
+
if (newLineCount > adjustedMax) {
|
|
624
|
+
if (!shouldRenderBottomEllipsis) adjustedMax -= 1;
|
|
625
|
+
({lineCount: newLineCount, removals: followingRemovals} = trimFollowing());
|
|
626
|
+
}
|
|
408
627
|
} else {
|
|
409
|
-
(
|
|
410
|
-
|
|
628
|
+
if (!shouldRenderBottomEllipsis) adjustedMax -= 1;
|
|
629
|
+
({lineCount: newLineCount, removals: followingRemovals} = trimFollowing());
|
|
630
|
+
if (newLineCount > adjustedMax) {
|
|
631
|
+
adjustedMax -= 1;
|
|
632
|
+
({lineCount: newLineCount, removals: precedingRemovals} = trimPreceding());
|
|
633
|
+
}
|
|
411
634
|
}
|
|
412
635
|
if (precedingRemovals > 0) {
|
|
413
636
|
shouldRenderTopEllipsis = true;
|
|
@@ -442,35 +665,27 @@ function getSelectedOptions(values, options) {
|
|
|
442
665
|
for (const option of options) if (values.includes(option.value)) results.push(option);
|
|
443
666
|
return results;
|
|
444
667
|
}
|
|
445
|
-
const withMarker
|
|
446
|
-
|
|
447
|
-
if (lines.length === 1) return `${marker} ${format(lines[0])}${firstLineSuffix}`;
|
|
448
|
-
const [firstLine, ...rest] = lines;
|
|
449
|
-
return [`${marker} ${format(firstLine)}${firstLineSuffix}`, ...rest.map((line) => ` ${format(line)}`)].join("\n");
|
|
450
|
-
};
|
|
451
|
-
const withMarkerAndIndicator = (marker, indicator, indicatorWidth, label, format, firstLineSuffix = "") => {
|
|
452
|
-
const lines = label.split("\n");
|
|
453
|
-
const continuationPrefix = ` ${" ".repeat(indicatorWidth)} `;
|
|
454
|
-
if (lines.length === 1) return `${marker} ${indicator} ${format(lines[0])}${firstLineSuffix}`;
|
|
455
|
-
const [firstLine, ...rest] = lines;
|
|
456
|
-
return [`${marker} ${indicator} ${format(firstLine)}${firstLineSuffix}`, ...rest.map((line) => `${continuationPrefix}${format(line)}`)].join("\n");
|
|
457
|
-
};
|
|
668
|
+
const withMarker = (output, marker, label, format, suffix = "") => optionText(output, `${marker} `, label, format, suffix);
|
|
669
|
+
const withMarkerAndIndicator = (output, marker, indicator, _width, label, format, suffix = "") => optionText(output, `${marker} ${indicator} `, label, format, suffix);
|
|
458
670
|
const autocomplete = (opts) => {
|
|
459
671
|
return new AutocompletePrompt({
|
|
460
672
|
options: opts.options,
|
|
461
|
-
initialValue: opts.initialValue ? [opts.initialValue] : void 0,
|
|
673
|
+
initialValue: opts.initialValue !== void 0 ? [opts.initialValue] : void 0,
|
|
462
674
|
initialUserInput: opts.initialUserInput,
|
|
675
|
+
placeholder: opts.placeholder,
|
|
676
|
+
completeOnTab: opts.completeOnTab,
|
|
463
677
|
filter: opts.filter ?? ((search, opt) => {
|
|
464
678
|
return getFilteredOption(search, opt);
|
|
465
679
|
}),
|
|
466
680
|
signal: opts.signal,
|
|
467
681
|
input: opts.input,
|
|
682
|
+
accessible: opts.accessible,
|
|
468
683
|
output: opts.output,
|
|
469
684
|
validate: opts.validate,
|
|
470
685
|
render() {
|
|
471
|
-
const hasGuide = opts
|
|
686
|
+
const hasGuide = getGuide(opts);
|
|
472
687
|
const nestedPrefix = " ";
|
|
473
|
-
const headings =
|
|
688
|
+
const headings = promptTitle(opts.message, this.state, opts).trimEnd().split("\n");
|
|
474
689
|
const userInput = this.userInput;
|
|
475
690
|
const options = this.options;
|
|
476
691
|
const placeholder = opts.placeholder;
|
|
@@ -480,12 +695,12 @@ const autocomplete = (opts) => {
|
|
|
480
695
|
const selected = getSelectedOptions(this.selectedValues, options);
|
|
481
696
|
const label = selected.length > 0 ? color.dim(selected.map(getLabel).join(", ")) : "";
|
|
482
697
|
const submitPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
|
|
483
|
-
return `${headings.join("\n")}\n${submitPrefix}${label}\n
|
|
698
|
+
return `${headings.join("\n")}\n${submitPrefix}${label}\n`;
|
|
484
699
|
}
|
|
485
700
|
case "cancel": {
|
|
486
701
|
const userInputText = userInput ? color.strikethrough(color.dim(userInput)) : "";
|
|
487
702
|
const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
|
|
488
|
-
return `${headings.join("\n")}\n${cancelPrefix}${userInputText}\n
|
|
703
|
+
return `${headings.join("\n")}\n${cancelPrefix}${userInputText}\n`;
|
|
489
704
|
}
|
|
490
705
|
default: {
|
|
491
706
|
const barColor = this.state === "error" ? color.yellow : color.blue;
|
|
@@ -498,23 +713,27 @@ const autocomplete = (opts) => {
|
|
|
498
713
|
} else searchText = ` ${this.userInputWithCursor}`;
|
|
499
714
|
const matches = this.filteredOptions.length !== options.length ? color.dim(` (${this.filteredOptions.length} match${this.filteredOptions.length === 1 ? "" : "es"})`) : "";
|
|
500
715
|
const noResults = this.filteredOptions.length === 0 && userInput ? [`${guidePrefix}${color.yellow("No matches found")}`] : [];
|
|
501
|
-
const validationError = this.state === "error" ? [
|
|
716
|
+
const validationError = this.state === "error" ? [wrapTextWithPrefix(opts.output, color.yellow(this.error), guidePrefix)] : [];
|
|
502
717
|
if (hasGuide) headings.push(guidePrefix.trimEnd());
|
|
503
|
-
headings.push(`${
|
|
504
|
-
const
|
|
505
|
-
`${color.dim("↑/↓")}
|
|
506
|
-
`${color.dim("
|
|
507
|
-
`${color.dim("
|
|
508
|
-
|
|
718
|
+
headings.push(wrapTextWithPrefix(opts.output, `${color.dim("Search:")}${searchText}${matches}`, guidePrefix), ...noResults, ...validationError);
|
|
719
|
+
const instructions = [
|
|
720
|
+
`${color.dim("↑/↓")} navigate`,
|
|
721
|
+
...opts.completeOnTab ? [`${color.dim("Tab")} complete`] : [],
|
|
722
|
+
`${color.dim("Enter")} confirm`,
|
|
723
|
+
`${color.dim("Type")} to search`
|
|
724
|
+
];
|
|
725
|
+
const footers = wrapTextWithPrefix(opts.output, color.dim(instructions.join(" · ")), guidePrefix).split("\n");
|
|
726
|
+
if (hasGuide) footers.push(guidePrefixEnd);
|
|
509
727
|
const displayOptions = this.filteredOptions.length === 0 ? [] : limitOptions({
|
|
510
728
|
cursor: this.cursor,
|
|
511
729
|
options: this.filteredOptions,
|
|
512
730
|
columnPadding: hasGuide ? 2 : 2,
|
|
513
|
-
rowPadding: headings.length + footers.length,
|
|
731
|
+
rowPadding: headings.flatMap((line) => line.split("\n")).length + footers.length,
|
|
514
732
|
style: (option, active) => {
|
|
515
733
|
const label = getLabel(option);
|
|
516
734
|
const hint = option.hint && option.value === this.focusedValue ? color.gray(` (${option.hint})`) : "";
|
|
517
|
-
|
|
735
|
+
if (option.disabled) return withMarker(opts.output, color.gray(" "), label, (text) => color.strikethrough(color.gray(text)));
|
|
736
|
+
return active ? withMarker(opts.output, color.blue(S_POINTER_ACTIVE), label, (text) => color.blue(color.bold(text)), hint) : withMarker(opts.output, color.dim(" "), label, color.dim, hint);
|
|
518
737
|
},
|
|
519
738
|
maxItems: opts.maxItems,
|
|
520
739
|
output: opts.output
|
|
@@ -534,31 +753,35 @@ const autocomplete = (opts) => {
|
|
|
534
753
|
*/
|
|
535
754
|
const autocompleteMultiselect = (opts) => {
|
|
536
755
|
const formatOption = (option, active, selectedValues, focusedValue) => {
|
|
756
|
+
if (option.disabled) return optionText(opts.output, `${color.gray(" ")} ${color.gray(S_CHECKBOX_INACTIVE)} `, option.label ?? String(option.value ?? ""), (text) => color.strikethrough(color.gray(text)));
|
|
537
757
|
const isSelected = selectedValues.includes(option.value);
|
|
538
758
|
const label = option.label ?? String(option.value ?? "");
|
|
539
759
|
const hint = option.hint && focusedValue !== void 0 && option.value === focusedValue ? color.gray(` (${option.hint})`) : "";
|
|
540
760
|
const checkboxRaw = isSelected ? S_CHECKBOX_SELECTED : S_CHECKBOX_INACTIVE;
|
|
541
761
|
const checkbox = isSelected ? color.blue(checkboxRaw) : color.dim(checkboxRaw);
|
|
542
762
|
const marker = active ? color.blue(S_POINTER_ACTIVE) : color.dim(" ");
|
|
543
|
-
return withMarkerAndIndicator(marker, checkbox, checkboxRaw.length, label, active ? (text) => color.blue(color.bold(text)) : color.dim, hint);
|
|
763
|
+
return withMarkerAndIndicator(opts.output, marker, checkbox, checkboxRaw.length, label, active ? (text) => color.blue(color.bold(text)) : color.dim, hint);
|
|
544
764
|
};
|
|
545
|
-
|
|
765
|
+
return new AutocompletePrompt({
|
|
546
766
|
options: opts.options,
|
|
547
767
|
multiple: true,
|
|
768
|
+
placeholder: opts.placeholder,
|
|
548
769
|
filter: opts.filter ?? ((search, opt) => {
|
|
549
770
|
return getFilteredOption(search, opt);
|
|
550
771
|
}),
|
|
551
|
-
validate: () => {
|
|
552
|
-
if (opts.required &&
|
|
772
|
+
validate: (value) => {
|
|
773
|
+
if (opts.required && (!Array.isArray(value) || value.length === 0)) return "Please select at least one item";
|
|
774
|
+
return opts.validate ? runValidation(opts.validate, value) : void 0;
|
|
553
775
|
},
|
|
554
776
|
initialValue: opts.initialValues,
|
|
555
777
|
signal: opts.signal,
|
|
556
778
|
input: opts.input,
|
|
779
|
+
accessible: opts.accessible,
|
|
557
780
|
output: opts.output,
|
|
558
781
|
render() {
|
|
559
|
-
const hasGuide = opts
|
|
782
|
+
const hasGuide = getGuide(opts);
|
|
560
783
|
const nestedPrefix = " ";
|
|
561
|
-
const title =
|
|
784
|
+
const title = promptTitle(opts.message, this.state, opts);
|
|
562
785
|
const userInput = this.userInput;
|
|
563
786
|
const placeholder = opts.placeholder;
|
|
564
787
|
const showPlaceholder = userInput === "" && placeholder !== void 0;
|
|
@@ -568,38 +791,39 @@ const autocompleteMultiselect = (opts) => {
|
|
|
568
791
|
switch (this.state) {
|
|
569
792
|
case "submit": {
|
|
570
793
|
const submitPrefix = hasGuide ? `${color.gray(S_BAR)} ` : "";
|
|
571
|
-
return `${title}${hasGuide ? submitPrefix : nestedPrefix}${color.dim(`${this.selectedValues.length} items selected`)}\n
|
|
794
|
+
return `${title}${hasGuide ? submitPrefix : nestedPrefix}${color.dim(`${this.selectedValues.length} items selected`)}\n`;
|
|
572
795
|
}
|
|
573
796
|
case "cancel": {
|
|
574
797
|
const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : "";
|
|
575
|
-
return `${title}${hasGuide ? cancelPrefix : nestedPrefix}${color.strikethrough(color.dim(userInput))}\n
|
|
798
|
+
return `${title}${hasGuide ? cancelPrefix : nestedPrefix}${color.strikethrough(color.dim(userInput))}\n`;
|
|
576
799
|
}
|
|
577
800
|
default: {
|
|
578
801
|
const barColor = this.state === "error" ? color.yellow : color.blue;
|
|
579
802
|
const prefix = hasGuide ? `${barColor(S_BAR)} ` : nestedPrefix;
|
|
580
803
|
const footerEnd = hasGuide ? [barColor(S_BAR_END)] : [];
|
|
581
804
|
const instructions = [
|
|
582
|
-
`${color.dim("↑/↓")}
|
|
583
|
-
`${color.dim(this.isNavigating ? "Space/Tab
|
|
584
|
-
`${color.dim("Enter
|
|
585
|
-
`${color.dim("Type
|
|
805
|
+
`${color.dim("↑/↓")} navigate`,
|
|
806
|
+
`${color.dim(this.isNavigating ? "Space/Tab" : "Tab")} select`,
|
|
807
|
+
`${color.dim("Enter")} confirm`,
|
|
808
|
+
`${color.dim("Type")} to search`
|
|
586
809
|
];
|
|
587
810
|
const noResults = this.filteredOptions.length === 0 && userInput ? [`${prefix}${color.yellow("No matches found")}`] : [];
|
|
588
|
-
const errorMessage = this.state === "error" ? [
|
|
811
|
+
const errorMessage = this.state === "error" ? [wrapTextWithPrefix(opts.output, color.yellow(this.error), prefix)] : [];
|
|
589
812
|
const headerLines = [
|
|
590
813
|
...title.trimEnd().split("\n"),
|
|
591
|
-
`${
|
|
814
|
+
wrapTextWithPrefix(opts.output, `${color.dim("Search:")} ${searchText}${matches}`, prefix),
|
|
592
815
|
...noResults,
|
|
593
816
|
...errorMessage
|
|
594
817
|
];
|
|
595
|
-
const footerLines = [
|
|
818
|
+
const footerLines = [...wrapTextWithPrefix(opts.output, color.dim(instructions.join(" · ")), prefix).split("\n"), ...footerEnd];
|
|
596
819
|
const displayOptions = limitOptions({
|
|
597
820
|
cursor: this.cursor,
|
|
598
821
|
options: this.filteredOptions,
|
|
599
822
|
style: (option, active) => formatOption(option, active, this.selectedValues, this.focusedValue),
|
|
600
823
|
maxItems: opts.maxItems,
|
|
601
824
|
output: opts.output,
|
|
602
|
-
|
|
825
|
+
columnPadding: 2,
|
|
826
|
+
rowPadding: headerLines.flatMap((line) => line.split("\n")).length + footerLines.length
|
|
603
827
|
});
|
|
604
828
|
return [
|
|
605
829
|
...headerLines,
|
|
@@ -609,165 +833,7 @@ const autocompleteMultiselect = (opts) => {
|
|
|
609
833
|
}
|
|
610
834
|
}
|
|
611
835
|
}
|
|
612
|
-
});
|
|
613
|
-
return prompt.prompt();
|
|
614
|
-
};
|
|
615
|
-
//#endregion
|
|
616
|
-
//#region ../../node_modules/.pnpm/fast-string-truncated-width@1.2.1/node_modules/fast-string-truncated-width/dist/utils.js
|
|
617
|
-
const isAmbiguous = (x) => {
|
|
618
|
-
return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
|
|
619
|
-
};
|
|
620
|
-
const isFullWidth = (x) => {
|
|
621
|
-
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
622
|
-
};
|
|
623
|
-
const isWide = (x) => {
|
|
624
|
-
return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9800 && x <= 9811 || x === 9855 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 19968 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x === 94192 || x === 94193 || x >= 94208 && x <= 100343 || x >= 100352 && x <= 101589 || x >= 101632 && x <= 101640 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128727 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129672 || x >= 129680 && x <= 129725 || x >= 129727 && x <= 129733 || x >= 129742 && x <= 129755 || x >= 129760 && x <= 129768 || x >= 129776 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
625
|
-
};
|
|
626
|
-
//#endregion
|
|
627
|
-
//#region ../../node_modules/.pnpm/fast-string-truncated-width@1.2.1/node_modules/fast-string-truncated-width/dist/index.js
|
|
628
|
-
const ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
|
|
629
|
-
const CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
630
|
-
const TAB_RE = /\t{1,1000}/y;
|
|
631
|
-
const EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy;
|
|
632
|
-
const LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
633
|
-
const MODIFIER_RE = /\p{M}+/gu;
|
|
634
|
-
const NO_TRUNCATION$1 = {
|
|
635
|
-
limit: Infinity,
|
|
636
|
-
ellipsis: ""
|
|
637
|
-
};
|
|
638
|
-
const getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
639
|
-
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
640
|
-
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
641
|
-
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION$1, widthOptions).width : 0);
|
|
642
|
-
const ANSI_WIDTH = widthOptions.ansiWidth ?? 0;
|
|
643
|
-
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
644
|
-
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
645
|
-
const AMBIGUOUS_WIDTH = widthOptions.ambiguousWidth ?? 1;
|
|
646
|
-
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
647
|
-
const FULL_WIDTH_WIDTH = widthOptions.fullWidthWidth ?? 2;
|
|
648
|
-
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
649
|
-
const WIDE_WIDTH = widthOptions.wideWidth ?? 2;
|
|
650
|
-
let indexPrev = 0;
|
|
651
|
-
let index = 0;
|
|
652
|
-
let length = input.length;
|
|
653
|
-
let lengthExtra = 0;
|
|
654
|
-
let truncationEnabled = false;
|
|
655
|
-
let truncationIndex = length;
|
|
656
|
-
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
657
|
-
let unmatchedStart = 0;
|
|
658
|
-
let unmatchedEnd = 0;
|
|
659
|
-
let width = 0;
|
|
660
|
-
let widthExtra = 0;
|
|
661
|
-
outer: while (true) {
|
|
662
|
-
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
663
|
-
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
664
|
-
lengthExtra = 0;
|
|
665
|
-
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
666
|
-
const codePoint = char.codePointAt(0) || 0;
|
|
667
|
-
if (isFullWidth(codePoint)) widthExtra = FULL_WIDTH_WIDTH;
|
|
668
|
-
else if (isWide(codePoint)) widthExtra = WIDE_WIDTH;
|
|
669
|
-
else if (AMBIGUOUS_WIDTH !== REGULAR_WIDTH && isAmbiguous(codePoint)) widthExtra = AMBIGUOUS_WIDTH;
|
|
670
|
-
else widthExtra = REGULAR_WIDTH;
|
|
671
|
-
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
672
|
-
if (width + widthExtra > LIMIT) {
|
|
673
|
-
truncationEnabled = true;
|
|
674
|
-
break outer;
|
|
675
|
-
}
|
|
676
|
-
lengthExtra += char.length;
|
|
677
|
-
width += widthExtra;
|
|
678
|
-
}
|
|
679
|
-
unmatchedStart = unmatchedEnd = 0;
|
|
680
|
-
}
|
|
681
|
-
if (index >= length) break;
|
|
682
|
-
LATIN_RE.lastIndex = index;
|
|
683
|
-
if (LATIN_RE.test(input)) {
|
|
684
|
-
lengthExtra = LATIN_RE.lastIndex - index;
|
|
685
|
-
widthExtra = lengthExtra * REGULAR_WIDTH;
|
|
686
|
-
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / REGULAR_WIDTH));
|
|
687
|
-
if (width + widthExtra > LIMIT) {
|
|
688
|
-
truncationEnabled = true;
|
|
689
|
-
break;
|
|
690
|
-
}
|
|
691
|
-
width += widthExtra;
|
|
692
|
-
unmatchedStart = indexPrev;
|
|
693
|
-
unmatchedEnd = index;
|
|
694
|
-
index = indexPrev = LATIN_RE.lastIndex;
|
|
695
|
-
continue;
|
|
696
|
-
}
|
|
697
|
-
ANSI_RE.lastIndex = index;
|
|
698
|
-
if (ANSI_RE.test(input)) {
|
|
699
|
-
if (width + ANSI_WIDTH > truncationLimit) truncationIndex = Math.min(truncationIndex, index);
|
|
700
|
-
if (width + ANSI_WIDTH > LIMIT) {
|
|
701
|
-
truncationEnabled = true;
|
|
702
|
-
break;
|
|
703
|
-
}
|
|
704
|
-
width += ANSI_WIDTH;
|
|
705
|
-
unmatchedStart = indexPrev;
|
|
706
|
-
unmatchedEnd = index;
|
|
707
|
-
index = indexPrev = ANSI_RE.lastIndex;
|
|
708
|
-
continue;
|
|
709
|
-
}
|
|
710
|
-
CONTROL_RE.lastIndex = index;
|
|
711
|
-
if (CONTROL_RE.test(input)) {
|
|
712
|
-
lengthExtra = CONTROL_RE.lastIndex - index;
|
|
713
|
-
widthExtra = lengthExtra * CONTROL_WIDTH;
|
|
714
|
-
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / CONTROL_WIDTH));
|
|
715
|
-
if (width + widthExtra > LIMIT) {
|
|
716
|
-
truncationEnabled = true;
|
|
717
|
-
break;
|
|
718
|
-
}
|
|
719
|
-
width += widthExtra;
|
|
720
|
-
unmatchedStart = indexPrev;
|
|
721
|
-
unmatchedEnd = index;
|
|
722
|
-
index = indexPrev = CONTROL_RE.lastIndex;
|
|
723
|
-
continue;
|
|
724
|
-
}
|
|
725
|
-
TAB_RE.lastIndex = index;
|
|
726
|
-
if (TAB_RE.test(input)) {
|
|
727
|
-
lengthExtra = TAB_RE.lastIndex - index;
|
|
728
|
-
widthExtra = lengthExtra * TAB_WIDTH;
|
|
729
|
-
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / TAB_WIDTH));
|
|
730
|
-
if (width + widthExtra > LIMIT) {
|
|
731
|
-
truncationEnabled = true;
|
|
732
|
-
break;
|
|
733
|
-
}
|
|
734
|
-
width += widthExtra;
|
|
735
|
-
unmatchedStart = indexPrev;
|
|
736
|
-
unmatchedEnd = index;
|
|
737
|
-
index = indexPrev = TAB_RE.lastIndex;
|
|
738
|
-
continue;
|
|
739
|
-
}
|
|
740
|
-
EMOJI_RE.lastIndex = index;
|
|
741
|
-
if (EMOJI_RE.test(input)) {
|
|
742
|
-
if (width + EMOJI_WIDTH > truncationLimit) truncationIndex = Math.min(truncationIndex, index);
|
|
743
|
-
if (width + EMOJI_WIDTH > LIMIT) {
|
|
744
|
-
truncationEnabled = true;
|
|
745
|
-
break;
|
|
746
|
-
}
|
|
747
|
-
width += EMOJI_WIDTH;
|
|
748
|
-
unmatchedStart = indexPrev;
|
|
749
|
-
unmatchedEnd = index;
|
|
750
|
-
index = indexPrev = EMOJI_RE.lastIndex;
|
|
751
|
-
continue;
|
|
752
|
-
}
|
|
753
|
-
index += 1;
|
|
754
|
-
}
|
|
755
|
-
return {
|
|
756
|
-
width: truncationEnabled ? truncationLimit : width,
|
|
757
|
-
index: truncationEnabled ? truncationIndex : length,
|
|
758
|
-
truncated: truncationEnabled,
|
|
759
|
-
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
760
|
-
};
|
|
761
|
-
};
|
|
762
|
-
//#endregion
|
|
763
|
-
//#region ../../node_modules/.pnpm/fast-string-width@1.1.0/node_modules/fast-string-width/dist/index.js
|
|
764
|
-
const NO_TRUNCATION = {
|
|
765
|
-
limit: Infinity,
|
|
766
|
-
ellipsis: "",
|
|
767
|
-
ellipsisWidth: 0
|
|
768
|
-
};
|
|
769
|
-
const fastStringWidth = (input, options = {}) => {
|
|
770
|
-
return getStringTruncatedWidth(input, NO_TRUNCATION, options).width;
|
|
836
|
+
}).prompt();
|
|
771
837
|
};
|
|
772
838
|
//#endregion
|
|
773
839
|
//#region src/box.ts
|
|
@@ -791,28 +857,28 @@ function getPaddingForLine(lineLength, innerWidth, padding, contentAlign) {
|
|
|
791
857
|
rightPadding = innerWidth - leftPadding - lineLength;
|
|
792
858
|
return [leftPadding, rightPadding];
|
|
793
859
|
}
|
|
794
|
-
const defaultFormatBorder =
|
|
860
|
+
const defaultFormatBorder = color.gray;
|
|
795
861
|
const box = (message = "", title = "", opts) => {
|
|
796
862
|
const output = opts?.output ?? process.stdout;
|
|
797
863
|
const columns = getColumns(output);
|
|
798
864
|
const borderTotalWidth = 2;
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
const width = opts?.width === void 0 || opts.width === "auto" ? 1 : Math.min(1, opts.width);
|
|
802
|
-
const linePrefix = !(opts
|
|
865
|
+
let titlePadding = Math.max(0, opts?.titlePadding ?? 1);
|
|
866
|
+
let contentPadding = Math.max(0, opts?.contentPadding ?? 2);
|
|
867
|
+
const width = opts?.width === void 0 || opts.width === "auto" ? 1 : Math.max(0, Math.min(1, opts.width));
|
|
868
|
+
const linePrefix = !getGuide(opts) ? "" : `${color.gray(S_BAR)} `;
|
|
803
869
|
const formatBorder = opts?.formatBorder ?? defaultFormatBorder;
|
|
804
|
-
const symbols = (opts?.rounded ? roundedSymbols : squareSymbols).map(formatBorder);
|
|
870
|
+
const symbols = (opts?.rounded !== false ? roundedSymbols : squareSymbols).map(formatBorder);
|
|
805
871
|
const hSymbol = formatBorder(S_BAR_H);
|
|
806
872
|
const vSymbol = formatBorder(S_BAR);
|
|
807
|
-
const linePrefixWidth = fastStringWidth(linePrefix);
|
|
808
|
-
const titleWidth = fastStringWidth(title);
|
|
873
|
+
const linePrefixWidth = fastStringWidth$1(linePrefix);
|
|
874
|
+
const titleWidth = fastStringWidth$1(title);
|
|
809
875
|
const maxBoxWidth = columns - linePrefixWidth;
|
|
810
|
-
let boxWidth = Math.floor(columns * width) - linePrefixWidth;
|
|
876
|
+
let boxWidth = Math.max(Math.min(8, maxBoxWidth), Math.floor(columns * width) - linePrefixWidth);
|
|
811
877
|
if (opts?.width === "auto") {
|
|
812
878
|
const lines = message.split("\n");
|
|
813
879
|
let longestLine = titleWidth + titlePadding * 2;
|
|
814
880
|
for (const line of lines) {
|
|
815
|
-
const lineWithPadding = fastStringWidth(line) + contentPadding * 2;
|
|
881
|
+
const lineWithPadding = fastStringWidth$1(line) + contentPadding * 2;
|
|
816
882
|
if (lineWithPadding > longestLine) longestLine = lineWithPadding;
|
|
817
883
|
}
|
|
818
884
|
const longestLineWidth = longestLine + borderTotalWidth;
|
|
@@ -822,18 +888,29 @@ const box = (message = "", title = "", opts) => {
|
|
|
822
888
|
if (boxWidth < maxBoxWidth) boxWidth++;
|
|
823
889
|
else boxWidth--;
|
|
824
890
|
}
|
|
825
|
-
const innerWidth = boxWidth - borderTotalWidth;
|
|
891
|
+
const innerWidth = Math.max(0, boxWidth - borderTotalWidth);
|
|
892
|
+
titlePadding = Math.min(titlePadding, Math.floor(innerWidth / 2));
|
|
893
|
+
contentPadding = Math.min(contentPadding, Math.max(0, Math.floor((innerWidth - 1) / 2)));
|
|
826
894
|
const maxTitleLength = innerWidth - titlePadding * 2;
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
895
|
+
let truncatedTitle = title;
|
|
896
|
+
if (titleWidth > maxTitleLength) {
|
|
897
|
+
truncatedTitle = "";
|
|
898
|
+
const suffix = maxTitleLength > 0 ? "…" : "";
|
|
899
|
+
for (const { segment } of new Intl.Segmenter().segment(stripVTControlCharacters(title))) {
|
|
900
|
+
if (fastStringWidth$1(truncatedTitle + segment + suffix) > maxTitleLength) break;
|
|
901
|
+
truncatedTitle += segment;
|
|
902
|
+
}
|
|
903
|
+
truncatedTitle += suffix;
|
|
904
|
+
}
|
|
905
|
+
const [titlePaddingLeft, titlePaddingRight] = getPaddingForLine(fastStringWidth$1(truncatedTitle), innerWidth, titlePadding, opts?.titleAlign);
|
|
906
|
+
const wrappedMessage = wrapAnsi(message, Math.max(1, innerWidth - contentPadding * 2), {
|
|
830
907
|
hard: true,
|
|
831
908
|
trim: false
|
|
832
909
|
});
|
|
833
910
|
output.write(`${linePrefix}${symbols[0]}${hSymbol.repeat(titlePaddingLeft)}${truncatedTitle}${hSymbol.repeat(titlePaddingRight)}${symbols[1]}\n`);
|
|
834
911
|
const wrappedLines = wrappedMessage.split("\n");
|
|
835
912
|
for (const line of wrappedLines) {
|
|
836
|
-
const [leftLinePadding, rightLinePadding] = getPaddingForLine(fastStringWidth(line), innerWidth, contentPadding, opts?.contentAlign);
|
|
913
|
+
const [leftLinePadding, rightLinePadding] = getPaddingForLine(fastStringWidth$1(line), innerWidth, contentPadding, opts?.contentAlign);
|
|
837
914
|
output.write(`${linePrefix}${vSymbol}${" ".repeat(leftLinePadding)}${line}${" ".repeat(rightLinePadding)}${vSymbol}\n`);
|
|
838
915
|
}
|
|
839
916
|
output.write(`${linePrefix}${symbols[2]}${hSymbol.repeat(innerWidth)}${symbols[3]}\n`);
|
|
@@ -888,12 +965,13 @@ const confirm = (opts) => {
|
|
|
888
965
|
inactive,
|
|
889
966
|
signal: opts.signal,
|
|
890
967
|
input: opts.input,
|
|
968
|
+
accessible: opts.accessible,
|
|
891
969
|
output: opts.output,
|
|
892
970
|
initialValue: opts.initialValue ?? true,
|
|
893
971
|
render() {
|
|
894
|
-
const hasGuide = opts
|
|
972
|
+
const hasGuide = getGuide(opts);
|
|
895
973
|
const nestedPrefix = " ";
|
|
896
|
-
const title =
|
|
974
|
+
const title = promptTitle(opts.message, this.state, opts);
|
|
897
975
|
const value = this.value ? active : inactive;
|
|
898
976
|
switch (this.state) {
|
|
899
977
|
case "submit": return `${title}${hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix}${color.dim(value)}\n${promptMilestone("confirm", opts.testId, "submit")}`;
|
|
@@ -901,7 +979,7 @@ const confirm = (opts) => {
|
|
|
901
979
|
default: {
|
|
902
980
|
const defaultPrefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
|
|
903
981
|
const defaultPrefixEnd = hasGuide ? color.blue(S_BAR_END) : "";
|
|
904
|
-
return `${title}${defaultPrefix}${this.value ? `${color.blue(S_POINTER_ACTIVE)} ${color.bold(active)}` : `${color.dim(" ")} ${color.dim(active)}`}${opts.vertical ? hasGuide ? `\n${color.blue(S_BAR)} ` : `\n${nestedPrefix}` : ` ${color.dim("/")} `}${!this.value ? `${color.blue(S_POINTER_ACTIVE)} ${color.bold(inactive)}` : `${color.dim(" ")} ${color.dim(inactive)}`}
|
|
982
|
+
return `${title}${defaultPrefix}${this.value ? `${color.blue(S_POINTER_ACTIVE)} ${color.bold(active)}` : `${color.dim(" ")} ${color.dim(active)}`}${opts.vertical ? hasGuide ? `\n${color.blue(S_BAR)} ` : `\n${nestedPrefix}` : ` ${color.dim("/")} `}${!this.value ? `${color.blue(S_POINTER_ACTIVE)} ${color.bold(inactive)}` : `${color.dim(" ")} ${color.dim(inactive)}`}${hasGuide ? `\n${defaultPrefixEnd}` : ""}\n${promptMilestone("confirm", opts.testId, this.value ? "yes" : "no")}`;
|
|
905
983
|
}
|
|
906
984
|
}
|
|
907
985
|
}
|
|
@@ -934,28 +1012,20 @@ const group = async (prompts, opts) => {
|
|
|
934
1012
|
//#region src/group-multi-select.ts
|
|
935
1013
|
const groupMultiselect = (opts) => {
|
|
936
1014
|
const { selectableGroups = true, groupSpacing = 0 } = opts;
|
|
937
|
-
const hasGuide = opts
|
|
1015
|
+
const hasGuide = getGuide(opts);
|
|
938
1016
|
const nestedPrefix = " ";
|
|
939
|
-
const withMarkerAndPrefix = (marker, prefix,
|
|
940
|
-
|
|
941
|
-
const continuationPrefix = ` ${" ".repeat(prefixWidth)}`;
|
|
942
|
-
if (lines.length === 1) return `${spacingPrefix}${marker} ${prefix}${format(lines[0])}${firstLineSuffix}`;
|
|
943
|
-
const [firstLine, ...rest] = lines;
|
|
944
|
-
return [`${spacingPrefix}${marker} ${prefix}${format(firstLine)}${firstLineSuffix}`, ...rest.map((line) => `${continuationPrefix}${format(line)}`)].join("\n");
|
|
1017
|
+
const withMarkerAndPrefix = (marker, prefix, _prefixWidth, label, format, firstLineSuffix = "", spacingPrefix = "") => {
|
|
1018
|
+
return spacingPrefix + optionText(opts.output, `${marker} ${prefix}`, label, format, firstLineSuffix);
|
|
945
1019
|
};
|
|
946
1020
|
const opt = (option, state, options = []) => {
|
|
947
1021
|
const label = option.label ?? String(option.value);
|
|
948
|
-
const hint = option.hint ? ` ${color.gray(`(${option.hint})`)}` : "";
|
|
1022
|
+
const hint = option.hint && (state === "active" || state === "active-selected") ? ` ${color.gray(`(${option.hint})`)}` : "";
|
|
949
1023
|
const isItem = typeof option.group === "string";
|
|
950
1024
|
const next = isItem && (options[options.indexOf(option) + 1] ?? { group: true });
|
|
951
1025
|
const isLast = isItem && next && next.group === true;
|
|
952
1026
|
const branchPrefixRaw = isItem ? selectableGroups ? `${isLast ? S_BAR_END : S_BAR} ` : " " : "";
|
|
953
1027
|
let spacingPrefix = "";
|
|
954
|
-
if (groupSpacing > 0 && !isItem)
|
|
955
|
-
const spacingPrefixText = hasGuide ? `\n${color.blue(S_BAR)}` : "\n";
|
|
956
|
-
const spacingSuffix = hasGuide ? " " : "";
|
|
957
|
-
spacingPrefix = `${spacingPrefixText.repeat(groupSpacing - 1)}${spacingPrefixText}${spacingSuffix}`;
|
|
958
|
-
}
|
|
1028
|
+
if (groupSpacing > 0 && !isItem && options.indexOf(option) > 0) spacingPrefix = "\n".repeat(groupSpacing);
|
|
959
1029
|
if (state === "cancelled") return color.strikethrough(color.dim(label));
|
|
960
1030
|
if (state === "submitted") return color.dim(label);
|
|
961
1031
|
const marker = state === "active" || state === "active-selected" ? color.blue(S_POINTER_ACTIVE) : color.dim(" ");
|
|
@@ -973,54 +1043,47 @@ const groupMultiselect = (opts) => {
|
|
|
973
1043
|
options: opts.options,
|
|
974
1044
|
signal: opts.signal,
|
|
975
1045
|
input: opts.input,
|
|
1046
|
+
accessible: opts.accessible,
|
|
976
1047
|
output: opts.output,
|
|
977
1048
|
initialValues: opts.initialValues,
|
|
978
1049
|
required,
|
|
979
1050
|
cursorAt: opts.cursorAt,
|
|
980
1051
|
selectableGroups,
|
|
981
1052
|
validate(selected) {
|
|
982
|
-
if (required && (selected === void 0 || selected.length === 0)) return
|
|
1053
|
+
if (required && (selected === void 0 || selected.length === 0)) return "Please select at least one option.";
|
|
983
1054
|
},
|
|
984
1055
|
render() {
|
|
985
|
-
const title =
|
|
1056
|
+
const title = promptTitle(opts.message, this.state, opts);
|
|
986
1057
|
const value = this.value ?? [];
|
|
987
1058
|
switch (this.state) {
|
|
988
1059
|
case "submit": {
|
|
989
1060
|
const selectedOptions = this.options.filter(({ value: optionValue }) => value.includes(optionValue)).map((option) => opt(option, "submitted"));
|
|
990
|
-
return `${title}${hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix}${selectedOptions.length === 0 ? "" : selectedOptions.join(color.dim(", "))}\n
|
|
1061
|
+
return `${title}${hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix}${selectedOptions.length === 0 ? "" : selectedOptions.join(color.dim(", "))}\n`;
|
|
991
1062
|
}
|
|
992
1063
|
case "cancel": {
|
|
993
1064
|
const label = this.options.filter(({ value: optionValue }) => value.includes(optionValue)).map((option) => opt(option, "cancelled")).join(color.dim(", "));
|
|
994
|
-
if (!label.trim()) return hasGuide ? `${title}${color.gray(S_BAR)}\n
|
|
1065
|
+
if (!label.trim()) return hasGuide ? `${title}${color.gray(S_BAR)}\n` : `${title.trimEnd()}\n`;
|
|
995
1066
|
const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
|
|
996
|
-
return hasGuide ? `${title}${cancelPrefix}${label}\n${color.gray(S_BAR)}\n
|
|
997
|
-
}
|
|
998
|
-
case "error": {
|
|
999
|
-
const prefix = hasGuide ? `${color.yellow(S_BAR)} ` : nestedPrefix;
|
|
1000
|
-
const footer = hasGuide ? this.error.split("\n").map((ln, i) => i === 0 ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}`).join("\n") : `${nestedPrefix}${color.yellow(this.error)}`;
|
|
1001
|
-
return `${title}${prefix}${this.options.map((option, i, options) => {
|
|
1002
|
-
const selected = value.includes(option.value) || option.group === true && this.isGroupSelected(String(option.value));
|
|
1003
|
-
const active = i === this.cursor;
|
|
1004
|
-
if (!active && typeof option.group === "string" && this.options[this.cursor].value === option.group) return opt(option, selected ? "group-active-selected" : "group-active", options);
|
|
1005
|
-
if (active && selected) return opt(option, "active-selected", options);
|
|
1006
|
-
if (selected) return opt(option, "selected", options);
|
|
1007
|
-
return opt(option, active ? "active" : "inactive", options);
|
|
1008
|
-
}).join(`\n${prefix}`)}\n${footer}\n`;
|
|
1067
|
+
return hasGuide ? `${title}${cancelPrefix}${label}\n${color.gray(S_BAR)}\n` : `${title}${cancelPrefix}${label}\n`;
|
|
1009
1068
|
}
|
|
1010
1069
|
default: {
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1070
|
+
const prefix = hasGuide ? `${this.state === "error" ? color.yellow(S_BAR) : color.blue(S_BAR)} ` : nestedPrefix;
|
|
1071
|
+
const footer = opts.showInstructions === false ? [] : formatInstructionFooter(MULTISELECT_INSTRUCTIONS, hasGuide, opts.output);
|
|
1072
|
+
if (this.state === "error") footer.push(wrapTextWithPrefix(opts.output, color.yellow(this.error), hasGuide ? `${color.yellow(S_BAR_END)} ` : nestedPrefix));
|
|
1073
|
+
else if (hasGuide) footer.push(color.blue(S_BAR_END));
|
|
1074
|
+
return `${title}${limitOptions({
|
|
1075
|
+
output: opts.output,
|
|
1076
|
+
options: this.options,
|
|
1077
|
+
cursor: this.cursor,
|
|
1078
|
+
maxItems: opts.maxItems,
|
|
1079
|
+
columnPadding: 2,
|
|
1080
|
+
rowPadding: title.split("\n").length + footer.length + 1,
|
|
1081
|
+
style: (option, active) => {
|
|
1082
|
+
const selected = value.includes(option.value) || option.group === true && this.isGroupSelected(String(option.value));
|
|
1083
|
+
const groupActive = !active && typeof option.group === "string" && this.options[this.cursor]?.value === option.group;
|
|
1084
|
+
return opt(option, groupActive ? selected ? "group-active-selected" : "group-active" : active ? selected ? "active-selected" : "active" : selected ? "selected" : "inactive", this.options);
|
|
1085
|
+
}
|
|
1086
|
+
}).map((line) => `${line ? prefix : hasGuide ? prefix.trimEnd() : ""}${line}`).join("\n")}\n${footer.join("\n")}\n`;
|
|
1024
1087
|
}
|
|
1025
1088
|
}
|
|
1026
1089
|
}
|
|
@@ -1029,19 +1092,20 @@ const groupMultiselect = (opts) => {
|
|
|
1029
1092
|
//#endregion
|
|
1030
1093
|
//#region src/log.ts
|
|
1031
1094
|
const log = {
|
|
1032
|
-
message: (message = [], { symbol
|
|
1095
|
+
message: (message = [], { symbol, secondarySymbol = color.gray(S_BAR), output = process.stdout, spacing = 0, withGuide } = {}) => {
|
|
1033
1096
|
const parts = [];
|
|
1034
|
-
const hasGuide = withGuide
|
|
1097
|
+
const hasGuide = getGuide({ withGuide });
|
|
1035
1098
|
const spacingString = !hasGuide ? "" : secondarySymbol;
|
|
1036
|
-
const prefix =
|
|
1037
|
-
const
|
|
1099
|
+
const prefix = symbol ? `${symbol} ` : hasGuide ? `${secondarySymbol} ` : "";
|
|
1100
|
+
const marker = symbol ?? secondarySymbol;
|
|
1101
|
+
const secondaryPrefix = hasGuide ? `${secondarySymbol} ` : symbol ? " " : "";
|
|
1038
1102
|
for (let i = 0; i < spacing; i++) parts.push(spacingString);
|
|
1039
1103
|
const messageParts = Array.isArray(message) ? message : message.split("\n");
|
|
1040
1104
|
if (messageParts.length > 0) {
|
|
1041
1105
|
const [firstLine, ...lines] = messageParts;
|
|
1042
|
-
if (firstLine.length > 0) parts.push(
|
|
1043
|
-
else parts.push(hasGuide
|
|
1044
|
-
for (const ln of lines) if (ln.length > 0) parts.push(
|
|
1106
|
+
if (firstLine.length > 0) parts.push(wrapTextWithPrefix(output, firstLine, secondaryPrefix, prefix));
|
|
1107
|
+
else parts.push(hasGuide || symbol ? marker : "");
|
|
1108
|
+
for (const ln of lines) if (ln.length > 0) parts.push(wrapTextWithPrefix(output, ln, secondaryPrefix));
|
|
1045
1109
|
else parts.push(hasGuide ? secondarySymbol : "");
|
|
1046
1110
|
}
|
|
1047
1111
|
output.write(`${parts.join("\n")}\n`);
|
|
@@ -1084,60 +1148,58 @@ const log = {
|
|
|
1084
1148
|
//#endregion
|
|
1085
1149
|
//#region src/messages.ts
|
|
1086
1150
|
const cancel = (message = "", opts) => {
|
|
1087
|
-
|
|
1151
|
+
const output = opts?.output ?? process.stdout;
|
|
1152
|
+
const prefix = getGuide(opts) ? `${color.gray(S_BAR_END)} ` : "";
|
|
1153
|
+
output.write(`${prefix}${color.red(message)}\n\n`);
|
|
1088
1154
|
};
|
|
1089
1155
|
const intro = (title = "", opts) => {
|
|
1090
|
-
|
|
1156
|
+
const output = opts?.output ?? process.stdout;
|
|
1157
|
+
const prefix = getGuide(opts) ? `${color.gray(S_BAR_START)} ` : "";
|
|
1158
|
+
output.write(`${prefix}${title}\n\n`);
|
|
1091
1159
|
};
|
|
1092
1160
|
const outro = (message = "", opts) => {
|
|
1093
|
-
|
|
1161
|
+
const output = opts?.output ?? process.stdout;
|
|
1162
|
+
const prefix = getGuide(opts) ? `${color.gray(S_BAR)}\n${color.gray(S_BAR_END)} ` : "";
|
|
1163
|
+
output.write(`${prefix}${message}\n\n`);
|
|
1094
1164
|
};
|
|
1095
1165
|
//#endregion
|
|
1096
1166
|
//#region src/multi-select.ts
|
|
1097
1167
|
const computeLabel$1 = (label, format) => {
|
|
1098
1168
|
return label.split("\n").map((line) => format(line)).join("\n");
|
|
1099
1169
|
};
|
|
1100
|
-
const withMarkerAndCheckbox = (marker, checkbox, checkboxWidth, label, format, firstLineSuffix = "") => {
|
|
1101
|
-
const lines = label.split("\n");
|
|
1102
|
-
const continuationPrefix = ` ${" ".repeat(checkboxWidth)} `;
|
|
1103
|
-
if (lines.length === 1) return `${marker} ${checkbox} ${format(lines[0])}${firstLineSuffix}`;
|
|
1104
|
-
const [firstLine, ...rest] = lines;
|
|
1105
|
-
return [`${marker} ${checkbox} ${format(firstLine)}${firstLineSuffix}`, ...rest.map((line) => `${continuationPrefix}${format(line)}`)].join("\n");
|
|
1106
|
-
};
|
|
1107
1170
|
const multiselect = (opts) => {
|
|
1171
|
+
const withMarkerAndCheckbox = (marker, checkbox, _width, label, format, suffix = "") => optionText(opts.output, `${marker} ${checkbox} `, label, format, suffix);
|
|
1108
1172
|
const opt = (option, state) => {
|
|
1109
1173
|
const label = option.label ?? String(option.value);
|
|
1110
1174
|
const hint = option.hint ? ` ${color.gray(`(${option.hint})`)}` : "";
|
|
1111
1175
|
if (state === "disabled") return withMarkerAndCheckbox(color.gray(" "), color.gray(S_CHECKBOX_INACTIVE), S_CHECKBOX_INACTIVE.length, label, (str) => color.strikethrough(color.gray(str)), option.hint ? ` ${color.dim(`(${option.hint ?? "disabled"})`)}` : "");
|
|
1112
1176
|
if (state === "active") return withMarkerAndCheckbox(color.blue(S_POINTER_ACTIVE), color.blue(S_CHECKBOX_ACTIVE), S_CHECKBOX_ACTIVE.length, label, (text) => color.blue(color.bold(text)), hint);
|
|
1113
|
-
if (state === "selected") return withMarkerAndCheckbox(color.dim(" "), color.blue(S_CHECKBOX_SELECTED), S_CHECKBOX_SELECTED.length, label, color.dim
|
|
1177
|
+
if (state === "selected") return withMarkerAndCheckbox(color.dim(" "), color.blue(S_CHECKBOX_SELECTED), S_CHECKBOX_SELECTED.length, label, color.dim);
|
|
1114
1178
|
if (state === "cancelled") return computeLabel$1(label, (text) => color.strikethrough(color.dim(text)));
|
|
1115
1179
|
if (state === "active-selected") return withMarkerAndCheckbox(color.blue(S_POINTER_ACTIVE), color.blue(S_CHECKBOX_SELECTED), S_CHECKBOX_SELECTED.length, label, (text) => color.blue(color.bold(text)), hint);
|
|
1116
1180
|
if (state === "submitted") return computeLabel$1(label, color.dim);
|
|
1117
1181
|
return withMarkerAndCheckbox(color.dim(" "), color.dim(S_CHECKBOX_INACTIVE), S_CHECKBOX_INACTIVE.length, label, color.dim);
|
|
1118
1182
|
};
|
|
1119
1183
|
const required = opts.required ?? true;
|
|
1120
|
-
const hint = " " + color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(" space ")))} to select, ${color.gray(color.bgWhite(color.inverse(" enter ")))} to submit`));
|
|
1121
1184
|
return new MultiSelectPrompt({
|
|
1122
1185
|
options: opts.options,
|
|
1123
1186
|
signal: opts.signal,
|
|
1124
1187
|
input: opts.input,
|
|
1188
|
+
accessible: opts.accessible,
|
|
1125
1189
|
output: opts.output,
|
|
1126
1190
|
initialValues: opts.initialValues,
|
|
1127
1191
|
required,
|
|
1128
1192
|
cursorAt: opts.cursorAt,
|
|
1129
1193
|
validate(selected) {
|
|
1130
|
-
if (required && (selected === void 0 || selected.length === 0)) return
|
|
1194
|
+
if (required && (selected === void 0 || selected.length === 0)) return "Please select at least one option.";
|
|
1131
1195
|
},
|
|
1132
1196
|
render() {
|
|
1133
|
-
const hasGuide = opts
|
|
1197
|
+
const hasGuide = getGuide(opts);
|
|
1134
1198
|
const nestedPrefix = " ";
|
|
1135
|
-
const
|
|
1136
|
-
return message.split("\n").map((line, index) => `${index === 0 ? `${symbol(this.state)} ` : nestedPrefix}${line}`).join("\n");
|
|
1137
|
-
};
|
|
1138
|
-
const wrappedMessage = hasGuide ? wrapTextWithPrefix(opts.output, opts.message, `${symbolBar(this.state)} `, `${symbol(this.state)} `) : formatMessageLines(opts.message);
|
|
1139
|
-
const title = `${hasGuide ? `${color.gray(S_BAR)}\n` : ""}${wrappedMessage}\n`;
|
|
1199
|
+
const title = promptTitle(opts.message, this.state, opts);
|
|
1140
1200
|
const value = this.value ?? [];
|
|
1201
|
+
const instructions = opts.showInstructions === false ? [] : formatInstructionFooter(MULTISELECT_INSTRUCTIONS, hasGuide, opts.output);
|
|
1202
|
+
const hint = instructions.join("\n");
|
|
1141
1203
|
const styleOption = (option, active) => {
|
|
1142
1204
|
if (option.disabled) return opt(option, "disabled");
|
|
1143
1205
|
const selected = value.includes(option.value);
|
|
@@ -1160,15 +1222,15 @@ const multiselect = (opts) => {
|
|
|
1160
1222
|
}
|
|
1161
1223
|
case "error": {
|
|
1162
1224
|
const prefix = hasGuide ? `${color.yellow(S_BAR)} ` : nestedPrefix;
|
|
1163
|
-
const footer =
|
|
1225
|
+
const footer = wrapTextWithPrefix(opts.output, color.yellow(this.error), hasGuide ? `${color.yellow(S_BAR_END)} ` : nestedPrefix);
|
|
1164
1226
|
const titleLineCount = title.split("\n").length;
|
|
1165
|
-
const footerLineCount = footer.split("\n").length + 1;
|
|
1227
|
+
const footerLineCount = footer.split("\n").length + instructions.length + 1;
|
|
1166
1228
|
return `${title}${prefix}${limitOptions({
|
|
1167
1229
|
output: opts.output,
|
|
1168
1230
|
options: this.options,
|
|
1169
1231
|
cursor: this.cursor,
|
|
1170
1232
|
maxItems: opts.maxItems,
|
|
1171
|
-
columnPadding:
|
|
1233
|
+
columnPadding: 2,
|
|
1172
1234
|
rowPadding: titleLineCount + footerLineCount,
|
|
1173
1235
|
style: styleOption
|
|
1174
1236
|
}).join(`\n${prefix}`)}\n${hint}\n${footer}\n`;
|
|
@@ -1176,16 +1238,16 @@ const multiselect = (opts) => {
|
|
|
1176
1238
|
default: {
|
|
1177
1239
|
const prefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
|
|
1178
1240
|
const titleLineCount = title.split("\n").length;
|
|
1179
|
-
const footerLineCount = hasGuide ? 2 : 1;
|
|
1241
|
+
const footerLineCount = instructions.length + (hasGuide ? 2 : 1);
|
|
1180
1242
|
return `${title}${prefix}${limitOptions({
|
|
1181
1243
|
output: opts.output,
|
|
1182
1244
|
options: this.options,
|
|
1183
1245
|
cursor: this.cursor,
|
|
1184
1246
|
maxItems: opts.maxItems,
|
|
1185
|
-
columnPadding:
|
|
1247
|
+
columnPadding: 2,
|
|
1186
1248
|
rowPadding: titleLineCount + footerLineCount,
|
|
1187
1249
|
style: styleOption
|
|
1188
|
-
}).join(`\n${prefix}`)}\n${hint}
|
|
1250
|
+
}).join(`\n${prefix}`)}\n${hint}${hasGuide ? `\n${color.blue(S_BAR_END)}` : ""}\n`;
|
|
1189
1251
|
}
|
|
1190
1252
|
}
|
|
1191
1253
|
}
|
|
@@ -1193,35 +1255,15 @@ const multiselect = (opts) => {
|
|
|
1193
1255
|
};
|
|
1194
1256
|
//#endregion
|
|
1195
1257
|
//#region src/note.ts
|
|
1196
|
-
|
|
1197
|
-
const wrapWithFormat = (message, width, format) => {
|
|
1198
|
-
const opts = {
|
|
1199
|
-
hard: true,
|
|
1200
|
-
trim: false
|
|
1201
|
-
};
|
|
1202
|
-
const wrapMsg = wrapAnsi(message, width, opts).split("\n");
|
|
1203
|
-
const maxWidthNormal = wrapMsg.reduce((sum, ln) => Math.max(fastStringWidth(ln), sum), 0);
|
|
1204
|
-
return wrapAnsi(message, width - (wrapMsg.map(format).reduce((sum, ln) => Math.max(fastStringWidth(ln), sum), 0) - maxWidthNormal), opts);
|
|
1205
|
-
};
|
|
1258
|
+
/** A compact, enclosed note. Guide bars never replace its side borders. */
|
|
1206
1259
|
const note = (message = "", title = "", opts) => {
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
];
|
|
1215
|
-
const titleLen = fastStringWidth(title);
|
|
1216
|
-
const len = Math.max(lines.reduce((sum, ln) => {
|
|
1217
|
-
const width = fastStringWidth(ln);
|
|
1218
|
-
return width > sum ? width : sum;
|
|
1219
|
-
}, 0), titleLen) + 2;
|
|
1220
|
-
const lineSymbol = hasGuide ? color.gray(S_BAR) : " ";
|
|
1221
|
-
const msg = lines.map((ln) => `${lineSymbol} ${ln}${" ".repeat(len - fastStringWidth(ln))}${lineSymbol}`).join("\n");
|
|
1222
|
-
const leadingBorder = hasGuide ? `${color.gray(S_BAR)}\n` : "";
|
|
1223
|
-
const bottomLeft = hasGuide ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
|
|
1224
|
-
output.write(`${leadingBorder}${completeColor(S_STEP_SUBMIT)} ${color.reset(title)} ${color.gray(S_BAR_H.repeat(Math.max(len - titleLen - 1, 1)) + S_CORNER_TOP_RIGHT)}\n${msg}\n${color.gray(bottomLeft + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n`);
|
|
1260
|
+
const content = opts?.format ? message.split("\n").map(opts.format).join("\n") : message;
|
|
1261
|
+
box(`\n${content}\n`, title, {
|
|
1262
|
+
...opts,
|
|
1263
|
+
width: "auto",
|
|
1264
|
+
rounded: true,
|
|
1265
|
+
formatBorder: color.gray
|
|
1266
|
+
});
|
|
1225
1267
|
};
|
|
1226
1268
|
//#endregion
|
|
1227
1269
|
//#region src/password.ts
|
|
@@ -1231,40 +1273,66 @@ const password = (opts) => {
|
|
|
1231
1273
|
mask: opts.mask ?? S_PASSWORD_MASK,
|
|
1232
1274
|
signal: opts.signal,
|
|
1233
1275
|
input: opts.input,
|
|
1276
|
+
accessible: opts.accessible,
|
|
1234
1277
|
output: opts.output,
|
|
1235
1278
|
render() {
|
|
1236
|
-
const hasGuide = opts
|
|
1279
|
+
const hasGuide = getGuide(opts);
|
|
1237
1280
|
const nestedPrefix = " ";
|
|
1238
|
-
const title =
|
|
1239
|
-
const userInput = this.userInputWithCursor;
|
|
1281
|
+
const title = promptTitle(opts.message, this.state, opts);
|
|
1282
|
+
const userInput = !this.userInput && opts.placeholder ? color.dim(opts.placeholder) : this.userInputWithCursor;
|
|
1240
1283
|
const masked = this.masked;
|
|
1241
1284
|
switch (this.state) {
|
|
1285
|
+
case "validating": {
|
|
1286
|
+
const prefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
|
|
1287
|
+
return `${title}${prefix}${color.dim(masked ?? "")}\n${prefix}${color.dim("Validating…")}\n`;
|
|
1288
|
+
}
|
|
1242
1289
|
case "error": {
|
|
1243
1290
|
const errorPrefix = hasGuide ? `${color.yellow(S_BAR)} ` : nestedPrefix;
|
|
1244
1291
|
const errorPrefixEnd = hasGuide ? `${color.yellow(S_BAR_END)} ` : "";
|
|
1245
1292
|
const maskedText = masked ?? "";
|
|
1246
1293
|
if (opts.clearOnError) this.clear();
|
|
1247
|
-
return `${title.trim()}\n${errorPrefix}${maskedText}\n${
|
|
1294
|
+
return `${title.trim()}\n${errorPrefix}${maskedText}\n${wrapTextWithPrefix(opts.output, color.yellow(this.error), hasGuide ? errorPrefixEnd : nestedPrefix)}\n`;
|
|
1248
1295
|
}
|
|
1249
1296
|
case "submit": return `${title}${hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix}${masked ? color.dim(masked) : ""}\n`;
|
|
1250
1297
|
case "cancel": return `${title}${hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix}${masked ? color.strikethrough(color.dim(masked)) : ""}${masked && hasGuide ? `\n${color.gray(S_BAR)}` : ""}\n`;
|
|
1251
|
-
default:
|
|
1298
|
+
default: {
|
|
1299
|
+
const defaultPrefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
|
|
1300
|
+
const defaultPrefixEnd = hasGuide ? color.blue(S_BAR_END) : "";
|
|
1301
|
+
return `${title}${defaultPrefix}${userInput}${hasGuide ? `\n${defaultPrefixEnd}` : ""}\n`;
|
|
1302
|
+
}
|
|
1252
1303
|
}
|
|
1253
1304
|
}
|
|
1254
1305
|
}).prompt();
|
|
1255
1306
|
};
|
|
1256
1307
|
//#endregion
|
|
1257
1308
|
//#region src/path.ts
|
|
1309
|
+
/**
|
|
1310
|
+
* The `path` prompt extends `autocomplete` to provide file and directory suggestions.
|
|
1311
|
+
*
|
|
1312
|
+
* @see https://bomb.sh/docs/clack/packages/prompts/#path-selection
|
|
1313
|
+
*
|
|
1314
|
+
* @example
|
|
1315
|
+
* ```ts
|
|
1316
|
+
* import { path } from '@voidzero-dev/vite-plus-prompts';
|
|
1317
|
+
*
|
|
1318
|
+
* const result = await path({
|
|
1319
|
+
* message: 'Select a file:',
|
|
1320
|
+
* root: process.cwd(),
|
|
1321
|
+
* directory: false,
|
|
1322
|
+
* });
|
|
1323
|
+
* ```
|
|
1324
|
+
*/
|
|
1258
1325
|
const path = (opts) => {
|
|
1259
1326
|
const validate = opts.validate;
|
|
1260
1327
|
return autocomplete({
|
|
1261
1328
|
...opts,
|
|
1262
1329
|
initialUserInput: opts.initialValue ?? opts.root ?? process.cwd(),
|
|
1263
1330
|
maxItems: 5,
|
|
1331
|
+
completeOnTab: true,
|
|
1264
1332
|
validate(value) {
|
|
1265
1333
|
if (Array.isArray(value)) return;
|
|
1266
1334
|
if (!value) return "Please select a path";
|
|
1267
|
-
if (validate) return validate
|
|
1335
|
+
if (validate) return runValidation(validate, value);
|
|
1268
1336
|
},
|
|
1269
1337
|
options() {
|
|
1270
1338
|
const userInput = this.userInput;
|
|
@@ -1272,8 +1340,9 @@ const path = (opts) => {
|
|
|
1272
1340
|
try {
|
|
1273
1341
|
let searchPath;
|
|
1274
1342
|
if (!existsSync(userInput)) searchPath = dirname(userInput);
|
|
1275
|
-
else if (lstatSync(userInput).isDirectory()) searchPath = userInput;
|
|
1343
|
+
else if (lstatSync(userInput).isDirectory() && (!opts.directory || userInput.endsWith("/"))) searchPath = userInput;
|
|
1276
1344
|
else searchPath = dirname(userInput);
|
|
1345
|
+
const prefix = userInput.length > 1 && userInput.endsWith("/") ? userInput.slice(0, -1) : userInput;
|
|
1277
1346
|
return readdirSync(searchPath).map((item) => {
|
|
1278
1347
|
const path = join(searchPath, item);
|
|
1279
1348
|
return {
|
|
@@ -1281,7 +1350,7 @@ const path = (opts) => {
|
|
|
1281
1350
|
path,
|
|
1282
1351
|
isDirectory: lstatSync(path).isDirectory()
|
|
1283
1352
|
};
|
|
1284
|
-
}).filter(({ path, isDirectory }) => path.startsWith(
|
|
1353
|
+
}).filter(({ path, isDirectory }) => path.startsWith(prefix) && (isDirectory || !opts.directory)).map((item) => ({ value: item.path }));
|
|
1285
1354
|
} catch {
|
|
1286
1355
|
return [];
|
|
1287
1356
|
}
|
|
@@ -1290,7 +1359,7 @@ const path = (opts) => {
|
|
|
1290
1359
|
};
|
|
1291
1360
|
//#endregion
|
|
1292
1361
|
//#region src/spinner.ts
|
|
1293
|
-
const defaultStyleFn = color.
|
|
1362
|
+
const defaultStyleFn = color.blue;
|
|
1294
1363
|
const removeTrailingDots = (msg) => {
|
|
1295
1364
|
return msg.replace(/\.+$/, "");
|
|
1296
1365
|
};
|
|
@@ -1311,7 +1380,7 @@ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancel
|
|
|
1311
1380
|
"O",
|
|
1312
1381
|
"0"
|
|
1313
1382
|
], delay = unicode ? 80 : 120, signal, ...opts } = {}) => {
|
|
1314
|
-
const isCI$1 = isCI();
|
|
1383
|
+
const isCI$1 = isCI() || !isTTY(output) || isAccessible(opts.accessible);
|
|
1315
1384
|
let unblock;
|
|
1316
1385
|
let loop;
|
|
1317
1386
|
let isSpinnerActive = false;
|
|
@@ -1354,7 +1423,7 @@ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancel
|
|
|
1354
1423
|
};
|
|
1355
1424
|
const clearPrevMessage = () => {
|
|
1356
1425
|
if (_prevMessage === void 0) return;
|
|
1357
|
-
if (isCI$1)
|
|
1426
|
+
if (isCI$1) return;
|
|
1358
1427
|
const prevLines = wrapAnsi(_prevMessage, columns, {
|
|
1359
1428
|
hard: true,
|
|
1360
1429
|
trim: false
|
|
@@ -1363,10 +1432,10 @@ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancel
|
|
|
1363
1432
|
output.write(cursor.to(0));
|
|
1364
1433
|
output.write(erase.down());
|
|
1365
1434
|
};
|
|
1366
|
-
const hasGuide = opts
|
|
1435
|
+
const hasGuide = getGuide(opts);
|
|
1367
1436
|
const startLoop = () => {
|
|
1368
1437
|
isSpinnerActive = true;
|
|
1369
|
-
unblock = block({ output });
|
|
1438
|
+
unblock = isCI$1 ? () => {} : block({ output });
|
|
1370
1439
|
_origin = performance.now();
|
|
1371
1440
|
_prevMessage = void 0;
|
|
1372
1441
|
if (hasGuide) output.write(`${color.gray(S_BAR)}\n`);
|
|
@@ -1374,10 +1443,9 @@ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancel
|
|
|
1374
1443
|
let indicatorTimer = 0;
|
|
1375
1444
|
registerHooks();
|
|
1376
1445
|
const renderFrame = () => {
|
|
1377
|
-
if (isCI$1 &&
|
|
1446
|
+
if (isCI$1 && _prevMessage !== void 0) return;
|
|
1378
1447
|
clearPrevMessage();
|
|
1379
|
-
|
|
1380
|
-
const frame = styleFn(frames[frameIndex]);
|
|
1448
|
+
const frame = styleFn(frames[frameIndex] ?? (unicode ? "◒" : "o"));
|
|
1381
1449
|
let outputMessage;
|
|
1382
1450
|
if (isCI$1) outputMessage = `${frame} ${_message}...`;
|
|
1383
1451
|
else if (indicator === "timer") outputMessage = `${frame} ${_message} ${formatTimer(getElapsedMs())}`;
|
|
@@ -1389,34 +1457,39 @@ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancel
|
|
|
1389
1457
|
hard: true,
|
|
1390
1458
|
trim: false
|
|
1391
1459
|
});
|
|
1392
|
-
output.write(wrapped);
|
|
1460
|
+
output.write(isCI$1 ? `${wrapped}\n` : wrapped);
|
|
1461
|
+
_prevMessage = wrapped;
|
|
1393
1462
|
frameIndex = frameIndex + 1 < frames.length ? frameIndex + 1 : 0;
|
|
1394
1463
|
indicatorTimer = indicatorTimer < 4 ? indicatorTimer + .125 : 0;
|
|
1395
1464
|
};
|
|
1396
1465
|
renderFrame();
|
|
1397
|
-
loop = setInterval(renderFrame, delay);
|
|
1466
|
+
if (!isCI$1) loop = setInterval(renderFrame, delay);
|
|
1467
|
+
if (signal?.aborted) signalEventHandler();
|
|
1398
1468
|
};
|
|
1399
1469
|
const start = (msg = "") => {
|
|
1470
|
+
if (isSpinnerActive) return;
|
|
1471
|
+
isCancelled = false;
|
|
1400
1472
|
_elapsedMs = 0;
|
|
1401
1473
|
_message = removeTrailingDots(msg);
|
|
1402
1474
|
startLoop();
|
|
1403
1475
|
};
|
|
1404
1476
|
const _stop = (msg = "", code = 0, silent = false, preserveElapsed = false) => {
|
|
1405
1477
|
if (!isSpinnerActive) return;
|
|
1478
|
+
const elapsedMs = getElapsedMs();
|
|
1406
1479
|
isSpinnerActive = false;
|
|
1480
|
+
isCancelled = code === 1;
|
|
1407
1481
|
clearInterval(loop);
|
|
1408
1482
|
clearPrevMessage();
|
|
1409
|
-
const elapsedMs = getElapsedMs();
|
|
1410
1483
|
const step = code === 0 ? completeColor(S_STEP_SUBMIT) : code === 1 ? color.red(S_STEP_CANCEL) : color.red(S_STEP_ERROR);
|
|
1411
1484
|
_message = msg ?? _message;
|
|
1412
1485
|
if (!silent) {
|
|
1413
|
-
if (indicator === "timer") output.write(`${step} ${_message} ${formatTimer(elapsedMs)}\n
|
|
1414
|
-
else output.write(`${step} ${_message}\n
|
|
1486
|
+
if (indicator === "timer") output.write(`${step} ${_message} ${formatTimer(elapsedMs)}\n`);
|
|
1487
|
+
else output.write(`${step} ${_message}\n`);
|
|
1415
1488
|
}
|
|
1416
1489
|
if (!preserveElapsed) _elapsedMs = 0;
|
|
1417
1490
|
_prevMessage = void 0;
|
|
1418
1491
|
clearHooks();
|
|
1419
|
-
unblock();
|
|
1492
|
+
unblock?.();
|
|
1420
1493
|
};
|
|
1421
1494
|
const pause = () => {
|
|
1422
1495
|
if (!isSpinnerActive) return;
|
|
@@ -1465,11 +1538,11 @@ function progress({ style = "heavy", max: userMax = 100, size: userSize = 40, ..
|
|
|
1465
1538
|
const activeStyle = (state) => {
|
|
1466
1539
|
switch (state) {
|
|
1467
1540
|
case "initial":
|
|
1468
|
-
case "active": return color.
|
|
1541
|
+
case "active": return color.blue;
|
|
1469
1542
|
case "error":
|
|
1470
1543
|
case "cancel": return color.red;
|
|
1471
1544
|
case "submit": return completeColor;
|
|
1472
|
-
default: return color.
|
|
1545
|
+
default: return color.blue;
|
|
1473
1546
|
}
|
|
1474
1547
|
};
|
|
1475
1548
|
const drawProgress = (state, msg) => {
|
|
@@ -1510,14 +1583,10 @@ const computeLabel = (label, format) => {
|
|
|
1510
1583
|
if (!label.includes("\n")) return format(label);
|
|
1511
1584
|
return label.split("\n").map((line) => format(line)).join("\n");
|
|
1512
1585
|
};
|
|
1513
|
-
const withMarker = (marker, label, format, firstLineSuffix = "") => {
|
|
1514
|
-
const lines = label.split("\n");
|
|
1515
|
-
if (lines.length === 1) return `${marker} ${format(lines[0])}${firstLineSuffix}`;
|
|
1516
|
-
const [firstLine, ...rest] = lines;
|
|
1517
|
-
return [`${marker} ${format(firstLine)}${firstLineSuffix}`, ...rest.map((line) => ` ${format(line)}`)].join("\n");
|
|
1518
|
-
};
|
|
1519
1586
|
const select = (opts) => {
|
|
1587
|
+
const withMarker = (marker, label, format, suffix = "") => optionText(opts.output, `${marker} `, label, format, suffix);
|
|
1520
1588
|
const opt = (option, state) => {
|
|
1589
|
+
if (!option) return "";
|
|
1521
1590
|
const label = option.label ?? String(option.value);
|
|
1522
1591
|
const hint = option.hint ? `: ${color.gray(option.hint)}` : "";
|
|
1523
1592
|
switch (state) {
|
|
@@ -1525,24 +1594,20 @@ const select = (opts) => {
|
|
|
1525
1594
|
case "selected": return computeLabel(label, color.dim);
|
|
1526
1595
|
case "active": return withMarker(color.blue(S_POINTER_ACTIVE), label, (text) => color.blue(color.bold(text)), hint);
|
|
1527
1596
|
case "cancelled": return computeLabel(label, (str) => color.strikethrough(color.dim(str)));
|
|
1528
|
-
default: return withMarker(color.dim(" "), label,
|
|
1597
|
+
default: return withMarker(color.dim(" "), label, color.dim);
|
|
1529
1598
|
}
|
|
1530
1599
|
};
|
|
1531
1600
|
return new SelectPrompt({
|
|
1532
1601
|
options: opts.options,
|
|
1533
1602
|
signal: opts.signal,
|
|
1534
1603
|
input: opts.input,
|
|
1604
|
+
accessible: opts.accessible,
|
|
1535
1605
|
output: opts.output,
|
|
1536
1606
|
initialValue: opts.initialValue,
|
|
1537
1607
|
render() {
|
|
1538
|
-
const hasGuide = opts
|
|
1608
|
+
const hasGuide = getGuide(opts);
|
|
1539
1609
|
const nestedPrefix = " ";
|
|
1540
|
-
const
|
|
1541
|
-
return message.split("\n").map((line, index) => `${index === 0 ? `${symbol(this.state)} ` : nestedPrefix}${line}`).join("\n");
|
|
1542
|
-
};
|
|
1543
|
-
const hasMessage = opts.message.trim().length > 0;
|
|
1544
|
-
const messageLines = !hasMessage ? "" : hasGuide ? wrapTextWithPrefix(opts.output, opts.message, `${symbolBar(this.state)} `, `${symbol(this.state)} `) : formatMessageLines(opts.message);
|
|
1545
|
-
const title = hasMessage ? `${hasGuide ? `${color.gray(S_BAR)}\n` : ""}${messageLines}\n` : "";
|
|
1610
|
+
const title = promptTitle(opts.message, this.state, opts);
|
|
1546
1611
|
switch (this.state) {
|
|
1547
1612
|
case "submit": {
|
|
1548
1613
|
const submitPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
|
|
@@ -1554,15 +1619,17 @@ const select = (opts) => {
|
|
|
1554
1619
|
}
|
|
1555
1620
|
default: {
|
|
1556
1621
|
const prefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
|
|
1557
|
-
const
|
|
1622
|
+
const footer = opts.showInstructions === false ? [] : formatInstructionFooter(SELECT_INSTRUCTIONS, hasGuide, opts.output);
|
|
1623
|
+
if (hasGuide) footer.push(color.blue(S_BAR_END));
|
|
1624
|
+
const prefixEnd = footer.join("\n");
|
|
1558
1625
|
const titleLineCount = title ? title.split("\n").length : 0;
|
|
1559
|
-
const footerLineCount =
|
|
1626
|
+
const footerLineCount = footer.length + 1;
|
|
1560
1627
|
return `${title}${prefix}${limitOptions({
|
|
1561
1628
|
output: opts.output,
|
|
1562
1629
|
cursor: this.cursor,
|
|
1563
1630
|
options: this.options,
|
|
1564
1631
|
maxItems: opts.maxItems,
|
|
1565
|
-
columnPadding:
|
|
1632
|
+
columnPadding: 2,
|
|
1566
1633
|
rowPadding: titleLineCount + footerLineCount,
|
|
1567
1634
|
style: (item, active) => opt(item, item.disabled ? "disabled" : active ? "active" : "inactive")
|
|
1568
1635
|
}).join(`\n${prefix}`)}\n${prefixEnd}\n${promptMilestone("select", opts.testId, String(this.cursor))}`;
|
|
@@ -1574,30 +1641,27 @@ const select = (opts) => {
|
|
|
1574
1641
|
//#endregion
|
|
1575
1642
|
//#region src/select-key.ts
|
|
1576
1643
|
const selectKey = (opts) => {
|
|
1577
|
-
const withMarker = (marker, value) => {
|
|
1578
|
-
const lines = value.split("\n");
|
|
1579
|
-
if (lines.length === 1) return `${marker} ${lines[0]}`;
|
|
1580
|
-
const [firstLine, ...rest] = lines;
|
|
1581
|
-
return [`${marker} ${firstLine}`, ...rest.map((line) => ` ${line}`)].join("\n");
|
|
1582
|
-
};
|
|
1644
|
+
const withMarker = (marker, value) => optionText(opts.output, `${marker} `, value, (text) => text);
|
|
1583
1645
|
const opt = (option, state = "inactive") => {
|
|
1646
|
+
if (!option) return "";
|
|
1584
1647
|
const label = option.label ?? option.value;
|
|
1585
1648
|
if (state === "selected") return color.dim(label);
|
|
1586
1649
|
if (state === "cancelled") return color.strikethrough(color.dim(label));
|
|
1587
|
-
if (state === "active") return withMarker(color.blue(S_POINTER_ACTIVE), `${color.
|
|
1588
|
-
return withMarker(color.dim(" "),
|
|
1650
|
+
if (state === "active") return withMarker(color.blue(S_POINTER_ACTIVE), `${color.blue(`[${option.value}]`)} ${color.blue(color.bold(label))}${option.hint ? ` ${color.dim(`(${option.hint})`)}` : ""}`);
|
|
1651
|
+
return withMarker(color.dim(" "), color.dim(`[${option.value}] ${label}`));
|
|
1589
1652
|
};
|
|
1590
1653
|
return new SelectKeyPrompt({
|
|
1591
1654
|
options: opts.options,
|
|
1592
1655
|
signal: opts.signal,
|
|
1593
1656
|
input: opts.input,
|
|
1657
|
+
accessible: opts.accessible,
|
|
1594
1658
|
output: opts.output,
|
|
1595
1659
|
initialValue: opts.initialValue,
|
|
1596
1660
|
caseSensitive: opts.caseSensitive,
|
|
1597
1661
|
render() {
|
|
1598
|
-
const hasGuide = opts
|
|
1662
|
+
const hasGuide = getGuide(opts);
|
|
1599
1663
|
const nestedPrefix = " ";
|
|
1600
|
-
const title =
|
|
1664
|
+
const title = promptTitle(opts.message, this.state, opts);
|
|
1601
1665
|
switch (this.state) {
|
|
1602
1666
|
case "submit": {
|
|
1603
1667
|
const submitPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
|
|
@@ -1611,7 +1675,7 @@ const selectKey = (opts) => {
|
|
|
1611
1675
|
default: {
|
|
1612
1676
|
const defaultPrefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
|
|
1613
1677
|
const defaultPrefixEnd = hasGuide ? color.blue(S_BAR_END) : "";
|
|
1614
|
-
return `${title}${this.options.map((option, i) => wrapTextWithPrefix(opts.output, opt(option, i === this.cursor ? "active" : "inactive"), defaultPrefix)).join("\n")}
|
|
1678
|
+
return `${title}${this.options.map((option, i) => wrapTextWithPrefix(opts.output, opt(option, i === this.cursor ? "active" : "inactive"), defaultPrefix)).join("\n")}${hasGuide ? `\n${defaultPrefixEnd}` : ""}\n`;
|
|
1615
1679
|
}
|
|
1616
1680
|
}
|
|
1617
1681
|
}
|
|
@@ -1685,22 +1749,23 @@ const taskLog = (opts) => {
|
|
|
1685
1749
|
const output = opts.output ?? process.stdout;
|
|
1686
1750
|
const columns = getColumns(output);
|
|
1687
1751
|
const secondarySymbol = color.gray(S_BAR);
|
|
1688
|
-
const spacing = opts.spacing ??
|
|
1689
|
-
const
|
|
1752
|
+
const spacing = opts.spacing ?? 0;
|
|
1753
|
+
const hasGuide = getGuide(opts);
|
|
1754
|
+
const barSize = hasGuide ? 3 : 0;
|
|
1690
1755
|
const retainLog = opts.retainLog === true;
|
|
1691
1756
|
const isTTY$1 = !isCI() && isTTY(output);
|
|
1692
|
-
output.write(`${secondarySymbol}\n`);
|
|
1757
|
+
if (hasGuide) output.write(`${secondarySymbol}\n`);
|
|
1693
1758
|
output.write(`${completeColor(S_STEP_SUBMIT)} ${opts.title}\n`);
|
|
1694
|
-
for (let i = 0; i < spacing; i++) output.write(`${secondarySymbol}\n`);
|
|
1759
|
+
for (let i = 0; i < spacing; i++) output.write(`${hasGuide ? secondarySymbol : ""}\n`);
|
|
1695
1760
|
const buffers = [{
|
|
1696
1761
|
value: "",
|
|
1697
1762
|
full: ""
|
|
1698
1763
|
}];
|
|
1699
1764
|
let lastMessageWasRaw = false;
|
|
1700
1765
|
const clear = (clearTitle) => {
|
|
1701
|
-
if (buffers.length === 0) return;
|
|
1766
|
+
if (!isTTY$1 || buffers.length === 0) return;
|
|
1702
1767
|
let lines = 0;
|
|
1703
|
-
if (clearTitle) lines += spacing +
|
|
1768
|
+
if (clearTitle) lines += spacing + 1 + (hasGuide ? 1 : 0);
|
|
1704
1769
|
for (const buffer of buffers) {
|
|
1705
1770
|
const { value, result } = buffer;
|
|
1706
1771
|
let text = result?.message ?? value;
|
|
@@ -1708,7 +1773,7 @@ const taskLog = (opts) => {
|
|
|
1708
1773
|
if (result === void 0 && buffer.header !== void 0 && buffer.header !== "") text += `\n${buffer.header}`;
|
|
1709
1774
|
const bufferHeight = text.split("\n").reduce((count, line) => {
|
|
1710
1775
|
if (line === "") return count + 1;
|
|
1711
|
-
return count + Math.ceil((line
|
|
1776
|
+
return count + Math.ceil((fastStringWidth$1(line) + (result ? 3 : barSize)) / columns);
|
|
1712
1777
|
}, 0);
|
|
1713
1778
|
lines += bufferHeight;
|
|
1714
1779
|
}
|
|
@@ -1721,14 +1786,16 @@ const taskLog = (opts) => {
|
|
|
1721
1786
|
const messages = full ? `${buffer.full}\n${buffer.value}` : buffer.value;
|
|
1722
1787
|
if (buffer.header !== void 0 && buffer.header !== "") log.message(buffer.header.split("\n").map(color.bold), {
|
|
1723
1788
|
output,
|
|
1789
|
+
withGuide: hasGuide,
|
|
1724
1790
|
secondarySymbol,
|
|
1725
|
-
symbol: secondarySymbol,
|
|
1791
|
+
symbol: hasGuide ? secondarySymbol : void 0,
|
|
1726
1792
|
spacing: 0
|
|
1727
1793
|
});
|
|
1728
1794
|
log.message(messages.split("\n").map(color.dim), {
|
|
1729
1795
|
output,
|
|
1796
|
+
withGuide: hasGuide,
|
|
1730
1797
|
secondarySymbol,
|
|
1731
|
-
symbol: secondarySymbol,
|
|
1798
|
+
symbol: hasGuide ? secondarySymbol : void 0,
|
|
1732
1799
|
spacing: messageSpacing ?? spacing
|
|
1733
1800
|
});
|
|
1734
1801
|
};
|
|
@@ -1759,11 +1826,13 @@ const taskLog = (opts) => {
|
|
|
1759
1826
|
for (const buffer of buffers) if (buffer.result) {
|
|
1760
1827
|
if (buffer.result.status === "error") log.error(buffer.result.message, {
|
|
1761
1828
|
output,
|
|
1829
|
+
withGuide: hasGuide,
|
|
1762
1830
|
secondarySymbol,
|
|
1763
1831
|
spacing: 0
|
|
1764
1832
|
});
|
|
1765
1833
|
else log.success(buffer.result.message, {
|
|
1766
1834
|
output,
|
|
1835
|
+
withGuide: hasGuide,
|
|
1767
1836
|
secondarySymbol,
|
|
1768
1837
|
spacing: 0
|
|
1769
1838
|
});
|
|
@@ -1807,8 +1876,9 @@ const taskLog = (opts) => {
|
|
|
1807
1876
|
clear(true);
|
|
1808
1877
|
log.error(message, {
|
|
1809
1878
|
output,
|
|
1879
|
+
withGuide: hasGuide,
|
|
1810
1880
|
secondarySymbol,
|
|
1811
|
-
spacing
|
|
1881
|
+
spacing
|
|
1812
1882
|
});
|
|
1813
1883
|
if (opts?.showLog !== false) renderBuffer();
|
|
1814
1884
|
buffers.splice(1, buffers.length - 1);
|
|
@@ -1819,6 +1889,7 @@ const taskLog = (opts) => {
|
|
|
1819
1889
|
clear(true);
|
|
1820
1890
|
log.success(message, {
|
|
1821
1891
|
output,
|
|
1892
|
+
withGuide: hasGuide,
|
|
1822
1893
|
secondarySymbol,
|
|
1823
1894
|
spacing: 1
|
|
1824
1895
|
});
|
|
@@ -1840,19 +1911,23 @@ const text = (opts) => {
|
|
|
1840
1911
|
output: opts.output,
|
|
1841
1912
|
signal: opts.signal,
|
|
1842
1913
|
input: opts.input,
|
|
1914
|
+
accessible: opts.accessible,
|
|
1843
1915
|
render() {
|
|
1844
|
-
const hasGuide = opts
|
|
1916
|
+
const hasGuide = getGuide(opts);
|
|
1845
1917
|
const nestedPrefix = " ";
|
|
1846
|
-
const title =
|
|
1918
|
+
const title = promptTitle(opts.message, this.state, opts);
|
|
1847
1919
|
const placeholder = opts.placeholder ? color.inverse(opts.placeholder[0]) + color.dim(opts.placeholder.slice(1)) : color.inverse(color.hidden("_"));
|
|
1848
1920
|
const userInput = !this.userInput ? placeholder : this.userInputWithCursor;
|
|
1849
1921
|
const value = this.value ?? "";
|
|
1850
1922
|
switch (this.state) {
|
|
1923
|
+
case "validating": {
|
|
1924
|
+
const prefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
|
|
1925
|
+
return `${title}${prefix}${color.dim(value)}\n${prefix}${color.dim("Validating…")}\n`;
|
|
1926
|
+
}
|
|
1851
1927
|
case "error": {
|
|
1852
|
-
const errorText = this.error ?
|
|
1928
|
+
const errorText = this.error ? wrapTextWithPrefix(opts.output, color.yellow(this.error), hasGuide ? `${color.yellow(S_BAR_END)} ` : nestedPrefix) : "";
|
|
1853
1929
|
const errorPrefix = hasGuide ? `${color.yellow(S_BAR)} ` : nestedPrefix;
|
|
1854
|
-
|
|
1855
|
-
return `${title.trim()}\n${errorPrefix}${userInput}\n${errorPrefixEnd}${errorText}\n${promptMilestone("text", opts.testId, "error")}`;
|
|
1930
|
+
return `${title.trim()}\n${errorPrefix}${userInput}\n${errorText}\n${promptMilestone("text", opts.testId, "error")}`;
|
|
1856
1931
|
}
|
|
1857
1932
|
case "submit": {
|
|
1858
1933
|
const valueText = value ? color.dim(value) : "";
|
|
@@ -1863,10 +1938,14 @@ const text = (opts) => {
|
|
|
1863
1938
|
const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
|
|
1864
1939
|
return `${title}${cancelPrefix}${valueText}${value.trim() ? `\n${cancelPrefix}` : ""}\n${promptMilestone("text", opts.testId, "cancel")}`;
|
|
1865
1940
|
}
|
|
1866
|
-
default:
|
|
1941
|
+
default: {
|
|
1942
|
+
const defaultPrefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
|
|
1943
|
+
const defaultPrefixEnd = hasGuide ? color.blue(S_BAR_END) : "";
|
|
1944
|
+
return `${title}${defaultPrefix}${userInput}${hasGuide ? `\n${defaultPrefixEnd}` : ""}\n${promptMilestone("text", opts.testId, this.value ?? "")}`;
|
|
1945
|
+
}
|
|
1867
1946
|
}
|
|
1868
1947
|
}
|
|
1869
1948
|
}).prompt();
|
|
1870
1949
|
};
|
|
1871
1950
|
//#endregion
|
|
1872
|
-
export { S_BAR, S_BAR_END, S_BAR_END_RIGHT, S_BAR_H, S_BAR_START, S_BAR_START_RIGHT, S_CHECKBOX_ACTIVE, S_CHECKBOX_INACTIVE, S_CHECKBOX_SELECTED, S_CONNECT_LEFT, S_CORNER_BOTTOM_LEFT, S_CORNER_BOTTOM_RIGHT, S_CORNER_TOP_LEFT, S_CORNER_TOP_RIGHT, S_ERROR, S_INFO, S_PASSWORD_MASK, S_POINTER_ACTIVE, S_POINTER_INACTIVE, S_RADIO_ACTIVE, S_RADIO_INACTIVE, S_STEP_ACTIVE, S_STEP_CANCEL, S_STEP_ERROR, S_STEP_SUBMIT, S_SUCCESS, S_WARN, autocomplete, autocompleteMultiselect, box, cancel, completeColor, confirm, group, groupMultiselect, intro, isCI, isCancel, isTTY, limitOptions, log, milestone, multiselect, note, outro, password, path, progress, promptMilestone, select, selectKey, settings, spinner, stream, symbol, symbolBar, taskLog, tasks, text, unicode, unicodeOr, updateSettings };
|
|
1951
|
+
export { CANCEL_SYMBOL, MULTISELECT_INSTRUCTIONS, SELECT_INSTRUCTIONS, S_BAR, S_BAR_END, S_BAR_END_RIGHT, S_BAR_H, S_BAR_START, S_BAR_START_RIGHT, S_CHECKBOX_ACTIVE, S_CHECKBOX_INACTIVE, S_CHECKBOX_SELECTED, S_CONNECT_LEFT, S_CORNER_BOTTOM_LEFT, S_CORNER_BOTTOM_RIGHT, S_CORNER_TOP_LEFT, S_CORNER_TOP_RIGHT, S_ERROR, S_INFO, S_PASSWORD_MASK, S_POINTER_ACTIVE, S_POINTER_INACTIVE, S_RADIO_ACTIVE, S_RADIO_INACTIVE, S_STEP_ACTIVE, S_STEP_CANCEL, S_STEP_ERROR, S_STEP_SUBMIT, S_SUCCESS, S_WARN, autocomplete, autocompleteMultiselect, box, cancel, completeColor, confirm, formatInstructionFooter, getGuide, group, groupMultiselect, intro, isCI, isCancel, isTTY, limitOptions, log, milestone, multiselect, note, optionText, outro, password, path, progress, promptMilestone, promptTitle, select, selectKey, settings, spinner, stream, symbol, symbolBar, taskLog, tasks, text, unicode, unicodeOr, updateSettings, wrapTextWithPrefix };
|