@kaynooo/cli-proc 0.6.0 → 0.7.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.
package/dist/ports-cli.js CHANGED
@@ -1,14 +1,32 @@
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 process14 from "process";
5
+ import process17 from "process";
6
6
  // ../kit/src/args.ts
7
- import process6 from "process";
7
+ import process9 from "process";
8
8
  import { parseArgs } from "util";
9
9
 
10
10
  // ../kit/src/format.ts
11
- import process4 from "process";
11
+ import process7 from "process";
12
+
13
+ // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
14
+ var N = new Map;
15
+ var Nt = /\s+\S*$/;
16
+ var Y = /\s/;
17
+ function ko(t, e, r = "...") {
18
+ let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
19
+ if (t.length <= e)
20
+ return t;
21
+ let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
22
+ if (o && !Y.test(t[c.length] ?? " "))
23
+ c = c.replace(Nt, "") || c;
24
+ if (o)
25
+ c = c.trimEnd();
26
+ return s ? (c + n).slice(0, l) : c + n;
27
+ }
28
+ 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));
29
+ var z = new Map;
12
30
 
13
31
  // ../kit/src/mode.ts
14
32
  import process2 from "process";
@@ -32,280 +50,296 @@ function isInteractive(streams = process2) {
32
50
  }
33
51
 
34
52
  // ../kit/src/style.ts
35
- import process3 from "process";
53
+ import process6 from "process";
36
54
 
37
- // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
38
- function x(s) {
39
- let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
40
- if (!/^[a-f0-9]+$/.test(r))
55
+ // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
56
+ var G2 = /^[a-f0-9]+$/i;
57
+ function b(r) {
58
+ let e = r.startsWith("#") ? r.slice(1) : r;
59
+ if (!G2.test(e))
41
60
  return [0, 0, 0];
42
- let t = r.length, n = (c) => Number.parseInt(c, 16);
43
- if (t === 3 || t === 4) {
44
- let c = n(r[0] + r[0]), u = n(r[1] + r[1]), h = n(r[2] + r[2]), g = t === 4 ? n(r[3] + r[3]) : undefined;
45
- return g !== undefined ? [c, u, h, g] : [c, u, h];
46
- }
47
- if (t !== 6 && t !== 8)
48
- throw Error(`Invalid hex color length: ${t}`);
49
- let a = n(r.slice(0, 2)), b = n(r.slice(2, 4)), o = n(r.slice(4, 6)), y = t === 8 ? n(r.slice(6, 8)) : undefined;
50
- if ([a, b, o].some(Number.isNaN) || y !== undefined && Number.isNaN(y))
51
- throw Error(`Invalid hex color value: ${s}`);
52
- return y !== undefined ? [a, b, o, y] : [a, b, o];
53
- }
54
- function A(s) {
55
- let [r, t, n, a] = s;
56
- if (a)
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)];
61
+ if (e.length === 3 || e.length === 4)
62
+ return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
63
+ if (e.length !== 6 && e.length !== 8)
64
+ throw Error(`Invalid hex color length: ${e.length}`);
65
+ return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
66
+ }
67
+ 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") => {
68
+ let [l, n, c] = b(r);
69
+ return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
70
+ }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
71
+ var h = new Set(["", "1", "2", "3", "true"]);
72
+ function C(r, e = globalThis.process?.env ?? {}) {
73
+ if (e.FORCE_COLOR !== undefined)
74
+ return h.has(e.FORCE_COLOR);
75
+ if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
76
+ return false;
77
+ return r?.isTTY === true;
78
+ }
79
+ function f(r, e = []) {
80
+ let l = "", n = "";
81
+ for (let t = 0, i = e.length;t < i; t++)
82
+ l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
83
+ let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
84
+ return new Proxy(c, { get(t, i) {
85
+ let a = B2[i];
86
+ if (Array.isArray(a)) {
87
+ let s = g.get(i);
88
+ if (s === undefined)
89
+ s = f(r, [...e, a]), g.set(i, s);
90
+ return s;
91
+ }
92
+ if (typeof a === "function")
93
+ return (...s) => {
94
+ let y = `${i}:${s.join(",")}`, u = g.get(y);
95
+ if (u === undefined) {
96
+ if (g.size >= 64)
97
+ g.clear();
98
+ u = f(r, [...e, a(...s)]), g.set(y, u);
99
+ }
100
+ return u;
101
+ };
102
+ throw Error(`Unknown style: ${String(i)}`);
103
+ } });
123
104
  }
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)];
105
+ function Fe(r = {}) {
106
+ return f(r);
127
107
  }
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)];
108
+ var o = Fe();
109
+
110
+ // ../kit/src/theme.ts
111
+ import { existsSync as existsSync2, readFileSync, statSync } from "fs";
112
+ import { homedir as homedir2 } from "os";
113
+ import { join as join3, resolve as resolve2 } from "path";
114
+ import process5 from "process";
115
+
116
+ // ../kit/src/config.ts
117
+ import { existsSync } from "fs";
118
+ import { dirname, join, resolve } from "path";
119
+ import process3 from "process";
120
+ function findUp(names, from = process3.cwd(), stop = () => false) {
121
+ const wanted = typeof names === "string" ? [names] : names;
122
+ for (let dir = resolve(from);; dir = dirname(dir)) {
123
+ const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
124
+ if (found !== undefined)
125
+ return found;
126
+ if (stop(dir) || dirname(dir) === dir)
127
+ return;
128
+ }
131
129
  }
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));
130
+
131
+ // ../kit/src/user-config.ts
132
+ import { homedir } from "os";
133
+ import { join as join2 } from "path";
134
+ import process4 from "process";
135
+ function configBase(where = {}) {
136
+ const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
137
+ return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
135
138
  }
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
+ function userConfigPath(bin, where = {}) {
140
+ return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
139
141
  }
