@stacksjs/bun-queue 0.0.1

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +231 -0
  4. package/dist/batch.d.ts +18 -0
  5. package/dist/bin/cli.js +1914 -0
  6. package/dist/cleanup.d.ts +22 -0
  7. package/dist/commands/index.d.ts +6 -0
  8. package/dist/commands/script-loader.d.ts +44 -0
  9. package/dist/config.d.ts +4 -0
  10. package/dist/cron-scheduler.d.ts +37 -0
  11. package/dist/dead-letter-queue.d.ts +16 -0
  12. package/dist/dispatch.d.ts +84 -0
  13. package/dist/distributed-lock.d.ts +25 -0
  14. package/dist/events.d.ts +27 -0
  15. package/dist/failed/failed-job-manager.d.ts +17 -0
  16. package/dist/failed/failed-job-provider.d.ts +37 -0
  17. package/dist/failed/index.d.ts +7 -0
  18. package/dist/group.d.ts +22 -0
  19. package/dist/index.d.ts +72 -0
  20. package/dist/job-base.d.ts +95 -0
  21. package/dist/job-processor.d.ts +21 -0
  22. package/dist/job.d.ts +27 -0
  23. package/dist/jobs/bus.d.ts +60 -0
  24. package/dist/jobs/index.d.ts +14 -0
  25. package/dist/jobs/middleware.d.ts +37 -0
  26. package/dist/leader-election.d.ts +39 -0
  27. package/dist/logger.d.ts +14 -0
  28. package/dist/metrics.d.ts +22 -0
  29. package/dist/middleware.d.ts +61 -0
  30. package/dist/observable.d.ts +23 -0
  31. package/dist/priority-queue.d.ts +40 -0
  32. package/dist/queue-manager.d.ts +24 -0
  33. package/dist/queue.d.ts +114 -0
  34. package/dist/rate-limiter.d.ts +13 -0
  35. package/dist/src/index.js +17057 -0
  36. package/dist/stalled-checker.d.ts +14 -0
  37. package/dist/types.d.ts +180 -0
  38. package/dist/utils.d.ts +26 -0
  39. package/dist/work-coordinator.d.ts +35 -0
  40. package/dist/worker.d.ts +19 -0
  41. package/dist/workers/index.d.ts +6 -0
  42. package/dist/workers/queue-worker.d.ts +62 -0
  43. package/dist/workers/worker-manager.d.ts +22 -0
  44. package/package.json +75 -0
