@libtmux/workspace-cli 0.1.0-alpha.11

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.
@@ -0,0 +1,1649 @@
1
+ import {
2
+ CliError,
3
+ colorEnabled,
4
+ scalarText,
5
+ styled,
6
+ write
7
+ } from "./main-gh3pafqb.js";
8
+ import {
9
+ __commonJS,
10
+ __toESM
11
+ } from "./main-1de529jm.js";
12
+
13
+ // ../../node_modules/.bun/ansi-regex@5.0.1/node_modules/ansi-regex/index.js
14
+ var require_ansi_regex = __commonJS(function(exports, module) {
15
+ module.exports = ({ onlyFirst = false } = {}) => {
16
+ const pattern = [
17
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
18
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"
19
+ ].join("|");
20
+ return new RegExp(pattern, onlyFirst ? undefined : "g");
21
+ };
22
+ });
23
+
24
+ // ../../node_modules/.bun/ansi-styles@6.2.3/node_modules/ansi-styles/index.js
25
+ var ANSI_BACKGROUND_OFFSET = 10;
26
+ var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
27
+ var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
28
+ var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
29
+ var styles = {
30
+ modifier: {
31
+ reset: [0, 0],
32
+ bold: [1, 22],
33
+ dim: [2, 22],
34
+ italic: [3, 23],
35
+ underline: [4, 24],
36
+ overline: [53, 55],
37
+ inverse: [7, 27],
38
+ hidden: [8, 28],
39
+ strikethrough: [9, 29]
40
+ },
41
+ color: {
42
+ black: [30, 39],
43
+ red: [31, 39],
44
+ green: [32, 39],
45
+ yellow: [33, 39],
46
+ blue: [34, 39],
47
+ magenta: [35, 39],
48
+ cyan: [36, 39],
49
+ white: [37, 39],
50
+ blackBright: [90, 39],
51
+ gray: [90, 39],
52
+ grey: [90, 39],
53
+ redBright: [91, 39],
54
+ greenBright: [92, 39],
55
+ yellowBright: [93, 39],
56
+ blueBright: [94, 39],
57
+ magentaBright: [95, 39],
58
+ cyanBright: [96, 39],
59
+ whiteBright: [97, 39]
60
+ },
61
+ bgColor: {
62
+ bgBlack: [40, 49],
63
+ bgRed: [41, 49],
64
+ bgGreen: [42, 49],
65
+ bgYellow: [43, 49],
66
+ bgBlue: [44, 49],
67
+ bgMagenta: [45, 49],
68
+ bgCyan: [46, 49],
69
+ bgWhite: [47, 49],
70
+ bgBlackBright: [100, 49],
71
+ bgGray: [100, 49],
72
+ bgGrey: [100, 49],
73
+ bgRedBright: [101, 49],
74
+ bgGreenBright: [102, 49],
75
+ bgYellowBright: [103, 49],
76
+ bgBlueBright: [104, 49],
77
+ bgMagentaBright: [105, 49],
78
+ bgCyanBright: [106, 49],
79
+ bgWhiteBright: [107, 49]
80
+ }
81
+ };
82
+ var modifierNames = Object.keys(styles.modifier);
83
+ var foregroundColorNames = Object.keys(styles.color);
84
+ var backgroundColorNames = Object.keys(styles.bgColor);
85
+ var colorNames = [...foregroundColorNames, ...backgroundColorNames];
86
+ function assembleStyles() {
87
+ const codes = new Map;
88
+ for (const [groupName, group] of Object.entries(styles)) {
89
+ for (const [styleName, style] of Object.entries(group)) {
90
+ styles[styleName] = {
91
+ open: `\x1B[${style[0]}m`,
92
+ close: `\x1B[${style[1]}m`
93
+ };
94
+ group[styleName] = styles[styleName];
95
+ codes.set(style[0], style[1]);
96
+ }
97
+ Object.defineProperty(styles, groupName, {
98
+ value: group,
99
+ enumerable: false
100
+ });
101
+ }
102
+ Object.defineProperty(styles, "codes", {
103
+ value: codes,
104
+ enumerable: false
105
+ });
106
+ styles.color.close = "\x1B[39m";
107
+ styles.bgColor.close = "\x1B[49m";
108
+ styles.color.ansi = wrapAnsi16();
109
+ styles.color.ansi256 = wrapAnsi256();
110
+ styles.color.ansi16m = wrapAnsi16m();
111
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
112
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
113
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
114
+ Object.defineProperties(styles, {
115
+ rgbToAnsi256: {
116
+ value(red, green, blue) {
117
+ if (red === green && green === blue) {
118
+ if (red < 8) {
119
+ return 16;
120
+ }
121
+ if (red > 248) {
122
+ return 231;
123
+ }
124
+ return Math.round((red - 8) / 247 * 24) + 232;
125
+ }
126
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
127
+ },
128
+ enumerable: false
129
+ },
130
+ hexToRgb: {
131
+ value(hex) {
132
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
133
+ if (!matches) {
134
+ return [0, 0, 0];
135
+ }
136
+ let [colorString] = matches;
137
+ if (colorString.length === 3) {
138
+ colorString = [...colorString].map((character) => character + character).join("");
139
+ }
140
+ const integer = Number.parseInt(colorString, 16);
141
+ return [
142
+ integer >> 16 & 255,
143
+ integer >> 8 & 255,
144
+ integer & 255
145
+ ];
146
+ },
147
+ enumerable: false
148
+ },
149
+ hexToAnsi256: {
150
+ value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
151
+ enumerable: false
152
+ },
153
+ ansi256ToAnsi: {
154
+ value(code) {
155
+ if (code < 8) {
156
+ return 30 + code;
157
+ }
158
+ if (code < 16) {
159
+ return 90 + (code - 8);
160
+ }
161
+ let red;
162
+ let green;
163
+ let blue;
164
+ if (code >= 232) {
165
+ red = ((code - 232) * 10 + 8) / 255;
166
+ green = red;
167
+ blue = red;
168
+ } else {
169
+ code -= 16;
170
+ const remainder = code % 36;
171
+ red = Math.floor(code / 36) / 5;
172
+ green = Math.floor(remainder / 6) / 5;
173
+ blue = remainder % 6 / 5;
174
+ }
175
+ const value = Math.max(red, green, blue) * 2;
176
+ if (value === 0) {
177
+ return 30;
178
+ }
179
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
180
+ if (value === 2) {
181
+ result += 60;
182
+ }
183
+ return result;
184
+ },
185
+ enumerable: false
186
+ },
187
+ rgbToAnsi: {
188
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
189
+ enumerable: false
190
+ },
191
+ hexToAnsi: {
192
+ value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
193
+ enumerable: false
194
+ }
195
+ });
196
+ return styles;
197
+ }
198
+ var ansiStyles = assembleStyles();
199
+ var ansi_styles_default = ansiStyles;
200
+
201
+ // ../../node_modules/.bun/get-east-asian-width@1.6.0/node_modules/get-east-asian-width/lookup-data.js
202
+ var ambiguousMinimalCodePoint = 161;
203
+ var ambiguousMaximumCodePoint = 1114109;
204
+ var ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
205
+ var fullwidthMinimalCodePoint = 12288;
206
+ var fullwidthMaximumCodePoint = 65510;
207
+ var fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
208
+ var wideMinimalCodePoint = 4352;
209
+ var wideMaximumCodePoint = 262141;
210
+ var wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101589, 101631, 101662, 101760, 101874, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110882, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110951, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128728, 128732, 128735, 128747, 128748, 128756, 128764, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129674, 129678, 129734, 129736, 129736, 129741, 129756, 129759, 129770, 129775, 129784, 131072, 196605, 196608, 262141];
211
+
212
+ // ../../node_modules/.bun/get-east-asian-width@1.6.0/node_modules/get-east-asian-width/utilities.js
213
+ var isInRange = (ranges, codePoint) => {
214
+ let low = 0;
215
+ let high = Math.floor(ranges.length / 2) - 1;
216
+ while (low <= high) {
217
+ const mid = Math.floor((low + high) / 2);
218
+ const i = mid * 2;
219
+ if (codePoint < ranges[i]) {
220
+ high = mid - 1;
221
+ } else if (codePoint > ranges[i + 1]) {
222
+ low = mid + 1;
223
+ } else {
224
+ return true;
225
+ }
226
+ }
227
+ return false;
228
+ };
229
+
230
+ // ../../node_modules/.bun/get-east-asian-width@1.6.0/node_modules/get-east-asian-width/lookup.js
231
+ var commonCjkCodePoint = 19968;
232
+ var [wideFastPathStart, wideFastPathEnd] = /* @__PURE__ */ findWideFastPathRange(wideRanges);
233
+ function findWideFastPathRange(ranges) {
234
+ let fastPathStart = ranges[0];
235
+ let fastPathEnd = ranges[1];
236
+ for (let index = 0;index < ranges.length; index += 2) {
237
+ const start = ranges[index];
238
+ const end = ranges[index + 1];
239
+ if (commonCjkCodePoint >= start && commonCjkCodePoint <= end) {
240
+ return [start, end];
241
+ }
242
+ if (end - start > fastPathEnd - fastPathStart) {
243
+ fastPathStart = start;
244
+ fastPathEnd = end;
245
+ }
246
+ }
247
+ return [fastPathStart, fastPathEnd];
248
+ }
249
+ var isAmbiguous = (codePoint) => {
250
+ if (codePoint < ambiguousMinimalCodePoint || codePoint > ambiguousMaximumCodePoint) {
251
+ return false;
252
+ }
253
+ return isInRange(ambiguousRanges, codePoint);
254
+ };
255
+ var isFullWidth = (codePoint) => {
256
+ if (codePoint < fullwidthMinimalCodePoint || codePoint > fullwidthMaximumCodePoint) {
257
+ return false;
258
+ }
259
+ return isInRange(fullwidthRanges, codePoint);
260
+ };
261
+ var isWide = (codePoint) => {
262
+ if (codePoint >= wideFastPathStart && codePoint <= wideFastPathEnd) {
263
+ return true;
264
+ }
265
+ if (codePoint < wideMinimalCodePoint || codePoint > wideMaximumCodePoint) {
266
+ return false;
267
+ }
268
+ return isInRange(wideRanges, codePoint);
269
+ };
270
+
271
+ // ../../node_modules/.bun/get-east-asian-width@1.6.0/node_modules/get-east-asian-width/index.js
272
+ function validate(codePoint) {
273
+ if (!Number.isSafeInteger(codePoint)) {
274
+ throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
275
+ }
276
+ }
277
+ function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
278
+ validate(codePoint);
279
+ if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
280
+ return 2;
281
+ }
282
+ return 1;
283
+ }
284
+
285
+ // ../../node_modules/.bun/is-fullwidth-code-point@5.1.0/node_modules/is-fullwidth-code-point/index.js
286
+ function isFullwidthCodePoint(codePoint) {
287
+ if (!Number.isInteger(codePoint)) {
288
+ return false;
289
+ }
290
+ return isFullWidth(codePoint) || isWide(codePoint);
291
+ }
292
+
293
+ // ../../node_modules/.bun/slice-ansi@9.0.0/node_modules/slice-ansi/tokenize-ansi.js
294
+ var ESCAPE_CODE_POINT = 27;
295
+ var C1_DCS_CODE_POINT = 144;
296
+ var C1_SOS_CODE_POINT = 152;
297
+ var C1_CSI_CODE_POINT = 155;
298
+ var C1_ST_CODE_POINT = 156;
299
+ var C1_OSC_CODE_POINT = 157;
300
+ var C1_PM_CODE_POINT = 158;
301
+ var C1_APC_CODE_POINT = 159;
302
+ var ESCAPES = new Set([
303
+ ESCAPE_CODE_POINT,
304
+ C1_DCS_CODE_POINT,
305
+ C1_SOS_CODE_POINT,
306
+ C1_CSI_CODE_POINT,
307
+ C1_ST_CODE_POINT,
308
+ C1_OSC_CODE_POINT,
309
+ C1_PM_CODE_POINT,
310
+ C1_APC_CODE_POINT
311
+ ]);
312
+ var ESCAPE = "\x1B";
313
+ var ANSI_BELL = "\x07";
314
+ var ANSI_CSI = "[";
315
+ var ANSI_OSC = "]";
316
+ var ANSI_DCS = "P";
317
+ var ANSI_SOS = "X";
318
+ var ANSI_PM = "^";
319
+ var ANSI_APC = "_";
320
+ var ANSI_SGR_TERMINATOR = "m";
321
+ var ANSI_OSC_TERMINATOR = "\\";
322
+ var ANSI_STRING_TERMINATOR = `${ESCAPE}${ANSI_OSC_TERMINATOR}`;
323
+ var C1_OSC = "";
324
+ var C1_STRING_TERMINATOR = "œ";
325
+ var ANSI_HYPERLINK_ESC_PREFIX = `${ESCAPE}${ANSI_OSC}8;`;
326
+ var ANSI_HYPERLINK_C1_PREFIX = `${C1_OSC}8;`;
327
+ var ANSI_HYPERLINK_ESC_CLOSE = `${ANSI_HYPERLINK_ESC_PREFIX};`;
328
+ var ANSI_HYPERLINK_C1_CLOSE = `${ANSI_HYPERLINK_C1_PREFIX};`;
329
+ var CODE_POINT_0 = "0".codePointAt(0);
330
+ var CODE_POINT_9 = "9".codePointAt(0);
331
+ var CODE_POINT_SEMICOLON = ";".codePointAt(0);
332
+ var CODE_POINT_COLON = ":".codePointAt(0);
333
+ var CODE_POINT_CSI_PARAMETER_START = "0".codePointAt(0);
334
+ var CODE_POINT_CSI_PARAMETER_END = "?".codePointAt(0);
335
+ var CODE_POINT_CSI_INTERMEDIATE_START = " ".codePointAt(0);
336
+ var CODE_POINT_CSI_INTERMEDIATE_END = "/".codePointAt(0);
337
+ var CODE_POINT_CSI_FINAL_START = "@".codePointAt(0);
338
+ var CODE_POINT_CSI_FINAL_END = "~".codePointAt(0);
339
+ var REGIONAL_INDICATOR_SYMBOL_LETTER_A = 127462;
340
+ var REGIONAL_INDICATOR_SYMBOL_LETTER_Z = 127487;
341
+ var SGR_RESET_CODE = 0;
342
+ var SGR_EXTENDED_FOREGROUND_CODE = 38;
343
+ var SGR_DEFAULT_FOREGROUND_CODE = 39;
344
+ var SGR_EXTENDED_BACKGROUND_CODE = 48;
345
+ var SGR_DEFAULT_BACKGROUND_CODE = 49;
346
+ var SGR_COLOR_TYPE_ANSI_256 = 5;
347
+ var SGR_COLOR_TYPE_TRUECOLOR = 2;
348
+ var SGR_ANSI_256_FRAGMENT_LENGTH = 3;
349
+ var SGR_TRUECOLOR_FRAGMENT_LENGTH = 5;
350
+ var SGR_ANSI_256_LAST_PARAMETER_OFFSET = 2;
351
+ var SGR_TRUECOLOR_LAST_PARAMETER_OFFSET = 4;
352
+ var VARIATION_SELECTOR_16_CODE_POINT = 65039;
353
+ var COMBINING_ENCLOSING_KEYCAP_CODE_POINT = 8419;
354
+ var EMOJI_PRESENTATION_GRAPHEME_REGEX = /\p{Emoji_Presentation}/v;
355
+ var GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, { granularity: "grapheme" });
356
+ var endCodeNumbers = new Set;
357
+ for (const [, end] of ansi_styles_default.codes) {
358
+ endCodeNumbers.add(end);
359
+ }
360
+ function isSgrParameterCharacter(codePoint) {
361
+ return codePoint >= CODE_POINT_0 && codePoint <= CODE_POINT_9 || codePoint === CODE_POINT_SEMICOLON || codePoint === CODE_POINT_COLON;
362
+ }
363
+ function isCsiParameterCharacter(codePoint) {
364
+ return codePoint >= CODE_POINT_CSI_PARAMETER_START && codePoint <= CODE_POINT_CSI_PARAMETER_END;
365
+ }
366
+ function isCsiIntermediateCharacter(codePoint) {
367
+ return codePoint >= CODE_POINT_CSI_INTERMEDIATE_START && codePoint <= CODE_POINT_CSI_INTERMEDIATE_END;
368
+ }
369
+ function isCsiFinalCharacter(codePoint) {
370
+ return codePoint >= CODE_POINT_CSI_FINAL_START && codePoint <= CODE_POINT_CSI_FINAL_END;
371
+ }
372
+ function isRegionalIndicatorCodePoint(codePoint) {
373
+ return codePoint >= REGIONAL_INDICATOR_SYMBOL_LETTER_A && codePoint <= REGIONAL_INDICATOR_SYMBOL_LETTER_Z;
374
+ }
375
+ function createControlParseResult(code, endIndex) {
376
+ return {
377
+ token: {
378
+ type: "control",
379
+ code
380
+ },
381
+ endIndex
382
+ };
383
+ }
384
+ function isEmojiStyleGrapheme(grapheme) {
385
+ if (EMOJI_PRESENTATION_GRAPHEME_REGEX.test(grapheme)) {
386
+ return true;
387
+ }
388
+ for (const character of grapheme) {
389
+ const codePoint = character.codePointAt(0);
390
+ if (codePoint === VARIATION_SELECTOR_16_CODE_POINT || codePoint === COMBINING_ENCLOSING_KEYCAP_CODE_POINT) {
391
+ return true;
392
+ }
393
+ }
394
+ return false;
395
+ }
396
+ function getGraphemeWidth(grapheme) {
397
+ let regionalIndicatorCount = 0;
398
+ for (const character of grapheme) {
399
+ const codePoint = character.codePointAt(0);
400
+ if (isFullwidthCodePoint(codePoint)) {
401
+ return 2;
402
+ }
403
+ if (isRegionalIndicatorCodePoint(codePoint)) {
404
+ regionalIndicatorCount++;
405
+ }
406
+ }
407
+ if (regionalIndicatorCount >= 1) {
408
+ return 2;
409
+ }
410
+ if (isEmojiStyleGrapheme(grapheme)) {
411
+ return 2;
412
+ }
413
+ return 1;
414
+ }
415
+ function getSgrPrefix(code) {
416
+ if (code.startsWith("›")) {
417
+ return "›";
418
+ }
419
+ return `${ESCAPE}${ANSI_CSI}`;
420
+ }
421
+ function createSgrCode(prefix, values) {
422
+ return `${prefix}${values.join(";")}${ANSI_SGR_TERMINATOR}`;
423
+ }
424
+ function getSgrFragments(code) {
425
+ const fragments = [];
426
+ const sgrPrefix = getSgrPrefix(code);
427
+ let parameterString;
428
+ if (code.startsWith(`${ESCAPE}${ANSI_CSI}`)) {
429
+ parameterString = code.slice(2, -1);
430
+ } else if (code.startsWith("›")) {
431
+ parameterString = code.slice(1, -1);
432
+ } else {
433
+ return fragments;
434
+ }
435
+ const rawCodes = parameterString.length === 0 ? [String(SGR_RESET_CODE)] : parameterString.split(";");
436
+ let index = 0;
437
+ while (index < rawCodes.length) {
438
+ const codeNumber = Number.parseInt(rawCodes[index], 10);
439
+ if (Number.isNaN(codeNumber)) {
440
+ index++;
441
+ continue;
442
+ }
443
+ if (codeNumber === SGR_RESET_CODE) {
444
+ fragments.push({ type: "reset" });
445
+ index++;
446
+ continue;
447
+ }
448
+ if (codeNumber === SGR_EXTENDED_FOREGROUND_CODE || codeNumber === SGR_EXTENDED_BACKGROUND_CODE) {
449
+ const colorType = Number.parseInt(rawCodes[index + 1], 10);
450
+ if (colorType === SGR_COLOR_TYPE_ANSI_256 && index + SGR_ANSI_256_LAST_PARAMETER_OFFSET < rawCodes.length) {
451
+ const openCode3 = createSgrCode(sgrPrefix, rawCodes.slice(index, index + SGR_ANSI_256_FRAGMENT_LENGTH));
452
+ fragments.push({
453
+ type: "start",
454
+ code: openCode3,
455
+ endCode: ansi_styles_default.color.ansi(codeNumber === SGR_EXTENDED_FOREGROUND_CODE ? SGR_DEFAULT_FOREGROUND_CODE : SGR_DEFAULT_BACKGROUND_CODE)
456
+ });
457
+ index += SGR_ANSI_256_FRAGMENT_LENGTH;
458
+ continue;
459
+ }
460
+ if (colorType === SGR_COLOR_TYPE_TRUECOLOR && index + SGR_TRUECOLOR_LAST_PARAMETER_OFFSET < rawCodes.length) {
461
+ const openCode3 = createSgrCode(sgrPrefix, rawCodes.slice(index, index + SGR_TRUECOLOR_FRAGMENT_LENGTH));
462
+ fragments.push({
463
+ type: "start",
464
+ code: openCode3,
465
+ endCode: ansi_styles_default.color.ansi(codeNumber === SGR_EXTENDED_FOREGROUND_CODE ? SGR_DEFAULT_FOREGROUND_CODE : SGR_DEFAULT_BACKGROUND_CODE)
466
+ });
467
+ index += SGR_TRUECOLOR_FRAGMENT_LENGTH;
468
+ continue;
469
+ }
470
+ const openCode2 = createSgrCode(sgrPrefix, [rawCodes[index]]);
471
+ fragments.push({
472
+ type: "start",
473
+ code: openCode2,
474
+ endCode: ansi_styles_default.color.ansi(codeNumber === SGR_EXTENDED_FOREGROUND_CODE ? SGR_DEFAULT_FOREGROUND_CODE : SGR_DEFAULT_BACKGROUND_CODE)
475
+ });
476
+ index++;
477
+ continue;
478
+ }
479
+ if (endCodeNumbers.has(codeNumber)) {
480
+ fragments.push({
481
+ type: "end",
482
+ endCode: ansi_styles_default.color.ansi(codeNumber)
483
+ });
484
+ index++;
485
+ continue;
486
+ }
487
+ const mappedEndCode = ansi_styles_default.codes.get(codeNumber);
488
+ if (mappedEndCode !== undefined) {
489
+ const openCode2 = createSgrCode(sgrPrefix, [rawCodes[index]]);
490
+ fragments.push({
491
+ type: "start",
492
+ code: openCode2,
493
+ endCode: ansi_styles_default.color.ansi(mappedEndCode)
494
+ });
495
+ index++;
496
+ continue;
497
+ }
498
+ const openCode = createSgrCode(sgrPrefix, [rawCodes[index]]);
499
+ fragments.push({
500
+ type: "start",
501
+ code: openCode,
502
+ endCode: ansi_styles_default.reset.open
503
+ });
504
+ index++;
505
+ }
506
+ if (fragments.length === 0) {
507
+ fragments.push({ type: "reset" });
508
+ }
509
+ return fragments;
510
+ }
511
+ function parseCsiCode(string, index) {
512
+ const escapeCodePoint = string.codePointAt(index);
513
+ let sequenceStartIndex;
514
+ if (escapeCodePoint === ESCAPE_CODE_POINT) {
515
+ if (string[index + 1] !== ANSI_CSI) {
516
+ return;
517
+ }
518
+ sequenceStartIndex = index + 2;
519
+ } else if (escapeCodePoint === C1_CSI_CODE_POINT) {
520
+ sequenceStartIndex = index + 1;
521
+ } else {
522
+ return;
523
+ }
524
+ let hasCanonicalSgrParameters = true;
525
+ for (let sequenceIndex = sequenceStartIndex;sequenceIndex < string.length; sequenceIndex++) {
526
+ const codePoint = string.codePointAt(sequenceIndex);
527
+ if (isCsiFinalCharacter(codePoint)) {
528
+ const code = string.slice(index, sequenceIndex + 1);
529
+ if (string[sequenceIndex] !== ANSI_SGR_TERMINATOR || !hasCanonicalSgrParameters) {
530
+ return createControlParseResult(code, sequenceIndex + 1);
531
+ }
532
+ return {
533
+ token: {
534
+ type: "sgr",
535
+ code,
536
+ fragments: getSgrFragments(code)
537
+ },
538
+ endIndex: sequenceIndex + 1
539
+ };
540
+ }
541
+ if (isCsiParameterCharacter(codePoint)) {
542
+ if (!isSgrParameterCharacter(codePoint)) {
543
+ hasCanonicalSgrParameters = false;
544
+ }
545
+ continue;
546
+ }
547
+ if (isCsiIntermediateCharacter(codePoint)) {
548
+ hasCanonicalSgrParameters = false;
549
+ continue;
550
+ }
551
+ const endIndex = sequenceIndex;
552
+ return createControlParseResult(string.slice(index, endIndex), endIndex);
553
+ }
554
+ return createControlParseResult(string.slice(index), string.length);
555
+ }
556
+ function parseHyperlinkCode(string, index) {
557
+ let hyperlinkPrefix;
558
+ let hyperlinkClose;
559
+ const codePoint = string.codePointAt(index);
560
+ if (codePoint === ESCAPE_CODE_POINT && string.startsWith(ANSI_HYPERLINK_ESC_PREFIX, index)) {
561
+ hyperlinkPrefix = ANSI_HYPERLINK_ESC_PREFIX;
562
+ hyperlinkClose = ANSI_HYPERLINK_ESC_CLOSE;
563
+ } else if (codePoint === C1_OSC_CODE_POINT && string.startsWith(ANSI_HYPERLINK_C1_PREFIX, index)) {
564
+ hyperlinkPrefix = ANSI_HYPERLINK_C1_PREFIX;
565
+ hyperlinkClose = ANSI_HYPERLINK_C1_CLOSE;
566
+ } else {
567
+ return;
568
+ }
569
+ const uriStart = string.indexOf(";", index + hyperlinkPrefix.length);
570
+ if (uriStart === -1) {
571
+ return createControlParseResult(string.slice(index), string.length);
572
+ }
573
+ for (let sequenceIndex = uriStart + 1;sequenceIndex < string.length; sequenceIndex++) {
574
+ const character = string[sequenceIndex];
575
+ if (character === ANSI_BELL) {
576
+ const code = string.slice(index, sequenceIndex + 1);
577
+ const action = sequenceIndex === uriStart + 1 ? "close" : "open";
578
+ return {
579
+ token: {
580
+ type: "hyperlink",
581
+ code,
582
+ action,
583
+ closePrefix: hyperlinkClose,
584
+ terminator: ANSI_BELL
585
+ },
586
+ endIndex: sequenceIndex + 1
587
+ };
588
+ }
589
+ if (character === ESCAPE && string[sequenceIndex + 1] === ANSI_OSC_TERMINATOR) {
590
+ const code = string.slice(index, sequenceIndex + 2);
591
+ const action = sequenceIndex === uriStart + 1 ? "close" : "open";
592
+ return {
593
+ token: {
594
+ type: "hyperlink",
595
+ code,
596
+ action,
597
+ closePrefix: hyperlinkClose,
598
+ terminator: ANSI_STRING_TERMINATOR
599
+ },
600
+ endIndex: sequenceIndex + 2
601
+ };
602
+ }
603
+ if (character === C1_STRING_TERMINATOR) {
604
+ const code = string.slice(index, sequenceIndex + 1);
605
+ const action = sequenceIndex === uriStart + 1 ? "close" : "open";
606
+ return {
607
+ token: {
608
+ type: "hyperlink",
609
+ code,
610
+ action,
611
+ closePrefix: hyperlinkClose,
612
+ terminator: C1_STRING_TERMINATOR
613
+ },
614
+ endIndex: sequenceIndex + 1
615
+ };
616
+ }
617
+ }
618
+ return createControlParseResult(string.slice(index), string.length);
619
+ }
620
+ function parseControlStringCode(string, index) {
621
+ const codePoint = string.codePointAt(index);
622
+ let sequenceStartIndex;
623
+ let supportsBellTerminator = false;
624
+ switch (codePoint) {
625
+ case ESCAPE_CODE_POINT: {
626
+ const command = string[index + 1];
627
+ switch (command) {
628
+ case ANSI_OSC: {
629
+ sequenceStartIndex = index + 2;
630
+ supportsBellTerminator = true;
631
+ break;
632
+ }
633
+ case ANSI_DCS:
634
+ case ANSI_SOS:
635
+ case ANSI_PM:
636
+ case ANSI_APC: {
637
+ sequenceStartIndex = index + 2;
638
+ break;
639
+ }
640
+ case ANSI_OSC_TERMINATOR: {
641
+ return createControlParseResult(ANSI_STRING_TERMINATOR, index + 2);
642
+ }
643
+ default: {
644
+ return;
645
+ }
646
+ }
647
+ break;
648
+ }
649
+ case C1_OSC_CODE_POINT: {
650
+ sequenceStartIndex = index + 1;
651
+ supportsBellTerminator = true;
652
+ break;
653
+ }
654
+ case C1_DCS_CODE_POINT:
655
+ case C1_SOS_CODE_POINT:
656
+ case C1_PM_CODE_POINT:
657
+ case C1_APC_CODE_POINT: {
658
+ sequenceStartIndex = index + 1;
659
+ break;
660
+ }
661
+ case C1_ST_CODE_POINT: {
662
+ return createControlParseResult(C1_STRING_TERMINATOR, index + 1);
663
+ }
664
+ default: {
665
+ return;
666
+ }
667
+ }
668
+ for (let sequenceIndex = sequenceStartIndex;sequenceIndex < string.length; sequenceIndex++) {
669
+ if (supportsBellTerminator && string[sequenceIndex] === ANSI_BELL) {
670
+ return createControlParseResult(string.slice(index, sequenceIndex + 1), sequenceIndex + 1);
671
+ }
672
+ if (string[sequenceIndex] === ESCAPE && string[sequenceIndex + 1] === ANSI_OSC_TERMINATOR) {
673
+ return createControlParseResult(string.slice(index, sequenceIndex + 2), sequenceIndex + 2);
674
+ }
675
+ if (string[sequenceIndex] === C1_STRING_TERMINATOR) {
676
+ return createControlParseResult(string.slice(index, sequenceIndex + 1), sequenceIndex + 1);
677
+ }
678
+ }
679
+ return createControlParseResult(string.slice(index), string.length);
680
+ }
681
+ function parseAnsiCode(string, index) {
682
+ const codePoint = string.codePointAt(index);
683
+ if (codePoint === ESCAPE_CODE_POINT || codePoint === C1_OSC_CODE_POINT) {
684
+ const hyperlinkCode = parseHyperlinkCode(string, index);
685
+ if (hyperlinkCode) {
686
+ return hyperlinkCode;
687
+ }
688
+ }
689
+ const controlStringCode = parseControlStringCode(string, index);
690
+ if (controlStringCode) {
691
+ return controlStringCode;
692
+ }
693
+ return parseCsiCode(string, index);
694
+ }
695
+ function appendTrailingAnsiTokens(string, index, tokens) {
696
+ while (index < string.length) {
697
+ const nextCodePoint = string.codePointAt(index);
698
+ if (!ESCAPES.has(nextCodePoint)) {
699
+ break;
700
+ }
701
+ const escapeCode = parseAnsiCode(string, index);
702
+ if (!escapeCode) {
703
+ break;
704
+ }
705
+ tokens.push(escapeCode.token);
706
+ index = escapeCode.endIndex;
707
+ }
708
+ return index;
709
+ }
710
+ function parseCharacterTokenWithRawSegmentation(string, index, graphemeSegments) {
711
+ const segment = graphemeSegments.containing(index);
712
+ if (!segment || segment.index !== index) {
713
+ return;
714
+ }
715
+ return {
716
+ token: {
717
+ type: "character",
718
+ value: segment.segment,
719
+ visibleWidth: getGraphemeWidth(segment.segment),
720
+ isGraphemeContinuation: false
721
+ },
722
+ endIndex: index + segment.segment.length
723
+ };
724
+ }
725
+ function collectVisibleCharacters(string) {
726
+ const visibleCharacters = [];
727
+ let index = 0;
728
+ while (index < string.length) {
729
+ const codePoint = string.codePointAt(index);
730
+ if (ESCAPES.has(codePoint)) {
731
+ const code = parseAnsiCode(string, index);
732
+ if (code) {
733
+ index = code.endIndex;
734
+ continue;
735
+ }
736
+ }
737
+ const value = String.fromCodePoint(codePoint);
738
+ visibleCharacters.push({
739
+ value,
740
+ visibleWidth: 1,
741
+ isGraphemeContinuation: false
742
+ });
743
+ index += value.length;
744
+ }
745
+ return visibleCharacters;
746
+ }
747
+ function applyGraphemeMetadata(visibleCharacters) {
748
+ if (visibleCharacters.length === 0) {
749
+ return;
750
+ }
751
+ const visibleString = visibleCharacters.map(({ value }) => value).join("");
752
+ const scalarOffsets = [];
753
+ let scalarOffset = 0;
754
+ for (const visibleCharacter of visibleCharacters) {
755
+ scalarOffsets.push(scalarOffset);
756
+ scalarOffset += visibleCharacter.value.length;
757
+ }
758
+ let scalarIndex = 0;
759
+ for (const segment of GRAPHEME_SEGMENTER.segment(visibleString)) {
760
+ while (scalarIndex < visibleCharacters.length && scalarOffsets[scalarIndex] < segment.index) {
761
+ scalarIndex++;
762
+ }
763
+ let graphemeIndex = scalarIndex;
764
+ let isFirstInGrapheme = true;
765
+ while (graphemeIndex < visibleCharacters.length && scalarOffsets[graphemeIndex] < segment.index + segment.segment.length) {
766
+ visibleCharacters[graphemeIndex].visibleWidth = isFirstInGrapheme ? getGraphemeWidth(segment.segment) : 0;
767
+ visibleCharacters[graphemeIndex].isGraphemeContinuation = !isFirstInGrapheme;
768
+ isFirstInGrapheme = false;
769
+ graphemeIndex++;
770
+ }
771
+ scalarIndex = graphemeIndex;
772
+ }
773
+ }
774
+ function tokenizeAnsiWithVisibleSegmentation(string, { endCharacter = Number.POSITIVE_INFINITY } = {}) {
775
+ const tokens = [];
776
+ const visibleCharacters = collectVisibleCharacters(string);
777
+ applyGraphemeMetadata(visibleCharacters);
778
+ let index = 0;
779
+ let visibleCharacterIndex = 0;
780
+ let visibleCount = 0;
781
+ while (index < string.length) {
782
+ const codePoint = string.codePointAt(index);
783
+ if (ESCAPES.has(codePoint)) {
784
+ const code = parseAnsiCode(string, index);
785
+ if (code) {
786
+ tokens.push(code.token);
787
+ index = code.endIndex;
788
+ continue;
789
+ }
790
+ }
791
+ const value = String.fromCodePoint(codePoint);
792
+ const visibleCharacter = visibleCharacters[visibleCharacterIndex];
793
+ let visibleWidth = isFullwidthCodePoint(codePoint) ? 2 : value.length;
794
+ if (visibleCharacter) {
795
+ visibleWidth = visibleCharacter.visibleWidth;
796
+ }
797
+ const token = {
798
+ type: "character",
799
+ value,
800
+ visibleWidth,
801
+ isGraphemeContinuation: visibleCharacter ? visibleCharacter.isGraphemeContinuation : false
802
+ };
803
+ tokens.push(token);
804
+ index += value.length;
805
+ visibleCharacterIndex++;
806
+ visibleCount += token.visibleWidth;
807
+ if (visibleCount >= endCharacter) {
808
+ const nextVisibleCharacter = visibleCharacters[visibleCharacterIndex];
809
+ if (!nextVisibleCharacter || !nextVisibleCharacter.isGraphemeContinuation) {
810
+ index = appendTrailingAnsiTokens(string, index, tokens);
811
+ break;
812
+ }
813
+ }
814
+ }
815
+ return tokens;
816
+ }
817
+ function areValuesInSameGrapheme(leftValue, rightValue) {
818
+ const pair = `${leftValue}${rightValue}`;
819
+ const splitIndex = leftValue.length;
820
+ for (const segment of GRAPHEME_SEGMENTER.segment(pair)) {
821
+ if (segment.index === splitIndex) {
822
+ return false;
823
+ }
824
+ if (segment.index > splitIndex) {
825
+ return true;
826
+ }
827
+ }
828
+ return true;
829
+ }
830
+ function hasAnsiSplitContinuationAhead(string, startIndex, previousVisibleValue, graphemeSegments) {
831
+ if (!previousVisibleValue) {
832
+ return false;
833
+ }
834
+ let index = startIndex;
835
+ let hasAnsiCode = false;
836
+ while (index < string.length) {
837
+ const codePoint = string.codePointAt(index);
838
+ if (ESCAPES.has(codePoint)) {
839
+ const code = parseAnsiCode(string, index);
840
+ if (code) {
841
+ hasAnsiCode = true;
842
+ index = code.endIndex;
843
+ continue;
844
+ }
845
+ }
846
+ if (!hasAnsiCode) {
847
+ return false;
848
+ }
849
+ const characterToken = parseCharacterTokenWithRawSegmentation(string, index, graphemeSegments);
850
+ if (!characterToken) {
851
+ return true;
852
+ }
853
+ return areValuesInSameGrapheme(previousVisibleValue, characterToken.token.value);
854
+ }
855
+ return false;
856
+ }
857
+ function tokenizeAnsi(string, { endCharacter = Number.POSITIVE_INFINITY } = {}) {
858
+ const tokens = [];
859
+ const graphemeSegments = GRAPHEME_SEGMENTER.segment(string);
860
+ let index = 0;
861
+ let visibleCount = 0;
862
+ let previousVisibleValue;
863
+ let hasAnsiSinceLastVisible = false;
864
+ while (index < string.length) {
865
+ const codePoint = string.codePointAt(index);
866
+ if (ESCAPES.has(codePoint)) {
867
+ const code = parseAnsiCode(string, index);
868
+ if (code) {
869
+ tokens.push(code.token);
870
+ index = code.endIndex;
871
+ hasAnsiSinceLastVisible = true;
872
+ continue;
873
+ }
874
+ }
875
+ const characterToken = parseCharacterTokenWithRawSegmentation(string, index, graphemeSegments);
876
+ if (!characterToken) {
877
+ return tokenizeAnsiWithVisibleSegmentation(string, { endCharacter });
878
+ }
879
+ if (hasAnsiSinceLastVisible && previousVisibleValue && areValuesInSameGrapheme(previousVisibleValue, characterToken.token.value)) {
880
+ return tokenizeAnsiWithVisibleSegmentation(string, { endCharacter });
881
+ }
882
+ tokens.push(characterToken.token);
883
+ index = characterToken.endIndex;
884
+ visibleCount += characterToken.token.visibleWidth;
885
+ hasAnsiSinceLastVisible = false;
886
+ previousVisibleValue = characterToken.token.value;
887
+ if (visibleCount >= endCharacter) {
888
+ if (hasAnsiSplitContinuationAhead(string, index, previousVisibleValue, graphemeSegments)) {
889
+ return tokenizeAnsiWithVisibleSegmentation(string, { endCharacter });
890
+ }
891
+ index = appendTrailingAnsiTokens(string, index, tokens);
892
+ break;
893
+ }
894
+ }
895
+ return tokens;
896
+ }
897
+
898
+ // ../../node_modules/.bun/slice-ansi@9.0.0/node_modules/slice-ansi/index.js
899
+ function applySgrFragments(activeStyles, fragments) {
900
+ for (const fragment of fragments) {
901
+ switch (fragment.type) {
902
+ case "reset": {
903
+ activeStyles.clear();
904
+ break;
905
+ }
906
+ case "end": {
907
+ activeStyles.delete(fragment.endCode);
908
+ break;
909
+ }
910
+ case "start": {
911
+ activeStyles.delete(fragment.endCode);
912
+ activeStyles.set(fragment.endCode, fragment.code);
913
+ break;
914
+ }
915
+ default: {
916
+ break;
917
+ }
918
+ }
919
+ }
920
+ return activeStyles;
921
+ }
922
+ function undoAnsiCodes(activeStyles) {
923
+ return [...activeStyles.keys()].toReversed().join("");
924
+ }
925
+ function closeHyperlink(hyperlinkToken) {
926
+ return `${hyperlinkToken.closePrefix}${hyperlinkToken.terminator}`;
927
+ }
928
+ function shouldIncludeSgrAfterEnd(token, activeStyles) {
929
+ let hasStartFragment = false;
930
+ let hasClosingEffect = false;
931
+ for (const fragment of token.fragments) {
932
+ if (fragment.type === "start") {
933
+ hasStartFragment = true;
934
+ continue;
935
+ }
936
+ if (fragment.type === "reset" && activeStyles.size > 0) {
937
+ hasClosingEffect = true;
938
+ continue;
939
+ }
940
+ if (fragment.type === "end" && activeStyles.has(fragment.endCode)) {
941
+ hasClosingEffect = true;
942
+ }
943
+ }
944
+ return hasClosingEffect && !hasStartFragment;
945
+ }
946
+ function hasSgrStartFragment(token) {
947
+ return token.fragments.some((fragment) => fragment.type === "start");
948
+ }
949
+ function discardPendingHyperlink(parameters) {
950
+ if (parameters.activeHyperlink && !parameters.activeHyperlinkHasVisibleText && parameters.activeHyperlinkOutputIndex !== undefined) {
951
+ const openCodeLength = parameters.activeHyperlink.code.length;
952
+ parameters.returnValue = parameters.returnValue.slice(0, parameters.activeHyperlinkOutputIndex) + parameters.returnValue.slice(parameters.activeHyperlinkOutputIndex + openCodeLength);
953
+ if (parameters.pendingSgrOutputIndex !== undefined && parameters.pendingSgrOutputIndex > parameters.activeHyperlinkOutputIndex) {
954
+ parameters.pendingSgrOutputIndex -= openCodeLength;
955
+ }
956
+ }
957
+ parameters.activeHyperlink = undefined;
958
+ parameters.activeHyperlinkHasVisibleText = false;
959
+ parameters.activeHyperlinkOutputIndex = undefined;
960
+ }
961
+ function applySgrToken(parameters) {
962
+ if (parameters.isPastEnd && !shouldIncludeSgrAfterEnd(parameters.token, parameters.activeStyles)) {
963
+ return parameters;
964
+ }
965
+ if (parameters.include && hasSgrStartFragment(parameters.token) && parameters.pendingSgrOutputIndex === undefined) {
966
+ parameters.pendingSgrOutputIndex = parameters.returnValue.length;
967
+ parameters.pendingSgrActiveStyles = new Map(parameters.activeStyles);
968
+ }
969
+ parameters.activeStyles = applySgrFragments(parameters.activeStyles, parameters.token.fragments);
970
+ if (parameters.include) {
971
+ parameters.returnValue += parameters.token.code;
972
+ }
973
+ return parameters;
974
+ }
975
+ function applyHyperlinkToken(parameters) {
976
+ if (parameters.isPastEnd && (parameters.token.action !== "close" || !parameters.activeHyperlink)) {
977
+ return parameters;
978
+ }
979
+ if (parameters.token.action === "open") {
980
+ parameters.activeHyperlink = parameters.token;
981
+ parameters.activeHyperlinkHasVisibleText = false;
982
+ parameters.activeHyperlinkOutputIndex = undefined;
983
+ if (parameters.include) {
984
+ parameters.activeHyperlinkOutputIndex = parameters.returnValue.length;
985
+ }
986
+ } else if (parameters.token.action === "close") {
987
+ if (parameters.include && parameters.activeHyperlink && !parameters.activeHyperlinkHasVisibleText) {
988
+ discardPendingHyperlink(parameters);
989
+ return parameters;
990
+ }
991
+ parameters.activeHyperlink = undefined;
992
+ parameters.activeHyperlinkHasVisibleText = false;
993
+ parameters.activeHyperlinkOutputIndex = undefined;
994
+ }
995
+ if (parameters.include) {
996
+ parameters.returnValue += parameters.token.code;
997
+ }
998
+ return parameters;
999
+ }
1000
+ function applyControlToken(parameters) {
1001
+ if (!parameters.isPastEnd && parameters.include) {
1002
+ parameters.returnValue += parameters.token.code;
1003
+ }
1004
+ return parameters;
1005
+ }
1006
+ function applyCharacterToken(parameters) {
1007
+ if (!parameters.include && parameters.position >= parameters.start && !parameters.token.isGraphemeContinuation) {
1008
+ parameters.include = true;
1009
+ parameters.returnValue = [...parameters.activeStyles.values()].join("");
1010
+ if (parameters.activeHyperlink) {
1011
+ parameters.activeHyperlinkOutputIndex = parameters.returnValue.length;
1012
+ parameters.returnValue += parameters.activeHyperlink.code;
1013
+ }
1014
+ }
1015
+ if (parameters.include) {
1016
+ parameters.returnValue += parameters.token.value;
1017
+ parameters.pendingSgrOutputIndex = undefined;
1018
+ parameters.pendingSgrActiveStyles = undefined;
1019
+ if (parameters.activeHyperlink) {
1020
+ parameters.activeHyperlinkHasVisibleText = true;
1021
+ }
1022
+ }
1023
+ parameters.position += parameters.token.visibleWidth;
1024
+ return parameters;
1025
+ }
1026
+ var tokenHandlers = {
1027
+ sgr: applySgrToken,
1028
+ hyperlink: applyHyperlinkToken,
1029
+ control: applyControlToken,
1030
+ character: applyCharacterToken
1031
+ };
1032
+ function applyToken(parameters) {
1033
+ const tokenHandler = tokenHandlers[parameters.token.type];
1034
+ if (!tokenHandler) {
1035
+ return parameters;
1036
+ }
1037
+ return tokenHandler(parameters);
1038
+ }
1039
+ function createHasContinuationAheadMap(tokens) {
1040
+ const hasContinuationAhead = Array.from({ length: tokens.length }, () => false);
1041
+ let nextCharacterIsContinuation = false;
1042
+ for (let tokenIndex = tokens.length - 1;tokenIndex >= 0; tokenIndex--) {
1043
+ const token = tokens[tokenIndex];
1044
+ hasContinuationAhead[tokenIndex] = nextCharacterIsContinuation;
1045
+ if (token.type === "character") {
1046
+ nextCharacterIsContinuation = Boolean(token.isGraphemeContinuation);
1047
+ }
1048
+ }
1049
+ return hasContinuationAhead;
1050
+ }
1051
+ function isPastEndBoundary(token, position, end) {
1052
+ if (end === undefined) {
1053
+ return false;
1054
+ }
1055
+ if (position >= end) {
1056
+ return true;
1057
+ }
1058
+ return token.type === "character" && !token.isGraphemeContinuation && position + token.visibleWidth > end;
1059
+ }
1060
+ function sliceAnsi(string, start, end) {
1061
+ const tokens = tokenizeAnsi(string, { endCharacter: end });
1062
+ const hasContinuationAhead = createHasContinuationAheadMap(tokens);
1063
+ let activeStyles = new Map;
1064
+ let activeHyperlink;
1065
+ let activeHyperlinkHasVisibleText = false;
1066
+ let activeHyperlinkOutputIndex;
1067
+ let pendingSgrOutputIndex;
1068
+ let pendingSgrActiveStyles;
1069
+ let position = 0;
1070
+ let returnValue = "";
1071
+ let include = false;
1072
+ for (const [tokenIndex, token] of tokens.entries()) {
1073
+ let isPastEnd = isPastEndBoundary(token, position, end);
1074
+ if (isPastEnd && token.type !== "character" && hasContinuationAhead[tokenIndex]) {
1075
+ isPastEnd = false;
1076
+ }
1077
+ if (isPastEnd && token.type === "character" && !token.isGraphemeContinuation) {
1078
+ if (activeHyperlink && !activeHyperlinkHasVisibleText) {
1079
+ const hyperlinkState = {
1080
+ activeHyperlink,
1081
+ activeHyperlinkHasVisibleText,
1082
+ activeHyperlinkOutputIndex,
1083
+ pendingSgrOutputIndex,
1084
+ returnValue
1085
+ };
1086
+ discardPendingHyperlink(hyperlinkState);
1087
+ ({
1088
+ activeHyperlink,
1089
+ activeHyperlinkHasVisibleText,
1090
+ activeHyperlinkOutputIndex,
1091
+ pendingSgrOutputIndex,
1092
+ returnValue
1093
+ } = hyperlinkState);
1094
+ }
1095
+ if (pendingSgrOutputIndex !== undefined) {
1096
+ returnValue = returnValue.slice(0, pendingSgrOutputIndex);
1097
+ activeStyles = pendingSgrActiveStyles;
1098
+ pendingSgrOutputIndex = undefined;
1099
+ pendingSgrActiveStyles = undefined;
1100
+ }
1101
+ break;
1102
+ }
1103
+ ({ activeStyles, activeHyperlink, activeHyperlinkHasVisibleText, activeHyperlinkOutputIndex, pendingSgrOutputIndex, pendingSgrActiveStyles, position, returnValue, include } = applyToken({
1104
+ token,
1105
+ isPastEnd,
1106
+ start,
1107
+ activeStyles,
1108
+ activeHyperlink,
1109
+ activeHyperlinkHasVisibleText,
1110
+ activeHyperlinkOutputIndex,
1111
+ pendingSgrOutputIndex,
1112
+ pendingSgrActiveStyles,
1113
+ position,
1114
+ returnValue,
1115
+ include
1116
+ }));
1117
+ }
1118
+ if (!include) {
1119
+ return "";
1120
+ }
1121
+ if (activeHyperlink) {
1122
+ returnValue += closeHyperlink(activeHyperlink);
1123
+ }
1124
+ returnValue += undoAnsiCodes(activeStyles);
1125
+ return returnValue;
1126
+ }
1127
+
1128
+ // ../../node_modules/.bun/strip-ansi@7.2.0/node_modules/strip-ansi/index.js
1129
+ var import_ansi_regex = __toESM(require_ansi_regex(), 1);
1130
+ var regex = import_ansi_regex.default();
1131
+ function stripAnsi(string) {
1132
+ if (typeof string !== "string") {
1133
+ throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
1134
+ }
1135
+ if (!string.includes("\x1B") && !string.includes("›")) {
1136
+ return string;
1137
+ }
1138
+ return string.replace(regex, "");
1139
+ }
1140
+
1141
+ // ../../node_modules/.bun/string-width@8.2.2/node_modules/string-width/index.js
1142
+ var segmenter = new Intl.Segmenter;
1143
+ var zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Nonspacing_Mark}|\p{Enclosing_Mark}|\p{Surrogate})+$/v;
1144
+ var leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Nonspacing_Mark}\p{Enclosing_Mark}\p{Surrogate}]+/v;
1145
+ var spacingMarkRegex = /\p{Spacing_Mark}/v;
1146
+ var rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
1147
+ var unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
1148
+ var extendedPictographicRegex = /\p{Extended_Pictographic}/gu;
1149
+ function isDoubleWidthNonRgiEmojiSequence(segment) {
1150
+ if (segment.length > 50) {
1151
+ return false;
1152
+ }
1153
+ if (unqualifiedKeycapRegex.test(segment)) {
1154
+ return true;
1155
+ }
1156
+ if (segment.includes("‍")) {
1157
+ const pictographics = segment.match(extendedPictographicRegex);
1158
+ return pictographics !== null && pictographics.length >= 2;
1159
+ }
1160
+ return false;
1161
+ }
1162
+ function baseVisible(segment) {
1163
+ return segment.replace(leadingNonPrintingRegex, "");
1164
+ }
1165
+ function isZeroWidthCluster(segment) {
1166
+ return zeroWidthClusterRegex.test(segment);
1167
+ }
1168
+ function isHangulLeadingJamo(codePoint) {
1169
+ return codePoint >= 4352 && codePoint <= 4447 || codePoint >= 43360 && codePoint <= 43388;
1170
+ }
1171
+ function isHangulVowelJamo(codePoint) {
1172
+ return codePoint >= 4448 && codePoint <= 4519 || codePoint >= 55216 && codePoint <= 55238;
1173
+ }
1174
+ function isHangulTrailingJamo(codePoint) {
1175
+ return codePoint >= 4520 && codePoint <= 4607 || codePoint >= 55243 && codePoint <= 55291;
1176
+ }
1177
+ function isHangulJamo(codePoint) {
1178
+ return isHangulLeadingJamo(codePoint) || isHangulVowelJamo(codePoint) || isHangulTrailingJamo(codePoint);
1179
+ }
1180
+ function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
1181
+ const codePoints = [];
1182
+ for (const character of visibleSegment) {
1183
+ if (zeroWidthClusterRegex.test(character)) {
1184
+ continue;
1185
+ }
1186
+ codePoints.push(character.codePointAt(0));
1187
+ }
1188
+ if (codePoints.length === 0) {
1189
+ return;
1190
+ }
1191
+ let width = 0;
1192
+ for (let index = 0;index < codePoints.length; index++) {
1193
+ const codePoint = codePoints[index];
1194
+ if (!isHangulJamo(codePoint)) {
1195
+ if (width === 0) {
1196
+ return;
1197
+ }
1198
+ for (let remaining = index;remaining < codePoints.length; remaining++) {
1199
+ width += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
1200
+ }
1201
+ return width;
1202
+ }
1203
+ if (isHangulLeadingJamo(codePoint) && isHangulVowelJamo(codePoints[index + 1])) {
1204
+ width += 2;
1205
+ index += isHangulTrailingJamo(codePoints[index + 2]) ? 2 : 1;
1206
+ continue;
1207
+ }
1208
+ width += eastAsianWidth(codePoint, eastAsianWidthOptions);
1209
+ }
1210
+ return width;
1211
+ }
1212
+ function trailingWidth(visibleSegment, eastAsianWidthOptions) {
1213
+ let extra = 0;
1214
+ let first = true;
1215
+ for (const character of visibleSegment) {
1216
+ if (first) {
1217
+ first = false;
1218
+ continue;
1219
+ }
1220
+ if (spacingMarkRegex.test(character) || character >= "＀" && character <= "￯") {
1221
+ extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
1222
+ }
1223
+ }
1224
+ return extra;
1225
+ }
1226
+ function stringWidth(input, options = {}) {
1227
+ if (typeof input !== "string" || input.length === 0) {
1228
+ return 0;
1229
+ }
1230
+ const {
1231
+ ambiguousIsNarrow = true,
1232
+ countAnsiEscapeCodes = false
1233
+ } = options;
1234
+ let string = input;
1235
+ if (!countAnsiEscapeCodes && (string.includes("\x1B") || string.includes("›"))) {
1236
+ string = stripAnsi(string);
1237
+ }
1238
+ if (string.length === 0) {
1239
+ return 0;
1240
+ }
1241
+ if (/^[\u0020-\u007E]*$/.test(string)) {
1242
+ return string.length;
1243
+ }
1244
+ let width = 0;
1245
+ const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
1246
+ for (const { segment } of segmenter.segment(string)) {
1247
+ if (isZeroWidthCluster(segment)) {
1248
+ continue;
1249
+ }
1250
+ if (rgiEmojiRegex.test(segment) || isDoubleWidthNonRgiEmojiSequence(segment)) {
1251
+ width += 2;
1252
+ continue;
1253
+ }
1254
+ const visibleSegment = baseVisible(segment);
1255
+ const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
1256
+ if (hangulWidth !== undefined) {
1257
+ width += hangulWidth;
1258
+ continue;
1259
+ }
1260
+ const codePoint = visibleSegment.codePointAt(0);
1261
+ width += eastAsianWidth(codePoint, eastAsianWidthOptions);
1262
+ width += trailingWidth(visibleSegment, eastAsianWidthOptions);
1263
+ }
1264
+ return width;
1265
+ }
1266
+
1267
+ // ../../node_modules/.bun/cli-truncate@6.1.1/node_modules/cli-truncate/index.js
1268
+ var validPositions = new Set(["start", "middle", "end"]);
1269
+ function getIndexOfNearestSpace(string, wantedIndex, shouldSearchRight) {
1270
+ if (string.charAt(wantedIndex) === " ") {
1271
+ return wantedIndex;
1272
+ }
1273
+ const direction = shouldSearchRight ? 1 : -1;
1274
+ for (let index = 0;index <= 3; index++) {
1275
+ const finalIndex = wantedIndex + index * direction;
1276
+ if (string.charAt(finalIndex) === " ") {
1277
+ return finalIndex;
1278
+ }
1279
+ }
1280
+ return wantedIndex;
1281
+ }
1282
+ function validateInput(text, columns, position, truncationCharacter) {
1283
+ if (typeof text !== "string") {
1284
+ throw new TypeError(`Expected \`input\` to be a string, got ${typeof text}`);
1285
+ }
1286
+ if (typeof columns !== "number") {
1287
+ throw new TypeError(`Expected \`columns\` to be a number, got ${typeof columns}`);
1288
+ }
1289
+ if (!Number.isFinite(columns)) {
1290
+ throw new TypeError(`Expected \`columns\` to be a finite number, got ${columns}`);
1291
+ }
1292
+ if (!validPositions.has(position)) {
1293
+ throw new TypeError(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${position}`);
1294
+ }
1295
+ if (typeof truncationCharacter !== "string") {
1296
+ throw new TypeError(`Expected \`options.truncationCharacter\` to be a string, got ${typeof truncationCharacter}`);
1297
+ }
1298
+ }
1299
+ function cliTruncate(text, columns, options = {}) {
1300
+ const {
1301
+ position = "end",
1302
+ space = false,
1303
+ preferTruncationOnSpace = false
1304
+ } = options;
1305
+ let { truncationCharacter = "…" } = options;
1306
+ validateInput(text, columns, position, truncationCharacter);
1307
+ if (columns < 1) {
1308
+ return "";
1309
+ }
1310
+ const length = stringWidth(text);
1311
+ if (length <= columns) {
1312
+ return text;
1313
+ }
1314
+ if (columns === 1) {
1315
+ return truncationCharacter;
1316
+ }
1317
+ const ANSI = {
1318
+ ESC: 27,
1319
+ LEFT_BRACKET: 91,
1320
+ LETTER_M: 109
1321
+ };
1322
+ const isSgrParameter = (code) => code >= 48 && code <= 57 || code === 59;
1323
+ function leadingSgrSpanEndIndex(string) {
1324
+ let index = 0;
1325
+ while (index + 2 < string.length && string.codePointAt(index) === ANSI.ESC && string.codePointAt(index + 1) === ANSI.LEFT_BRACKET) {
1326
+ let j = index + 2;
1327
+ while (j < string.length && isSgrParameter(string.codePointAt(j))) {
1328
+ j++;
1329
+ }
1330
+ if (j < string.length && string.codePointAt(j) === ANSI.LETTER_M) {
1331
+ index = j + 1;
1332
+ continue;
1333
+ }
1334
+ break;
1335
+ }
1336
+ return index;
1337
+ }
1338
+ function trailingSgrSpanStartIndex(string) {
1339
+ let start = string.length;
1340
+ while (start > 1 && string.codePointAt(start - 1) === ANSI.LETTER_M) {
1341
+ let j = start - 2;
1342
+ while (j >= 0 && isSgrParameter(string.codePointAt(j))) {
1343
+ j--;
1344
+ }
1345
+ if (j >= 1 && string.codePointAt(j - 1) === ANSI.ESC && string.codePointAt(j) === ANSI.LEFT_BRACKET) {
1346
+ start = j - 1;
1347
+ continue;
1348
+ }
1349
+ break;
1350
+ }
1351
+ return start;
1352
+ }
1353
+ function appendWithInheritedStyleFromEnd(visible, suffix) {
1354
+ const start = trailingSgrSpanStartIndex(visible);
1355
+ if (start === visible.length) {
1356
+ return visible + suffix;
1357
+ }
1358
+ return visible.slice(0, start) + suffix + visible.slice(start);
1359
+ }
1360
+ function prependWithInheritedStyleFromStart(prefix, visible) {
1361
+ const end = leadingSgrSpanEndIndex(visible);
1362
+ if (end === 0) {
1363
+ return prefix + visible;
1364
+ }
1365
+ return visible.slice(0, end) + prefix + visible.slice(end);
1366
+ }
1367
+ if (position === "start") {
1368
+ if (preferTruncationOnSpace) {
1369
+ const nearestSpace = getIndexOfNearestSpace(text, length - columns + stringWidth(truncationCharacter), true);
1370
+ const right2 = sliceAnsi(text, nearestSpace, length).trim();
1371
+ return prependWithInheritedStyleFromStart(truncationCharacter, right2);
1372
+ }
1373
+ if (space) {
1374
+ truncationCharacter += " ";
1375
+ }
1376
+ const right = sliceAnsi(text, length - columns + stringWidth(truncationCharacter), length);
1377
+ return prependWithInheritedStyleFromStart(truncationCharacter, right);
1378
+ }
1379
+ if (position === "middle") {
1380
+ if (space) {
1381
+ truncationCharacter = ` ${truncationCharacter} `;
1382
+ if (stringWidth(truncationCharacter) >= columns) {
1383
+ truncationCharacter = truncationCharacter.trim();
1384
+ }
1385
+ }
1386
+ const truncationWidth = stringWidth(truncationCharacter);
1387
+ const half = Math.min(Math.floor(columns / 2), Math.max(0, columns - truncationWidth));
1388
+ if (preferTruncationOnSpace) {
1389
+ const spaceNearFirstBreakPoint = getIndexOfNearestSpace(text, half);
1390
+ const spaceNearSecondBreakPoint = getIndexOfNearestSpace(text, length - (columns - half) + truncationWidth, true);
1391
+ return sliceAnsi(text, 0, spaceNearFirstBreakPoint) + truncationCharacter + sliceAnsi(text, spaceNearSecondBreakPoint, length).trim();
1392
+ }
1393
+ return sliceAnsi(text, 0, half) + truncationCharacter + sliceAnsi(text, length - (columns - half) + truncationWidth, length);
1394
+ }
1395
+ if (position === "end") {
1396
+ if (preferTruncationOnSpace) {
1397
+ const nearestSpace = getIndexOfNearestSpace(text, columns - stringWidth(truncationCharacter));
1398
+ const left2 = sliceAnsi(text, 0, nearestSpace);
1399
+ return appendWithInheritedStyleFromEnd(left2, truncationCharacter);
1400
+ }
1401
+ if (space) {
1402
+ truncationCharacter = ` ${truncationCharacter}`;
1403
+ }
1404
+ const left = sliceAnsi(text, 0, columns - stringWidth(truncationCharacter));
1405
+ return appendWithInheritedStyleFromEnd(left, truncationCharacter);
1406
+ }
1407
+ }
1408
+
1409
+ // src/progress.ts
1410
+ var presets = {
1411
+ default: "Loading workspace: {session} {bar} {progress} {window}",
1412
+ minimal: "Loading workspace: {session} [{window_progress}]",
1413
+ window: "Loading workspace: {session} {window_bar} {window_progress_rel}",
1414
+ pane: "Loading workspace: {session} {pane_bar} {session_pane_progress}",
1415
+ verbose: "Loading workspace: {session} [window {window_index} of {window_total} · pane {pane_index} of {pane_total}] {window}"
1416
+ };
1417
+ var retainedCharacters = 65536;
1418
+
1419
+ class LoadProgress {
1420
+ painted = [];
1421
+ lastDraw = -Infinity;
1422
+ active = false;
1423
+ countsKnown = true;
1424
+ windowIndex = 0;
1425
+ windowTotal = 0;
1426
+ windowsDone = 0;
1427
+ paneIndex = 0;
1428
+ paneTotal = 0;
1429
+ panesDone = 0;
1430
+ sessionPaneTotal = 0;
1431
+ sessionPanesDone = 0;
1432
+ session = "";
1433
+ window = "";
1434
+ workspace = "";
1435
+ history = [];
1436
+ pending = {};
1437
+ afterCarriageReturn = { stdout: false, stderr: false };
1438
+ scriptOrder = 0;
1439
+ rawLineOpen = false;
1440
+ pendingWrite = Promise.resolve();
1441
+ context;
1442
+ format;
1443
+ lines;
1444
+ color;
1445
+ constructor(context, format, lines, color) {
1446
+ this.context = context;
1447
+ this.format = format;
1448
+ this.lines = lines;
1449
+ this.color = color;
1450
+ }
1451
+ static create(request, context) {
1452
+ if (request.mode !== "human" || !context.stderr.isTTY || context.env.TERM === "dumb" || request.values.no_progress || context.env.TMUXP_PROGRESS === "0")
1453
+ return;
1454
+ const value = request.values.panel_lines ?? context.env.TMUXP_PROGRESS_LINES ?? 3;
1455
+ if (!/^-?\d+$/.test(scalarText(value)) || !Number.isSafeInteger(Number(value)) || Number(value) < -1)
1456
+ throw new CliError("usage", "Progress lines must be an integer at least -1", 2);
1457
+ const format = scalarText(request.values.progress_format ?? context.env.TMUXP_PROGRESS_FORMAT ?? "default");
1458
+ return new LoadProgress(context, Object.hasOwn(presets, format) ? presets[format] : format, Number(value), colorEnabled(request.mode, request.values.color, context.env, true));
1459
+ }
1460
+ dimensions() {
1461
+ const stream = this.context.stderr;
1462
+ const dimension = (value, fallback) => value !== undefined && Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
1463
+ return { columns: dimension(stream.columns, 80), rows: dimension(stream.rows, 24) };
1464
+ }
1465
+ panelRows() {
1466
+ const available = Math.max(0, this.dimensions().rows - 2);
1467
+ return this.lines === -1 ? available : Math.min(this.lines, available);
1468
+ }
1469
+ script(stream, text) {
1470
+ if (!text)
1471
+ return;
1472
+ if (this.afterCarriageReturn[stream] && text.startsWith(`
1473
+ `))
1474
+ text = text.slice(1);
1475
+ this.afterCarriageReturn[stream] = text.endsWith("\r");
1476
+ const chunks = ((this.pending[stream]?.text ?? "") + text).slice(-retainedCharacters).split(/\r\n|[\r\n]/);
1477
+ const partial = chunks.pop() ?? "";
1478
+ this.history = [
1479
+ ...this.history,
1480
+ ...chunks.map((line) => ({ text: line, order: ++this.scriptOrder }))
1481
+ ].slice(-Math.max(1, this.panelRows()));
1482
+ let remaining = retainedCharacters;
1483
+ for (let index = this.history.length - 1;index >= 0; index--) {
1484
+ const line = this.history[index];
1485
+ line.text = line.text.slice(-remaining);
1486
+ remaining -= line.text.length;
1487
+ if (remaining === 0) {
1488
+ this.history = this.history.slice(index);
1489
+ break;
1490
+ }
1491
+ }
1492
+ if (partial)
1493
+ this.pending[stream] = { text: partial, order: ++this.scriptOrder };
1494
+ else
1495
+ delete this.pending[stream];
1496
+ }
1497
+ tokens() {
1498
+ const ratio = (done, total) => total ? `${done}/${total}` : "";
1499
+ const bar = (done, total) => {
1500
+ const filled = total ? Math.min(10, Math.floor(10 * done / total)) : 0;
1501
+ return styled("success", "█".repeat(filled), this.color) + styled("secondary", "░".repeat(10 - filled), this.color);
1502
+ };
1503
+ const windowProgress = this.windowIndex ? ratio(this.windowIndex, this.windowTotal) : "";
1504
+ const paneProgress = this.paneIndex ? ratio(this.paneIndex, this.paneTotal) : "";
1505
+ return {
1506
+ session: styled("subject", this.session, this.color),
1507
+ workspace_path: styled("info", this.workspace, this.color),
1508
+ window: styled("heading", this.window, this.color),
1509
+ window_index: this.windowIndex,
1510
+ window_total: this.windowTotal,
1511
+ window_progress: windowProgress,
1512
+ pane_index: this.paneIndex,
1513
+ pane_total: this.paneTotal,
1514
+ pane_progress: paneProgress,
1515
+ progress: [windowProgress && `${windowProgress} win`, paneProgress && `${paneProgress} pane`].filter(Boolean).join(" · "),
1516
+ windows_done: this.windowsDone,
1517
+ windows_remaining: Math.max(0, this.windowTotal - this.windowsDone),
1518
+ window_progress_rel: ratio(this.windowsDone, this.windowTotal),
1519
+ pane_done: this.panesDone,
1520
+ pane_remaining: Math.max(0, this.paneTotal - this.panesDone),
1521
+ pane_progress_rel: ratio(this.panesDone, this.paneTotal),
1522
+ session_pane_total: this.sessionPaneTotal,
1523
+ session_panes_done: this.sessionPanesDone,
1524
+ session_panes_remaining: Math.max(0, this.sessionPaneTotal - this.sessionPanesDone),
1525
+ session_pane_progress: ratio(this.sessionPanesDone, this.sessionPaneTotal),
1526
+ overall_percent: this.sessionPaneTotal ? Math.floor(100 * this.sessionPanesDone / this.sessionPaneTotal) : 0,
1527
+ summary: `[${this.windowsDone} win, ${this.sessionPanesDone} panes]`,
1528
+ bar: bar(this.sessionPanesDone, this.sessionPaneTotal),
1529
+ pane_bar: bar(this.sessionPanesDone, this.sessionPaneTotal),
1530
+ window_bar: bar(this.windowsDone, this.windowTotal),
1531
+ status_icon: ""
1532
+ };
1533
+ }
1534
+ erase() {
1535
+ const { columns, rows } = this.dimensions();
1536
+ const height = Math.min(rows, this.painted.reduce((total, width) => total + Math.max(1, Math.ceil(width / columns)), 0));
1537
+ return height ? `\r${height > 1 ? `\x1B[${height - 1}A` : ""}\x1B[0J` : "";
1538
+ }
1539
+ enqueue(operation) {
1540
+ const task = this.pendingWrite.then(operation);
1541
+ this.pendingWrite = task.then(() => {}, () => {});
1542
+ return task;
1543
+ }
1544
+ clear(signal = this.context.signal) {
1545
+ return this.enqueue(async () => {
1546
+ await this.separate(signal);
1547
+ await this.eraseFrame(signal);
1548
+ });
1549
+ }
1550
+ async separate(signal = this.context.signal) {
1551
+ if (this.rawLineOpen)
1552
+ await write(this.context.stderr, `
1553
+ `, signal);
1554
+ this.rawLineOpen = false;
1555
+ }
1556
+ async eraseFrame(signal = this.context.signal) {
1557
+ const erase = this.erase();
1558
+ if (erase)
1559
+ await write(this.context.stderr, erase, signal);
1560
+ this.painted = [];
1561
+ }
1562
+ async draw(force = false) {
1563
+ if (!this.active || !force && this.painted.length && performance.now() - this.lastDraw < 50)
1564
+ return;
1565
+ await this.separate();
1566
+ const tokens = this.tokens();
1567
+ const format = this.countsKnown ? this.format : "Loading workspace: {session}";
1568
+ const label = styled("secondary", format, false).replace(/\{\{|\}\}|\{([^{}]+)\}/g, (match, token) => match === "{{" ? "{" : match === "}}" ? "}" : token && Object.hasOwn(tokens, token) ? String(tokens[token]) : match);
1569
+ const count = this.panelRows();
1570
+ const panel = count ? [...this.history, ...Object.values(this.pending)].sort((a, b) => a.order - b.order).slice(-count) : [];
1571
+ const rows = [label, ...panel.map((line) => styled("secondary", line.text, this.color))].map((line) => cliTruncate(line, Math.max(0, this.dimensions().columns - 1)));
1572
+ const erase = this.erase();
1573
+ this.context.signal?.throwIfAborted();
1574
+ this.painted = rows.map((line) => stringWidth(line));
1575
+ this.lastDraw = performance.now();
1576
+ await write(this.context.stderr, erase + rows.join(`
1577
+ `), this.context.signal);
1578
+ }
1579
+ event(event, data) {
1580
+ return this.enqueue(() => this.update(event, data));
1581
+ }
1582
+ async update(event, data) {
1583
+ switch (event) {
1584
+ case "workspace-started":
1585
+ this.active = true;
1586
+ this.session = scalarText(data.session_name ?? "");
1587
+ this.workspace = scalarText(data.input ?? "");
1588
+ this.window = "";
1589
+ this.countsKnown = data.window_total !== undefined;
1590
+ this.windowTotal = Number(data.window_total ?? 0);
1591
+ this.sessionPaneTotal = Number(data.session_pane_total ?? 0);
1592
+ this.windowIndex = this.windowsDone = this.paneIndex = this.paneTotal = this.panesDone = this.sessionPanesDone = 0;
1593
+ this.history = [];
1594
+ this.pending = {};
1595
+ this.afterCarriageReturn.stdout = this.afterCarriageReturn.stderr = false;
1596
+ await this.draw(true);
1597
+ break;
1598
+ case "window-created":
1599
+ this.window = scalarText(data.window_name ?? "");
1600
+ this.windowIndex = Number(data.window_index);
1601
+ this.paneTotal = Number(data.pane_total);
1602
+ this.paneIndex = this.panesDone = 0;
1603
+ await this.draw();
1604
+ break;
1605
+ case "pane-created":
1606
+ this.paneIndex = Number(data.pane_index);
1607
+ await this.draw();
1608
+ break;
1609
+ case "pane-completed":
1610
+ this.panesDone++;
1611
+ this.sessionPanesDone++;
1612
+ await this.draw();
1613
+ break;
1614
+ case "window-completed":
1615
+ this.windowsDone++;
1616
+ await this.draw();
1617
+ break;
1618
+ case "script-output":
1619
+ if (this.lines === 0 || this.panelRows() === 0) {
1620
+ await this.eraseFrame();
1621
+ const stream = data.stream === "stderr" ? "stderr" : "stdout";
1622
+ const text = scalarText(data.text ?? "");
1623
+ if (text && this.context[stream].isTTY)
1624
+ this.rawLineOpen = !text.endsWith(`
1625
+ `);
1626
+ return false;
1627
+ }
1628
+ {
1629
+ const first = !this.history.length && !this.pending.stdout && !this.pending.stderr;
1630
+ this.script(data.stream === "stderr" ? "stderr" : "stdout", scalarText(data.text ?? ""));
1631
+ await this.draw(first);
1632
+ }
1633
+ return true;
1634
+ case "workspace-completed":
1635
+ case "completed":
1636
+ case "failed":
1637
+ this.active = false;
1638
+ await this.separate();
1639
+ await this.eraseFrame();
1640
+ break;
1641
+ default:
1642
+ await this.draw();
1643
+ }
1644
+ return false;
1645
+ }
1646
+ }
1647
+ export {
1648
+ LoadProgress
1649
+ };