140
142
 
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);
143
+ // ../kit/src/theme.ts
144
+ var ENDS = new Map;
145
+ var DEFAULT = {
146
+ colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
147
+ glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
148
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
149
+ bins: {},
150
+ gradient: ["#c084fc", "#67e8f9"]
151
+ };
152
+ var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
153
+ var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
154
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
155
+ var PRESETS = {
156
+ default: {},
157
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
158
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
159
+ ascii: { glyphs: ASCII }
160
+ };
161
+ 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"]);
162
+ var HEX = /^#[0-9a-f]{6}$/i;
163
+ var CONTROL = /\p{Cc}/u;
164
+ var MAX_FILE_BYTES = 64 * 1024;
165
+ var SPACES = /\s+/;
166
+ function isColorSpec(spec) {
167
+ if (typeof spec === "number")
168
+ return Number.isInteger(spec) && spec >= 0 && spec <= 255;
169
+ return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
170
+ }
171
+ var CUBE = [0, 95, 135, 175, 215, 255];
172
+ function cubeLevel(channel) {
173
+ return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
174
+ }
175
+ function nearest256(hex) {
176
+ const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
177
+ const levels = rgb.map(cubeLevel);
178
+ const cube = levels.map((level) => CUBE[level]);
179
+ const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
180
+ const greyValue = 8 + grey * 10;
181
+ const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
182
+ return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
183
+ }
184
+ function hasTrueColor(env) {
185
+ return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
186
+ }
187
+ function tinted(colors, spec, env = process5.env) {
188
+ if (typeof spec === "number")
189
+ return colors.ansi256(spec);
190
+ return spec.trim().split(SPACES).reduce((chain, token) => {
191
+ if (HEX.test(token))
192
+ return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
193
+ return chain[token] ?? chain;
194
+ }, colors);
195
+ }
196
+ function isRecord(value) {
197
+ return typeof value === "object" && value !== null && !Array.isArray(value);
198
+ }
199
+ function readThemeFile(path, warn) {
200
+ try {
201
+ const stat = statSync(path, { throwIfNoEntry: false });
202
+ if (stat === undefined)
203
+ return;
204
+ if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
205
+ warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
206
+ return;
179
207
  }
180
- if (s === "cmyk") {
181
- let t, n, a, b, o;
182
- if (Array.isArray(r))
183
- [t, n, a, b, o] = r;
208
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
209
+ if (isRecord(parsed))
210
+ return parsed;
211
+ warn(`${path} is not a JSON object, theme ignored`);
212
+ } catch (error) {
213
+ warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
214
+ }
215
+ return;
216
+ }
217
+ function applyPreset(theme, name, warn, where) {
218
+ if (name === undefined)
219
+ return;
220
+ if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
221
+ warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
222
+ return;
223
+ }
224
+ const preset = PRESETS[name];
225
+ Object.assign(theme.colors, preset.colors);
226
+ Object.assign(theme.glyphs, preset.glyphs);
227
+ if (preset.accents !== undefined)
228
+ theme.accents = [...preset.accents];
229
+ if (Object.hasOwn(preset, "gradient"))
230
+ theme.gradient = preset.gradient;
231
+ return name;
232
+ }
233
+ function applyFile(theme, file, where, warn) {
234
+ if (isRecord(file.colors)) {
235
+ for (const [key, value] of Object.entries(file.colors)) {
236
+ if (!Object.hasOwn(DEFAULT.colors, key))
237
+ warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
238
+ else if (!isColorSpec(value))
239
+ warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
184
240
  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);
241
+ theme.colors[key] = value;
188
242
  }
189
- if (s === "oklch") {
190
- let t, n, a, b;
191
- if (Array.isArray(r))
192
- [t, n, a, b] = r;
243
+ }
244
+ if (isRecord(file.glyphs)) {
245
+ for (const [key, value] of Object.entries(file.glyphs)) {
246
+ if (!Object.hasOwn(DEFAULT.glyphs, key))
247
+ warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
248
+ else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
249
+ warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
193
250
  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);
251
+ theme.glyphs[key] = value;
197
252
  }
198
- if (s === "oklab") {
199
- let t, n, a, b;
200
- if (Array.isArray(r))
201
- [t, n, a, b] = r;
253
+ }
254
+ if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
255
+ theme.accents = [...file.accents];
256
+ else if (file.accents !== undefined)
257
+ warn(`${where}: accents must be a non-empty list of colours`);
258
+ if (file.gradient === null)
259
+ theme.gradient = undefined;
260
+ else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
261
+ theme.gradient = [file.gradient[0], file.gradient[1]];
262
+ else if (file.gradient !== undefined)
263
+ warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
264
+ if (isRecord(file.bins)) {
265
+ for (const [bin, value] of Object.entries(file.bins)) {
266
+ if (isColorSpec(value))
267
+ theme.bins[bin] = value;
202
268
  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];
269
+ warn(`${where}: bin ${bin} has no valid colour`);
241
270
  }
242
271
  }
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);
272
+ }
273
+ function endsWalk(home) {
274
+ return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
275
+ }
276
+ var warned = new Set;
277
+ function warnOnce(message) {
278
+ if (warned.has(message))
279
+ return;
280
+ warned.add(message);
281
+ console.error(`warning: theme ${message}`);
282
+ }
283
+ function isPath(chosen) {
284
+ return chosen.includes("/") || chosen.endsWith(".json");
285
+ }
286
+ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
287
+ const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
288
+ const sources = [];
289
+ const chosen = env.KIT_THEME ?? "";
290
+ const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
291
+ if (isPath(chosen))
292
+ wanted.push(resolve2(from, chosen));
293
+ const files = [];
294
+ for (const path of wanted) {
295
+ const file = path === undefined ? undefined : readThemeFile(path, warn);
296
+ if (path !== undefined && file !== undefined)
297
+ files.push({ path, file });
298
+ }
299
+ let preset = "default";
300
+ if (chosen !== "" && !isPath(chosen)) {
301
+ preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
302
+ } else {
303
+ const named = files.findLast(({ file }) => file.preset !== undefined);
304
+ if (named !== undefined)
305
+ preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
250
306
  }
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;
307
+ for (const { path, file } of files) {
308
+ applyFile(theme, file, path, warn);
309
+ sources.push(path);
254
310
  }