@@ -0,0 +1,1914 @@
1
+ // @bun
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __toESM = (mod, isNodeMode, target) => {
8
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
9
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
+ for (let key of __getOwnPropNames(mod))
11
+ if (!__hasOwnProp.call(to, key))
12
+ __defProp(to, key, {
13
+ get: () => mod[key],
14
+ enumerable: true
15
+ });
16
+ return to;
17
+ };
18
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
29
+ var __promiseAll = (args) => Promise.all(args);
30
+ var __require = import.meta.require;
31
+
32
+ // ../../node_modules/@stacksjs/clapp/dist/index.js
33
+ import { EventEmitter } from "events";
34
+ import process2 from "process";
35
+ import process3 from "process";
36
+ import process4 from "process";
37
+ import process5, { stdin, stdout } from "process";
38
+ import process6, { stdin as stdin2, stdout as stdout2 } from "process";
39
+ import readline2 from "readline";
40
+ var __create2 = Object.create;
41
+ var __getProtoOf2 = Object.getPrototypeOf;
42
+ var __defProp2 = Object.defineProperty;
43
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
44
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
45
+ var __toESM2 = (mod, isNodeMode, target) => {
46
+ target = mod != null ? __create2(__getProtoOf2(mod)) : {};
47
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target;
48
+ for (let key of __getOwnPropNames2(mod))
49
+ if (!__hasOwnProp2.call(to, key))
50
+ __defProp2(to, key, {
51
+ get: () => mod[key],
52
+ enumerable: true
53
+ });
54
+ return to;
55
+ };
56
+ var __commonJS2 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
57
+ var require_lib = __commonJS2((exports, module) => {
58
+ function toArr(any) {
59
+ return any == null ? [] : Array.isArray(any) ? any : [any];
60
+ }
61
+ function toVal(out, key, val, opts) {
62
+ var x, old = out[key], nxt = ~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : ~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
63
+ out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
64
+ }
65
+ module.exports = function(args, opts) {
66
+ args = args || [];
67
+ opts = opts || {};
68
+ var k, arr, arg, name, val, out = { _: [] };
69
+ var i = 0, j = 0, idx = 0, len = args.length;
70
+ const alibi = opts.alias !== undefined;
71
+ const strict = opts.unknown !== undefined;
72
+ const defaults = opts.default !== undefined;
73
+ opts.alias = opts.alias || {};
74
+ opts.string = toArr(opts.string);
75
+ opts.boolean = toArr(opts.boolean);
76
+ if (alibi) {
77
+ for (k in opts.alias) {
78
+ arr = opts.alias[k] = toArr(opts.alias[k]);
79
+ for (i = 0;i < arr.length; i++) {
80
+ (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
81
+ }
82
+ }
83
+ }
84
+ for (i = opts.boolean.length;i-- > 0; ) {
85
+ arr = opts.alias[opts.boolean[i]] || [];
86
+ for (j = arr.length;j-- > 0; )
87
+ opts.boolean.push(arr[j]);
88
+ }
89
+ for (i = opts.string.length;i-- > 0; ) {
90
+ arr = opts.alias[opts.string[i]] || [];
91
+ for (j = arr.length;j-- > 0; )
92
+ opts.string.push(arr[j]);
93
+ }
94
+ if (defaults) {
95
+ for (k in opts.default) {
96
+ name = typeof opts.default[k];
97
+ arr = opts.alias[k] = opts.alias[k] || [];
98
+ if (opts[name] !== undefined) {
99
+ opts[name].push(k);
100
+ for (i = 0;i < arr.length; i++) {
101
+ opts[name].push(arr[i]);
102
+ }
103
+ }
104
+ }
105
+ }
106
+ const keys = strict ? Object.keys(opts.alias) : [];
107
+ for (i = 0;i < len; i++) {
108
+ arg = args[i];
109
+ if (arg === "--") {
110
+ out._ = out._.concat(args.slice(++i));
111
+ break;
112
+ }
113
+ for (j = 0;j < arg.length; j++) {
114
+ if (arg.charCodeAt(j) !== 45)
115
+ break;
116
+ }
117
+ if (j === 0) {
118
+ out._.push(arg);
119
+ } else if (arg.substring(j, j + 3) === "no-") {
120
+ name = arg.substring(j + 3);
121
+ if (strict && !~keys.indexOf(name)) {
122
+ return opts.unknown(arg);
123
+ }
124
+ out[name] = false;
125
+ } else {
126
+ for (idx = j + 1;idx < arg.length; idx++) {
127
+ if (arg.charCodeAt(idx) === 61)
128
+ break;
129
+ }
130
+ name = arg.substring(j, idx);
131
+ val = arg.substring(++idx) || (i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i]);
132
+ arr = j === 2 ? [name] : name;
133
+ for (idx = 0;idx < arr.length; idx++) {
134
+ name = arr[idx];
135
+ if (strict && !~keys.indexOf(name))
136
+ return opts.unknown("-".repeat(j) + name);
137
+ toVal(out, name, idx + 1 < arr.length || val, opts);
138
+ }
139
+ }
140
+ }
141
+ if (defaults) {
142
+ for (k in opts.default) {
143
+ if (out[k] === undefined) {
144
+ out[k] = opts.default[k];
145
+ }
146
+ }
147
+ }
148
+ if (alibi) {
149
+ for (k in out) {
150
+ arr = opts.alias[k] || [];
151
+ while (arr.length > 0) {
152
+ out[arr.shift()] = out[k];
153
+ }
154
+ }
155
+ }
156
+ return out;
157
+ };
158
+ });
159
+ var require_picocolors = __commonJS2((exports, module) => {
160
+ var p = process || {};
161
+ var argv = p.argv || [];
162
+ var env = p.env || {};
163
+ var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
164
+ var formatter = (open, close, replace = open) => (input) => {
165
+ let string = "" + input, index = string.indexOf(close, open.length);
166
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
167
+ };
168
+ var replaceClose = (string, close, replace, index) => {
169
+ let result = "", cursor2 = 0;
170
+ do {
171
+ result += string.substring(cursor2, index) + replace;
172
+ cursor2 = index + close.length;
173
+ index = string.indexOf(close, cursor2);
174
+ } while (~index);
175
+ return result + string.substring(cursor2);
176
+ };
177
+ var createColors = (enabled = isColorSupported) => {
178
+ let f = enabled ? formatter : () => String;
179
+ return {
180
+ isColorSupported: enabled,
181
+ reset: f("\x1B[0m", "\x1B[0m"),
182
+ bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
183
+ dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
184
+ italic: f("\x1B[3m", "\x1B[23m"),
185
+ underline: f("\x1B[4m", "\x1B[24m"),
186
+ inverse: f("\x1B[7m", "\x1B[27m"),
187
+ hidden: f("\x1B[8m", "\x1B[28m"),
188
+ strikethrough: f("\x1B[9m", "\x1B[29m"),
189
+ black: f("\x1B[30m", "\x1B[39m"),
190
+ red: f("\x1B[31m", "\x1B[39m"),
191
+ green: f("\x1B[32m", "\x1B[39m"),
192
+ yellow: f("\x1B[33m", "\x1B[39m"),
193
+ blue: f("\x1B[34m", "\x1B[39m"),
194
+ magenta: f("\x1B[35m", "\x1B[39m"),
195
+ cyan: f("\x1B[36m", "\x1B[39m"),
196
+ white: f("\x1B[37m", "\x1B[39m"),
197
+ gray: f("\x1B[90m", "\x1B[39m"),
198
+ bgBlack: f("\x1B[40m", "\x1B[49m"),
199
+ bgRed: f("\x1B[41m", "\x1B[49m"),
200
+ bgGreen: f("\x1B[42m", "\x1B[49m"),
201
+ bgYellow: f("\x1B[43m", "\x1B[49m"),
202
+ bgBlue: f("\x1B[44m", "\x1B[49m"),
203
+ bgMagenta: f("\x1B[45m", "\x1B[49m"),
204
+ bgCyan: f("\x1B[46m", "\x1B[49m"),
205
+ bgWhite: f("\x1B[47m", "\x1B[49m"),
206
+ blackBright: f("\x1B[90m", "\x1B[39m"),
207
+ redBright: f("\x1B[91m", "\x1B[39m"),
208
+ greenBright: f("\x1B[92m", "\x1B[39m"),
209
+ yellowBright: f("\x1B[93m", "\x1B[39m"),
210
+ blueBright: f("\x1B[94m", "\x1B[39m"),
211
+ magentaBright: f("\x1B[95m", "\x1B[39m"),
212
+ cyanBright: f("\x1B[96m", "\x1B[39m"),
213
+ whiteBright: f("\x1B[97m", "\x1B[39m"),
214
+ bgBlackBright: f("\x1B[100m", "\x1B[49m"),
215
+ bgRedBright: f("\x1B[101m", "\x1B[49m"),
216
+ bgGreenBright: f("\x1B[102m", "\x1B[49m"),
217
+ bgYellowBright: f("\x1B[103m", "\x1B[49m"),
218
+ bgBlueBright: f("\x1B[104m", "\x1B[49m"),
219
+ bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
220
+ bgCyanBright: f("\x1B[106m", "\x1B[49m"),
221
+ bgWhiteBright: f("\x1B[107m", "\x1B[49m")
222
+ };
223
+ };
224
+ module.exports = createColors();
225
+ module.exports.createColors = createColors;
226
+ });
227
+ var require_emoji_regex = __commonJS2((exports, module) => {
228
+ module.exports = () => {
229
+ return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE89\uDE8F-\uDEC2\uDEC6\uDECE-\uDEDC\uDEDF-\uDEE9]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
230
+ };
231
+ });
232
+ var import_mri = __toESM2(require_lib(), 1);
233
+ function removeBrackets(v) {
234
+ return v.replace(/[<[].+/, "").trim();
235
+ }
236
+ function findAllBrackets(v) {
237
+ const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
238
+ const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
239
+ const res = [];
240
+ const parse = (match) => {
241
+ let variadic = false;
242
+ let value = match[1];
243
+ if (value.startsWith("...")) {
244
+ value = value.slice(3);
245
+ variadic = true;
246
+ }
247
+ return {
248
+ required: match[0].startsWith("<"),
249
+ value,
250
+ variadic
251
+ };
252
+ };
253
+ let angledMatch;
254
+ while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
255
+ res.push(parse(angledMatch));
256
+ }
257
+ let squareMatch;
258
+ while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
259
+ res.push(parse(squareMatch));
260
+ }
261
+ return res;
262
+ }
263
+ function getMriOptions(options) {
264
+ const result = { alias: {}, boolean: [] };
265
+ for (const [index, option] of options.entries()) {
266
+ if (option.names.length > 1) {
267
+ result.alias[option.names[0]] = option.names.slice(1);
268
+ }
269
+ if (option.isBoolean) {
270
+ if (option.negated) {
271
+ const hasStringTypeOption = options.some((o, i) => {
272
+ return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
273
+ });
274
+ if (!hasStringTypeOption) {
275
+ result.boolean.push(option.names[0]);
276
+ }
277
+ } else {
278
+ result.boolean.push(option.names[0]);
279
+ }
280
+ }
281
+ }
282
+ return result;
283
+ }
284
+ function findLongest(arr) {
285
+ return arr.sort((a, b) => {
286
+ return a.length > b.length ? -1 : 1;
287
+ })[0];
288
+ }
289
+ function padRight(str, length) {
290
+ return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
291
+ }
292
+ function camelcase(input) {
293
+ return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
294
+ return p1 + p2.toUpperCase();
295
+ });
296
+ }
297
+ function setDotProp(obj, keys, val) {
298
+ let i = 0;
299
+ const length = keys.length;
300
+ let t = obj;
301
+ let x;
302
+ for (;i < length; ++i) {
303
+ x = t[keys[i]];
304
+ t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
305
+ }
306
+ }
307
+ function setByType(obj, transforms) {
308
+ for (const key of Object.keys(transforms)) {
309
+ const transform = transforms[key];
310
+ if (transform.shouldTransform) {
311
+ obj[key] = Array.prototype.concat.call([], obj[key]);
312
+ if (typeof transform.transformFunction === "function") {
313
+ obj[key] = obj[key].map(transform.transformFunction);
314
+ }
315
+ }
316
+ }
317
+ }
318
+ function getFileName(input) {
319
+ const m = /([^\\/]+)$/.exec(input);
320
+ return m ? m[1] : "";
321
+ }
322
+ function camelcaseOptionName(name) {
323
+ return name.split(".").map((v, i) => {
324
+ return i === 0 ? camelcase(v) : v;
325
+ }).join(".");
326
+ }
327
+
328
+ class ClappError extends Error {
329
+ constructor(message) {
330
+ super(message);
331
+ this.name = this.constructor.name;
332
+ if (typeof Error.captureStackTrace === "function") {
333
+ Error.captureStackTrace(this, this.constructor);
334
+ } else {
335
+ this.stack = new Error(message).stack;
336
+ }
337
+ }
338
+ }
339
+ function isUnicodeSupported() {
340
+ const { env } = process2;
341
+ const { TERM, TERM_PROGRAM } = env;
342
+ if (process2.platform !== "win32") {
343
+ return TERM !== "linux";
344
+ }
345
+ return Boolean(env.WT_SESSION) || Boolean(env.TERMINUS_SUBLIME) || env.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
346
+ }
347
+ var ESC = "\x1B";
348
+ var CSI = `${ESC}[`;
349
+ var cursor = {
350
+ to(x, y) {
351
+ if (!y)
352
+ return `${CSI}${x + 1}G`;
353
+ return `${CSI}${y + 1};${x + 1}H`;
354
+ },
355
+ move(x, y) {
356
+ let ret = "";
357
+ if (x < 0)
358
+ ret += `${CSI}${-x}D`;
359
+ else if (x > 0)
360
+ ret += `${CSI}${x}C`;
361
+ if (y < 0)
362
+ ret += `${CSI}${-y}A`;
363
+ else if (y > 0)
364
+ ret += `${CSI}${y}B`;
365
+ return ret;
366
+ },
367
+ up: (count = 1) => `${CSI}${count}A`,
368
+ down: (count = 1) => `${CSI}${count}B`,
369
+ forward: (count = 1) => `${CSI}${count}C`,
370
+ backward: (count = 1) => `${CSI}${count}D`,
371
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
372
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
373
+ left: `${CSI}G`,
374
+ hide: `${CSI}?25l`,
375
+ show: `${CSI}?25h`,
376
+ save: `${ESC}7`,
377
+ restore: `${ESC}8`
378
+ };
379
+ var erase = {
380
+ screen: `${CSI}2J`,
381
+ up: (count = 1) => `${CSI}1J`.repeat(count),
382
+ down: (count = 1) => `${CSI}J`.repeat(count),
383
+ line: `${CSI}2K`,
384
+ lineEnd: `${CSI}K`,
385
+ lineStart: `${CSI}1K`,
386
+ lines(count) {
387
+ let clear = "";
388
+ for (let i = 0;i < count; i++)
389
+ clear += this.line + (i < count - 1 ? cursor.up() : "");
390
+ if (count)
391
+ clear += cursor.left;
392
+ return clear;
393
+ }
394
+ };
395
+ var clear = {
396
+ screen: `${ESC}c`
397
+ };
398
+
399
+ class Option {
400
+ rawName;
401
+ description;
402
+ name;
403
+ names;
404
+ isBoolean;
405
+ required;
406
+ config;
407
+ negated;
408
+ constructor(rawName, description, config) {
409
+ this.rawName = rawName;
410
+ this.description = description;
411
+ this.config = Object.assign({}, config);
412
+ rawName = rawName.replace(/\.\*/g, "");
413
+ this.negated = false;
414
+ this.names = removeBrackets(rawName).split(",").map((v) => {
415
+ let name = v.trim().replace(/^-{1,2}/, "");
416
+ if (name.startsWith("no-")) {
417
+ this.negated = true;
418
+ name = name.replace(/^no-/, "");
419
+ }
420
+ return camelcaseOptionName(name);
421
+ }).sort((a, b) => a.length > b.length ? 1 : -1);
422
+ this.name = this.names[this.names.length - 1];
423
+ if (this.negated && this.config.default == null) {
424
+ this.config.default = true;
425
+ }
426
+ if (rawName.includes("<")) {
427
+ this.required = true;
428
+ } else if (rawName.includes("[")) {
429
+ this.required = false;
430
+ } else {
431
+ this.isBoolean = true;
432
+ }
433
+ }
434
+ }
435
+ var processArgs = process3.argv;
436
+ var platformInfo = `${process3.platform}-${process3.arch} bun-v${typeof Bun !== "undefined" ? Bun.version : "unknown"}`;
437
+ var processArgs2 = process4.argv;
438
+ var platformInfo2 = `${process4.platform}-${process4.arch} node-${process4.version}`;
439
+
440
+ class Command {
441
+ rawName;
442
+ description;
443
+ config;
444
+ cli;
445
+ options;
446
+ aliasNames;
447
+ name;
448
+ args;
449
+ commandAction;
450
+ usageText;
451
+ versionNumber;
452
+ examples;
453
+ helpCallback;
454
+ globalCommand;
455
+ constructor(rawName, description, config, cli) {
456
+ this.rawName = rawName;
457
+ this.description = description;
458
+ this.config = config;
459
+ this.cli = cli;
460
+ this.options = [];
461
+ this.aliasNames = [];
462
+ this.name = removeBrackets(rawName);
463
+ this.args = findAllBrackets(rawName);
464
+ this.examples = [];
465
+ if (!config) {
466
+ this.config = {};
467
+ }
468
+ }
469
+ usage(text) {
470
+ this.usageText = text;
471
+ return this;
472
+ }
473
+ allowUnknownOptions() {
474
+ this.config.allowUnknownOptions = true;
475
+ return this;
476
+ }
477
+ ignoreOptionDefaultValue() {
478
+ this.config.ignoreOptionDefaultValue = true;
479
+ return this;
480
+ }
481
+ version(version, customFlags = "-v, --version") {
482
+ this.versionNumber = version;
483
+ this.option(customFlags, "Display version number");
484
+ return this;
485
+ }
486
+ example(example) {
487
+ this.examples.push(example);
488
+ return this;
489
+ }
490
+ option(rawName, description, config) {
491
+ const option = new Option(rawName, description, config);
492
+ this.options.push(option);
493
+ return this;
494
+ }
495
+ alias(name) {
496
+ this.aliasNames.push(name);
497
+ return this;
498
+ }
499
+ action(callback) {
500
+ this.commandAction = callback;
501
+ return this;
502
+ }
503
+ isMatched(name) {
504
+ return this.name === name || this.aliasNames.includes(name);
505
+ }
506
+ get isDefaultCommand() {
507
+ return this.name === "" || this.aliasNames.includes("!");
508
+ }
509
+ get isGlobalCommand() {
510
+ return this instanceof GlobalCommand;
511
+ }
512
+ hasOption(name) {
513
+ name = name.split(".")[0];
514
+ return !!this.options.find((option) => {
515
+ return option.names.includes(name);
516
+ });
517
+ }
518
+ outputHelp() {
519
+ const { name, commands } = this.cli;
520
+ const {
521
+ versionNumber,
522
+ options: globalOptions,
523
+ helpCallback
524
+ } = this.cli.globalCommand;
525
+ let sections = [
526
+ {
527
+ body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
528
+ }
529
+ ];
530
+ sections.push({
531
+ title: "Usage",
532
+ body: ` $ ${name} ${this.usageText || this.rawName}`
533
+ });
534
+ const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
535
+ if (showCommands) {
536
+ const longestCommandName = findLongest(commands.map((command) => command.rawName));
537
+ sections.push({
538
+ title: "Commands",
539
+ body: commands.map((command) => {
540
+ return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
541
+ }).join(`
542
+ `)
543
+ });
544
+ sections.push({
545
+ title: `For more info, run any command with the \`--help\` flag`,
546
+ body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join(`
547
+ `)
548
+ });
549
+ }
550
+ let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
551
+ if (!this.isGlobalCommand && !this.isDefaultCommand) {
552
+ options = options.filter((option) => option.name !== "version");
553
+ }
554
+ if (options.length > 0) {
555
+ const longestOptionName = findLongest(options.map((option) => option.rawName));
556
+ sections.push({
557
+ title: "Options",
558
+ body: options.map((option) => {
559
+ return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === undefined ? "" : `(default: ${option.config.default})`}`;
560
+ }).join(`
561
+ `)
562
+ });
563
+ }
564
+ if (this.examples.length > 0) {
565
+ sections.push({
566
+ title: "Examples",
567
+ body: this.examples.map((example) => {
568
+ if (typeof example === "function") {
569
+ return example(name);
570
+ }
571
+ return example;
572
+ }).join(`
573
+ `)
574
+ });
575
+ }
576
+ if (helpCallback) {
577
+ sections = helpCallback(sections) || sections;
578
+ }
579
+ console.log(sections.map((section) => {
580
+ return section.title ? `${section.title}:
581
+ ${section.body}` : section.body;
582
+ }).join(`
583
+
584
+ `));
585
+ }
586
+ outputVersion() {
587
+ const { name } = this.cli;
588
+ const { versionNumber } = this.cli.globalCommand;
589
+ if (versionNumber) {
590
+ let platformInfo3;
591
+ if (Bun) {
592
+ platformInfo3 = platformInfo;
593
+ } else {
594
+ platformInfo3 = platformInfo2;
595
+ }
596
+ console.log(`${name}/${versionNumber} ${platformInfo3}`);
597
+ }
598
+ }
599
+ checkRequiredArgs() {
600
+ const minimalArgsCount = this.args.filter((arg) => arg.required).length;
601
+ if (this.cli.args.length < minimalArgsCount) {
602
+ throw new ClappError(`missing required args for command \`${this.rawName}\``);
603
+ }
604
+ }
605
+ checkUnknownOptions() {
606
+ const { options, globalCommand } = this.cli;
607
+ if (!this.config.allowUnknownOptions) {
608
+ for (const name of Object.keys(options)) {
609
+ if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
610
+ throw new ClappError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
611
+ }
612
+ }
613
+ }
614
+ }
615
+ checkOptionValue() {
616
+ const { options: parsedOptions, globalCommand } = this.cli;
617
+ const options = [...globalCommand.options, ...this.options];
618
+ for (const option of options) {
619
+ const value = parsedOptions[option.name.split(".")[0]];
620
+ if (option.required) {
621
+ const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
622
+ if (value === true || value === false && !hasNegated) {
623
+ throw new ClappError(`option \`${option.rawName}\` value is missing`);
624
+ }
625
+ }
626
+ }
627
+ }
628
+ }
629
+
630
+ class GlobalCommand extends Command {
631
+ constructor(cli) {
632
+ super("@@global@@", "", {}, cli);
633
+ }
634
+ }
635
+ var Command_default = Command;
636
+
637
+ class CLI extends EventEmitter {
638
+ name;
639
+ commands;
640
+ globalCommand;
641
+ matchedCommand;
642
+ matchedCommandName;
643
+ rawArgs;
644
+ args;
645
+ options;
646
+ showHelpOnExit;
647
+ showVersionOnExit;
648
+ constructor(name = "") {
649
+ super();
650
+ this.name = name;
651
+ this.commands = [];
652
+ this.rawArgs = [];
653
+ this.args = [];
654
+ this.options = {};
655
+ this.globalCommand = new GlobalCommand(this);
656
+ this.globalCommand.usage("<command> [options]");
657
+ }
658
+ usage(text) {
659
+ this.globalCommand.usage(text);
660
+ return this;
661
+ }
662
+ command(rawName, description, config) {
663
+ if (!config) {
664
+ config = {};
665
+ }
666
+ const command = new Command_default(rawName, description || "", config, this);
667
+ command.globalCommand = this.globalCommand;
668
+ this.commands.push(command);
669
+ return command;
670
+ }
671
+ option(rawName, description, config) {
672
+ this.globalCommand.option(rawName, description, config);
673
+ return this;
674
+ }
675
+ help(callback) {
676
+ this.globalCommand.option("-h, --help", "Display this message");
677
+ this.globalCommand.helpCallback = callback;
678
+ this.showHelpOnExit = true;
679
+ return this;
680
+ }
681
+ version(version, customFlags = "-v, --version") {
682
+ this.globalCommand.version(version, customFlags);
683
+ this.showVersionOnExit = true;
684
+ return this;
685
+ }
686
+ example(example) {
687
+ this.globalCommand.example(example);
688
+ return this;
689
+ }
690
+ outputHelp() {
691
+ if (this.matchedCommand) {
692
+ this.matchedCommand.outputHelp();
693
+ } else {
694
+ this.globalCommand.outputHelp();
695
+ }
696
+ }
697
+ outputVersion() {
698
+ this.globalCommand.outputVersion();
699
+ }
700
+ setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
701
+ this.args = args;
702
+ this.options = options;
703
+ if (matchedCommand) {
704
+ this.matchedCommand = matchedCommand;
705
+ }
706
+ if (matchedCommandName) {
707
+ this.matchedCommandName = matchedCommandName;
708
+ }
709
+ return this;
710
+ }
711
+ unsetMatchedCommand() {
712
+ this.matchedCommand = undefined;
713
+ this.matchedCommandName = undefined;
714
+ }
715
+ parse(argv = processArgs2, {
716
+ run = true
717
+ } = {}) {
718
+ this.rawArgs = argv;
719
+ if (!this.name) {
720
+ this.name = argv[1] ? getFileName(argv[1]) : "cli";
721
+ }
722
+ let shouldParse = true;
723
+ for (const command of this.commands) {
724
+ const parsed = this.mri(argv.slice(2), command);
725
+ const commandName = parsed.args[0];
726
+ if (command.isMatched(commandName)) {
727
+ shouldParse = false;
728
+ const parsedInfo = {
729
+ ...parsed,
730
+ args: parsed.args.slice(1)
731
+ };
732
+ this.setParsedInfo(parsedInfo, command, commandName);
733
+ this.emit(`command:${commandName}`, command);
734
+ }
735
+ }
736
+ if (shouldParse) {
737
+ for (const command of this.commands) {
738
+ if (command.name === "") {
739
+ shouldParse = false;
740
+ const parsed = this.mri(argv.slice(2), command);
741
+ this.setParsedInfo(parsed, command);
742
+ this.emit(`command:!`, command);
743
+ }
744
+ }
745
+ }
746
+ if (shouldParse) {
747
+ const parsed = this.mri(argv.slice(2));
748
+ this.setParsedInfo(parsed);
749
+ }
750
+ if (this.options.help && this.showHelpOnExit) {
751
+ this.outputHelp();
752
+ run = false;
753
+ this.unsetMatchedCommand();
754
+ }
755
+ if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
756
+ this.outputVersion();
757
+ run = false;
758
+ this.unsetMatchedCommand();
759
+ }
760
+ const parsedArgv = { args: this.args, options: this.options };
761
+ if (run) {
762
+ this.runMatchedCommand();
763
+ }
764
+ if (!this.matchedCommand && this.args[0]) {
765
+ this.emit("command:*");
766
+ }
767
+ return parsedArgv;
768
+ }
769
+ mri(argv, command) {
770
+ const cliOptions = [
771
+ ...this.globalCommand.options,
772
+ ...command ? command.options : []
773
+ ];
774
+ const mriOptions = getMriOptions(cliOptions);
775
+ let argsAfterDoubleDashes = [];
776
+ const doubleDashesIndex = argv.indexOf("--");
777
+ if (doubleDashesIndex > -1) {
778
+ argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
779
+ argv = argv.slice(0, doubleDashesIndex);
780
+ }
781
+ let parsed = import_mri.default(argv, mriOptions);
782
+ parsed = Object.keys(parsed).reduce((res, name) => {
783
+ return {
784
+ ...res,
785
+ [camelcaseOptionName(name)]: parsed[name]
786
+ };
787
+ }, { _: [] });
788
+ const args = parsed._;
789
+ const options = {
790
+ "--": argsAfterDoubleDashes
791
+ };
792
+ const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
793
+ const transforms = Object.create(null);
794
+ for (const cliOption of cliOptions) {
795
+ if (!ignoreDefault && cliOption.config.default !== undefined) {
796
+ for (const name of cliOption.names) {
797
+ options[name] = cliOption.config.default;
798
+ }
799
+ }
800
+ if (Array.isArray(cliOption.config.type)) {
801
+ if (transforms[cliOption.name] === undefined) {
802
+ transforms[cliOption.name] = Object.create(null);
803
+ transforms[cliOption.name].shouldTransform = true;
804
+ transforms[cliOption.name].transformFunction = cliOption.config.type[0];
805
+ }
806
+ }
807
+ }
808
+ for (const key of Object.keys(parsed)) {
809
+ if (key !== "_") {
810
+ const keys = key.split(".");
811
+ setDotProp(options, keys, parsed[key]);
812
+ setByType(options, transforms);
813
+ }
814
+ }
815
+ return {
816
+ args,
817
+ options
818
+ };
819
+ }
820
+ runMatchedCommand() {
821
+ const { args, options, matchedCommand: command } = this;
822
+ if (!command || !command.commandAction)
823
+ return;
824
+ command.checkUnknownOptions();
825
+ command.checkOptionValue();
826
+ command.checkRequiredArgs();
827
+ const actionArgs = [];
828
+ command.args.forEach((arg, index) => {
829
+ if (arg.variadic) {
830
+ actionArgs.push(args.slice(index));
831
+ } else {
832
+ actionArgs.push(args[index]);
833
+ }
834
+ });
835
+ actionArgs.push(options);
836
+ return command.commandAction.apply(this, actionArgs);
837
+ }
838
+ }
839
+ var import_picocolors6 = __toESM2(require_picocolors(), 1);
840
+ var actions = ["up", "down", "left", "right", "space", "enter", "cancel"];
841
+ var settings = {
842
+ actions: new Set(actions),
843
+ aliases: new Map([
844
+ ["k", "up"],
845
+ ["j", "down"],
846
+ ["h", "left"],
847
+ ["l", "right"],
848
+ ["\x03", "cancel"],
849
+ ["escape", "cancel"]
850
+ ]),
851
+ messages: {
852
+ cancel: "Canceled",
853
+ error: "Something went wrong"
854
+ }
855
+ };
856
+ function isActionKey(key, action) {
857
+ if (typeof key === "string") {
858
+ return settings.aliases.get(key) === action;
859
+ }
860
+ for (const value of key) {
861
+ if (value === undefined)
862
+ continue;
863
+ if (isActionKey(value, action)) {
864
+ return true;
865
+ }
866
+ }
867
+ return false;
868
+ }
869
+ function diffLines(a, b) {
870
+ if (a === b)
871
+ return [];
872
+ const aLines = a.split(`
873
+ `);
874
+ const bLines = b.split(`
875
+ `);
876
+ const diff = [];
877
+ for (let i = 0;i < Math.max(aLines.length, bLines.length); i++) {
878
+ if (aLines[i] !== bLines[i])
879
+ diff.push(i);
880
+ }
881
+ return diff;
882
+ }
883
+ var isWindows = process5.platform.startsWith("win");
884
+ var CANCEL_SYMBOL = Symbol("clapp:cancel");
885
+ function setRawMode(input, value) {
886
+ const i = input;
887
+ if (i.isTTY)
888
+ i.setRawMode(value);
889
+ }
890
+ var import_picocolors = __toESM2(require_picocolors(), 1);
891
+ function ansiRegex({ onlyFirst = false } = {}) {
892
+ const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
893
+ const osc = `(?:\\u001B\\][\\s\\S]*?${ST})`;
894
+ const csi = "[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";
895
+ const pattern = `${osc}|${csi}`;
896
+ return new RegExp(pattern, onlyFirst ? undefined : "g");
897
+ }
898
+ var regex = ansiRegex();
899
+ function stripAnsi(string2) {
900
+ if (typeof string2 !== "string") {
901
+ throw new TypeError(`Expected a \`string\`, got \`${typeof string2}\``);
902
+ }
903
+ return string2.replace(regex, "");
904
+ }
905
+ function isAmbiguous(x) {
906
+ 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;
907
+ }
908
+ function isFullWidth(x) {
909
+ return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
910
+ }
911
+ function isWide(x) {
912
+ 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 >= 9776 && x <= 9783 || x >= 9800 && x <= 9811 || x === 9855 || x >= 9866 && x <= 9871 || 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 <= 12773 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && 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 >= 101631 && 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 >= 119552 && x <= 119638 || x >= 119648 && x <= 119670 || 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 <= 129673 || x >= 129679 && x <= 129734 || x >= 129742 && x <= 129756 || x >= 129759 && x <= 129769 || x >= 129776 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
913
+ }
914
+ function validate(codePoint) {
915
+ if (!Number.isSafeInteger(codePoint)) {
916
+ throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
917
+ }
918
+ }
919
+ function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
920
+ validate(codePoint);
921
+ if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
922
+ return 2;
923
+ }
924
+ return 1;
925
+ }
926
+ var import_emoji_regex = __toESM2(require_emoji_regex(), 1);
927
+ var segmenter = new Intl.Segmenter;
928
+ var defaultIgnorableCodePointRegex = /^\p{Default_Ignorable_Code_Point}$/u;
929
+ function stringWidth(string2, options = {}) {
930
+ if (typeof string2 !== "string" || string2.length === 0) {
931
+ return 0;
932
+ }
933
+ const {
934
+ ambiguousIsNarrow = true,
935
+ countAnsiEscapeCodes = false
936
+ } = options;
937
+ if (!countAnsiEscapeCodes) {
938
+ string2 = stripAnsi(string2);
939
+ }
940
+ if (string2.length === 0) {
941
+ return 0;
942
+ }
943
+ let width = 0;
944
+ const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
945
+ for (const { segment: character } of segmenter.segment(string2)) {
946
+ const codePoint = character.codePointAt(0);
947
+ if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
948
+ continue;
949
+ }
950
+ if (codePoint >= 8203 && codePoint <= 8207 || codePoint === 65279) {
951
+ continue;
952
+ }
953
+ if (codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071) {
954
+ continue;
955
+ }
956
+ if (codePoint >= 55296 && codePoint <= 57343) {
957
+ continue;
958
+ }
959
+ if (codePoint >= 65024 && codePoint <= 65039) {
960
+ continue;
961
+ }
962
+ if (defaultIgnorableCodePointRegex.test(character)) {
963
+ continue;
964
+ }
965
+ if (import_emoji_regex.default().test(character)) {
966
+ width += 2;
967
+ continue;
968
+ }
969
+ width += eastAsianWidth(codePoint, eastAsianWidthOptions);
970
+ }
971
+ return width;
972
+ }
973
+ var ANSI_BACKGROUND_OFFSET = 10;
974
+ var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
975
+ var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
976
+ var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
977
+ var styles = {
978
+ modifier: {
979
+ reset: [0, 0],
980
+ bold: [1, 22],
981
+ dim: [2, 22],
982
+ italic: [3, 23],
983
+ underline: [4, 24],
984
+ overline: [53, 55],
985
+ inverse: [7, 27],
986
+ hidden: [8, 28],
987
+ strikethrough: [9, 29]
988
+ },
989
+ color: {
990
+ black: [30, 39],
991
+ red: [31, 39],
992
+ green: [32, 39],
993
+ yellow: [33, 39],
994
+ blue: [34, 39],
995
+ magenta: [35, 39],
996
+ cyan: [36, 39],
997
+ white: [37, 39],
998
+ blackBright: [90, 39],
999
+ gray: [90, 39],
1000
+ grey: [90, 39],
1001
+ redBright: [91, 39],
1002
+ greenBright: [92, 39],
1003
+ yellowBright: [93, 39],
1004
+ blueBright: [94, 39],
1005
+ magentaBright: [95, 39],
1006
+ cyanBright: [96, 39],
1007
+ whiteBright: [97, 39]
1008
+ },
1009
+ bgColor: {
1010
+ bgBlack: [40, 49],
1011
+ bgRed: [41, 49],
1012
+ bgGreen: [42, 49],
1013
+ bgYellow: [43, 49],
1014
+ bgBlue: [44, 49],
1015
+ bgMagenta: [45, 49],
1016
+ bgCyan: [46, 49],
1017
+ bgWhite: [47, 49],
1018
+ bgBlackBright: [100, 49],
1019
+ bgGray: [100, 49],
1020
+ bgGrey: [100, 49],
1021
+ bgRedBright: [101, 49],
1022
+ bgGreenBright: [102, 49],
1023
+ bgYellowBright: [103, 49],
1024
+ bgBlueBright: [104, 49],
1025
+ bgMagentaBright: [105, 49],
1026
+ bgCyanBright: [106, 49],
1027
+ bgWhiteBright: [107, 49]
1028
+ }
1029
+ };
1030
+ var modifierNames = Object.keys(styles.modifier);
1031
+ var foregroundColorNames = Object.keys(styles.color);
1032
+ var backgroundColorNames = Object.keys(styles.bgColor);
1033
+ var colorNames = [...foregroundColorNames, ...backgroundColorNames];
1034
+ function assembleStyles() {
1035
+ const codes = new Map;
1036
+ for (const [groupName, group] of Object.entries(styles)) {
1037
+ for (const [styleName, style] of Object.entries(group)) {
1038
+ styles[styleName] = {
1039
+ open: `\x1B[${style[0]}m`,
1040
+ close: `\x1B[${style[1]}m`
1041
+ };
1042
+ group[styleName] = styles[styleName];
1043
+ codes.set(style[0], style[1]);
1044
+ }
1045
+ Object.defineProperty(styles, groupName, {
1046
+ value: group,
1047
+ enumerable: false
1048
+ });
1049
+ }
1050
+ Object.defineProperty(styles, "codes", {
1051
+ value: codes,
1052
+ enumerable: false
1053
+ });
1054
+ styles.color.close = "\x1B[39m";
1055
+ styles.bgColor.close = "\x1B[49m";
1056
+ styles.color.ansi = wrapAnsi16();
1057
+ styles.color.ansi256 = wrapAnsi256();
1058
+ styles.color.ansi16m = wrapAnsi16m();
1059
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
1060
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
1061
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
1062
+ Object.defineProperties(styles, {
1063
+ rgbToAnsi256: {
1064
+ value: (red, green, blue) => {
1065
+ if (red === green && green === blue) {
1066
+ if (red < 8) {
1067
+ return 16;
1068
+ }
1069
+ if (red > 248) {
1070
+ return 231;
1071
+ }
1072
+ return Math.round((red - 8) / 247 * 24) + 232;
1073
+ }
1074
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
1075
+ },
1076
+ enumerable: false
1077
+ },
1078
+ hexToRgb: {
1079
+ value: (hex) => {
1080
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
1081
+ if (!matches) {
1082
+ return [0, 0, 0];
1083
+ }
1084
+ let [colorString] = matches;
1085
+ if (colorString.length === 3) {
1086
+ colorString = [...colorString].map((character) => character + character).join("");
1087
+ }
1088
+ const integer = Number.parseInt(colorString, 16);
1089
+ return [
1090
+ integer >> 16 & 255,
1091
+ integer >> 8 & 255,
1092
+ integer & 255
1093
+ ];
1094
+ },
1095
+ enumerable: false
1096
+ },
1097
+ hexToAnsi256: {
1098
+ value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
1099
+ enumerable: false
1100
+ },
1101
+ ansi256ToAnsi: {
1102
+ value: (code) => {
1103
+ if (code < 8) {
1104
+ return 30 + code;
1105
+ }
1106
+ if (code < 16) {
1107
+ return 90 + (code - 8);
1108
+ }
1109
+ let red;
1110
+ let green;
1111
+ let blue;
1112
+ if (code >= 232) {
1113
+ red = ((code - 232) * 10 + 8) / 255;
1114
+ green = red;
1115
+ blue = red;
1116
+ } else {
1117
+ code -= 16;
1118
+ const remainder = code % 36;
1119
+ red = Math.floor(code / 36) / 5;
1120
+ green = Math.floor(remainder / 6) / 5;
1121
+ blue = remainder % 6 / 5;
1122
+ }
1123
+ const value = Math.max(red, green, blue) * 2;
1124
+ if (value === 0) {
1125
+ return 30;
1126
+ }
1127
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
1128
+ if (value === 2) {
1129
+ result += 60;
1130
+ }
1131
+ return result;
1132
+ },
1133
+ enumerable: false
1134
+ },
1135
+ rgbToAnsi: {
1136
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
1137
+ enumerable: false
1138
+ },
1139
+ hexToAnsi: {
1140
+ value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
1141
+ enumerable: false
1142
+ }
1143
+ });
1144
+ return styles;
1145
+ }
1146
+ var ansiStyles = assembleStyles();
1147
+ var ansi_styles_default = ansiStyles;
1148
+ var ESCAPES = new Set([
1149
+ "\x1B",
1150
+ "\x9B"
1151
+ ]);
1152
+ var END_CODE = 39;
1153
+ var ANSI_ESCAPE_BELL = "\x07";
1154
+ var ANSI_CSI = "[";
1155
+ var ANSI_OSC = "]";
1156
+ var ANSI_SGR_TERMINATOR = "m";
1157
+ var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
1158
+ var wrapAnsiCode = (code) => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
1159
+ var wrapAnsiHyperlink = (url) => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
1160
+ var wordLengths = (string2) => string2.split(" ").map((character) => stringWidth(character));
1161
+ var wrapWord = (rows, word, columns) => {
1162
+ const characters = [...word];
1163
+ let isInsideEscape = false;
1164
+ let isInsideLinkEscape = false;
1165
+ let visible = stringWidth(stripAnsi(rows.at(-1)));
1166
+ for (const [index, character] of characters.entries()) {
1167
+ const characterLength = stringWidth(character);
1168
+ if (visible + characterLength <= columns) {
1169
+ rows[rows.length - 1] += character;
1170
+ } else {
1171
+ rows.push(character);
1172
+ visible = 0;
1173
+ }
1174
+ if (ESCAPES.has(character)) {
1175
+ isInsideEscape = true;
1176
+ const ansiEscapeLinkCandidate = characters.slice(index + 1, index + 1 + ANSI_ESCAPE_LINK.length).join("");
1177
+ isInsideLinkEscape = ansiEscapeLinkCandidate === ANSI_ESCAPE_LINK;
1178
+ }
1179
+ if (isInsideEscape) {
1180
+ if (isInsideLinkEscape) {
1181
+ if (character === ANSI_ESCAPE_BELL) {
1182
+ isInsideEscape = false;
1183
+ isInsideLinkEscape = false;
1184
+ }
1185
+ } else if (character === ANSI_SGR_TERMINATOR) {
1186
+ isInsideEscape = false;
1187
+ }
1188
+ continue;
1189
+ }
1190
+ visible += characterLength;
1191
+ if (visible === columns && index < characters.length - 1) {
1192
+ rows.push("");
1193
+ visible = 0;
1194
+ }
1195
+ }
1196
+ if (!visible && rows.at(-1).length > 0 && rows.length > 1) {
1197
+ rows[rows.length - 2] += rows.pop();
1198
+ }
1199
+ };
1200
+ var stringVisibleTrimSpacesRight = (string2) => {
1201
+ const words = string2.split(" ");
1202
+ let last = words.length;
1203
+ while (last > 0) {
1204
+ if (stringWidth(words[last - 1]) > 0) {
1205
+ break;
1206
+ }
1207
+ last--;
1208
+ }
1209
+ if (last === words.length) {
1210
+ return string2;
1211
+ }
1212
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
1213
+ };
1214
+ var exec = (string2, columns, options = {}) => {
1215
+ if (options.trim !== false && string2.trim() === "") {
1216
+ return "";
1217
+ }
1218
+ let returnValue = "";
1219
+ let escapeCode;
1220
+ let escapeUrl;
1221
+ const lengths = wordLengths(string2);
1222
+ let rows = [""];
1223
+ for (const [index, word] of string2.split(" ").entries()) {
1224
+ if (options.trim !== false) {
1225
+ rows[rows.length - 1] = rows.at(-1).trimStart();
1226
+ }
1227
+ let rowLength = stringWidth(rows.at(-1));
1228
+ if (index !== 0) {
1229
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
1230
+ rows.push("");
1231
+ rowLength = 0;
1232
+ }
1233
+ if (rowLength > 0 || options.trim === false) {
1234
+ rows[rows.length - 1] += " ";
1235
+ rowLength++;
1236
+ }
1237
+ }
1238
+ if (options.hard && lengths[index] > columns) {
1239
+ const remainingColumns = columns - rowLength;
1240
+ const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
1241
+ const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
1242
+ if (breaksStartingNextLine < breaksStartingThisLine) {
1243
+ rows.push("");
1244
+ }
1245
+ wrapWord(rows, word, columns);
1246
+ continue;
1247
+ }
1248
+ if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
1249
+ if (options.wordWrap === false && rowLength < columns) {
1250
+ wrapWord(rows, word, columns);
1251
+ continue;
1252
+ }
1253
+ rows.push("");
1254
+ }
1255
+ if (rowLength + lengths[index] > columns && options.wordWrap === false) {
1256
+ wrapWord(rows, word, columns);
1257
+ continue;
1258
+ }
1259
+ rows[rows.length - 1] += word;
1260
+ }
1261
+ if (options.trim !== false) {
1262
+ rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
1263
+ }
1264
+ const preString = rows.join(`
1265
+ `);
1266
+ const pre = [...preString];
1267
+ let preStringIndex = 0;
1268
+ for (const [index, character] of pre.entries()) {
1269
+ returnValue += character;
1270
+ if (ESCAPES.has(character)) {
1271
+ const { groups } = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(preString.slice(preStringIndex)) || { groups: {} };
1272
+ if (groups.code !== undefined) {
1273
+ const code2 = Number.parseFloat(groups.code);
1274
+ escapeCode = code2 === END_CODE ? undefined : code2;
1275
+ } else if (groups.uri !== undefined) {
1276
+ escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
1277
+ }
1278
+ }
1279
+ const code = ansi_styles_default.codes.get(Number(escapeCode));
1280
+ if (pre[index + 1] === `
1281
+ `) {
1282
+ if (escapeUrl) {
1283
+ returnValue += wrapAnsiHyperlink("");
1284
+ }
1285
+ if (escapeCode && code) {
1286
+ returnValue += wrapAnsiCode(code);
1287
+ }
1288
+ } else if (character === `
1289
+ `) {
1290
+ if (escapeCode && code) {
1291
+ returnValue += wrapAnsiCode(escapeCode);
1292
+ }
1293
+ if (escapeUrl) {
1294
+ returnValue += wrapAnsiHyperlink(escapeUrl);
1295
+ }
1296
+ }
1297
+ preStringIndex += character.length;
1298
+ }
1299
+ return returnValue;
1300
+ };
1301
+ function wrapAnsi(string2, columns, options) {
1302
+ return String(string2).normalize().replaceAll(`\r
1303
+ `, `
1304
+ `).split(`
1305
+ `).map((line) => exec(line, columns, options)).join(`
1306
+ `);
1307
+ }
1308
+
1309
+ class Prompt {
1310
+ input;
1311
+ output;
1312
+ _abortSignal;
1313
+ rl;
1314
+ opts;
1315
+ _render;
1316
+ _track = false;
1317
+ _prevFrame = "";
1318
+ _subscribers = new Map;
1319
+ _cursor = 0;
1320
+ _manualLine = "";
1321
+ state = "initial";
1322
+ error = "";
1323
+ value;
1324
+ userInput = "";
1325
+ constructor(options, trackValue = true) {
1326
+ const { input = stdin2, output = stdout2, render, signal, ...opts } = options;
1327
+ this.opts = opts;
1328
+ this.onKeypress = this.onKeypress.bind(this);
1329
+ this.close = this.close.bind(this);
1330
+ this.render = this.render.bind(this);
1331
+ this._render = render.bind(this);
1332
+ this._track = trackValue;
1333
+ this._abortSignal = signal;
1334
+ this.input = input;
1335
+ this.output = output;
1336
+ }
1337
+ unsubscribe() {
1338
+ this._subscribers.clear();
1339
+ }
1340
+ setSubscriber(event, opts) {
1341
+ const params = this._subscribers.get(event) ?? [];
1342
+ params.push(opts);
1343
+ this._subscribers.set(event, params);
1344
+ }
1345
+ on(event, cb) {
1346
+ this.setSubscriber(event, { cb });
1347
+ return this;
1348
+ }
1349
+ once(event, cb) {
1350
+ this.setSubscriber(event, { cb, once: true });
1351
+ return this;
1352
+ }
1353
+ emit(event, ...data) {
1354
+ const cbs = this._subscribers.get(event) ?? [];
1355
+ const cleanup = [];
1356
+ for (const subscriber of cbs) {
1357
+ subscriber.cb(...data);
1358
+ if (subscriber.once) {
1359
+ cleanup.push(() => cbs.splice(cbs.indexOf(subscriber), 1));
1360
+ }
1361
+ }
1362
+ for (const cb of cleanup) {
1363
+ cb();
1364
+ }
1365
+ return this;
1366
+ }
1367
+ prompt() {
1368
+ return new Promise((resolve) => {
1369
+ if (this._abortSignal) {
1370
+ if (this._abortSignal.aborted) {
1371
+ this.state = "cancel";
1372
+ this.close();
1373
+ return resolve(CANCEL_SYMBOL);
1374
+ }
1375
+ this._abortSignal.addEventListener("abort", () => {
1376
+ this.state = "cancel";
1377
+ this.close();
1378
+ }, { once: true });
1379
+ }
1380
+ this.rl = readline2.createInterface({
1381
+ input: this.input,
1382
+ tabSize: 2,
1383
+ prompt: "",
1384
+ escapeCodeTimeout: 50,
1385
+ terminal: true
1386
+ });
1387
+ this.rl.prompt();
1388
+ if (this.opts.initialUserInput !== undefined) {
1389
+ this._setUserInput(this.opts.initialUserInput, true);
1390
+ }
1391
+ this.input.on("keypress", this.onKeypress);
1392
+ setRawMode(this.input, true);
1393
+ this.output.on("resize", this.render);
1394
+ this.render();
1395
+ this.once("submit", () => {
1396
+ this.output.write(cursor.show);
1397
+ this.output.off("resize", this.render);
1398
+ setRawMode(this.input, false);
1399
+ resolve(this.value);
1400
+ });
1401
+ this.once("cancel", () => {
1402
+ this.output.write(cursor.show);
1403
+ this.output.off("resize", this.render);
1404
+ setRawMode(this.input, false);
1405
+ resolve(CANCEL_SYMBOL);
1406
+ });
1407
+ });
1408
+ }
1409
+ _isActionKey(char, _key) {
1410
+ return char === "\t";
1411
+ }
1412
+ _setValue(value) {
1413
+ this.value = value;
1414
+ this.emit("value", this.value);
1415
+ }
1416
+ _setUserInput(value, write) {
1417
+ this.userInput = value ?? "";
1418
+ this.emit("userInput", this.userInput);
1419
+ if (write && this._track && this.rl) {
1420
+ this.rl.write(this.userInput);
1421
+ this._cursor = this.rl.cursor;
1422
+ }
1423
+ }
1424
+ onKeypress(char, key) {
1425
+ if (this._track && key.name !== "return") {
1426
+ if (key.name && this._isActionKey(char, key)) {
1427
+ this.rl?.write(null, { ctrl: true, name: "h" });
1428
+ }
1429
+ this._cursor = this.rl?.cursor ?? 0;
1430
+ const isSpecialKey = key.name === "tab" || key.name === "escape" || key.name === "backspace" || key.name === "delete" || key.name === "enter" || key.name === "return" || key.name && ["up", "down", "left", "right"].includes(key.name);
1431
+ if (char && !isSpecialKey && char.length === 1 && char >= " ") {
1432
+ this._manualLine += char;
1433
+ } else if (key.name === "backspace" && this._manualLine.length > 0) {
1434
+ this._manualLine = this._manualLine.slice(0, -1);
1435
+ }
1436
+ const effectiveLine = this._manualLine.length >= (this.rl?.line?.length || 0) ? this._manualLine : this.rl?.line;
1437
+ this._setUserInput(effectiveLine);
1438
+ }
1439
+ if (this.state === "error") {
1440
+ this.state = "active";
1441
+ this.error = "";
1442
+ }
1443
+ if (key?.name) {
1444
+ if (!this._track && settings.aliases.has(key.name)) {
1445
+ this.emit("cursor", settings.aliases.get(key.name));
1446
+ }
1447
+ if (settings.actions.has(key.name)) {
1448
+ this.emit("cursor", key.name);
1449
+ }
1450
+ }
1451
+ if (char && (char.toLowerCase() === "y" || char.toLowerCase() === "n")) {
1452
+ this.emit("confirm", char.toLowerCase() === "y");
1453
+ }
1454
+ this.emit("key", char?.toLowerCase(), key);
1455
+ if (key?.name === "return") {
1456
+ if (this.opts.validate) {
1457
+ const problem = this.opts.validate(this.value);
1458
+ if (problem) {
1459
+ this.error = problem instanceof Error ? problem.message : problem;
1460
+ this.state = "error";
1461
+ }
1462
+ }
1463
+ if (this.state !== "error") {
1464
+ this.state = "submit";
1465
+ }
1466
+ }
1467
+ if (isActionKey([char, key?.name, key?.sequence], "cancel")) {
1468
+ this.state = "cancel";
1469
+ }
1470
+ if (this.state === "submit" || this.state === "cancel") {
1471
+ this.emit("finalize");
1472
+ }
1473
+ this.render();
1474
+ if (this.state === "submit" || this.state === "cancel") {
1475
+ this.close();
1476
+ }
1477
+ }
1478
+ close() {
1479
+ this.input.unpipe();
1480
+ this.input.removeListener("keypress", this.onKeypress);
1481
+ this.output.write(`
1482
+ `);
1483
+ setRawMode(this.input, false);
1484
+ this.rl?.close();
1485
+ this.rl = undefined;
1486
+ this.emit(`${this.state}`, this.value);
1487
+ if (this.state === "cancel") {
1488
+ setTimeout(() => {
1489
+ this.unsubscribe();
1490
+ }, 10);
1491
+ } else {
1492
+ this.unsubscribe();
1493
+ }
1494
+ }
1495
+ restoreCursor() {
1496
+ const lines = wrapAnsi(this._prevFrame, process6.stdout.columns, { hard: true, trim: false }).split(`
1497
+ `).length - 1;
1498
+ this.output.write(cursor.move(-999, lines * -1));
1499
+ }
1500
+ render() {
1501
+ const frame = wrapAnsi(this._render(this) ?? "", process6.stdout.columns, {
1502
+ hard: true,
1503
+ trim: false
1504
+ });
1505
+ if (frame === this._prevFrame) {
1506
+ return;
1507
+ }
1508
+ if (this.state === "initial") {
1509
+ this.output.write(cursor.hide);
1510
+ } else {
1511
+ const diff = diffLines(this._prevFrame, frame);
1512
+ this.restoreCursor();
1513
+ if (diff && diff?.length === 1) {
1514
+ const diffLine = diff[0];
1515
+ this.output.write(cursor.move(0, diffLine));
1516
+ this.output.write(erase.lines(1));
1517
+ const lines = frame.split(`
1518
+ `);
1519
+ this.output.write(lines[diffLine]);
1520
+ this._prevFrame = frame;
1521
+ this.output.write(cursor.move(0, lines.length - diffLine - 1));
1522
+ return;
1523
+ }
1524
+ if (diff && diff?.length > 1) {
1525
+ const diffLine = diff[0];
1526
+ this.output.write(cursor.move(0, diffLine));
1527
+ this.output.write(erase.down());
1528
+ const lines = frame.split(`
1529
+ `);
1530
+ const newLines = lines.slice(diffLine);
1531
+ this.output.write(newLines.join(`
1532
+ `));
1533
+ this._prevFrame = frame;
1534
+ return;
1535
+ }
1536
+ this.output.write(erase.down());
1537
+ }
1538
+ this.output.write(frame);
1539
+ if (this.state === "initial") {
1540
+ this.state = "active";
1541
+ }
1542
+ this._prevFrame = frame;
1543
+ }
1544
+ }
1545
+ function getCursorForValue(selected, items) {
1546
+ if (selected === undefined) {
1547
+ return 0;
1548
+ }
1549
+ const currLength = items.length;
1550
+ if (currLength === 0) {
1551
+ return 0;
1552
+ }
1553
+ const index = items.findIndex((item) => item.value === selected);
1554
+ return index !== -1 ? index : 0;
1555
+ }
1556
+ function defaultFilter(input, option) {
1557
+ const label = option.label ?? String(option.value);
1558
+ return label.toLowerCase().includes(input.toLowerCase());
1559
+ }
1560
+ function normalisedValue(multiple, values) {
1561
+ if (!values) {
1562
+ return;
1563
+ }
1564
+ if (multiple) {
1565
+ return values;
1566
+ }
1567
+ return values[0];
1568
+ }
1569
+
1570
+ class AutocompletePrompt extends Prompt {
1571
+ filteredOptions;
1572
+ multiple;
1573
+ isNavigating = false;
1574
+ selectedValues = [];
1575
+ focusedValue;
1576
+ #cursor = 0;
1577
+ #lastUserInput = "";
1578
+ #filterFn;
1579
+ #options;
1580
+ get cursor() {
1581
+ return this.#cursor;
1582
+ }
1583
+ get userInputWithCursor() {
1584
+ if (!this.userInput) {
1585
+ return import_picocolors.default.inverse(import_picocolors.default.hidden("_"));
1586
+ }
1587
+ if (this._cursor >= this.userInput.length) {
1588
+ return `${this.userInput}\u2588`;
1589
+ }
1590
+ const s1 = this.userInput.slice(0, this._cursor);
1591
+ const [s2, ...s3] = this.userInput.slice(this._cursor);
1592
+ return `${s1}${import_picocolors.default.inverse(s2)}${s3.join("")}`;
1593
+ }
1594
+ get options() {
1595
+ if (typeof this.#options === "function") {
1596
+ return this.#options();
1597
+ }
1598
+ return this.#options;
1599
+ }
1600
+ constructor(opts) {
1601
+ super(opts);
1602
+ this.#options = opts.options;
1603
+ const options = this.options;
1604
+ this.filteredOptions = [...options];
1605
+ this.multiple = opts.multiple === true;
1606
+ this.#filterFn = opts.filter ?? defaultFilter;
1607
+ let initialValues;
1608
+ if (opts.initialValue && Array.isArray(opts.initialValue)) {
1609
+ if (this.multiple) {
1610
+ initialValues = opts.initialValue;
1611
+ } else {
1612
+ initialValues = opts.initialValue.slice(0, 1);
1613
+ }
1614
+ } else {
1615
+ if (!this.multiple && this.options.length > 0) {
1616
+ initialValues = [this.options[0].value];
1617
+ }
1618
+ }
1619
+ if (initialValues) {
1620
+ for (const selectedValue of initialValues) {
1621
+ const selectedIndex = options.findIndex((opt) => opt.value === selectedValue);
1622
+ if (selectedIndex !== -1) {
1623
+ this.toggleSelected(selectedValue);
1624
+ this.#cursor = selectedIndex;
1625
+ }
1626
+ }
1627
+ }
1628
+ this.focusedValue = this.options[this.#cursor]?.value;
1629
+ this.on("key", (char, key) => this.#onKey(char, key));
1630
+ this.on("userInput", (value) => this.#onUserInputChanged(value));
1631
+ }
1632
+ _isActionKey(char, key) {
1633
+ return char === "\t" || this.multiple && this.isNavigating && key.name === "space" && char !== undefined && char !== "";
1634
+ }
1635
+ #onKey(_char, key) {
1636
+ const isUpKey = key.name === "up";
1637
+ const isDownKey = key.name === "down";
1638
+ const isReturnKey = key.name === "return";
1639
+ if (isUpKey || isDownKey) {
1640
+ this.#cursor = Math.max(0, Math.min(this.#cursor + (isUpKey ? -1 : 1), this.filteredOptions.length - 1));
1641
+ this.focusedValue = this.filteredOptions[this.#cursor]?.value;
1642
+ if (!this.multiple) {
1643
+ this.selectedValues = [this.focusedValue];
1644
+ }
1645
+ this.isNavigating = true;
1646
+ } else if (isReturnKey) {
1647
+ this.value = normalisedValue(this.multiple, this.selectedValues);
1648
+ } else {
1649
+ if (this.multiple) {
1650
+ if (this.focusedValue !== undefined && (key.name === "tab" || this.isNavigating && key.name === "space")) {
1651
+ this.toggleSelected(this.focusedValue);
1652
+ } else {
1653
+ this.isNavigating = false;
1654
+ }
1655
+ } else {
1656
+ if (this.focusedValue) {
1657
+ this.selectedValues = [this.focusedValue];
1658
+ }
1659
+ this.isNavigating = false;
1660
+ }
1661
+ }
1662
+ }
1663
+ deselectAll() {
1664
+ this.selectedValues = [];
1665
+ }
1666
+ toggleSelected(value) {
1667
+ if (this.filteredOptions.length === 0) {
1668
+ return;
1669
+ }
1670
+ if (this.multiple) {
1671
+ if (this.selectedValues.includes(value)) {
1672
+ this.selectedValues = this.selectedValues.filter((v) => v !== value);
1673
+ } else {
1674
+ this.selectedValues = [...this.selectedValues, value];
1675
+ }
1676
+ } else {
1677
+ this.selectedValues = [value];
1678
+ }
1679
+ }
1680
+ #onUserInputChanged(value) {
1681
+ if (value !== this.#lastUserInput) {
1682
+ this.#lastUserInput = value;
1683
+ const options = this.options;
1684
+ if (value) {
1685
+ this.filteredOptions = options.filter((opt) => this.#filterFn(value, opt));
1686
+ } else {
1687
+ this.filteredOptions = [...options];
1688
+ }
1689
+ this.#cursor = getCursorForValue(this.focusedValue, this.filteredOptions);
1690
+ this.focusedValue = this.filteredOptions[this.#cursor]?.value;
1691
+ if (!this.multiple) {
1692
+ if (this.focusedValue !== undefined) {
1693
+ this.toggleSelected(this.focusedValue);
1694
+ } else {
1695
+ this.deselectAll();
1696
+ }
1697
+ }
1698
+ }
1699
+ }
1700
+ }
1701
+ class GroupMultiSelectPrompt extends Prompt {
1702
+ options;
1703
+ cursor = 0;
1704
+ #selectableGroups;
1705
+ getGroupItems(group) {
1706
+ return this.options.filter((o) => o.group === group);
1707
+ }
1708
+ isGroupSelected(group) {
1709
+ const items = this.getGroupItems(group);
1710
+ const value = this.value;
1711
+ if (value === undefined) {
1712
+ return false;
1713
+ }
1714
+ return items.every((i) => value.includes(i.value));
1715
+ }
1716
+ toggleValue() {
1717
+ const item = this.options[this.cursor];
1718
+ if (this.value === undefined) {
1719
+ this.value = [];
1720
+ }
1721
+ if (item.group === true) {
1722
+ const group = item.value;
1723
+ const groupedItems = this.getGroupItems(group);
1724
+ if (this.isGroupSelected(group)) {
1725
+ this.value = this.value.filter((v) => groupedItems.findIndex((i) => i.value === v) === -1);
1726
+ } else {
1727
+ this.value = [...this.value, ...groupedItems.map((i) => i.value)];
1728
+ }
1729
+ this.value = Array.from(new Set(this.value));
1730
+ } else {
1731
+ const selected = this.value.includes(item.value);
1732
+ this.value = selected ? this.value.filter((v) => v !== item.value) : [...this.value, item.value];
1733
+ }
1734
+ }
1735
+ constructor(opts) {
1736
+ super(opts, false);
1737
+ const { options } = opts;
1738
+ this.#selectableGroups = opts.selectableGroups !== false;
1739
+ this.options = Object.entries(options).flatMap(([key, option]) => [
1740
+ { value: key, group: true, label: key },
1741
+ ...option.map((opt) => ({ ...opt, group: key }))
1742
+ ]);
1743
+ this.value = [...opts.initialValues ?? []];
1744
+ this.cursor = Math.max(this.options.findIndex(({ value }) => value === opts.cursorAt), this.#selectableGroups ? 0 : 1);
1745
+ this.on("cursor", (key) => {
1746
+ switch (key) {
1747
+ case "left":
1748
+ case "up": {
1749
+ this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
1750
+ const currentIsGroup = this.options[this.cursor]?.group === true;
1751
+ if (!this.#selectableGroups && currentIsGroup) {
1752
+ this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
1753
+ }
1754
+ break;
1755
+ }
1756
+ case "down":
1757
+ case "right": {
1758
+ this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
1759
+ const currentIsGroup = this.options[this.cursor]?.group === true;
1760
+ if (!this.#selectableGroups && currentIsGroup) {
1761
+ this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
1762
+ }
1763
+ break;
1764
+ }
1765
+ case "space":
1766
+ this.toggleValue();
1767
+ break;
1768
+ }
1769
+ });
1770
+ }
1771
+ }
1772
+ var import_picocolors2 = __toESM2(require_picocolors(), 1);
1773
+ var import_picocolors3 = __toESM2(require_picocolors(), 1);
1774
+ var import_picocolors4 = __toESM2(require_picocolors(), 1);
1775
+ var codes = {
1776
+ red: ["\x1B[31m", "\x1B[39m"],
1777
+ green: ["\x1B[32m", "\x1B[39m"],
1778
+ blue: ["\x1B[34m", "\x1B[39m"],
1779
+ yellow: ["\x1B[33m", "\x1B[39m"],
1780
+ cyan: ["\x1B[36m", "\x1B[39m"],
1781
+ magenta: ["\x1B[35m", "\x1B[39m"],
1782
+ white: ["\x1B[37m", "\x1B[39m"],
1783
+ gray: ["\x1B[90m", "\x1B[39m"],
1784
+ bgRed: ["\x1B[41m", "\x1B[49m"],
1785
+ bgGreen: ["\x1B[42m", "\x1B[49m"],
1786
+ bgBlue: ["\x1B[44m", "\x1B[49m"],
1787
+ bgYellow: ["\x1B[43m", "\x1B[49m"],
1788
+ bgCyan: ["\x1B[46m", "\x1B[49m"],
1789
+ bgMagenta: ["\x1B[45m", "\x1B[49m"],
1790
+ bold: ["\x1B[1m", "\x1B[22m"],
1791
+ italic: ["\x1B[3m", "\x1B[23m"],
1792
+ underline: ["\x1B[4m", "\x1B[24m"],
1793
+ dim: ["\x1B[2m", "\x1B[22m"],
1794
+ inverse: ["\x1B[7m", "\x1B[27m"],
1795
+ hidden: ["\x1B[8m", "\x1B[28m"],
1796
+ strikethrough: ["\x1B[9m", "\x1B[29m"]
1797
+ };
1798
+ var theme = {
1799
+ primary: "blue",
1800
+ secondary: "cyan",
1801
+ success: "green",
1802
+ warning: "yellow",
1803
+ error: "red",
1804
+ info: "magenta",
1805
+ muted: "gray"
1806
+ };
1807
+ function detectColorSupport() {
1808
+ return true;
1809
+ }
1810
+ function createStyler() {
1811
+ const styler = {};
1812
+ styler.supportsColor = detectColorSupport();
1813
+ function createStyleFunction(styleName, styles2 = []) {
1814
+ const styleList = styleName === "" ? [] : [...styles2, styleName];
1815
+ const fn = function(text) {
1816
+ if (!styler.supportsColor)
1817
+ return text;
1818
+ let openCodes = "";
1819
+ let closeCodes = "";
1820
+ for (const style of styleList) {
1821
+ if (style in theme && theme[style] in codes) {
1822
+ const themeStyle = theme[style];
1823
+ openCodes += codes[themeStyle][0];
1824
+ closeCodes = codes[themeStyle][1] + closeCodes;
1825
+ } else if (style in codes) {
1826
+ openCodes += codes[style][0];
1827
+ closeCodes = codes[style][1] + closeCodes;
1828
+ }
1829
+ }
1830
+ return openCodes + text + closeCodes;
1831
+ };
1832
+ const allStyles2 = [...Object.keys(codes), ...Object.keys(theme)];
1833
+ for (const style of allStyles2) {
1834
+ if (!(style in fn)) {
1835
+ Object.defineProperty(fn, style, {
1836
+ get() {
1837
+ return createStyleFunction(style, styleList);
1838
+ }
1839
+ });
1840
+ }
1841
+ }
1842
+ return fn;
1843
+ }
1844
+ const allStyles = [...Object.keys(codes), ...Object.keys(theme)];
1845
+ for (const style of allStyles) {
1846
+ if (!(style in styler)) {
1847
+ Object.defineProperty(styler, style, {
1848
+ get() {
1849
+ return createStyleFunction(style);
1850
+ }
1851
+ });
1852
+ }
1853
+ }
1854
+ return styler;
1855
+ }
1856
+ var style = createStyler();
1857
+ var unicode = isUnicodeSupported();
1858
+ var unicodeOr = (c, fallback) => unicode ? c : fallback;
1859
+ var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
1860
+ var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
1861
+ var S_STEP_ERROR = unicodeOr("\u25B2", "x");
1862
+ var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
1863
+ var S_BAR_START = unicodeOr("\u250C", "T");
1864
+ var S_BAR = unicodeOr("\u2502", "|");
1865
+ var S_BAR_END = unicodeOr("\u2514", "\u2014");
1866
+ var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
1867
+ var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
1868
+ var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
1869
+ var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
1870
+ var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
1871
+ var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
1872
+ var S_BAR_H = unicodeOr("\u2500", "-");
1873
+ var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
1874
+ var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
1875
+ var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
1876
+ var S_INFO = unicodeOr("\u25CF", "\u2022");
1877
+ var S_SUCCESS = unicodeOr("\u25C6", "*");
1878
+ var S_WARN = unicodeOr("\u25B2", "!");
1879
+ var S_ERROR = unicodeOr("\u25A0", "x");
1880
+ var import_picocolors5 = __toESM2(require_picocolors(), 1);
1881
+ var import_picocolors7 = __toESM2(require_picocolors(), 1);
1882
+ var import_picocolors8 = __toESM2(require_picocolors(), 1);
1883
+ var import_picocolors9 = __toESM2(require_picocolors(), 1);
1884
+ var import_picocolors10 = __toESM2(require_picocolors(), 1);
1885
+ var import_picocolors11 = __toESM2(require_picocolors(), 1);
1886
+ var import_picocolors12 = __toESM2(require_picocolors(), 1);
1887
+ var import_picocolors13 = __toESM2(require_picocolors(), 1);
1888
+ var import_picocolors15 = __toESM2(require_picocolors(), 1);
1889
+ var import_picocolors14 = __toESM2(require_picocolors(), 1);
1890
+ var S_PROGRESS_CHAR = {
1891
+ light: unicodeOr("\u2500", "-"),
1892
+ heavy: unicodeOr("\u2501", "="),
1893
+ block: unicodeOr("\u2588", "#")
1894
+ };
1895
+ var import_picocolors16 = __toESM2(require_picocolors(), 1);
1896
+ var import_picocolors17 = __toESM2(require_picocolors(), 1);
1897
+ var import_picocolors18 = __toESM2(require_picocolors(), 1);
1898
+ function getPrefix() {
1899
+ return `${import_picocolors18.default.gray(S_BAR)} `;
1900
+ }
1901
+ var prefix = getPrefix();
1902
+ var color18 = __toESM2(require_picocolors(), 1);
1903
+ var import_picocolors19 = __toESM2(require_picocolors(), 1);
1904
+ // package.json
1905
+ var version = "0.0.1";
1906
+
1907
+ // bin/cli.ts
1908
+ var cli = new CLI("queue");
1909
+ cli.command("version", "Show the version of the CLI").action(() => {
1910
+ console.log(version);
1911
+ });
1912
+ cli.version(version);
1913
+ cli.help();
1914
+ cli.parse();