@kaynooo/cli-proc 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pid-cli.js +144 -533
- package/dist/ports-cli.js +125 -529
- package/dist/proc-cli.js +164 -555
- package/dist/procs-cli.js +151 -541
- package/package.json +2 -2
- package/src/pid-cli.ts +1 -1
- package/src/ports-cli.ts +1 -1
- package/src/ports.ts +1 -2
- package/src/proc-cli.ts +1 -1
- package/src/procs-cli.ts +1 -1
- package/src/procs.ts +1 -2
package/dist/ports-cli.js
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
|
-
#!/usr/bin/env -S bun --no-env-file
|
|
1
|
+
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/ports-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process14 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process6 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
|
-
import
|
|
12
|
-
|
|
11
|
+
import process4 from "process";
|
|
12
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
13
|
+
var N = new Map;
|
|
14
|
+
var Nt = /\s+\S*$/;
|
|
15
|
+
var Y = /\s/;
|
|
16
|
+
function ko(t, e, r = "...") {
|
|
17
|
+
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
18
|
+
if (t.length <= e)
|
|
19
|
+
return t;
|
|
20
|
+
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
21
|
+
if (o && !Y.test(t[c.length] ?? " "))
|
|
22
|
+
c = c.replace(Nt, "") || c;
|
|
23
|
+
if (o)
|
|
24
|
+
c = c.trimEnd();
|
|
25
|
+
return s ? (c + n).slice(0, l) : c + n;
|
|
26
|
+
}
|
|
27
|
+
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
28
|
+
var z = new Map;
|
|
13
29
|
// ../kit/src/mode.ts
|
|
14
30
|
import process2 from "process";
|
|
15
31
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -32,479 +48,75 @@ function isInteractive(streams = process2) {
|
|
|
32
48
|
}
|
|
33
49
|
|
|
34
50
|
// ../kit/src/style.ts
|
|
35
|
-
import
|
|
51
|
+
import process3 from "process";
|
|
36
52
|
|
|
37
|
-
// ../../node_modules/.bun/@kaynooo+utils@
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
54
|
+
var G2 = /^[a-f0-9]+$/i;
|
|
55
|
+
function b(r) {
|
|
56
|
+
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
57
|
+
if (!G2.test(e))
|
|
41
58
|
return [0, 0, 0];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
|
|
58
|
-
return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
|
|
59
|
-
}
|
|
60
|
-
function R(s, r, t) {
|
|
61
|
-
s = (s % 360 + 360) % 360, t /= 100;
|
|
62
|
-
let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
|
|
63
|
-
let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
|
|
64
|
-
return Math.round(255 * y);
|
|
65
|
-
};
|
|
66
|
-
return [a(0), a(8), a(4)];
|
|
67
|
-
}
|
|
68
|
-
function k(s) {
|
|
69
|
-
let [r, t, n] = s;
|
|
70
|
-
r /= 255, t /= 255, n /= 255;
|
|
71
|
-
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
|
|
72
|
-
if (a !== b) {
|
|
73
|
-
let u = a - b;
|
|
74
|
-
if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
|
|
75
|
-
o = (t - n) / u + (t < n ? 6 : 0);
|
|
76
|
-
else if (a === t)
|
|
77
|
-
o = (n - r) / u + 2;
|
|
78
|
-
else
|
|
79
|
-
o = (r - t) / u + 4;
|
|
80
|
-
o /= 6;
|
|
81
|
-
}
|
|
82
|
-
return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
|
|
83
|
-
}
|
|
84
|
-
function H(s, r, t) {
|
|
85
|
-
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
86
|
-
let n = (a) => {
|
|
87
|
-
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
88
|
-
return Math.round(255 * o);
|
|
89
|
-
};
|
|
90
|
-
return [n(5), n(3), n(1)];
|
|
91
|
-
}
|
|
92
|
-
function f(s) {
|
|
93
|
-
let [r, t, n] = s;
|
|
94
|
-
r /= 255, t /= 255, n /= 255;
|
|
95
|
-
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = a - b, y = 0, c = a === 0 ? 0 : o / a, u = a;
|
|
96
|
-
if (o !== 0) {
|
|
97
|
-
if (a === r)
|
|
98
|
-
y = (t - n) / o + (t < n ? 6 : 0);
|
|
99
|
-
else if (a === t)
|
|
100
|
-
y = (n - r) / o + 2;
|
|
101
|
-
else
|
|
102
|
-
y = (r - t) / o + 4;
|
|
103
|
-
y /= 6;
|
|
104
|
-
}
|
|
105
|
-
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
106
|
-
}
|
|
107
|
-
function O(s) {
|
|
108
|
-
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
109
|
-
if (a === 1)
|
|
110
|
-
return [0, 0, 0, 100];
|
|
111
|
-
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
112
|
-
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
113
|
-
}
|
|
114
|
-
function v(s, r, t, n) {
|
|
115
|
-
return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
|
|
116
|
-
}
|
|
117
|
-
var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
118
|
-
var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
|
|
119
|
-
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
120
|
-
function T(s) {
|
|
121
|
-
let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
|
|
122
|
-
return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
|
|
123
|
-
}
|
|
124
|
-
function M(s, r, t) {
|
|
125
|
-
let n = (s + 0.3963377774 * r + 0.2158037573 * t) ** 3, a = (s - 0.1055613458 * r - 0.0638541728 * t) ** 3, b = (s - 0.0894841775 * r - 1.291485548 * t) ** 3, o = p(4.0767416621 * n - 3.3077115913 * a + 0.2309699292 * b), y = p(-1.2684380046 * n + 2.6097574011 * a - 0.3413193965 * b), c = p(-0.0041960863 * n - 0.7034186147 * a + 1.707614701 * b), u = (h) => Math.min(255, Math.max(0, Math.round(h * 255)));
|
|
126
|
-
return [u(o), u(y), u(c)];
|
|
127
|
-
}
|
|
128
|
-
function d(s) {
|
|
129
|
-
let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
|
|
130
|
-
return [i(r, 4), i(a, 4), i(b, 2)];
|
|
131
|
-
}
|
|
132
|
-
function C(s, r, t) {
|
|
133
|
-
let n = t * Math.PI / 180;
|
|
134
|
-
return M(s, r * Math.cos(n), r * Math.sin(n));
|
|
135
|
-
}
|
|
136
|
-
function l(s) {
|
|
137
|
-
let r = s / 255;
|
|
138
|
-
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
class e {
|
|
142
|
-
r;
|
|
143
|
-
g;
|
|
144
|
-
b;
|
|
145
|
-
a;
|
|
146
|
-
constructor(s, r, t, n = 1) {
|
|
147
|
-
this.r = s, this.g = r, this.b = t, this.a = n;
|
|
148
|
-
}
|
|
149
|
-
static from(s, r) {
|
|
150
|
-
if (s === "hex") {
|
|
151
|
-
let [t, n, a, b] = x(r);
|
|
152
|
-
return new e(t, n, a, b);
|
|
153
|
-
}
|
|
154
|
-
if (s === "rgb") {
|
|
155
|
-
if (Array.isArray(r)) {
|
|
156
|
-
let [o, y, c, u] = r;
|
|
157
|
-
return new e(o, y, c, u);
|
|
158
|
-
}
|
|
159
|
-
let { r: t, g: n, b: a, a: b } = r;
|
|
160
|
-
return new e(t, n, a, b);
|
|
161
|
-
}
|
|
162
|
-
if (s === "hsl") {
|
|
163
|
-
let t, n, a, b;
|
|
164
|
-
if (Array.isArray(r))
|
|
165
|
-
[t, n, a, b] = r;
|
|
166
|
-
else
|
|
167
|
-
({ h: t, s: n, l: a, a: b } = r);
|
|
168
|
-
let [o, y, c] = R(t, n, a);
|
|
169
|
-
return new e(o, y, c, b);
|
|
170
|
-
}
|
|
171
|
-
if (s === "hsv") {
|
|
172
|
-
let t, n, a, b;
|
|
173
|
-
if (Array.isArray(r))
|
|
174
|
-
[t, n, a, b] = r;
|
|
175
|
-
else
|
|
176
|
-
({ h: t, s: n, v: a, a: b } = r);
|
|
177
|
-
let [o, y, c] = H(t, n, a);
|
|
178
|
-
return new e(o, y, c, b);
|
|
179
|
-
}
|
|
180
|
-
if (s === "cmyk") {
|
|
181
|
-
let t, n, a, b, o;
|
|
182
|
-
if (Array.isArray(r))
|
|
183
|
-
[t, n, a, b, o] = r;
|
|
184
|
-
else
|
|
185
|
-
({ c: t, m: n, y: a, k: b, a: o } = r);
|
|
186
|
-
let [y, c, u] = v(t, n, a, b);
|
|
187
|
-
return new e(y, c, u, o);
|
|
188
|
-
}
|
|
189
|
-
if (s === "oklch") {
|
|
190
|
-
let t, n, a, b;
|
|
191
|
-
if (Array.isArray(r))
|
|
192
|
-
[t, n, a, b] = r;
|
|
193
|
-
else
|
|
194
|
-
({ l: t, c: n, h: a, a: b } = r);
|
|
195
|
-
let [o, y, c] = C(t, n, a);
|
|
196
|
-
return new e(o, y, c, b);
|
|
197
|
-
}
|
|
198
|
-
if (s === "oklab") {
|
|
199
|
-
let t, n, a, b;
|
|
200
|
-
if (Array.isArray(r))
|
|
201
|
-
[t, n, a, b] = r;
|
|
202
|
-
else
|
|
203
|
-
({ l: t, a: n, b: a, alpha: b } = r);
|
|
204
|
-
let [o, y, c] = M(t, n, a);
|
|
205
|
-
return new e(o, y, c, b);
|
|
206
|
-
}
|
|
207
|
-
throw Error("Invalid input");
|
|
208
|
-
}
|
|
209
|
-
to(s) {
|
|
210
|
-
switch (s) {
|
|
211
|
-
case "rgb":
|
|
212
|
-
return [this.r, this.g, this.b];
|
|
213
|
-
case "rgba":
|
|
214
|
-
return [this.r, this.g, this.b, this.a];
|
|
215
|
-
case "hex":
|
|
216
|
-
return A([this.r, this.g, this.b]);
|
|
217
|
-
case "hexa":
|
|
218
|
-
return A([this.r, this.g, this.b, this.a]);
|
|
219
|
-
case "hsl":
|
|
220
|
-
return k([this.r, this.g, this.b]);
|
|
221
|
-
case "hsla":
|
|
222
|
-
return [...k([this.r, this.g, this.b]), this.a];
|
|
223
|
-
case "hsv":
|
|
224
|
-
return f([this.r, this.g, this.b]);
|
|
225
|
-
case "hsva":
|
|
226
|
-
return [...f([this.r, this.g, this.b]), this.a];
|
|
227
|
-
case "cmyk":
|
|
228
|
-
return O([this.r, this.g, this.b]);
|
|
229
|
-
case "cmyka":
|
|
230
|
-
return [...O([this.r, this.g, this.b]), this.a];
|
|
231
|
-
case "oklch":
|
|
232
|
-
return d([this.r, this.g, this.b]);
|
|
233
|
-
case "oklcha":
|
|
234
|
-
return [...d([this.r, this.g, this.b]), this.a];
|
|
235
|
-
case "oklab":
|
|
236
|
-
return T([this.r, this.g, this.b]);
|
|
237
|
-
case "oklaba":
|
|
238
|
-
return [...T([this.r, this.g, this.b]), this.a];
|
|
239
|
-
default:
|
|
240
|
-
return [this.r, this.g, this.b];
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
getLuminance() {
|
|
244
|
-
let s = l(this.r), r = l(this.g), t = l(this.b);
|
|
245
|
-
return 0.2126 * s + 0.7152 * r + 0.0722 * t;
|
|
246
|
-
}
|
|
247
|
-
contrastRatio(s) {
|
|
248
|
-
let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
|
|
249
|
-
return (n + 0.05) / (a + 0.05);
|
|
250
|
-
}
|
|
251
|
-
bestContrastForeground() {
|
|
252
|
-
let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
|
|
253
|
-
return t >= n ? s : r;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
258
|
-
var r = 39;
|
|
259
|
-
var o = 49;
|
|
260
|
-
var f2 = "\x1B[";
|
|
261
|
-
var C2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
|
|
262
|
-
let [a, l, s] = e.from("hex", i).to("rgb");
|
|
263
|
-
return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
|
|
264
|
-
}, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
|
|
265
|
-
var b = new Set(["", "1", "2", "3", "true"]);
|
|
266
|
-
function h(i, n = globalThis.process?.env ?? {}) {
|
|
267
|
-
if (n.FORCE_COLOR !== undefined)
|
|
268
|
-
return b.has(n.FORCE_COLOR);
|
|
269
|
-
if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
|
|
59
|
+
if (e.length === 3 || e.length === 4)
|
|
60
|
+
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
61
|
+
if (e.length !== 6 && e.length !== 8)
|
|
62
|
+
throw Error(`Invalid hex color length: ${e.length}`);
|
|
63
|
+
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
64
|
+
}
|
|
65
|
+
var B2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
66
|
+
let [l, n, c] = b(r);
|
|
67
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
68
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
69
|
+
var h = new Set(["", "1", "2", "3", "true"]);
|
|
70
|
+
function C(r, e = globalThis.process?.env ?? {}) {
|
|
71
|
+
if (e.FORCE_COLOR !== undefined)
|
|
72
|
+
return h.has(e.FORCE_COLOR);
|
|
73
|
+
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
270
74
|
return false;
|
|
271
|
-
return
|
|
272
|
-
}
|
|
273
|
-
function
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if (
|
|
287
|
-
return
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
75
|
+
return r?.isTTY === true;
|
|
76
|
+
}
|
|
77
|
+
function f2(r, e = []) {
|
|
78
|
+
let l = "", n = "";
|
|
79
|
+
for (let t = 0, i = e.length;t < i; t++)
|
|
80
|
+
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
81
|
+
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
82
|
+
return new Proxy(c, { get(t, i) {
|
|
83
|
+
let a = B2[i];
|
|
84
|
+
if (Array.isArray(a)) {
|
|
85
|
+
let s = g.get(i);
|
|
86
|
+
if (s === undefined)
|
|
87
|
+
s = f2(r, [...e, a]), g.set(i, s);
|
|
88
|
+
return s;
|
|
89
|
+
}
|
|
90
|
+
if (typeof a === "function")
|
|
91
|
+
return (...s) => {
|
|
92
|
+
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
93
|
+
if (u === undefined) {
|
|
94
|
+
if (g.size >= 64)
|
|
95
|
+
g.clear();
|
|
96
|
+
u = f2(r, [...e, a(...s)]), g.set(y, u);
|
|
97
|
+
}
|
|
98
|
+
return u;
|
|
99
|
+
};
|
|
100
|
+
throw Error(`Unknown style: ${String(i)}`);
|
|
291
101
|
} });
|
|
292
102
|
}
|
|
293
|
-
function
|
|
294
|
-
return
|
|
103
|
+
function Fe2(r = {}) {
|
|
104
|
+
return f2(r);
|
|
295
105
|
}
|
|
296
|
-
var
|
|
106
|
+
var o2 = Fe2();
|
|
297
107
|
|
|
298
108
|
// ../kit/src/theme.ts
|
|
299
|
-
|
|
300
|
-
import { homedir as homedir2 } from "os";
|
|
301
|
-
import { join as join3, resolve as resolve2 } from "path";
|
|
302
|
-
import process5 from "process";
|
|
303
|
-
|
|
304
|
-
// ../kit/src/config.ts
|
|
305
|
-
import { existsSync } from "fs";
|
|
306
|
-
import { dirname, join, resolve } from "path";
|
|
307
|
-
import process3 from "process";
|
|
308
|
-
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
309
|
-
const wanted = typeof names === "string" ? [names] : names;
|
|
310
|
-
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
311
|
-
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
312
|
-
if (found !== undefined)
|
|
313
|
-
return found;
|
|
314
|
-
if (stop(dir) || dirname(dir) === dir)
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// ../kit/src/user-config.ts
|
|
320
|
-
import { homedir } from "os";
|
|
321
|
-
import { join as join2 } from "path";
|
|
322
|
-
import process4 from "process";
|
|
323
|
-
function configBase(where = {}) {
|
|
324
|
-
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
325
|
-
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
326
|
-
}
|
|
327
|
-
function userConfigPath(bin, where = {}) {
|
|
328
|
-
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// ../kit/src/theme.ts
|
|
332
|
-
var DEFAULT = {
|
|
333
|
-
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
334
|
-
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D" },
|
|
335
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
336
|
-
bins: {}
|
|
337
|
-
};
|
|
338
|
-
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
339
|
-
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
340
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+" };
|
|
341
|
-
var PRESETS = {
|
|
342
|
-
default: {},
|
|
343
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
|
|
344
|
-
mono: { colors: MONO, accents: ["bold"] },
|
|
345
|
-
ascii: { glyphs: ASCII }
|
|
346
|
-
};
|
|
109
|
+
var ENDS = new Map;
|
|
347
110
|
var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
348
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
349
|
-
var CONTROL = /\p{Cc}/u;
|
|
350
111
|
var MAX_FILE_BYTES = 64 * 1024;
|
|
351
|
-
var SPACES = /\s+/;
|
|
352
|
-
function isColorSpec(spec) {
|
|
353
|
-
if (typeof spec === "number")
|
|
354
|
-
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
355
|
-
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
356
|
-
}
|
|
357
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
358
|
-
function cubeLevel(channel) {
|
|
359
|
-
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
360
|
-
}
|
|
361
|
-
function nearest256(hex) {
|
|
362
|
-
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
363
|
-
const levels = rgb.map(cubeLevel);
|
|
364
|
-
const cube = levels.map((level) => CUBE[level]);
|
|
365
|
-
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
366
|
-
const greyValue = 8 + grey * 10;
|
|
367
|
-
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
368
|
-
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
369
|
-
}
|
|
370
|
-
function hasTrueColor(env) {
|
|
371
|
-
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
372
|
-
}
|
|
373
|
-
function tinted(colors, spec, env = process5.env) {
|
|
374
|
-
if (typeof spec === "number")
|
|
375
|
-
return colors.ansi256(spec);
|
|
376
|
-
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
377
|
-
if (HEX.test(token))
|
|
378
|
-
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
379
|
-
return chain[token] ?? chain;
|
|
380
|
-
}, colors);
|
|
381
|
-
}
|
|
382
|
-
function isRecord(value) {
|
|
383
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
384
|
-
}
|
|
385
|
-
function readThemeFile(path, warn) {
|
|
386
|
-
try {
|
|
387
|
-
const stat = statSync(path, { throwIfNoEntry: false });
|
|
388
|
-
if (stat === undefined)
|
|
389
|
-
return;
|
|
390
|
-
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
391
|
-
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
395
|
-
if (isRecord(parsed))
|
|
396
|
-
return parsed;
|
|
397
|
-
warn(`${path} is not a JSON object, theme ignored`);
|
|
398
|
-
} catch (error) {
|
|
399
|
-
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
400
|
-
}
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
function applyPreset(theme, name, warn, where) {
|
|
404
|
-
if (name === undefined)
|
|
405
|
-
return;
|
|
406
|
-
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
407
|
-
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
const preset = PRESETS[name];
|
|
411
|
-
Object.assign(theme.colors, preset.colors);
|
|
412
|
-
Object.assign(theme.glyphs, preset.glyphs);
|
|
413
|
-
if (preset.accents !== undefined)
|
|
414
|
-
theme.accents = [...preset.accents];
|
|
415
|
-
return name;
|
|
416
|
-
}
|
|
417
|
-
function applyFile(theme, file, where, warn) {
|
|
418
|
-
if (isRecord(file.colors)) {
|
|
419
|
-
for (const [key, value] of Object.entries(file.colors)) {
|
|
420
|
-
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
421
|
-
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
422
|
-
else if (!isColorSpec(value))
|
|
423
|
-
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
424
|
-
else
|
|
425
|
-
theme.colors[key] = value;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
if (isRecord(file.glyphs)) {
|
|
429
|
-
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
430
|
-
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
431
|
-
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
432
|
-
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
433
|
-
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
434
|
-
else
|
|
435
|
-
theme.glyphs[key] = value;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
439
|
-
theme.accents = [...file.accents];
|
|
440
|
-
else if (file.accents !== undefined)
|
|
441
|
-
warn(`${where}: accents must be a non-empty list of colours`);
|
|
442
|
-
if (isRecord(file.bins)) {
|
|
443
|
-
for (const [bin, value] of Object.entries(file.bins)) {
|
|
444
|
-
if (isColorSpec(value))
|
|
445
|
-
theme.bins[bin] = value;
|
|
446
|
-
else
|
|
447
|
-
warn(`${where}: bin ${bin} has no valid colour`);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
function endsWalk(home) {
|
|
452
|
-
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
453
|
-
}
|
|
454
112
|
var warned = new Set;
|
|
455
|
-
function warnOnce(message) {
|
|
456
|
-
if (warned.has(message))
|
|
457
|
-
return;
|
|
458
|
-
warned.add(message);
|
|
459
|
-
console.error(`warning: theme ${message}`);
|
|
460
|
-
}
|
|
461
|
-
function isPath(chosen) {
|
|
462
|
-
return chosen.includes("/") || chosen.endsWith(".json");
|
|
463
|
-
}
|
|
464
|
-
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
465
|
-
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
|
|
466
|
-
const sources = [];
|
|
467
|
-
const chosen = env.KIT_THEME ?? "";
|
|
468
|
-
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
469
|
-
if (isPath(chosen))
|
|
470
|
-
wanted.push(resolve2(from, chosen));
|
|
471
|
-
const files = [];
|
|
472
|
-
for (const path of wanted) {
|
|
473
|
-
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
474
|
-
if (path !== undefined && file !== undefined)
|
|
475
|
-
files.push({ path, file });
|
|
476
|
-
}
|
|
477
|
-
let preset = "default";
|
|
478
|
-
if (chosen !== "" && !isPath(chosen)) {
|
|
479
|
-
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
480
|
-
} else {
|
|
481
|
-
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
482
|
-
if (named !== undefined)
|
|
483
|
-
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
484
|
-
}
|
|
485
|
-
for (const { path, file } of files) {
|
|
486
|
-
applyFile(theme, file, path, warn);
|
|
487
|
-
sources.push(path);
|
|
488
|
-
}
|
|
489
|
-
return { theme, sources, preset };
|
|
490
|
-
}
|
|
491
|
-
var current;
|
|
492
|
-
var currentKey = "";
|
|
493
|
-
function activeTheme() {
|
|
494
|
-
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
495
|
-
if (current === undefined || key !== currentKey) {
|
|
496
|
-
current = loadTheme();
|
|
497
|
-
currentKey = key;
|
|
498
|
-
}
|
|
499
|
-
return current;
|
|
500
|
-
}
|
|
501
113
|
|
|
502
114
|
// ../kit/src/style.ts
|
|
503
|
-
function takesControlCodes(stream, env =
|
|
115
|
+
function takesControlCodes(stream, env = process3.env) {
|
|
504
116
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
505
117
|
}
|
|
506
|
-
function paint(stream, env =
|
|
507
|
-
return
|
|
118
|
+
function paint(stream, env = process3.env) {
|
|
119
|
+
return Fe2({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
508
120
|
}
|
|
509
121
|
var STATUS_WORDS = {
|
|
510
122
|
passed: ["passed", "success", "succeeded", "ok"],
|
|
@@ -514,21 +126,6 @@ var STATUS_WORDS = {
|
|
|
514
126
|
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
515
127
|
};
|
|
516
128
|
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
517
|
-
function header(bin, context, stream, env = process6.env) {
|
|
518
|
-
if (!takesControlCodes(stream, env))
|
|
519
|
-
return "";
|
|
520
|
-
const colors = paint(stream, env);
|
|
521
|
-
const hash = [...bin].reduce((sum, char) => sum + char.charCodeAt(0), 0);
|
|
522
|
-
const { theme } = activeTheme();
|
|
523
|
-
const spec = theme.bins[bin] ?? theme.accents[hash % theme.accents.length];
|
|
524
|
-
const accent = tinted(typeof spec === "string" && spec.split(" ").includes("bold") ? colors : colors.bold, spec, env);
|
|
525
|
-
return `${accent(bin)}${context === undefined ? "" : colors.dim(` \u203A ${context}`)}`;
|
|
526
|
-
}
|
|
527
|
-
function printHeader(bin, context, stream = process6.stdout, env = process6.env) {
|
|
528
|
-
const line = header(bin, context, stream, env);
|
|
529
|
-
if (line !== "")
|
|
530
|
-
console.log(line);
|
|
531
|
-
}
|
|
532
129
|
|
|
533
130
|
// ../kit/src/format.ts
|
|
534
131
|
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
@@ -550,14 +147,14 @@ function upTo(text, separator) {
|
|
|
550
147
|
return end === -1 ? text : text.slice(0, end);
|
|
551
148
|
}
|
|
552
149
|
function truncate(text, width) {
|
|
553
|
-
return text
|
|
150
|
+
return ko(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
554
151
|
}
|
|
555
152
|
var LINE_BREAKS = /\s*\n\s*/g;
|
|
556
153
|
var ESCAPE = String.fromCharCode(27);
|
|
557
154
|
function textWidth(text) {
|
|
558
155
|
return Bun.stringWidth(text);
|
|
559
156
|
}
|
|
560
|
-
function table(rows, { cellWidth, header = false, align = [], fit, stream =
|
|
157
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process4.stdout, env = process4.env } = {}) {
|
|
561
158
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
562
159
|
if (outputMode(stream, env) === "agent")
|
|
563
160
|
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
@@ -596,7 +193,7 @@ function narrow(rows, widths, limit) {
|
|
|
596
193
|
}
|
|
597
194
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
598
195
|
}
|
|
599
|
-
function jsonText(value, replacer, { stream =
|
|
196
|
+
function jsonText(value, replacer, { stream = process4.stdout, env = process4.env } = {}) {
|
|
600
197
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
601
198
|
}
|
|
602
199
|
function printJson(value) {
|
|
@@ -604,27 +201,27 @@ function printJson(value) {
|
|
|
604
201
|
}
|
|
605
202
|
|
|
606
203
|
// ../kit/src/help.ts
|
|
607
|
-
import
|
|
204
|
+
import process5 from "process";
|
|
608
205
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
609
206
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
610
207
|
var FULL_STOP = /\.$/;
|
|
611
|
-
function usageLine(usage, colors = paint(
|
|
208
|
+
function usageLine(usage, colors = paint(process5.stdout)) {
|
|
612
209
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
613
210
|
}
|
|
614
|
-
function helpText(usage, options, colors = paint(
|
|
211
|
+
function helpText(usage, options, colors = paint(process5.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
615
212
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
616
213
|
`);
|
|
617
214
|
}
|
|
618
|
-
function exitRows(exits, colors = paint(
|
|
215
|
+
function exitRows(exits, colors = paint(process5.stdout)) {
|
|
619
216
|
if (exits.length === 0)
|
|
620
217
|
return [];
|
|
621
218
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
622
219
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
623
220
|
}
|
|
624
|
-
function replacesRows(replaces, colors = paint(
|
|
221
|
+
function replacesRows(replaces, colors = paint(process5.stdout)) {
|
|
625
222
|
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
626
223
|
}
|
|
627
|
-
function wantsHelpJson(env =
|
|
224
|
+
function wantsHelpJson(env = process5.env) {
|
|
628
225
|
return env.KIT_HELP === "json";
|
|
629
226
|
}
|
|
630
227
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -643,12 +240,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
643
240
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
644
241
|
};
|
|
645
242
|
}
|
|
646
|
-
function exampleRows(examples, colors = paint(
|
|
243
|
+
function exampleRows(examples, colors = paint(process5.stdout)) {
|
|
647
244
|
if (examples.length === 0 || outputMode() === "agent")
|
|
648
245
|
return [];
|
|
649
246
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
650
247
|
}
|
|
651
|
-
function optionRows(options, colors = paint(
|
|
248
|
+
function optionRows(options, colors = paint(process5.stdout)) {
|
|
652
249
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
653
250
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
654
251
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -749,7 +346,7 @@ var OUTPUT_OPTIONS = {
|
|
|
749
346
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
750
347
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
751
348
|
};
|
|
752
|
-
function applyOutput(color, plain, env =
|
|
349
|
+
function applyOutput(color, plain, env = process6.env) {
|
|
753
350
|
const when = plain === true ? "never" : color ?? "auto";
|
|
754
351
|
if (when === "auto")
|
|
755
352
|
return;
|
|
@@ -920,7 +517,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
920
517
|
}
|
|
921
518
|
// ../kit/src/process.ts
|
|
922
519
|
import { constants } from "os";
|
|
923
|
-
import
|
|
520
|
+
import process7 from "process";
|
|
924
521
|
var KILL_GRACE_MS = 2000;
|
|
925
522
|
function exitCodeOf(code, signal) {
|
|
926
523
|
if (code !== null)
|
|
@@ -940,7 +537,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
940
537
|
return;
|
|
941
538
|
try {
|
|
942
539
|
if (grouped)
|
|
943
|
-
|
|
540
|
+
process7.kill(-proc.pid, killing);
|
|
944
541
|
else
|
|
945
542
|
proc.kill(killing);
|
|
946
543
|
} catch {}
|
|
@@ -1014,15 +611,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
1014
611
|
var RESET_STYLE = `${ESC}[0m`;
|
|
1015
612
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1016
613
|
// ../kit/src/cli.ts
|
|
1017
|
-
import { readFileSync
|
|
1018
|
-
import { dirname as
|
|
1019
|
-
import
|
|
614
|
+
import { readFileSync, realpathSync } from "fs";
|
|
615
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
616
|
+
import process9 from "process";
|
|
1020
617
|
|
|
1021
618
|
// ../kit/src/usage.ts
|
|
1022
619
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1023
|
-
import { homedir
|
|
1024
|
-
import { dirname
|
|
1025
|
-
import
|
|
620
|
+
import { homedir } from "os";
|
|
621
|
+
import { dirname, isAbsolute, join } from "path";
|
|
622
|
+
import process8 from "process";
|
|
1026
623
|
|
|
1027
624
|
// ../kit/src/logs.ts
|
|
1028
625
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1036,14 +633,14 @@ var usageError;
|
|
|
1036
633
|
function noteUsageError(message) {
|
|
1037
634
|
usageError = message;
|
|
1038
635
|
}
|
|
1039
|
-
function stateHome(env =
|
|
636
|
+
function stateHome(env = process8.env) {
|
|
1040
637
|
const dir = env.XDG_STATE_HOME;
|
|
1041
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
638
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
1042
639
|
}
|
|
1043
|
-
function usagePath(env =
|
|
1044
|
-
return
|
|
640
|
+
function usagePath(env = process8.env) {
|
|
641
|
+
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1045
642
|
}
|
|
1046
|
-
function usageRecorded(env =
|
|
643
|
+
function usageRecorded(env = process8.env) {
|
|
1047
644
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1048
645
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1049
646
|
}
|
|
@@ -1057,12 +654,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1057
654
|
usageError = undefined;
|
|
1058
655
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1059
656
|
}
|
|
1060
|
-
function recordUsage(entry, env =
|
|
657
|
+
function recordUsage(entry, env = process8.env) {
|
|
1061
658
|
if (!usageRecorded(env))
|
|
1062
659
|
return;
|
|
1063
660
|
try {
|
|
1064
661
|
const path = usagePath(env);
|
|
1065
|
-
mkdirSync(
|
|
662
|
+
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
1066
663
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1067
664
|
`, { mode: 384 });
|
|
1068
665
|
} catch {}
|
|
@@ -1148,8 +745,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1148
745
|
`);
|
|
1149
746
|
}
|
|
1150
747
|
function printError(prefix, message, hint, cause) {
|
|
1151
|
-
const colors = paint(
|
|
1152
|
-
const styled = takesControlCodes(
|
|
748
|
+
const colors = paint(process9.stderr);
|
|
749
|
+
const styled = takesControlCodes(process9.stderr);
|
|
1153
750
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1154
751
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1155
752
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1192,11 +789,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1192
789
|
}
|
|
1193
790
|
}
|
|
1194
791
|
if (name === undefined && level.path.length > 1) {
|
|
1195
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
792
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stderr));
|
|
1196
793
|
return 2;
|
|
1197
794
|
}
|
|
1198
795
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1199
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
796
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stdout));
|
|
1200
797
|
return 0;
|
|
1201
798
|
}
|
|
1202
799
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1313,17 +910,17 @@ async function printCandidates(found) {
|
|
|
1313
910
|
return 0;
|
|
1314
911
|
}
|
|
1315
912
|
function packageVersion(entry = Bun.main) {
|
|
1316
|
-
for (let dir =
|
|
913
|
+
for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
|
|
1317
914
|
try {
|
|
1318
|
-
const { version } = JSON.parse(
|
|
915
|
+
const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
|
|
1319
916
|
if (typeof version === "string")
|
|
1320
917
|
return version;
|
|
1321
918
|
} catch {}
|
|
1322
|
-
if (
|
|
919
|
+
if (dirname2(dir) === dir)
|
|
1323
920
|
return "0.0.0";
|
|
1324
921
|
}
|
|
1325
922
|
}
|
|
1326
|
-
async function runCli(cli, argv =
|
|
923
|
+
async function runCli(cli, argv = process9.argv.slice(2)) {
|
|
1327
924
|
const version = cli.version ?? packageVersion();
|
|
1328
925
|
if (argv[0] === COMPLETE)
|
|
1329
926
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1350,7 +947,7 @@ function commandPath(scope, argv) {
|
|
|
1350
947
|
}
|
|
1351
948
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1352
949
|
}
|
|
1353
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
950
|
+
async function runMain({ name, version, run, redact, usage }, argv = process9.argv.slice(2)) {
|
|
1354
951
|
if (argv[0] === COMPLETE)
|
|
1355
952
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1356
953
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1394,7 +991,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1394
991
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1395
992
|
}
|
|
1396
993
|
// ../kit/src/watch.ts
|
|
1397
|
-
import
|
|
994
|
+
import process10 from "process";
|
|
1398
995
|
import { format } from "util";
|
|
1399
996
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1400
997
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1416,7 +1013,7 @@ function withoutWatch(args) {
|
|
|
1416
1013
|
}
|
|
1417
1014
|
return rest;
|
|
1418
1015
|
}
|
|
1419
|
-
async function watching(value, step, stream =
|
|
1016
|
+
async function watching(value, step, stream = process10.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1420
1017
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1421
1018
|
if (!takesControlCodes(stream))
|
|
1422
1019
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1424,12 +1021,12 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1424
1021
|
for (let round = 0;round < rounds; round++) {
|
|
1425
1022
|
const held = [];
|
|
1426
1023
|
const { log, info } = console;
|
|
1427
|
-
const write =
|
|
1024
|
+
const write = process10.stdout.write.bind(process10.stdout);
|
|
1428
1025
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1429
1026
|
`);
|
|
1430
1027
|
console.log = hold;
|
|
1431
1028
|
console.info = hold;
|
|
1432
|
-
|
|
1029
|
+
process10.stdout.write = (text) => {
|
|
1433
1030
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1434
1031
|
return true;
|
|
1435
1032
|
};
|
|
@@ -1438,7 +1035,7 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1438
1035
|
} finally {
|
|
1439
1036
|
console.log = log;
|
|
1440
1037
|
console.info = info;
|
|
1441
|
-
|
|
1038
|
+
process10.stdout.write = write;
|
|
1442
1039
|
}
|
|
1443
1040
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1444
1041
|
await sleep(interval);
|
|
@@ -1447,10 +1044,10 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1447
1044
|
}
|
|
1448
1045
|
// src/ports.ts
|
|
1449
1046
|
import { basename as basename2 } from "path";
|
|
1450
|
-
import
|
|
1047
|
+
import process13 from "process";
|
|
1451
1048
|
|
|
1452
1049
|
// ../kit/src/prompt.ts
|
|
1453
|
-
import
|
|
1050
|
+
import process12 from "process";
|
|
1454
1051
|
|
|
1455
1052
|
// ../kit/src/picker/score.ts
|
|
1456
1053
|
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
@@ -1534,7 +1131,7 @@ function asking(colors, question, typed, keys) {
|
|
|
1534
1131
|
function answer(colors, question, state, picked) {
|
|
1535
1132
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1536
1133
|
}
|
|
1537
|
-
async function ask(question, { hint, terminal =
|
|
1134
|
+
async function ask(question, { hint, terminal = process12 }, render, press) {
|
|
1538
1135
|
const { stdin, stderr } = terminal;
|
|
1539
1136
|
if (!isInteractive(terminal))
|
|
1540
1137
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -2033,7 +1630,7 @@ function refusal(row, proc, guard) {
|
|
|
2033
1630
|
return reason === undefined ? undefined : `pid ${row.pid} is ${reason}`;
|
|
2034
1631
|
}
|
|
2035
1632
|
function render(rows) {
|
|
2036
|
-
const colors = paint(
|
|
1633
|
+
const colors = paint(process13.stdout);
|
|
2037
1634
|
const cells = rows.map((row) => [
|
|
2038
1635
|
colors.cyan(String(row.port)),
|
|
2039
1636
|
row.protocol,
|
|
@@ -2045,7 +1642,7 @@ function render(rows) {
|
|
|
2045
1642
|
return table([["PORT", "PROTO", "ADDRESS", "PID", "COMMAND", "CWD"], ...cells], { header: true });
|
|
2046
1643
|
}
|
|
2047
1644
|
async function stop(port, rows, procs, values) {
|
|
2048
|
-
const guard = { uid:
|
|
1645
|
+
const guard = { uid: process13.getuid?.() ?? -1, mine: new Set(ancestry(process13.pid, procs)) };
|
|
2049
1646
|
const targets = new Map;
|
|
2050
1647
|
for (const row of rows) {
|
|
2051
1648
|
const reason = refusal(row, row.pid === undefined ? undefined : procs.get(row.pid), guard);
|
|
@@ -2058,7 +1655,7 @@ async function stop(port, rows, procs, values) {
|
|
|
2058
1655
|
return 1;
|
|
2059
1656
|
const names = [...targets].map(([pid, row]) => `${pid} (${truncate(row.command ?? "", 40)})`).join(", ");
|
|
2060
1657
|
if (values.yes !== true) {
|
|
2061
|
-
if (!
|
|
1658
|
+
if (!process13.stdin.isTTY)
|
|
2062
1659
|
fail(`stopping ${names} needs a terminal to ask on: pass --yes`, 2);
|
|
2063
1660
|
if (await confirm(`Stop ${names}?`, { default: false }) !== true)
|
|
2064
1661
|
return 1;
|
|
@@ -2089,7 +1686,7 @@ async function ports(args) {
|
|
|
2089
1686
|
badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`);
|
|
2090
1687
|
if (values.kill === true && port === undefined)
|
|
2091
1688
|
badUsage("--kill takes the port to free: ports <port> --kill");
|
|
2092
|
-
const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid ===
|
|
1689
|
+
const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process13.getuid?.())]);
|
|
2093
1690
|
const byPid = new Map(procs.map((proc) => [proc.pid, proc]));
|
|
2094
1691
|
const wanted = sockets.filter((socket) => port === undefined || socket.port === port);
|
|
2095
1692
|
const needsDocker = wanted.some((socket) => {
|
|
@@ -2107,13 +1704,12 @@ async function ports(args) {
|
|
|
2107
1704
|
printJson(rows);
|
|
2108
1705
|
return 0;
|
|
2109
1706
|
}
|
|
2110
|
-
printHeader("ports");
|
|
2111
1707
|
console.log(render(rows));
|
|
2112
1708
|
const unknown = rows.filter((row) => row.pid === undefined && row.container === undefined).length;
|
|
2113
1709
|
if (unknown > 0)
|
|
2114
|
-
console.error(paint(
|
|
1710
|
+
console.error(paint(process13.stderr).dim(`${unknown} ${unknown === 1 ? "port has" : "ports have"} an owner this user cannot read, shown as -`));
|
|
2115
1711
|
return 0;
|
|
2116
1712
|
}
|
|
2117
1713
|
|
|
2118
1714
|
// src/ports-cli.ts
|
|
2119
|
-
|
|
1715
|
+
process14.exitCode = await runMain({ name: "ports", run: ports });
|