311
+ return { theme, sources, preset };
255
312
  }
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")
270
- return false;
271
- return i?.isTTY === true;
272
- }
273
- function d2(i, n, a) {
274
- if (!h(a.stream ?? globalThis.process?.stdout, a.env))
275
- return n;
276
- let l = "", s = "";
277
- for (let g = 0, y = i.length;g < y; g++) {
278
- let [c, p] = i[g];
279
- l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
280
- }
281
- return l + n + s;
282
- }
283
- function u(i, n = []) {
284
- return new Proxy((l) => d2(n, l, i), { get(l, s) {
285
- let g = C2[s];
286
- if (Array.isArray(g))
287
- return u(i, [...n, g]);
288
- if (typeof g === "function")
289
- return (...y) => u(i, [...n, g(...y)]);
290
- throw Error(`Unknown style: ${String(s)}`);
291
- } });
292
- }
293
- function le(i = {}) {
294
- return u(i);
313
+ var current;
314
+ var currentKey = "";
315
+ function activeTheme() {
316
+ const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
317
+ if (current === undefined || key !== currentKey) {
318
+ current = loadTheme();
319
+ currentKey = key;
320
+ }
321
+ return current;
295
322
  }
296
- var t = le();
297
-
298
- // ../kit/src/theme.ts
299
- 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"]);
300
- var MAX_FILE_BYTES = 64 * 1024;
301
- var warned = new Set;
302
323
 
303
324
  // ../kit/src/style.ts
304
- function takesControlCodes(stream, env = process3.env) {
325
+ var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
326
+ function takesControlCodes(stream, env = process6.env) {
305
327
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
306
328
  }
307
- function paint(stream, env = process3.env) {
308
- return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
329
+ function paint(stream, env = process6.env) {
330
+ return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
331
+ }
332
+ function marked(mark, text, stream, detail, env = process6.env) {
333
+ const colors = paint(stream, env);
334
+ let head = MARK_WORDS[mark];
335
+ if (takesControlCodes(stream, env)) {
336
+ const { theme } = activeTheme();
337
+ head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
338
+ }
339
+ return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
340
+ }
341
+ function problem(text, detail) {
342
+ console.error(marked("problem", text, process6.stderr, detail));
309
343
  }
310
344
  var STATUS_WORDS = {
311
345
  passed: ["passed", "success", "succeeded", "ok"],
@@ -336,14 +370,14 @@ function upTo(text, separator) {
336
370
  return end === -1 ? text : text.slice(0, end);
337
371
  }
338
372
  function truncate(text, width) {
339
- return text.length <= width ? text : `${text.slice(0, Math.max(0, width - 1))}\u2026`;
373
+ return ko(text, width, { suffix: "\u2026", includeSuffix: true });
340
374
  }
341
375
  var LINE_BREAKS = /\s*\n\s*/g;
342
376
  var ESCAPE = String.fromCharCode(27);
343
377
  function textWidth(text) {
344
378
  return Bun.stringWidth(text);
345
379
  }
346
- function table(rows, { cellWidth, header = false, align = [], fit, stream = process4.stdout, env = process4.env } = {}) {
380
+ function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
347
381
  const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
348
382
  if (outputMode(stream, env) === "agent")
349
383
  return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
@@ -382,7 +416,7 @@ function narrow(rows, widths, limit) {
382
416
  }
383
417
  return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
384
418
  }
385
- function jsonText(value, replacer, { stream = process4.stdout, env = process4.env } = {}) {
419
+ function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
386
420
  return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
387
421
  }
388
422
  function printJson(value) {
@@ -390,27 +424,27 @@ function printJson(value) {
390
424
  }
391
425
 
392
426
  // ../kit/src/help.ts
393
- import process5 from "process";
427
+ import process8 from "process";
394
428
  var OPTIONAL = /\[[^\]]+\]/g;
395
429
  var USAGE_PREFIX = /^usage:\s*/i;
396
430
  var FULL_STOP = /\.$/;
397
- function usageLine(usage, colors = paint(process5.stdout)) {
431
+ function usageLine(usage, colors = paint(process8.stdout)) {
398
432
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
399
433
  }
400
- function helpText(usage, options, colors = paint(process5.stdout), { examples = [], replaces, exits = [] } = {}) {
434
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
401
435
  return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
402
436
  `);
403
437
  }
404
- function exitRows(exits, colors = paint(process5.stdout)) {
438
+ function exitRows(exits, colors = paint(process8.stdout)) {
405
439
  if (exits.length === 0)
406
440
  return [];
407
441
  const width = Math.max(...exits.map(([code]) => String(code).length));
408
442
  return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
409
443
  }
410
- function replacesRows(replaces, colors = paint(process5.stdout)) {
444
+ function replacesRows(replaces, colors = paint(process8.stdout)) {
411
445
  return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
412
446
  }
413
- function wantsHelpJson(env = process5.env) {
447
+ function wantsHelpJson(env = process8.env) {
414
448
  return env.KIT_HELP === "json";
415
449
  }
416
450
  function description(usage, { examples = [], replaces, exits } = {}, options) {
@@ -429,12 +463,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
429
463
  ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
430
464
  };
431
465
  }
432
- function exampleRows(examples, colors = paint(process5.stdout)) {
466
+ function exampleRows(examples, colors = paint(process8.stdout)) {
433
467
  if (examples.length === 0 || outputMode() === "agent")
434
468
  return [];
435
469
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
436
470
  }
437
- function optionRows(options, colors = paint(process5.stdout)) {
471
+ function optionRows(options, colors = paint(process8.stdout)) {
438
472
  const rows = Object.entries(options).map(([name, option]) => {
439
473
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
440
474
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -535,7 +569,7 @@ var OUTPUT_OPTIONS = {
535
569
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
536
570
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
537
571
  };
538
- function applyOutput(color, plain, env = process6.env) {
572
+ function applyOutput(color, plain, env = process9.env) {
539
573
  const when = plain === true ? "never" : color ?? "auto";
540
574
  if (when === "auto")
541
575
  return;
@@ -706,7 +740,7 @@ function nearestOption(message, options, allowNegative) {
706
740
  }
707
741
  // ../kit/src/process.ts
708
742
  import { constants } from "os";
709
- import process7 from "process";
743
+ import process10 from "process";
710
744
  var KILL_GRACE_MS = 2000;
711
745
  function exitCodeOf(code, signal) {
712
746
  if (code !== null)
@@ -726,7 +760,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
726
760
  return;
727
761
  try {
728
762
  if (grouped)
729
- process7.kill(-proc.pid, killing);
763
+ process10.kill(-proc.pid, killing);
730
764
  else
731
765
  proc.kill(killing);
732
766
  } catch {}
@@ -800,15 +834,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
800
834
  var RESET_STYLE = `${ESC}[0m`;
801
835
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
802
836
  // ../kit/src/cli.ts
803
- import { readFileSync, realpathSync } from "fs";
804
- import { dirname as dirname2, join as join2 } from "path";
805
- import process9 from "process";
837
+ import { readFileSync as readFileSync2, realpathSync } from "fs";
838
+ import { dirname as dirname3, join as join5 } from "path";
839
+ import process12 from "process";
806
840
 
807
841
  // ../kit/src/usage.ts
808
842
  import { appendFileSync, mkdirSync } from "fs";
809
- import { homedir } from "os";
810
- import { dirname, isAbsolute, join } from "path";
811
- import process8 from "process";
843
+ import { homedir as homedir3 } from "os";
844
+ import { dirname as dirname2, isAbsolute, join as join4 } from "path";
845
+ import process11 from "process";
812
846
 
813
847
  // ../kit/src/logs.ts
814
848
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -822,14 +856,14 @@ var usageError;
822
856
  function noteUsageError(message) {
823
857
  usageError = message;
824
858
  }
825
- function stateHome(env = process8.env) {
859
+ function stateHome(env = process11.env) {
826
860
  const dir = env.XDG_STATE_HOME;
827
- return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
861
+ return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
828
862
  }
829
- function usagePath(env = process8.env) {
830
- return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
863
+ function usagePath(env = process11.env) {
864
+ return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
831
865
  }
832
- function usageRecorded(env = process8.env) {
866
+ function usageRecorded(env = process11.env) {
833
867
  const off = env.KAYNOOO_CLI_NO_USAGE;
834
868
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
835
869
  }
@@ -843,12 +877,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
843
877
  usageError = undefined;
844
878
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
845
879
  }
846
- function recordUsage(entry, env = process8.env) {
880
+ function recordUsage(entry, env = process11.env) {
847
881
  if (!usageRecorded(env))
848
882
  return;
849
883
  try {
850
884
  const path = usagePath(env);
851
- mkdirSync(dirname(path), { recursive: true, mode: 448 });
885
+ mkdirSync(dirname2(path), { recursive: true, mode: 448 });
852
886
  appendFileSync(path, `${JSON.stringify(entry)}
853
887
  `, { mode: 384 });
854
888
  } catch {}
@@ -934,8 +968,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
934
968
  `);
935
969
  }
936
970
  function printError(prefix, message, hint, cause) {
937
- const colors = paint(process9.stderr);
938
- const styled = takesControlCodes(process9.stderr);
971
+ const colors = paint(process12.stderr);
972
+ const styled = takesControlCodes(process12.stderr);
939
973
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
940
974
  const under = (label, text, tint) => text === undefined ? "" : `
941
975
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -978,11 +1012,11 @@ async function dispatch(level, typed, { version, redact }) {
978
1012
  }
979
1013
  }
980
1014
  if (name === undefined && level.path.length > 1) {
981
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stderr));
1015
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stderr));
982
1016
  return 2;
983
1017
  }
984
1018
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
985
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stdout));
1019
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stdout));
986
1020
  return 0;
987
1021
  }
988
1022
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1099,17 +1133,17 @@ async function printCandidates(found) {
1099
1133
  return 0;
1100
1134
  }
1101
1135
  function packageVersion(entry = Bun.main) {
1102
- for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
1136
+ for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1103
1137
  try {
1104
- const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
1138
+ const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
1105
1139
  if (typeof version === "string")
1106
1140
  return version;
1107
1141
  } catch {}
1108
- if (dirname2(dir) === dir)
1142
+ if (dirname3(dir) === dir)
1109
1143
  return "0.0.0";
1110
1144
  }
1111
1145
  }
1112
- async function runCli(cli, argv = process9.argv.slice(2)) {
1146
+ async function runCli(cli, argv = process12.argv.slice(2)) {
1113
1147
  const version = cli.version ?? packageVersion();
1114
1148
  if (argv[0] === COMPLETE)
1115
1149
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
@@ -1136,7 +1170,7 @@ function commandPath(scope, argv) {
1136
1170
  }
1137
1171
  return path.length === 0 ? undefined : path.join(" ");
1138
1172
  }
1139
- async function runMain({ name, version, run, redact, usage }, argv = process9.argv.slice(2)) {
1173
+ async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
1140
1174
  if (argv[0] === COMPLETE)
1141
1175
  return printCandidates(leafCandidates(run, argv.slice(1)));
1142
1176
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1180,7 +1214,7 @@ function parseSize(text, bareUnit = 1) {
1180
1214
  return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
1181
1215
  }
1182
1216
  // ../kit/src/watch.ts
1183
- import process10 from "process";
1217
+ import process13 from "process";
1184
1218
  import { format } from "util";
1185
1219
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1186
1220
  var DEFAULT_SECONDS = 2;
@@ -1202,7 +1236,7 @@ function withoutWatch(args) {
1202
1236
  }
1203
1237
  return rest;
1204
1238
  }
1205
- async function watching(value, step, stream = process10.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1239
+ async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1206
1240
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1207
1241
  if (!takesControlCodes(stream))
1208
1242
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1210,12 +1244,12 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
1210
1244
  for (let round = 0;round < rounds; round++) {
1211
1245
  const held = [];
1212
1246
  const { log, info } = console;
1213
- const write = process10.stdout.write.bind(process10.stdout);
1247
+ const write = process13.stdout.write.bind(process13.stdout);
1214
1248
  const hold = (...parts) => void held.push(`${format(...parts)}
1215
1249
  `);
1216
1250
  console.log = hold;
1217
1251
  console.info = hold;
1218
- process10.stdout.write = (text) => {
1252
+ process13.stdout.write = (text) => {
1219
1253
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1220
1254
  return true;
1221
1255
  };
@@ -1224,7 +1258,7 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
1224
1258
  } finally {
1225
1259
  console.log = log;
1226
1260
  console.info = info;
1227
- process10.stdout.write = write;
1261
+ process13.stdout.write = write;
1228
1262
  }
1229
1263
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1230
1264
  await sleep(interval);
@@ -1233,10 +1267,10 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
1233
1267
  }
1234
1268
  // src/ports.ts
1235
1269
  import { basename as basename2 } from "path";
1236
- import process13 from "process";
1270
+ import process16 from "process";
1237
1271
 
1238
1272
  // ../kit/src/prompt.ts
1239
- import process12 from "process";
1273
+ import process15 from "process";
1240
1274
 
1241
1275
  // ../kit/src/picker/score.ts
1242
1276
  var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
@@ -1246,7 +1280,9 @@ var NONE = Number.NEGATIVE_INFINITY;
1246
1280
  var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
1247
1281
  var PASTE_START = "\x1B[200~";
1248
1282
  var PASTE_END = "\x1B[201~";
1249
- var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
1283
+ var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
1284
+ var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
1285
+ var WHEEL_LINES = 3;
1250
1286
  var KEYS = {
1251
1287
  "\x1B[A": "up",
1252
1288
  "\x1BOA": "up",
@@ -1275,9 +1311,15 @@ var KEYS = {
1275
1311
  "\x1BOP": "help",
1276
1312
  "\x1B[11~": "help"
1277
1313
  };
1314
+ function repeat(value, count) {
1315
+ return Array.from({ length: count }).fill(value);
1316
+ }
1278
1317
  function parseKeys(input, paste = { active: false }, ctrls = []) {
1279
1318
  const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
1280
1319
  return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
1320
+ const wheel = MOUSE.exec(sequence)?.[1];
1321
+ if (wheel !== undefined)
1322
+ return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
1281
1323
  const named = codes.get(sequence);
1282
1324
  const key = named === undefined ? KEYS[sequence] : { ctrl: named };
1283
1325
  if (sequence === PASTE_START || sequence === PASTE_END) {
@@ -1320,21 +1362,18 @@ function asking(colors, question, typed, keys) {
1320
1362
  function answer(colors, question, state, picked) {
1321
1363
  return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
1322
1364
  }
1323
- async function ask(question, { hint, terminal = process12 }, render, press) {
1365
+ async function ask(question, { hint, terminal = process15 }, render, press) {
1324
1366
  const { stdin, stderr } = terminal;
1325
1367
  if (!isInteractive(terminal))
1326
1368
  fail(`cannot ask "${question}" off a terminal`, 2, hint);
1327
1369
  const colors = paint(stderr);
1328
- let drawn = [];
1329
1370
  let current = "asking";
1330
1371
  let outcome;
1331
1372
  const columns = () => stderr.columns || 80;
1332
- const draw = (state) => {
1373
+ const draw = (state, last = false) => {
1333
1374
  const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
1334
- const rows = drawn.reduce((sum, line) => sum + Math.max(1, Math.ceil(Bun.stringWidth(line) / columns())), 0);
1335
- stderr.write(`${rows > 1 ? `\x1B[${rows - 1}A` : ""}\r\x1B[0J${frame.join(`
1336
- `)}`);
1337
- drawn = frame;
1375
+ stderr.write(`\r\x1B[0J${frame.join(`
1376
+ `)}${last || frame.length < 2 ? "" : `\x1B[${frame.length - 1}A`}${last ? "" : "\r"}`);
1338
1377
  current = state;
1339
1378
  };
1340
1379
  const redraw = () => draw(current);
@@ -1370,7 +1409,7 @@ async function ask(question, { hint, terminal = process12 }, render, press) {
1370
1409
  });
1371
1410
  } finally {
1372
1411
  stderr.off?.("resize", redraw);
1373
- draw(outcome ?? "cancel");
1412
+ draw(outcome ?? "cancel", true);
1374
1413
  stderr.write(`
1375
1414
  \x1B[?25h\x1B[?2004l`);
1376
1415
  stdin.setRawMode(false);
@@ -1778,6 +1817,7 @@ var options = {
1778
1817
  watch: watchOption("the ports"),
1779
1818
  force: { type: "boolean", description: "with --kill, SIGKILL what SIGTERM did not stop within --grace" },
1780
1819
  yes: { type: "boolean", short: "y", description: "with --kill, do not ask first" },
1820
+ quiet: { type: "boolean", short: "q", description: "with --kill, print nothing about what was stopped" },
1781
1821
  grace: { type: "string", description: "with --force, how long SIGTERM gets before SIGKILL (5s)" }
1782
1822
  };
1783
1823
  function buildRows(sockets, owners, procs, containers) {
@@ -1819,7 +1859,7 @@ function refusal(row, proc, guard) {
1819
1859
  return reason === undefined ? undefined : `pid ${row.pid} is ${reason}`;
1820
1860
  }
1821
1861
  function render(rows) {
1822
- const colors = paint(process13.stdout);
1862
+ const colors = paint(process16.stdout);
1823
1863
  const cells = rows.map((row) => [
1824
1864
  colors.cyan(String(row.port)),
1825
1865
  row.protocol,
@@ -1831,12 +1871,12 @@ function render(rows) {
1831
1871
  return table([["PORT", "PROTO", "ADDRESS", "PID", "COMMAND", "CWD"], ...cells], { header: true });
1832
1872
  }
1833
1873
  async function stop(port, rows, procs, values) {
1834
- const guard = { uid: process13.getuid?.() ?? -1, mine: new Set(ancestry(process13.pid, procs)) };
1874
+ const guard = { uid: process16.getuid?.() ?? -1, mine: new Set(ancestry(process16.pid, procs)) };
1835
1875
  const targets = new Map;
1836
1876
  for (const row of rows) {
1837
1877
  const reason = refusal(row, row.pid === undefined ? undefined : procs.get(row.pid), guard);
1838
1878
  if (reason !== undefined)
1839
- console.error(`port ${port}: ${reason}`);
1879
+ problem(`port ${port}: ${reason}`);
1840
1880
  else if (row.pid !== undefined)
1841
1881
  targets.set(row.pid, row);
1842
1882
  }
@@ -1844,16 +1884,16 @@ async function stop(port, rows, procs, values) {
1844
1884
  return 1;
1845
1885
  const names = [...targets].map(([pid, row]) => `${pid} (${truncate(row.command ?? "", 40)})`).join(", ");
1846
1886
  if (values.yes !== true) {
1847
- if (!process13.stdin.isTTY)
1887
+ if (!process16.stdin.isTTY)
1848
1888
  fail(`stopping ${names} needs a terminal to ask on: pass --yes`, 2);
1849
1889
  if (await confirm(`Stop ${names}?`, { default: false }) !== true)
1850
1890
  return 1;
1851
1891
  }
1852
1892
  const outcome = await terminate([...targets.keys()], { escalate: values.force === true, graceMs: duration(values.grace, "grace", 5000) });
1853
- for (const pid of [...outcome.terminated, ...outcome.killed])
1893
+ for (const pid of values.quiet === true ? [] : [...outcome.terminated, ...outcome.killed])
1854
1894
  console.log(`stopped ${pid}${outcome.killed.includes(pid) ? " (SIGKILL)" : ""}`);
1855
1895
  for (const pid of outcome.survived)
1856
- console.error(`${pid} is still running${values.force === true ? "" : ", pass --force to SIGKILL it"}`);
1896
+ problem(`${pid} is still running${values.force === true ? "" : ", pass --force to SIGKILL it"}`);
1857
1897
  return outcome.survived.length === 0 ? 0 : 1;
1858
1898
  }
1859
1899
  async function ports(args) {
@@ -1875,7 +1915,7 @@ async function ports(args) {
1875
1915
  badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`);
1876
1916
  if (values.kill === true && port === undefined)
1877
1917
  badUsage("--kill takes the port to free: ports <port> --kill");
1878
- const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process13.getuid?.())]);
1918
+ const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process16.getuid?.())]);
1879
1919
  const byPid = new Map(procs.map((proc) => [proc.pid, proc]));
1880
1920
  const wanted = sockets.filter((socket) => port === undefined || socket.port === port);
1881
1921
  const needsDocker = wanted.some((socket) => {
@@ -1884,7 +1924,7 @@ async function ports(args) {
1884
1924
  });
1885
1925
  const rows = buildRows(wanted, owners, byPid, needsDocker ? await dockerContainers() : []);
1886
1926
  if (port !== undefined && rows.length === 0) {
1887
- console.error(`nothing listens on port ${port}`);
1927
+ problem(`nothing listens on port ${port}`);
1888
1928
  return 1;
1889
1929
  }
1890
1930
  if (values.kill === true && port !== undefined)
@@ -1896,9 +1936,9 @@ async function ports(args) {
1896
1936
  console.log(render(rows));
1897
1937
  const unknown = rows.filter((row) => row.pid === undefined && row.container === undefined).length;
1898
1938
  if (unknown > 0)
1899
- console.error(paint(process13.stderr).dim(`${unknown} ${unknown === 1 ? "port has" : "ports have"} an owner this user cannot read, shown as -`));
1939
+ console.error(paint(process16.stderr).dim(`${unknown} ${unknown === 1 ? "port has" : "ports have"} an owner this user cannot read, shown as -`));
1900
1940
  return 0;
1901
1941
  }
1902
1942
 
1903
1943
  // src/ports-cli.ts
1904
- process14.exitCode = await runMain({ name: "ports", run: ports });
1944
+ process17.exitCode = await runMain({ name: "ports", run: ports });