@kaynooo/cli-check 0.20.1 → 0.21.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/README.md +17 -15
- package/dist/cli.js +376 -202
- package/dist/errs-cli.js +362 -163
- package/dist/j-cli.js +1537 -1305
- package/package.json +7 -9
- package/dist/fix-cli.js +0 -2216
package/dist/j-cli.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
+
var __esm = (fn, res, err) => () => {
|
|
4
|
+
if (fn)
|
|
5
|
+
try {
|
|
6
|
+
res = fn(fn = 0);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
err = [e];
|
|
9
|
+
}
|
|
10
|
+
if (err)
|
|
11
|
+
throw err[0];
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
3
14
|
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
// ../kit/src/args.ts
|
|
7
|
-
import process10 from "process";
|
|
8
|
-
import { parseArgs } from "util";
|
|
9
|
-
|
|
10
|
-
// ../kit/src/format.ts
|
|
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 = "...") {
|
|
15
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
16
|
+
function Ao(t, e, r = "...") {
|
|
18
17
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
19
18
|
if (t.length <= e)
|
|
20
19
|
return t;
|
|
@@ -25,13 +24,22 @@ function ko(t, e, r = "...") {
|
|
|
25
24
|
c = c.trimEnd();
|
|
26
25
|
return s ? (c + n).slice(0, l) : c + n;
|
|
27
26
|
}
|
|
28
|
-
var
|
|
29
|
-
var
|
|
27
|
+
var N, Nt, Y, be, W;
|
|
28
|
+
var init_chunk_rkhsft4a = __esm(() => {
|
|
29
|
+
N = new Map;
|
|
30
|
+
Nt = /\s+\S*$/;
|
|
31
|
+
Y = /\s/;
|
|
32
|
+
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));
|
|
33
|
+
W = new Map;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
37
|
+
var init_text = __esm(() => {
|
|
38
|
+
init_chunk_rkhsft4a();
|
|
39
|
+
});
|
|
30
40
|
|
|
31
41
|
// ../kit/src/mode.ts
|
|
32
42
|
import process2 from "process";
|
|
33
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
34
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
35
43
|
function isSet(value) {
|
|
36
44
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
37
45
|
}
|
|
@@ -48,12 +56,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
48
56
|
function isInteractive(streams = process2) {
|
|
49
57
|
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
50
58
|
}
|
|
59
|
+
var MODES, AGENT_VARIABLES;
|
|
60
|
+
var init_mode = __esm(() => {
|
|
61
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
62
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
63
|
+
});
|
|
51
64
|
|
|
52
|
-
//
|
|
53
|
-
import process6 from "process";
|
|
54
|
-
|
|
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;
|
|
65
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
57
66
|
function b(r) {
|
|
58
67
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
59
68
|
if (!G2.test(e))
|
|
@@ -64,11 +73,6 @@ function b(r) {
|
|
|
64
73
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
65
74
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
66
75
|
}
|
|
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
76
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
73
77
|
if (e.FORCE_COLOR !== undefined)
|
|
74
78
|
return h.has(e.FORCE_COLOR);
|
|
@@ -82,7 +86,7 @@ function f(r, e = []) {
|
|
|
82
86
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
83
87
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
84
88
|
return new Proxy(c, { get(t, i) {
|
|
85
|
-
let a =
|
|
89
|
+
let a = B[i];
|
|
86
90
|
if (Array.isArray(a)) {
|
|
87
91
|
let s = g.get(i);
|
|
88
92
|
if (s === undefined)
|
|
@@ -105,13 +109,21 @@ function f(r, e = []) {
|
|
|
105
109
|
function Fe(r = {}) {
|
|
106
110
|
return f(r);
|
|
107
111
|
}
|
|
108
|
-
var
|
|
112
|
+
var G2, B, h, o;
|
|
113
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
114
|
+
G2 = /^[a-f0-9]+$/i;
|
|
115
|
+
B = { 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") => {
|
|
116
|
+
let [l, n, c] = b(r);
|
|
117
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
118
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
119
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
120
|
+
o = Fe();
|
|
121
|
+
});
|
|
109
122
|
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
import process5 from "process";
|
|
123
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
124
|
+
var init_colors = __esm(() => {
|
|
125
|
+
init_chunk_x450vn3m();
|
|
126
|
+
});
|
|
115
127
|
|
|
116
128
|
// ../kit/src/config.ts
|
|
117
129
|
import { existsSync } from "fs";
|
|
@@ -127,6 +139,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
127
139
|
return;
|
|
128
140
|
}
|
|
129
141
|
}
|
|
142
|
+
var init_config = __esm(() => {
|
|
143
|
+
init_args();
|
|
144
|
+
});
|
|
130
145
|
|
|
131
146
|
// ../kit/src/user-config.ts
|
|
132
147
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
@@ -158,36 +173,18 @@ function readUserConfig(bin, where = {}, legacy = []) {
|
|
|
158
173
|
return {};
|
|
159
174
|
}
|
|
160
175
|
}
|
|
176
|
+
var init_user_config = () => {};
|
|
161
177
|
|
|
162
178
|
// ../kit/src/theme.ts
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
168
|
-
bins: {},
|
|
169
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
170
|
-
};
|
|
171
|
-
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" };
|
|
172
|
-
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" };
|
|
173
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
174
|
-
var PRESETS = {
|
|
175
|
-
default: {},
|
|
176
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
177
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
178
|
-
ascii: { glyphs: ASCII }
|
|
179
|
-
};
|
|
180
|
-
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"]);
|
|
181
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
182
|
-
var CONTROL = /\p{Cc}/u;
|
|
183
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
184
|
-
var SPACES = /\s+/;
|
|
179
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
180
|
+
import { homedir as homedir2 } from "os";
|
|
181
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
182
|
+
import process5 from "process";
|
|
185
183
|
function isColorSpec(spec) {
|
|
186
184
|
if (typeof spec === "number")
|
|
187
185
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
188
186
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
189
187
|
}
|
|
190
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
191
188
|
function cubeLevel(channel) {
|
|
192
189
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
193
190
|
}
|
|
@@ -292,7 +289,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
292
289
|
function endsWalk(home) {
|
|
293
290
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
294
291
|
}
|
|
295
|
-
var warned = new Set;
|
|
296
292
|
function warnOnce(message) {
|
|
297
293
|
if (warned.has(message))
|
|
298
294
|
return;
|
|
@@ -329,8 +325,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
329
325
|
}
|
|
330
326
|
return { theme, sources, preset };
|
|
331
327
|
}
|
|
332
|
-
var current;
|
|
333
|
-
var currentKey = "";
|
|
334
328
|
function activeTheme() {
|
|
335
329
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
336
330
|
if (current === undefined || key !== currentKey) {
|
|
@@ -339,9 +333,38 @@ function activeTheme() {
|
|
|
339
333
|
}
|
|
340
334
|
return current;
|
|
341
335
|
}
|
|
336
|
+
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
337
|
+
var init_theme = __esm(() => {
|
|
338
|
+
init_config();
|
|
339
|
+
init_user_config();
|
|
340
|
+
ENDS = new Map;
|
|
341
|
+
DEFAULT = {
|
|
342
|
+
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" },
|
|
343
|
+
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" },
|
|
344
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
345
|
+
bins: {},
|
|
346
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
347
|
+
};
|
|
348
|
+
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" };
|
|
349
|
+
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" };
|
|
350
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
351
|
+
PRESETS = {
|
|
352
|
+
default: {},
|
|
353
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
354
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
355
|
+
ascii: { glyphs: ASCII }
|
|
356
|
+
};
|
|
357
|
+
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"]);
|
|
358
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
359
|
+
CONTROL = /\p{Cc}/u;
|
|
360
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
361
|
+
SPACES = /\s+/;
|
|
362
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
363
|
+
warned = new Set;
|
|
364
|
+
});
|
|
342
365
|
|
|
343
366
|
// ../kit/src/style.ts
|
|
344
|
-
|
|
367
|
+
import process6 from "process";
|
|
345
368
|
function takesControlCodes(stream, env = process6.env) {
|
|
346
369
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
347
370
|
}
|
|
@@ -364,14 +387,6 @@ function role(name, stream, env = process6.env) {
|
|
|
364
387
|
const colors = paint(stream, env);
|
|
365
388
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
366
389
|
}
|
|
367
|
-
var STATUS_WORDS = {
|
|
368
|
-
passed: ["passed", "success", "succeeded", "ok"],
|
|
369
|
-
failed: ["failed", "failure", "error", "errored"],
|
|
370
|
-
running: ["running", "in_progress", "started", "holding"],
|
|
371
|
-
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
372
|
-
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
373
|
-
};
|
|
374
|
-
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
375
390
|
function header(bin, context, stream, env = process6.env) {
|
|
376
391
|
if (!takesControlCodes(stream, env))
|
|
377
392
|
return "";
|
|
@@ -382,9 +397,24 @@ function header(bin, context, stream, env = process6.env) {
|
|
|
382
397
|
const accent = tinted(typeof spec === "string" && spec.split(" ").includes("bold") ? colors : colors.bold, spec, env);
|
|
383
398
|
return `${accent(bin)}${context === undefined ? "" : colors.dim(` \u203A ${context}`)}`;
|
|
384
399
|
}
|
|
400
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
401
|
+
var init_style = __esm(() => {
|
|
402
|
+
init_colors();
|
|
403
|
+
init_mode();
|
|
404
|
+
init_theme();
|
|
405
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
406
|
+
STATUS_WORDS = {
|
|
407
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
408
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
409
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
410
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
411
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
412
|
+
};
|
|
413
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
414
|
+
});
|
|
385
415
|
|
|
386
416
|
// ../kit/src/format.ts
|
|
387
|
-
|
|
417
|
+
import process7 from "process";
|
|
388
418
|
function formatSeconds(total) {
|
|
389
419
|
let rest = Math.max(0, Math.round(total));
|
|
390
420
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -406,10 +436,8 @@ function upTo(text, separator) {
|
|
|
406
436
|
return end === -1 ? text : text.slice(0, end);
|
|
407
437
|
}
|
|
408
438
|
function truncate(text, width) {
|
|
409
|
-
return
|
|
439
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
410
440
|
}
|
|
411
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
412
|
-
var ESCAPE = String.fromCharCode(27);
|
|
413
441
|
function textWidth(text) {
|
|
414
442
|
return Bun.stringWidth(text);
|
|
415
443
|
}
|
|
@@ -458,14 +486,40 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
458
486
|
function printJson(value) {
|
|
459
487
|
console.log(jsonText(value));
|
|
460
488
|
}
|
|
489
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
490
|
+
var init_format = __esm(() => {
|
|
491
|
+
init_text();
|
|
492
|
+
init_mode();
|
|
493
|
+
init_style();
|
|
494
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
495
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
496
|
+
ESCAPE = String.fromCharCode(27);
|
|
497
|
+
});
|
|
461
498
|
|
|
462
499
|
// ../kit/src/help.ts
|
|
463
500
|
import process8 from "process";
|
|
464
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
465
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
466
|
-
var FULL_STOP = /\.$/;
|
|
467
501
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
468
|
-
|
|
502
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
503
|
+
`);
|
|
504
|
+
const blank = lines.indexOf("");
|
|
505
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
506
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
507
|
+
const colon = synopses[0].indexOf(": ");
|
|
508
|
+
const inline = synopses[0].slice(colon + 2);
|
|
509
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
510
|
+
if (colon !== -1)
|
|
511
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
512
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
513
|
+
`)}`;
|
|
514
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
515
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
516
|
+
return [head, ...lead, ...rest].join(`
|
|
517
|
+
`);
|
|
518
|
+
}
|
|
519
|
+
function prose(line, colors) {
|
|
520
|
+
if (colors.cyan("x") === "x")
|
|
521
|
+
return line;
|
|
522
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
469
523
|
}
|
|
470
524
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
471
525
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -500,7 +554,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
500
554
|
return [];
|
|
501
555
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
502
556
|
}
|
|
503
|
-
var MAX_INLINE_CHOICES = 24;
|
|
504
557
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
505
558
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
506
559
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -515,9 +568,17 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
515
568
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
516
569
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
517
570
|
}
|
|
571
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
572
|
+
var init_help = __esm(() => {
|
|
573
|
+
init_mode();
|
|
574
|
+
init_style();
|
|
575
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
576
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
577
|
+
FULL_STOP = /\.$/;
|
|
578
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
579
|
+
});
|
|
518
580
|
|
|
519
581
|
// ../kit/src/text.ts
|
|
520
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
521
582
|
function stripAnsi(text) {
|
|
522
583
|
return text.replace(ANSI, "");
|
|
523
584
|
}
|
|
@@ -546,10 +607,13 @@ function closest(name, names) {
|
|
|
546
607
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
547
608
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
548
609
|
}
|
|
610
|
+
var ANSI;
|
|
611
|
+
var init_text2 = __esm(() => {
|
|
612
|
+
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
613
|
+
});
|
|
614
|
+
|
|
549
615
|
// ../kit/src/input.ts
|
|
550
616
|
import process9 from "process";
|
|
551
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
552
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
553
617
|
function duration(value, name, fallback, unit = "s") {
|
|
554
618
|
if (value === undefined)
|
|
555
619
|
return fallback;
|
|
@@ -570,40 +634,26 @@ async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
|
570
634
|
fail(`no file ${path}`);
|
|
571
635
|
return file.text();
|
|
572
636
|
}
|
|
637
|
+
var DURATION, UNIT_MS;
|
|
638
|
+
var init_input = __esm(() => {
|
|
639
|
+
init_args();
|
|
640
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
641
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
642
|
+
});
|
|
573
643
|
|
|
574
644
|
// ../kit/src/args.ts
|
|
575
|
-
|
|
645
|
+
import process10 from "process";
|
|
646
|
+
import { parseArgs } from "util";
|
|
576
647
|
function jsonOption(holds) {
|
|
577
648
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
578
649
|
}
|
|
579
|
-
class Exit extends Error {
|
|
580
|
-
code;
|
|
581
|
-
hint;
|
|
582
|
-
constructor(message, code, hint) {
|
|
583
|
-
super(message);
|
|
584
|
-
this.code = code;
|
|
585
|
-
this.hint = hint;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
650
|
function fail(message, code = 2, hint) {
|
|
589
651
|
throw new Exit(message, code, hint);
|
|
590
652
|
}
|
|
591
|
-
|
|
592
|
-
class UsageError extends Exit {
|
|
593
|
-
constructor(message, hint) {
|
|
594
|
-
super(message, 2, hint);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
653
|
function badUsage(message) {
|
|
598
654
|
throw new UsageError(message);
|
|
599
655
|
}
|
|
600
656
|
|
|
601
|
-
class HelpShown extends Exit {
|
|
602
|
-
constructor() {
|
|
603
|
-
super("help shown", 0);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
657
|
class Completing {
|
|
608
658
|
options;
|
|
609
659
|
positionals;
|
|
@@ -614,11 +664,6 @@ class Completing {
|
|
|
614
664
|
this.candidates = candidates;
|
|
615
665
|
}
|
|
616
666
|
}
|
|
617
|
-
var completion = { active: false };
|
|
618
|
-
var OUTPUT_OPTIONS = {
|
|
619
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
620
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
621
|
-
};
|
|
622
667
|
function applyOutput(color, plain, env = process10.env) {
|
|
623
668
|
const when = plain === true ? "never" : color ?? "auto";
|
|
624
669
|
if (when === "auto")
|
|
@@ -772,7 +817,6 @@ function parseError(error) {
|
|
|
772
817
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
773
818
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
774
819
|
}
|
|
775
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
776
820
|
function nearestOption(message, options, allowNegative) {
|
|
777
821
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
778
822
|
if (typed === undefined)
|
|
@@ -788,1087 +832,1459 @@ function nearestOption(message, options, allowNegative) {
|
|
|
788
832
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
789
833
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
790
834
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
}
|
|
809
|
-
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
810
|
-
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
811
|
-
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
812
|
-
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
813
|
-
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
814
|
-
}
|
|
815
|
-
// ../kit/src/process.ts
|
|
816
|
-
import { constants } from "os";
|
|
817
|
-
import process12 from "process";
|
|
818
|
-
var KILL_GRACE_MS = 2000;
|
|
819
|
-
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
820
|
-
function exitCodeOf(code, signal) {
|
|
821
|
-
if (code !== null)
|
|
822
|
-
return code;
|
|
823
|
-
if (typeof signal === "number")
|
|
824
|
-
return 128 + signal;
|
|
825
|
-
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
826
|
-
}
|
|
827
|
-
function holdSignals(cleanup) {
|
|
828
|
-
let received;
|
|
829
|
-
let child;
|
|
830
|
-
const held = {
|
|
831
|
-
get signal() {
|
|
832
|
-
return received;
|
|
833
|
-
},
|
|
834
|
-
forward: (to) => {
|
|
835
|
-
child = to;
|
|
836
|
-
},
|
|
837
|
-
release: () => {
|
|
838
|
-
for (const signal of SIGNALS)
|
|
839
|
-
process12.off(signal, onSignal);
|
|
835
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
836
|
+
var init_args = __esm(() => {
|
|
837
|
+
init_format();
|
|
838
|
+
init_help();
|
|
839
|
+
init_text2();
|
|
840
|
+
init_help();
|
|
841
|
+
init_input();
|
|
842
|
+
DASHES = /^-+/;
|
|
843
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
844
|
+
Exit = class Exit extends Error {
|
|
845
|
+
code;
|
|
846
|
+
hint;
|
|
847
|
+
[EXIT] = true;
|
|
848
|
+
constructor(message, code, hint) {
|
|
849
|
+
super(message);
|
|
850
|
+
this.code = code;
|
|
851
|
+
this.hint = hint;
|
|
840
852
|
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
child.kill(signal);
|
|
846
|
-
return;
|
|
853
|
+
static [Symbol.hasInstance](value) {
|
|
854
|
+
if (this !== Exit)
|
|
855
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
856
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
847
857
|
}
|
|
848
|
-
if (cleanup === undefined)
|
|
849
|
-
return;
|
|
850
|
-
held.release();
|
|
851
|
-
cleanup(signal);
|
|
852
|
-
process12.kill(process12.pid, signal);
|
|
853
|
-
}
|
|
854
|
-
for (const signal of SIGNALS)
|
|
855
|
-
process12.on(signal, onSignal);
|
|
856
|
-
return held;
|
|
857
|
-
}
|
|
858
|
-
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
859
|
-
const chunks = [];
|
|
860
|
-
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
861
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
862
|
-
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
863
|
-
const timers = [];
|
|
864
|
-
const killGroup = (killing) => {
|
|
865
|
-
if (state.done)
|
|
866
|
-
return;
|
|
867
|
-
try {
|
|
868
|
-
if (grouped)
|
|
869
|
-
process12.kill(-proc.pid, killing);
|
|
870
|
-
else
|
|
871
|
-
proc.kill(killing);
|
|
872
|
-
} catch {}
|
|
873
|
-
};
|
|
874
|
-
const stop = () => {
|
|
875
|
-
killGroup("SIGTERM");
|
|
876
|
-
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
877
858
|
};
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
state.timedOut = true;
|
|
882
|
-
stop();
|
|
883
|
-
}, timeoutMs));
|
|
884
|
-
}
|
|
885
|
-
if (signal?.aborted === true)
|
|
886
|
-
onAbort();
|
|
887
|
-
else
|
|
888
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
889
|
-
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
890
|
-
const drain = async (stream, name) => {
|
|
891
|
-
for await (const data of stream) {
|
|
892
|
-
if (state.failure !== undefined)
|
|
893
|
-
continue;
|
|
894
|
-
try {
|
|
895
|
-
onChunk?.({ stream: name, data });
|
|
896
|
-
} catch (error) {
|
|
897
|
-
state.failure = error;
|
|
898
|
-
stop();
|
|
899
|
-
continue;
|
|
900
|
-
}
|
|
901
|
-
if (state.kept + data.length > maxBytes) {
|
|
902
|
-
state.truncated = true;
|
|
903
|
-
continue;
|
|
904
|
-
}
|
|
905
|
-
state.kept += data.length;
|
|
906
|
-
chunks.push({ stream: name, data });
|
|
859
|
+
UsageError = class UsageError extends Exit {
|
|
860
|
+
constructor(message, hint) {
|
|
861
|
+
super(message, 2, hint);
|
|
907
862
|
}
|
|
908
863
|
};
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
} finally {
|
|
913
|
-
state.done = true;
|
|
914
|
-
for (const timer of timers)
|
|
915
|
-
clearTimeout(timer);
|
|
916
|
-
signal?.removeEventListener("abort", onAbort);
|
|
917
|
-
}
|
|
918
|
-
if (state.failure !== undefined)
|
|
919
|
-
throw state.failure;
|
|
920
|
-
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
921
|
-
let output;
|
|
922
|
-
let text;
|
|
923
|
-
return {
|
|
924
|
-
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
925
|
-
chunks,
|
|
926
|
-
timedOut: state.timedOut,
|
|
927
|
-
truncated: state.truncated,
|
|
928
|
-
get output() {
|
|
929
|
-
return output ??= joined();
|
|
930
|
-
},
|
|
931
|
-
get text() {
|
|
932
|
-
return text ??= (output ??= joined()).toString();
|
|
864
|
+
HelpShown = class HelpShown extends Exit {
|
|
865
|
+
constructor() {
|
|
866
|
+
super("help shown", 0);
|
|
933
867
|
}
|
|
934
868
|
};
|
|
935
|
-
}
|
|
869
|
+
completion = { active: false };
|
|
870
|
+
OUTPUT_OPTIONS = {
|
|
871
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
872
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
873
|
+
};
|
|
874
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
875
|
+
});
|
|
936
876
|
|
|
937
|
-
// ../kit/src/
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
877
|
+
// ../kit/src/folders.ts
|
|
878
|
+
import { homedir as homedir5 } from "os";
|
|
879
|
+
import { join as join7 } from "path";
|
|
880
|
+
import process18 from "process";
|
|
881
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
882
|
+
const configured = readUserConfig("config", where).ignore;
|
|
883
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
884
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
885
|
+
}
|
|
886
|
+
function cacheFolder({ home = homedir5(), env = process18.env } = {}) {
|
|
887
|
+
return env.XDG_CACHE_HOME ?? join7(home, ".cache");
|
|
888
|
+
}
|
|
889
|
+
var SKIPPED_FOLDERS;
|
|
890
|
+
var init_folders = __esm(() => {
|
|
891
|
+
init_user_config();
|
|
892
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
893
|
+
});
|
|
946
894
|
|
|
947
|
-
// ../kit/src/
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
951
|
-
set -l current (commandline -ct)
|
|
952
|
-
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
953
|
-
if test "$line" = __files__
|
|
954
|
-
__fish_complete_path $current
|
|
955
|
-
else
|
|
956
|
-
echo $line
|
|
957
|
-
end
|
|
958
|
-
end
|
|
959
|
-
end`;
|
|
960
|
-
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
961
|
-
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
962
|
-
local -a lines
|
|
963
|
-
COMPREPLY=()
|
|
964
|
-
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
965
|
-
for line in "\${lines[@]}"; do
|
|
966
|
-
if [[ $line == __files__ ]]; then
|
|
967
|
-
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
968
|
-
else
|
|
969
|
-
words+="\${line%%$'\\t'*}"$'\\n'
|
|
970
|
-
fi
|
|
971
|
-
done
|
|
972
|
-
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
973
|
-
}`;
|
|
974
|
-
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
975
|
-
local line
|
|
976
|
-
local -a described plain
|
|
977
|
-
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
978
|
-
if [[ $line == __files__ ]]; then
|
|
979
|
-
_files
|
|
980
|
-
elif [[ $line == *$'\\t'* ]]; then
|
|
981
|
-
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
982
|
-
else
|
|
983
|
-
plain+=("$line")
|
|
984
|
-
fi
|
|
985
|
-
done
|
|
986
|
-
(( \${#described} )) && _describe -V value described
|
|
987
|
-
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
988
|
-
return 0
|
|
989
|
-
}`;
|
|
990
|
-
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
991
|
-
if (shell === "fish")
|
|
992
|
-
return `${header}
|
|
993
|
-
${FISH_FUNCTION}
|
|
994
|
-
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
995
|
-
`).join("")}`;
|
|
996
|
-
if (shell === "bash")
|
|
997
|
-
return `${header}
|
|
998
|
-
${BASH_FUNCTION}
|
|
999
|
-
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1000
|
-
`;
|
|
1001
|
-
return `${header}
|
|
1002
|
-
${ZSH_FUNCTION}
|
|
1003
|
-
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1004
|
-
`;
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
// ../kit/src/notify.ts
|
|
1008
|
-
import process13 from "process";
|
|
1009
|
-
var NOTIFY_AFTER_MS = 1e4;
|
|
1010
|
-
var CANCELLED = 130;
|
|
1011
|
-
function base64(text) {
|
|
1012
|
-
return Buffer.from(text).toString("base64");
|
|
895
|
+
// ../kit/src/picker/line.ts
|
|
896
|
+
function isEditKey(key) {
|
|
897
|
+
return EDIT_KEYS.has(key);
|
|
1013
898
|
}
|
|
1014
|
-
function
|
|
1015
|
-
|
|
1016
|
-
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
1017
|
-
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
899
|
+
function endsKills(key) {
|
|
900
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
1018
901
|
}
|
|
1019
|
-
function
|
|
1020
|
-
|
|
1021
|
-
return;
|
|
1022
|
-
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
902
|
+
function isWord(char) {
|
|
903
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
1023
904
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
// ../kit/src/logs.ts
|
|
1032
|
-
import { lstatSync, openSync } from "fs";
|
|
1033
|
-
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
1034
|
-
import { homedir as homedir3, tmpdir } from "os";
|
|
1035
|
-
import { join as join4 } from "path";
|
|
1036
|
-
import process14 from "process";
|
|
1037
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1038
|
-
var CLI_FOLDER = "kaynooo-cli";
|
|
1039
|
-
function isPrivateDirectory(path) {
|
|
1040
|
-
try {
|
|
1041
|
-
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
1042
|
-
return info !== undefined && info.isDirectory() && info.uid === (process14.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
1043
|
-
} catch {
|
|
1044
|
-
return false;
|
|
1045
|
-
}
|
|
905
|
+
function wordStart(chars, from) {
|
|
906
|
+
let at = from;
|
|
907
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
908
|
+
at--;
|
|
909
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
910
|
+
at--;
|
|
911
|
+
return at;
|
|
1046
912
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
return path;
|
|
1055
|
-
} catch {}
|
|
1056
|
-
return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
913
|
+
function wordEnd(chars, from) {
|
|
914
|
+
let at = from;
|
|
915
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
916
|
+
at++;
|
|
917
|
+
while (at < chars.length && isWord(chars[at]))
|
|
918
|
+
at++;
|
|
919
|
+
return at;
|
|
1057
920
|
}
|
|
1058
|
-
|
|
1059
|
-
let
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
for (const name of names) {
|
|
1066
|
-
const path = join4(dir, name);
|
|
1067
|
-
try {
|
|
1068
|
-
const info = await stat(path);
|
|
1069
|
-
if (info.isDirectory())
|
|
1070
|
-
await sweepLogs(path, maxAgeMs, now);
|
|
1071
|
-
if (now - info.mtimeMs > maxAgeMs)
|
|
1072
|
-
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
1073
|
-
} catch {
|
|
1074
|
-
continue;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
921
|
+
function spacedStart(chars, from) {
|
|
922
|
+
let at = from;
|
|
923
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
924
|
+
at--;
|
|
925
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
926
|
+
at--;
|
|
927
|
+
return at;
|
|
1077
928
|
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1081
|
-
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1082
|
-
var LONGEST_NAME = 40;
|
|
1083
|
-
var usageError;
|
|
1084
|
-
function noteUsageError(message) {
|
|
1085
|
-
usageError = message;
|
|
929
|
+
function cut2(chars, from, to) {
|
|
930
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
1086
931
|
}
|
|
1087
|
-
function
|
|
1088
|
-
const
|
|
1089
|
-
return
|
|
932
|
+
function insert(chars, at, text) {
|
|
933
|
+
const typed = [...text];
|
|
934
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
1090
935
|
}
|
|
1091
|
-
function
|
|
1092
|
-
|
|
936
|
+
function editLine(line, key) {
|
|
937
|
+
const { killed = "", chained = false } = line;
|
|
938
|
+
const chars = [...line.text];
|
|
939
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
940
|
+
const edited = edit(chars, at, key, killed);
|
|
941
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
942
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
943
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
944
|
+
if (taken === "")
|
|
945
|
+
return { ...edited, killed, chained };
|
|
946
|
+
if (!chained)
|
|
947
|
+
return { ...edited, killed: taken, chained: true };
|
|
948
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
1093
949
|
}
|
|
1094
|
-
function
|
|
1095
|
-
const
|
|
1096
|
-
|
|
950
|
+
function edit(chars, at, key, killed) {
|
|
951
|
+
const text = chars.join("");
|
|
952
|
+
if (typeof key === "object")
|
|
953
|
+
return insert(chars, at, key.text);
|
|
954
|
+
switch (key) {
|
|
955
|
+
case "left":
|
|
956
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
957
|
+
case "right":
|
|
958
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
959
|
+
case "wordleft":
|
|
960
|
+
return { text, caret: wordStart(chars, at) };
|
|
961
|
+
case "wordright":
|
|
962
|
+
return { text, caret: wordEnd(chars, at) };
|
|
963
|
+
case "linestart":
|
|
964
|
+
return { text, caret: 0 };
|
|
965
|
+
case "lineend":
|
|
966
|
+
return { text, caret: chars.length };
|
|
967
|
+
case "erase":
|
|
968
|
+
return cut2(chars, Math.max(at - 1, 0), at);
|
|
969
|
+
case "delete":
|
|
970
|
+
return cut2(chars, at, Math.min(at + 1, chars.length));
|
|
971
|
+
case "word":
|
|
972
|
+
return cut2(chars, spacedStart(chars, at), at);
|
|
973
|
+
case "killword":
|
|
974
|
+
return cut2(chars, wordStart(chars, at), at);
|
|
975
|
+
case "killnext":
|
|
976
|
+
return cut2(chars, at, wordEnd(chars, at));
|
|
977
|
+
case "clear":
|
|
978
|
+
return cut2(chars, 0, at);
|
|
979
|
+
case "killend":
|
|
980
|
+
return cut2(chars, at, chars.length);
|
|
981
|
+
case "yank":
|
|
982
|
+
return insert(chars, at, killed);
|
|
983
|
+
}
|
|
1097
984
|
}
|
|
1098
|
-
function
|
|
1099
|
-
const
|
|
1100
|
-
const
|
|
1101
|
-
|
|
985
|
+
function visible({ text, caret }, room) {
|
|
986
|
+
const chars = [...text];
|
|
987
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
988
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
989
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
990
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
991
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
992
|
+
let start = at;
|
|
993
|
+
let end = at + 1;
|
|
994
|
+
while (start > 0 && fits(start - 1, end))
|
|
995
|
+
start--;
|
|
996
|
+
while (end < cells.length && fits(start, end + 1))
|
|
997
|
+
end++;
|
|
998
|
+
const left = start > 0 ? "\u2026" : "";
|
|
999
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
1000
|
+
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
1102
1001
|
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1002
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
|
|
1003
|
+
var init_line = __esm(() => {
|
|
1004
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1005
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1006
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1007
|
+
WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
1008
|
+
SPACE = /\s/;
|
|
1009
|
+
});
|
|
1010
|
+
|
|
1011
|
+
// ../kit/src/picker/score.ts
|
|
1012
|
+
function startsWord(text, index) {
|
|
1013
|
+
if (index === 0)
|
|
1014
|
+
return true;
|
|
1015
|
+
const before = text[index - 1];
|
|
1016
|
+
return BOUNDARY_AFTER.has(before) || LOWER.test(before) && UPPER.test(text[index]);
|
|
1107
1017
|
}
|
|
1108
|
-
function
|
|
1109
|
-
if (
|
|
1018
|
+
function fuzzy(query, text) {
|
|
1019
|
+
if (query === "")
|
|
1020
|
+
return { score: 0, positions: [] };
|
|
1021
|
+
const exact = query !== query.toLowerCase();
|
|
1022
|
+
const needle = exact ? query : query.toLowerCase();
|
|
1023
|
+
const haystack = exact ? text : text.toLowerCase();
|
|
1024
|
+
if (haystack.length !== text.length || needle.length > haystack.length)
|
|
1110
1025
|
return;
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1026
|
+
const width = haystack.length;
|
|
1027
|
+
const best = Array.from({ length: needle.length }, () => new Array(width).fill(NONE));
|
|
1028
|
+
const from = Array.from({ length: needle.length }, () => new Array(width).fill(-1));
|
|
1029
|
+
for (let j = 0;j < needle.length; j++) {
|
|
1030
|
+
let run = NONE;
|
|
1031
|
+
let runAt = -1;
|
|
1032
|
+
for (let i = j;i < width; i++) {
|
|
1033
|
+
if (j > 0 && i - 2 >= j - 1) {
|
|
1034
|
+
const candidate = best[j - 1][i - 2] + (i - 2) * GAP;
|
|
1035
|
+
if (candidate > run) {
|
|
1036
|
+
run = candidate;
|
|
1037
|
+
runAt = i - 2;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
if (haystack[i] !== needle[j])
|
|
1041
|
+
continue;
|
|
1042
|
+
const here = MATCH + (startsWord(text, i) ? BOUNDARY2 : 0) + (i === 0 ? PREFIX : 0);
|
|
1043
|
+
if (j === 0) {
|
|
1044
|
+
best[0][i] = here - i * GAP;
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
1047
|
+
const joined = best[j - 1][i - 1] + CONSECUTIVE;
|
|
1048
|
+
const skipped = run - (i - 1) * GAP;
|
|
1049
|
+
if (joined > NONE && joined >= skipped) {
|
|
1050
|
+
best[j][i] = joined + here;
|
|
1051
|
+
from[j][i] = i - 1;
|
|
1052
|
+
} else if (skipped > NONE) {
|
|
1053
|
+
best[j][i] = skipped + here;
|
|
1054
|
+
from[j][i] = runAt;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
const last = best[needle.length - 1];
|
|
1059
|
+
let end = -1;
|
|
1060
|
+
for (let i = 0;i < width; i++) {
|
|
1061
|
+
if (last[i] > NONE && (end === -1 || last[i] > last[end]))
|
|
1062
|
+
end = i;
|
|
1063
|
+
}
|
|
1064
|
+
if (end === -1)
|
|
1065
|
+
return;
|
|
1066
|
+
const positions = [];
|
|
1067
|
+
for (let j = needle.length - 1, i = end;j >= 0; j--) {
|
|
1068
|
+
positions.unshift(i);
|
|
1069
|
+
i = from[j][i];
|
|
1070
|
+
}
|
|
1071
|
+
return { score: last[end], positions };
|
|
1117
1072
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
};
|
|
1129
|
-
function printError(prefix, message, hint, cause) {
|
|
1130
|
-
const colors = paint(process16.stderr);
|
|
1131
|
-
const styled = takesControlCodes(process16.stderr);
|
|
1132
|
-
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1133
|
-
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1134
|
-
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
1135
|
-
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1136
|
-
}
|
|
1137
|
-
function printJsonError(message, hint, cause) {
|
|
1138
|
-
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
1139
|
-
}
|
|
1140
|
-
function wantsJson(argv) {
|
|
1141
|
-
const end = argv.indexOf("--");
|
|
1142
|
-
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
1073
|
+
function rank(query, lines) {
|
|
1074
|
+
if (query === "")
|
|
1075
|
+
return lines.map((_, index) => ({ index, positions: [] }));
|
|
1076
|
+
const found = [];
|
|
1077
|
+
for (const [index, line] of lines.entries()) {
|
|
1078
|
+
const match = fuzzy(query, line);
|
|
1079
|
+
if (match !== undefined)
|
|
1080
|
+
found.push({ index, positions: match.positions, score: match.score });
|
|
1081
|
+
}
|
|
1082
|
+
return found.sort((a, b) => b.score - a.score || lines[a.index].length - lines[b.index].length || a.index - b.index);
|
|
1143
1083
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
return
|
|
1084
|
+
var MATCH = 16, CONSECUTIVE = 12, BOUNDARY2 = 10, PREFIX = 8, GAP = 1, BOUNDARY_AFTER, UPPER, LOWER, NONE;
|
|
1085
|
+
var init_score = __esm(() => {
|
|
1086
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1087
|
+
UPPER = /\p{Lu}/u;
|
|
1088
|
+
LOWER = /\p{Ll}/u;
|
|
1089
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
// ../kit/src/picker/state.ts
|
|
1093
|
+
function repeat(value, count) {
|
|
1094
|
+
return Array.from({ length: count }).fill(value);
|
|
1155
1095
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1096
|
+
function styled(line) {
|
|
1097
|
+
let text = "";
|
|
1098
|
+
const styles = [];
|
|
1099
|
+
let active = "";
|
|
1100
|
+
let colored = false;
|
|
1101
|
+
let last = 0;
|
|
1102
|
+
function add(chunk) {
|
|
1103
|
+
const flat = chunk.replace(CONTROL2, " ");
|
|
1104
|
+
text += flat;
|
|
1105
|
+
colored ||= active !== "" && flat !== "";
|
|
1106
|
+
styles.push(...repeat(active, flat.length));
|
|
1167
1107
|
}
|
|
1168
|
-
|
|
1108
|
+
for (const found of line.matchAll(ANSI)) {
|
|
1109
|
+
add(line.slice(last, found.index));
|
|
1110
|
+
last = found.index + found[0].length;
|
|
1111
|
+
if (SGR.test(found[0]))
|
|
1112
|
+
active = RESET.test(found[0]) ? "" : active + found[0];
|
|
1113
|
+
}
|
|
1114
|
+
add(line.slice(last));
|
|
1115
|
+
return { text, styles: colored ? styles : undefined };
|
|
1169
1116
|
}
|
|
1170
|
-
function
|
|
1171
|
-
|
|
1117
|
+
function lay(rows, searched) {
|
|
1118
|
+
const parsed = rows.map((row) => row.cells.map(styled));
|
|
1119
|
+
const widths = (parsed[0] ?? []).map((_, column) => Math.max(...parsed.map((cells) => Bun.stringWidth(cells[column]?.text ?? ""))));
|
|
1120
|
+
return parsed.map((cells, at) => {
|
|
1121
|
+
let text = "";
|
|
1122
|
+
const styles = [];
|
|
1123
|
+
let colored = false;
|
|
1124
|
+
let searchEnd = 0;
|
|
1125
|
+
for (const [column, cell] of cells.entries()) {
|
|
1126
|
+
const last = column === cells.length - 1;
|
|
1127
|
+
const shown = cells.length > 1 && last ? cell.text.trimEnd() : cell.text;
|
|
1128
|
+
text += shown;
|
|
1129
|
+
colored ||= cell.styles !== undefined;
|
|
1130
|
+
styles.push(...cell.styles?.slice(0, shown.length) ?? repeat("", shown.length));
|
|
1131
|
+
if (column < searched)
|
|
1132
|
+
searchEnd = cells.length > 1 ? text.trimEnd().length : text.length;
|
|
1133
|
+
if (!last) {
|
|
1134
|
+
const pad = widths[column] - Bun.stringWidth(cell.text) + COLUMN_GAP;
|
|
1135
|
+
text += " ".repeat(pad);
|
|
1136
|
+
styles.push(...repeat("", pad));
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
return { text, styles: colored ? styles : undefined, searchable: rows[at].search ?? text.slice(0, searchEnd) };
|
|
1140
|
+
});
|
|
1172
1141
|
}
|
|
1173
|
-
function
|
|
1174
|
-
const
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1142
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1143
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1144
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1145
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1146
|
+
if (wheel !== undefined)
|
|
1147
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1148
|
+
const named = codes.get(sequence);
|
|
1149
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1150
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1151
|
+
paste.active = sequence === PASTE_START;
|
|
1152
|
+
return [];
|
|
1182
1153
|
}
|
|
1183
|
-
if (
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
if (typed.length < positionals.length)
|
|
1191
|
-
return { name: positionals[typed.length], typed };
|
|
1192
|
-
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1154
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
1155
|
+
`))
|
|
1156
|
+
return [];
|
|
1157
|
+
if (key !== undefined)
|
|
1158
|
+
return [key];
|
|
1159
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1160
|
+
});
|
|
1193
1161
|
}
|
|
1194
|
-
|
|
1195
|
-
const
|
|
1196
|
-
|
|
1197
|
-
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1198
|
-
const flag = words.at(-2);
|
|
1199
|
-
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1200
|
-
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1201
|
-
if (option?.type === "string") {
|
|
1202
|
-
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1203
|
-
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1204
|
-
}
|
|
1205
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1206
|
-
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1162
|
+
function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
|
|
1163
|
+
const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, caret: [...query].length, killed: "", chained: false, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
|
|
1164
|
+
return withRows(state, rows);
|
|
1207
1165
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1166
|
+
function withRows(state, rows, header = state.header) {
|
|
1167
|
+
const cells = rows.map((row) => typeof row === "string" ? { hidden: [], cells: [row] } : row);
|
|
1168
|
+
const laid = lay(cells, state.searched);
|
|
1169
|
+
const searchable = laid.map((row) => row.searchable);
|
|
1170
|
+
const matches = rank(state.query, searchable);
|
|
1171
|
+
return { ...state, rows: cells, items: laid.map((row) => row.text), styles: laid.map((row) => row.styles), searchable, header, matches, cursor: Math.max(0, Math.min(matches.length - 1, state.cursor)), marked: new Set };
|
|
1211
1172
|
}
|
|
1212
|
-
function
|
|
1213
|
-
const
|
|
1214
|
-
|
|
1215
|
-
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1216
|
-
return 2;
|
|
1217
|
-
}
|
|
1218
|
-
console.log(completionScript(shell, [name]).trimEnd());
|
|
1219
|
-
return 0;
|
|
1173
|
+
function withQuery(state, key) {
|
|
1174
|
+
const { text, caret, killed = "", chained = false } = editLine({ text: state.query, caret: state.caret, killed: state.killed, chained: state.chained }, key);
|
|
1175
|
+
return text === state.query ? { ...state, caret, killed, chained } : { ...state, query: text, caret, killed, chained, matches: rank(text, state.searchable), cursor: 0 };
|
|
1220
1176
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
console.log(line);
|
|
1224
|
-
return 0;
|
|
1177
|
+
function move(state, by) {
|
|
1178
|
+
return { ...state, cursor: Math.max(0, Math.min(state.matches.length - 1, state.cursor + by)) };
|
|
1225
1179
|
}
|
|
1226
|
-
function
|
|
1227
|
-
|
|
1228
|
-
try {
|
|
1229
|
-
resolved = realpathSync2(entry);
|
|
1230
|
-
} catch {}
|
|
1231
|
-
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1232
|
-
try {
|
|
1233
|
-
const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
|
|
1234
|
-
if (typeof version === "string")
|
|
1235
|
-
return version;
|
|
1236
|
-
} catch {}
|
|
1237
|
-
if (dirname3(dir) === dir)
|
|
1238
|
-
return "0.0.0";
|
|
1239
|
-
}
|
|
1180
|
+
function highlighted(state) {
|
|
1181
|
+
return state.matches[state.cursor]?.index;
|
|
1240
1182
|
}
|
|
1241
|
-
|
|
1242
|
-
if (
|
|
1243
|
-
return
|
|
1244
|
-
if (
|
|
1245
|
-
|
|
1246
|
-
if (
|
|
1247
|
-
|
|
1248
|
-
|
|
1183
|
+
function press(state, key) {
|
|
1184
|
+
if (state.done !== undefined)
|
|
1185
|
+
return state;
|
|
1186
|
+
if (state.chained && endsKills(key))
|
|
1187
|
+
state = { ...state, chained: false };
|
|
1188
|
+
if (state.help)
|
|
1189
|
+
return { ...state, help: false };
|
|
1190
|
+
if (typeof key === "object") {
|
|
1191
|
+
if ("text" in key)
|
|
1192
|
+
return withQuery(state, key);
|
|
1193
|
+
return state.expect.includes(key.ctrl) ? { ...state, done: "accept", key: key.ctrl } : state;
|
|
1249
1194
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1195
|
+
if (isEditKey(key))
|
|
1196
|
+
return withQuery(state, key);
|
|
1197
|
+
switch (key) {
|
|
1198
|
+
case "up":
|
|
1199
|
+
return move(state, -1);
|
|
1200
|
+
case "down":
|
|
1201
|
+
return move(state, 1);
|
|
1202
|
+
case "pageup":
|
|
1203
|
+
return move(state, -state.page);
|
|
1204
|
+
case "pagedown":
|
|
1205
|
+
return move(state, state.page);
|
|
1206
|
+
case "home":
|
|
1207
|
+
return move(state, -state.matches.length);
|
|
1208
|
+
case "end":
|
|
1209
|
+
return move(state, state.matches.length);
|
|
1210
|
+
case "cancel":
|
|
1211
|
+
return { ...state, done: "cancel" };
|
|
1212
|
+
case "help":
|
|
1213
|
+
return { ...state, help: true };
|
|
1214
|
+
case "suspend":
|
|
1215
|
+
return state;
|
|
1216
|
+
case "enter":
|
|
1217
|
+
return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
|
|
1218
|
+
case "tab": {
|
|
1219
|
+
const at = highlighted(state);
|
|
1220
|
+
if (!state.multi || at === undefined)
|
|
1221
|
+
return state;
|
|
1222
|
+
const marked = new Set(state.marked);
|
|
1223
|
+
if (!marked.delete(at))
|
|
1224
|
+
marked.add(at);
|
|
1225
|
+
return move({ ...state, marked }, 1);
|
|
1226
|
+
}
|
|
1256
1227
|
}
|
|
1257
|
-
notifyEnd(name, code, performance.now() - started);
|
|
1258
|
-
if (usage !== false) {
|
|
1259
|
-
try {
|
|
1260
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1261
|
-
} catch {}
|
|
1262
|
-
}
|
|
1263
|
-
return code;
|
|
1264
1228
|
}
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
1271
|
-
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
1272
|
-
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1273
|
-
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
1274
|
-
var TSC_ERROR = /\berror TS\d+/;
|
|
1275
|
-
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
1276
|
-
var TSC_FRAME = /^\s*[~^|]/;
|
|
1277
|
-
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
1278
|
-
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
1279
|
-
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
1280
|
-
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
1281
|
-
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
1282
|
-
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
1283
|
-
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
1284
|
-
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
1285
|
-
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
1286
|
-
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
1287
|
-
var MAX_TESTS = 10;
|
|
1288
|
-
var MAX_LINES = 100;
|
|
1289
|
-
var TAIL = 30;
|
|
1290
|
-
var bunTest = (lines) => {
|
|
1291
|
-
const seen = new Set;
|
|
1292
|
-
const blocks = [];
|
|
1293
|
-
for (const [index, line] of lines.entries()) {
|
|
1294
|
-
const name = line.replace(DURATION2, "");
|
|
1295
|
-
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
1296
|
-
continue;
|
|
1297
|
-
seen.add(name);
|
|
1298
|
-
if (blocks.length < MAX_TESTS)
|
|
1299
|
-
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
1300
|
-
`).trim());
|
|
1301
|
-
}
|
|
1302
|
-
if (blocks.length === 0)
|
|
1303
|
-
return;
|
|
1304
|
-
if (seen.size > MAX_TESTS)
|
|
1305
|
-
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
1306
|
-
return [...blocks.join(`
|
|
1307
|
-
|
|
1308
|
-
`).split(`
|
|
1309
|
-
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
1310
|
-
};
|
|
1311
|
-
var bunCheck = (lines) => {
|
|
1312
|
-
const text = lines.join(`
|
|
1313
|
-
`);
|
|
1314
|
-
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
1315
|
-
if (blocks === null)
|
|
1316
|
-
return;
|
|
1317
|
-
const errors = blocks.map((block) => {
|
|
1318
|
-
const { file, line, column, code, message } = bunCheckFields(block);
|
|
1319
|
-
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
1320
|
-
});
|
|
1321
|
-
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
1322
|
-
};
|
|
1323
|
-
function bunCheckFields(block) {
|
|
1324
|
-
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
1325
|
-
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
1326
|
-
return {
|
|
1327
|
-
file: attributes.file ?? "",
|
|
1328
|
-
line: attributes.line ?? "",
|
|
1329
|
-
column: attributes.column ?? "",
|
|
1330
|
-
code: attributes.code ?? "",
|
|
1331
|
-
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
1332
|
-
`).slice(1, -1).join(`
|
|
1333
|
-
`).trim()
|
|
1334
|
-
};
|
|
1229
|
+
function chosen(state) {
|
|
1230
|
+
if (state.marked.size > 0)
|
|
1231
|
+
return state.rows.filter((_, index) => state.marked.has(index));
|
|
1232
|
+
const at = highlighted(state);
|
|
1233
|
+
return at === undefined ? [] : [state.rows[at]];
|
|
1335
1234
|
}
|
|
1336
|
-
var
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
out.pop();
|
|
1402
|
-
return out;
|
|
1235
|
+
var CONTROL2, IS_CONTROL, SGR, RESET, COLUMN_GAP = 2, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS, CTRL_KEY;
|
|
1236
|
+
var init_state = __esm(() => {
|
|
1237
|
+
init_text2();
|
|
1238
|
+
init_line();
|
|
1239
|
+
init_score();
|
|
1240
|
+
CONTROL2 = /[\x00-\x1F\x7F-\x9F]/g;
|
|
1241
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1242
|
+
SGR = /^\x1B\[[0-9;]*m$/;
|
|
1243
|
+
RESET = /^\x1B\[0?m$/;
|
|
1244
|
+
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1245
|
+
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1246
|
+
KEYS = {
|
|
1247
|
+
"\x1B[A": "up",
|
|
1248
|
+
"\x1BOA": "up",
|
|
1249
|
+
"\x10": "up",
|
|
1250
|
+
"\x1B[B": "down",
|
|
1251
|
+
"\x1BOB": "down",
|
|
1252
|
+
"\x0E": "down",
|
|
1253
|
+
"\x1B[5~": "pageup",
|
|
1254
|
+
"\x1B[6~": "pagedown",
|
|
1255
|
+
"\x1B[H": "home",
|
|
1256
|
+
"\x1B[1~": "home",
|
|
1257
|
+
"\x1BOH": "home",
|
|
1258
|
+
"\x1B[F": "end",
|
|
1259
|
+
"\x1B[4~": "end",
|
|
1260
|
+
"\x1BOF": "end",
|
|
1261
|
+
"\r": "enter",
|
|
1262
|
+
"\n": "enter",
|
|
1263
|
+
"\x03": "cancel",
|
|
1264
|
+
"\x1B": "cancel",
|
|
1265
|
+
"\x1B[D": "left",
|
|
1266
|
+
"\x1BOD": "left",
|
|
1267
|
+
"\x1B[C": "right",
|
|
1268
|
+
"\x1BOC": "right",
|
|
1269
|
+
"\x1B[1;5D": "wordleft",
|
|
1270
|
+
"\x1B[1;3D": "wordleft",
|
|
1271
|
+
"\x1Bb": "wordleft",
|
|
1272
|
+
"\x1B[1;5C": "wordright",
|
|
1273
|
+
"\x1B[1;3C": "wordright",
|
|
1274
|
+
"\x1Bf": "wordright",
|
|
1275
|
+
"\x01": "linestart",
|
|
1276
|
+
"\x05": "lineend",
|
|
1277
|
+
"\x7F": "erase",
|
|
1278
|
+
"\x1B[3~": "delete",
|
|
1279
|
+
"\b": "killword",
|
|
1280
|
+
"\x1B\x7F": "killword",
|
|
1281
|
+
"\x1B[3;5~": "killnext",
|
|
1282
|
+
"\x1Bd": "killnext",
|
|
1283
|
+
"\x15": "clear",
|
|
1284
|
+
"\v": "killend",
|
|
1285
|
+
"\x17": "word",
|
|
1286
|
+
"\x19": "yank",
|
|
1287
|
+
"\x1A": "suspend",
|
|
1288
|
+
"\t": "tab",
|
|
1289
|
+
"\x1F": "help",
|
|
1290
|
+
"\x1BOP": "help",
|
|
1291
|
+
"\x1B[11~": "help"
|
|
1292
|
+
};
|
|
1293
|
+
CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1296
|
+
// ../kit/src/job.ts
|
|
1297
|
+
import process20 from "process";
|
|
1298
|
+
function stopJob() {
|
|
1299
|
+
process20.kill(0, "SIGTSTP");
|
|
1403
1300
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1301
|
+
var init_job = () => {};
|
|
1302
|
+
|
|
1303
|
+
// ../kit/src/redraw.ts
|
|
1304
|
+
function overwrite(lines, columns) {
|
|
1305
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1407
1306
|
`);
|
|
1408
1307
|
}
|
|
1409
|
-
function
|
|
1410
|
-
return
|
|
1308
|
+
function rowsTaken(lines, columns) {
|
|
1309
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1411
1310
|
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1311
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
1312
|
+
var init_redraw = __esm(() => {
|
|
1313
|
+
init_format();
|
|
1314
|
+
});
|
|
1315
|
+
|
|
1316
|
+
// ../kit/src/answers.ts
|
|
1317
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync2 } from "fs";
|
|
1318
|
+
import { dirname as dirname5, join as join9 } from "path";
|
|
1319
|
+
function answersFile() {
|
|
1320
|
+
return join9(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
1418
1321
|
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1322
|
+
function stored() {
|
|
1323
|
+
try {
|
|
1324
|
+
const parsed = JSON.parse(readFileSync6(answersFile(), "utf-8"));
|
|
1325
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
1326
|
+
return {};
|
|
1327
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
1328
|
+
} catch {
|
|
1329
|
+
return {};
|
|
1330
|
+
}
|
|
1429
1331
|
}
|
|
1430
|
-
function
|
|
1431
|
-
return
|
|
1332
|
+
function earlierAnswers(key) {
|
|
1333
|
+
return stored()[key] ?? [];
|
|
1432
1334
|
}
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
1447
|
-
import { dirname as dirname4, join as join8 } from "path";
|
|
1448
|
-
import process22 from "process";
|
|
1335
|
+
function rememberAnswer(key, answer) {
|
|
1336
|
+
const all = stored();
|
|
1337
|
+
const file = answersFile();
|
|
1338
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
1339
|
+
try {
|
|
1340
|
+
mkdirSync3(dirname5(file), { recursive: true });
|
|
1341
|
+
writeFileSync2(file, JSON.stringify(all));
|
|
1342
|
+
} catch {}
|
|
1343
|
+
}
|
|
1344
|
+
var KEPT = 50;
|
|
1345
|
+
var init_answers = __esm(() => {
|
|
1346
|
+
init_folders();
|
|
1347
|
+
});
|
|
1449
1348
|
|
|
1450
|
-
// ../kit/src/
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
function isEditKey(key) {
|
|
1455
|
-
return EDIT_KEYS.has(key);
|
|
1349
|
+
// ../kit/src/prompt.ts
|
|
1350
|
+
import process24 from "process";
|
|
1351
|
+
function readKeys(input, paste = { active: false }) {
|
|
1352
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1456
1353
|
}
|
|
1457
|
-
function
|
|
1458
|
-
return
|
|
1354
|
+
function roomAfter(question, columns) {
|
|
1355
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
1459
1356
|
}
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
return
|
|
1357
|
+
function withCaret(colors, line, room, dim = false) {
|
|
1358
|
+
const { before, at, after } = visible(line, room);
|
|
1359
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
1360
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
1464
1361
|
}
|
|
1465
|
-
function
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1362
|
+
function sharedStart(texts) {
|
|
1363
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
1364
|
+
let length = first.length;
|
|
1365
|
+
for (const chars of rest) {
|
|
1366
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
1367
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
1368
|
+
}
|
|
1369
|
+
return first.slice(0, length).join("");
|
|
1472
1370
|
}
|
|
1473
|
-
function
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
return at;
|
|
1371
|
+
function listed2(colors, found, columns) {
|
|
1372
|
+
const shared = sharedStart(found);
|
|
1373
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
1374
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
1375
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
1376
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
1480
1377
|
}
|
|
1481
|
-
function
|
|
1482
|
-
let
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1378
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
1379
|
+
let line = { text: "", caret: 0 };
|
|
1380
|
+
let invalid;
|
|
1381
|
+
let completions = [];
|
|
1382
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
1383
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
1384
|
+
let recalled = -1;
|
|
1385
|
+
let draft = line;
|
|
1386
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
1387
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
1388
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
1389
|
+
if (state !== "asking")
|
|
1390
|
+
return [answer(colors, question, state, shown())];
|
|
1391
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
1392
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
1393
|
+
}, (key) => {
|
|
1394
|
+
if (key === "cancel")
|
|
1395
|
+
return "cancel";
|
|
1396
|
+
invalid = undefined;
|
|
1397
|
+
completions = [];
|
|
1398
|
+
if (line.chained === true && endsKills(key))
|
|
1399
|
+
line = { ...line, chained: false };
|
|
1400
|
+
if (key === "tab") {
|
|
1401
|
+
const chars = [...line.text];
|
|
1402
|
+
const before = chars.slice(0, line.caret).join("");
|
|
1403
|
+
const found = complete?.(before) ?? [];
|
|
1404
|
+
const filled = sharedStart(found);
|
|
1405
|
+
if ([...filled].length > [...before].length)
|
|
1406
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
1407
|
+
else
|
|
1408
|
+
completions = found;
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
if (key === "enter") {
|
|
1412
|
+
invalid = validate?.(taken());
|
|
1413
|
+
return invalid === undefined ? "enter" : undefined;
|
|
1414
|
+
}
|
|
1415
|
+
if (key === "up" || key === "down") {
|
|
1416
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
1417
|
+
if (recalled === -1)
|
|
1418
|
+
draft = line;
|
|
1419
|
+
recalled = to;
|
|
1420
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
1421
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
1425
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
1426
|
+
line = editLine(line, edit);
|
|
1427
|
+
return;
|
|
1428
|
+
});
|
|
1429
|
+
if (!accepted)
|
|
1430
|
+
return;
|
|
1431
|
+
if (remembered !== undefined && taken() !== "")
|
|
1432
|
+
rememberAnswer(remembered, taken());
|
|
1433
|
+
return taken();
|
|
1488
1434
|
}
|
|
1489
|
-
function
|
|
1490
|
-
return
|
|
1435
|
+
function answer(colors, question, state, picked) {
|
|
1436
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1491
1437
|
}
|
|
1492
|
-
function
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1438
|
+
async function ask(question, { hint, terminal = process24 }, render, press) {
|
|
1439
|
+
const { stdin, stderr } = terminal;
|
|
1440
|
+
if (!isInteractive(terminal))
|
|
1441
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1442
|
+
const colors = paint(stderr);
|
|
1443
|
+
let current = "asking";
|
|
1444
|
+
let outcome;
|
|
1445
|
+
const columns = () => stderr.columns || 80;
|
|
1446
|
+
const draw = (state, last = false) => {
|
|
1447
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1448
|
+
const rows = rowsTaken(frame, columns());
|
|
1449
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1450
|
+
current = state;
|
|
1451
|
+
};
|
|
1452
|
+
const redraw = () => draw(current);
|
|
1453
|
+
const paste = { active: false };
|
|
1454
|
+
const stop = terminal.stop ?? (terminal === process24 ? stopJob : undefined);
|
|
1455
|
+
const suspend = () => {
|
|
1456
|
+
if (stop === undefined)
|
|
1457
|
+
return;
|
|
1458
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1459
|
+
stdin.setRawMode(false);
|
|
1460
|
+
stop();
|
|
1461
|
+
stdin.setRawMode(true);
|
|
1462
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1463
|
+
};
|
|
1464
|
+
try {
|
|
1465
|
+
stderr.on?.("resize", redraw);
|
|
1466
|
+
stdin.setRawMode(true);
|
|
1467
|
+
stdin.resume();
|
|
1468
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1469
|
+
draw("asking");
|
|
1470
|
+
return await new Promise((resolve) => {
|
|
1471
|
+
function onData(data) {
|
|
1472
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
1473
|
+
if (key === "suspend") {
|
|
1474
|
+
suspend();
|
|
1475
|
+
continue;
|
|
1476
|
+
}
|
|
1477
|
+
const pressed = press(key);
|
|
1478
|
+
if (pressed !== undefined) {
|
|
1479
|
+
settle(pressed);
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
draw("asking");
|
|
1484
|
+
}
|
|
1485
|
+
function onEnd() {
|
|
1486
|
+
settle("cancel");
|
|
1487
|
+
}
|
|
1488
|
+
function settle(settled) {
|
|
1489
|
+
outcome = settled;
|
|
1490
|
+
stdin.off("data", onData);
|
|
1491
|
+
stdin.off("end", onEnd);
|
|
1492
|
+
resolve(settled === "enter");
|
|
1493
|
+
}
|
|
1494
|
+
stdin.on("data", onData);
|
|
1495
|
+
stdin.on("end", onEnd);
|
|
1496
|
+
});
|
|
1497
|
+
} finally {
|
|
1498
|
+
stderr.off?.("resize", redraw);
|
|
1499
|
+
draw(outcome ?? "cancel", true);
|
|
1500
|
+
stderr.write(`
|
|
1501
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1502
|
+
stdin.setRawMode(false);
|
|
1503
|
+
stdin.pause();
|
|
1504
|
+
}
|
|
1495
1505
|
}
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1506
|
+
var PROMPT_KEYS, MAX_LISTED = 12;
|
|
1507
|
+
var init_prompt = __esm(() => {
|
|
1508
|
+
init_answers();
|
|
1509
|
+
init_args();
|
|
1510
|
+
init_format();
|
|
1511
|
+
init_job();
|
|
1512
|
+
init_mode();
|
|
1513
|
+
init_line();
|
|
1514
|
+
init_state();
|
|
1515
|
+
init_redraw();
|
|
1516
|
+
init_style();
|
|
1517
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1518
|
+
});
|
|
1519
|
+
|
|
1520
|
+
// src/j-cli.ts
|
|
1521
|
+
import process27 from "process";
|
|
1522
|
+
|
|
1523
|
+
// ../kit/src/index.ts
|
|
1524
|
+
init_args();
|
|
1525
|
+
|
|
1526
|
+
// ../kit/src/argv.ts
|
|
1527
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
1528
|
+
import { resolve as resolve3 } from "path";
|
|
1529
|
+
import process11 from "process";
|
|
1530
|
+
function commandLine() {
|
|
1531
|
+
try {
|
|
1532
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
1533
|
+
} catch {
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1509
1536
|
}
|
|
1510
|
-
function
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
case "left":
|
|
1516
|
-
return { text, caret: Math.max(at - 1, 0) };
|
|
1517
|
-
case "right":
|
|
1518
|
-
return { text, caret: Math.min(at + 1, chars.length) };
|
|
1519
|
-
case "wordleft":
|
|
1520
|
-
return { text, caret: wordStart(chars, at) };
|
|
1521
|
-
case "wordright":
|
|
1522
|
-
return { text, caret: wordEnd(chars, at) };
|
|
1523
|
-
case "linestart":
|
|
1524
|
-
return { text, caret: 0 };
|
|
1525
|
-
case "lineend":
|
|
1526
|
-
return { text, caret: chars.length };
|
|
1527
|
-
case "erase":
|
|
1528
|
-
return cut2(chars, Math.max(at - 1, 0), at);
|
|
1529
|
-
case "delete":
|
|
1530
|
-
return cut2(chars, at, Math.min(at + 1, chars.length));
|
|
1531
|
-
case "word":
|
|
1532
|
-
return cut2(chars, spacedStart(chars, at), at);
|
|
1533
|
-
case "killword":
|
|
1534
|
-
return cut2(chars, wordStart(chars, at), at);
|
|
1535
|
-
case "killnext":
|
|
1536
|
-
return cut2(chars, at, wordEnd(chars, at));
|
|
1537
|
-
case "clear":
|
|
1538
|
-
return cut2(chars, 0, at);
|
|
1539
|
-
case "killend":
|
|
1540
|
-
return cut2(chars, at, chars.length);
|
|
1541
|
-
case "yank":
|
|
1542
|
-
return insert(chars, at, killed);
|
|
1537
|
+
function realPath(word) {
|
|
1538
|
+
try {
|
|
1539
|
+
return realpathSync(resolve3(word));
|
|
1540
|
+
} catch {
|
|
1541
|
+
return;
|
|
1543
1542
|
}
|
|
1544
1543
|
}
|
|
1545
|
-
function
|
|
1546
|
-
const
|
|
1547
|
-
const at =
|
|
1548
|
-
const
|
|
1549
|
-
|
|
1550
|
-
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
1551
|
-
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
1552
|
-
let start = at;
|
|
1553
|
-
let end = at + 1;
|
|
1554
|
-
while (start > 0 && fits(start - 1, end))
|
|
1555
|
-
start--;
|
|
1556
|
-
while (end < cells.length && fits(start, end + 1))
|
|
1557
|
-
end++;
|
|
1558
|
-
const left = start > 0 ? "\u2026" : "";
|
|
1559
|
-
const right = end < cells.length ? "\u2026" : "";
|
|
1560
|
-
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
1544
|
+
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
1545
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
1546
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
1547
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
1548
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
1561
1549
|
}
|
|
1550
|
+
// ../kit/src/chart.ts
|
|
1551
|
+
init_format();
|
|
1552
|
+
init_mode();
|
|
1553
|
+
init_style();
|
|
1554
|
+
init_theme();
|
|
1555
|
+
// ../kit/src/ci.ts
|
|
1556
|
+
init_args();
|
|
1557
|
+
init_format();
|
|
1562
1558
|
|
|
1563
|
-
// ../kit/src/
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
var
|
|
1570
|
-
var
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
if (
|
|
1575
|
-
return
|
|
1576
|
-
|
|
1577
|
-
return BOUNDARY_AFTER.has(before) || LOWER.test(before) && UPPER.test(text[index]);
|
|
1559
|
+
// ../kit/src/progress.ts
|
|
1560
|
+
init_format();
|
|
1561
|
+
|
|
1562
|
+
// ../kit/src/process.ts
|
|
1563
|
+
import { constants } from "os";
|
|
1564
|
+
import process12 from "process";
|
|
1565
|
+
var KILL_GRACE_MS = 2000;
|
|
1566
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
1567
|
+
function exitCodeOf(code, signal) {
|
|
1568
|
+
if (code !== null)
|
|
1569
|
+
return code;
|
|
1570
|
+
if (typeof signal === "number")
|
|
1571
|
+
return 128 + signal;
|
|
1572
|
+
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
1578
1573
|
}
|
|
1579
|
-
function
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
const
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1574
|
+
function holdSignals(cleanup) {
|
|
1575
|
+
let received;
|
|
1576
|
+
let child;
|
|
1577
|
+
const held = {
|
|
1578
|
+
get signal() {
|
|
1579
|
+
return received;
|
|
1580
|
+
},
|
|
1581
|
+
forward: (to) => {
|
|
1582
|
+
child = to;
|
|
1583
|
+
},
|
|
1584
|
+
release: () => {
|
|
1585
|
+
for (const signal of SIGNALS)
|
|
1586
|
+
process12.off(signal, onSignal);
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
function onSignal(signal) {
|
|
1590
|
+
received = signal;
|
|
1591
|
+
if (child !== undefined) {
|
|
1592
|
+
child.kill(signal);
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
if (cleanup === undefined)
|
|
1596
|
+
return;
|
|
1597
|
+
held.release();
|
|
1598
|
+
cleanup(signal);
|
|
1599
|
+
process12.kill(process12.pid, signal);
|
|
1600
|
+
}
|
|
1601
|
+
for (const signal of SIGNALS)
|
|
1602
|
+
process12.on(signal, onSignal);
|
|
1603
|
+
return held;
|
|
1604
|
+
}
|
|
1605
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
1606
|
+
const chunks = [];
|
|
1607
|
+
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
1608
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin: input === undefined ? stdin : new TextEncoder().encode(input), stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
1609
|
+
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
1610
|
+
const timers = [];
|
|
1611
|
+
const killGroup = (killing) => {
|
|
1612
|
+
if (state.done)
|
|
1613
|
+
return;
|
|
1614
|
+
try {
|
|
1615
|
+
if (grouped)
|
|
1616
|
+
process12.kill(-proc.pid, killing);
|
|
1617
|
+
else
|
|
1618
|
+
proc.kill(killing);
|
|
1619
|
+
} catch {}
|
|
1620
|
+
};
|
|
1621
|
+
const stop = () => {
|
|
1622
|
+
killGroup("SIGTERM");
|
|
1623
|
+
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
1624
|
+
};
|
|
1625
|
+
const onAbort = () => stop();
|
|
1626
|
+
if (timeoutMs !== undefined) {
|
|
1627
|
+
timers.push(setTimeout(() => {
|
|
1628
|
+
state.timedOut = true;
|
|
1629
|
+
stop();
|
|
1630
|
+
}, timeoutMs));
|
|
1631
|
+
}
|
|
1632
|
+
if (signal?.aborted === true)
|
|
1633
|
+
onAbort();
|
|
1634
|
+
else
|
|
1635
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1636
|
+
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
1637
|
+
const drain = async (stream, name) => {
|
|
1638
|
+
for await (const data of stream) {
|
|
1639
|
+
if (state.failure !== undefined)
|
|
1602
1640
|
continue;
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1641
|
+
try {
|
|
1642
|
+
onChunk?.({ stream: name, data });
|
|
1643
|
+
} catch (error) {
|
|
1644
|
+
state.failure = error;
|
|
1645
|
+
stop();
|
|
1606
1646
|
continue;
|
|
1607
1647
|
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
best[j][i] = joined + here;
|
|
1612
|
-
from[j][i] = i - 1;
|
|
1613
|
-
} else if (skipped > NONE) {
|
|
1614
|
-
best[j][i] = skipped + here;
|
|
1615
|
-
from[j][i] = runAt;
|
|
1648
|
+
if (state.kept + data.length > maxBytes) {
|
|
1649
|
+
state.truncated = true;
|
|
1650
|
+
continue;
|
|
1616
1651
|
}
|
|
1652
|
+
state.kept += data.length;
|
|
1653
|
+
chunks.push({ stream: name, data });
|
|
1617
1654
|
}
|
|
1655
|
+
};
|
|
1656
|
+
try {
|
|
1657
|
+
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
1658
|
+
await proc.exited;
|
|
1659
|
+
} finally {
|
|
1660
|
+
state.done = true;
|
|
1661
|
+
for (const timer of timers)
|
|
1662
|
+
clearTimeout(timer);
|
|
1663
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1618
1664
|
}
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1665
|
+
if (state.failure !== undefined)
|
|
1666
|
+
throw state.failure;
|
|
1667
|
+
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
1668
|
+
let output;
|
|
1669
|
+
let text;
|
|
1670
|
+
return {
|
|
1671
|
+
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
1672
|
+
chunks,
|
|
1673
|
+
timedOut: state.timedOut,
|
|
1674
|
+
truncated: state.truncated,
|
|
1675
|
+
get output() {
|
|
1676
|
+
return output ??= joined();
|
|
1677
|
+
},
|
|
1678
|
+
get text() {
|
|
1679
|
+
return text ??= (output ??= joined()).toString();
|
|
1680
|
+
}
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
// ../kit/src/progress.ts
|
|
1685
|
+
init_style();
|
|
1686
|
+
init_theme();
|
|
1687
|
+
var ESC = String.fromCharCode(27);
|
|
1688
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
1689
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
1690
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1691
|
+
|
|
1692
|
+
// ../kit/src/ci.ts
|
|
1693
|
+
init_style();
|
|
1694
|
+
|
|
1695
|
+
// ../kit/src/tool.ts
|
|
1696
|
+
init_format();
|
|
1697
|
+
// ../kit/src/cli.ts
|
|
1698
|
+
init_args();
|
|
1699
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
1700
|
+
import { dirname as dirname3, join as join6 } from "path";
|
|
1701
|
+
import process17 from "process";
|
|
1702
|
+
|
|
1703
|
+
// ../kit/src/askpass.ts
|
|
1704
|
+
import process13 from "process";
|
|
1705
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1706
|
+
async function askpassClient(argv) {
|
|
1707
|
+
const socketPath = process13.env[SOCKET_VARIABLE];
|
|
1708
|
+
if (socketPath === undefined)
|
|
1626
1709
|
return;
|
|
1627
|
-
const
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1710
|
+
const request = { prompt: argv[0] ?? "", ...process13.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1711
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1712
|
+
let received = "";
|
|
1713
|
+
try {
|
|
1714
|
+
await Bun.connect({
|
|
1715
|
+
unix: socketPath,
|
|
1716
|
+
socket: {
|
|
1717
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1718
|
+
`),
|
|
1719
|
+
data: (_, chunk) => {
|
|
1720
|
+
received += chunk.toString();
|
|
1721
|
+
},
|
|
1722
|
+
close: () => resolve(received),
|
|
1723
|
+
error: () => resolve("")
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
} catch {
|
|
1727
|
+
return 1;
|
|
1631
1728
|
}
|
|
1632
|
-
|
|
1729
|
+
const reply = await promise;
|
|
1730
|
+
if (reply === "")
|
|
1731
|
+
return 1;
|
|
1732
|
+
const { answer } = JSON.parse(reply);
|
|
1733
|
+
if (request.notice === true)
|
|
1734
|
+
return 0;
|
|
1735
|
+
if (answer === undefined)
|
|
1736
|
+
return 1;
|
|
1737
|
+
process13.stdout.write(`${answer}
|
|
1738
|
+
`);
|
|
1739
|
+
return 0;
|
|
1633
1740
|
}
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1741
|
+
|
|
1742
|
+
// ../kit/src/completions.ts
|
|
1743
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
1744
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
1745
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1746
|
+
set -l current (commandline -ct)
|
|
1747
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1748
|
+
if test "$line" = __files__
|
|
1749
|
+
__fish_complete_path $current
|
|
1750
|
+
else
|
|
1751
|
+
echo $line
|
|
1752
|
+
end
|
|
1753
|
+
end
|
|
1754
|
+
end`;
|
|
1755
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1756
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1757
|
+
local -a lines
|
|
1758
|
+
COMPREPLY=()
|
|
1759
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1760
|
+
for line in "\${lines[@]}"; do
|
|
1761
|
+
if [[ $line == __files__ ]]; then
|
|
1762
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1763
|
+
else
|
|
1764
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1765
|
+
fi
|
|
1766
|
+
done
|
|
1767
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1768
|
+
}`;
|
|
1769
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1770
|
+
local line
|
|
1771
|
+
local -a described plain
|
|
1772
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1773
|
+
if [[ $line == __files__ ]]; then
|
|
1774
|
+
_files
|
|
1775
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1776
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1777
|
+
else
|
|
1778
|
+
plain+=("$line")
|
|
1779
|
+
fi
|
|
1780
|
+
done
|
|
1781
|
+
(( \${#described} )) && _describe -V value described
|
|
1782
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1783
|
+
return 0
|
|
1784
|
+
}`;
|
|
1785
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1786
|
+
if (shell === "fish")
|
|
1787
|
+
return `${header}
|
|
1788
|
+
${FISH_FUNCTION}
|
|
1789
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1790
|
+
`).join("")}`;
|
|
1791
|
+
if (shell === "bash")
|
|
1792
|
+
return `${header}
|
|
1793
|
+
${BASH_FUNCTION}
|
|
1794
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1795
|
+
`;
|
|
1796
|
+
return `${header}
|
|
1797
|
+
${ZSH_FUNCTION}
|
|
1798
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1799
|
+
`;
|
|
1644
1800
|
}
|
|
1645
1801
|
|
|
1646
|
-
// ../kit/src/
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
var
|
|
1651
|
-
var
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1655
|
-
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1656
|
-
var WHEEL_LINES = 3;
|
|
1657
|
-
var KEYS = {
|
|
1658
|
-
"\x1B[A": "up",
|
|
1659
|
-
"\x1BOA": "up",
|
|
1660
|
-
"\x10": "up",
|
|
1661
|
-
"\x1B[B": "down",
|
|
1662
|
-
"\x1BOB": "down",
|
|
1663
|
-
"\x0E": "down",
|
|
1664
|
-
"\x1B[5~": "pageup",
|
|
1665
|
-
"\x1B[6~": "pagedown",
|
|
1666
|
-
"\x1B[H": "home",
|
|
1667
|
-
"\x1B[1~": "home",
|
|
1668
|
-
"\x1BOH": "home",
|
|
1669
|
-
"\x1B[F": "end",
|
|
1670
|
-
"\x1B[4~": "end",
|
|
1671
|
-
"\x1BOF": "end",
|
|
1672
|
-
"\r": "enter",
|
|
1673
|
-
"\n": "enter",
|
|
1674
|
-
"\x03": "cancel",
|
|
1675
|
-
"\x1B": "cancel",
|
|
1676
|
-
"\x1B[D": "left",
|
|
1677
|
-
"\x1BOD": "left",
|
|
1678
|
-
"\x1B[C": "right",
|
|
1679
|
-
"\x1BOC": "right",
|
|
1680
|
-
"\x1B[1;5D": "wordleft",
|
|
1681
|
-
"\x1B[1;3D": "wordleft",
|
|
1682
|
-
"\x1Bb": "wordleft",
|
|
1683
|
-
"\x1B[1;5C": "wordright",
|
|
1684
|
-
"\x1B[1;3C": "wordright",
|
|
1685
|
-
"\x1Bf": "wordright",
|
|
1686
|
-
"\x01": "linestart",
|
|
1687
|
-
"\x05": "lineend",
|
|
1688
|
-
"\x7F": "erase",
|
|
1689
|
-
"\x1B[3~": "delete",
|
|
1690
|
-
"\b": "killword",
|
|
1691
|
-
"\x1B\x7F": "killword",
|
|
1692
|
-
"\x1B[3;5~": "killnext",
|
|
1693
|
-
"\x1Bd": "killnext",
|
|
1694
|
-
"\x15": "clear",
|
|
1695
|
-
"\v": "killend",
|
|
1696
|
-
"\x17": "word",
|
|
1697
|
-
"\x19": "yank",
|
|
1698
|
-
"\x1A": "suspend",
|
|
1699
|
-
"\t": "tab",
|
|
1700
|
-
"\x1F": "help",
|
|
1701
|
-
"\x1BOP": "help",
|
|
1702
|
-
"\x1B[11~": "help"
|
|
1703
|
-
};
|
|
1704
|
-
var CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
|
|
1705
|
-
function repeat(value, count) {
|
|
1706
|
-
return Array.from({ length: count }).fill(value);
|
|
1802
|
+
// ../kit/src/notify.ts
|
|
1803
|
+
init_format();
|
|
1804
|
+
init_mode();
|
|
1805
|
+
import process14 from "process";
|
|
1806
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1807
|
+
var CANCELLED = 130;
|
|
1808
|
+
function base64(text) {
|
|
1809
|
+
return Buffer.from(text).toString("base64");
|
|
1707
1810
|
}
|
|
1708
|
-
function
|
|
1709
|
-
|
|
1710
|
-
const
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1811
|
+
function notification(title, body, env = process14.env) {
|
|
1812
|
+
const id = `kit${process14.pid}`;
|
|
1813
|
+
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
1814
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1815
|
+
}
|
|
1816
|
+
function notifyEnd(command, code, ms, { stream = process14.stderr, env = process14.env } = {}) {
|
|
1817
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1818
|
+
return;
|
|
1819
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
// ../kit/src/cli.ts
|
|
1823
|
+
init_style();
|
|
1824
|
+
init_text2();
|
|
1825
|
+
|
|
1826
|
+
// ../kit/src/usage.ts
|
|
1827
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
1828
|
+
import { homedir as homedir4 } from "os";
|
|
1829
|
+
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
1830
|
+
import process16 from "process";
|
|
1831
|
+
|
|
1832
|
+
// ../kit/src/logs.ts
|
|
1833
|
+
import { lstatSync, openSync } from "fs";
|
|
1834
|
+
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
1835
|
+
import { homedir as homedir3, tmpdir } from "os";
|
|
1836
|
+
import { join as join4 } from "path";
|
|
1837
|
+
import process15 from "process";
|
|
1838
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1839
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
1840
|
+
function isPrivateDirectory(path) {
|
|
1841
|
+
try {
|
|
1842
|
+
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
1843
|
+
return info !== undefined && info.isDirectory() && info.uid === (process15.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
1844
|
+
} catch {
|
|
1845
|
+
return false;
|
|
1725
1846
|
}
|
|
1726
|
-
add(line.slice(last));
|
|
1727
|
-
return { text, styles: colored ? styles : undefined };
|
|
1728
1847
|
}
|
|
1729
|
-
function
|
|
1730
|
-
const
|
|
1731
|
-
const
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1848
|
+
async function privateLogDirectory(name, env = process15.env) {
|
|
1849
|
+
const runtime = env.XDG_RUNTIME_DIR;
|
|
1850
|
+
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
1851
|
+
const path = join4(base, name);
|
|
1852
|
+
try {
|
|
1853
|
+
await mkdir(path, { recursive: true, mode: 448 });
|
|
1854
|
+
if (isPrivateDirectory(path))
|
|
1855
|
+
return path;
|
|
1856
|
+
} catch {}
|
|
1857
|
+
return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
1858
|
+
}
|
|
1859
|
+
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
1860
|
+
let names;
|
|
1861
|
+
try {
|
|
1862
|
+
names = await readdir(dir);
|
|
1863
|
+
} catch {
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
for (const name of names) {
|
|
1867
|
+
const path = join4(dir, name);
|
|
1868
|
+
try {
|
|
1869
|
+
const info = await stat(path);
|
|
1870
|
+
if (info.isDirectory())
|
|
1871
|
+
await sweepLogs(path, maxAgeMs, now);
|
|
1872
|
+
if (now - info.mtimeMs > maxAgeMs)
|
|
1873
|
+
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
1874
|
+
} catch {
|
|
1875
|
+
continue;
|
|
1750
1876
|
}
|
|
1751
|
-
|
|
1752
|
-
});
|
|
1877
|
+
}
|
|
1753
1878
|
}
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1879
|
+
|
|
1880
|
+
// ../kit/src/usage.ts
|
|
1881
|
+
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1882
|
+
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1883
|
+
var LONGEST_NAME = 40;
|
|
1884
|
+
var usageError;
|
|
1885
|
+
function noteUsageError(message) {
|
|
1886
|
+
usageError = message;
|
|
1887
|
+
}
|
|
1888
|
+
function stateHome(env = process16.env) {
|
|
1889
|
+
const dir = env.XDG_STATE_HOME;
|
|
1890
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
1891
|
+
}
|
|
1892
|
+
function usagePath(env = process16.env) {
|
|
1893
|
+
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1894
|
+
}
|
|
1895
|
+
function usageRecorded(env = process16.env) {
|
|
1896
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1897
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1898
|
+
}
|
|
1899
|
+
function flagNames(argv) {
|
|
1900
|
+
const end = argv.indexOf("--");
|
|
1901
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1902
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1903
|
+
}
|
|
1904
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
1905
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1906
|
+
usageError = undefined;
|
|
1907
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1908
|
+
}
|
|
1909
|
+
function recordUsage(entry, env = process16.env) {
|
|
1910
|
+
if (!usageRecorded(env))
|
|
1911
|
+
return;
|
|
1912
|
+
try {
|
|
1913
|
+
const path = usagePath(env);
|
|
1914
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
1915
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1916
|
+
`, { mode: 384 });
|
|
1917
|
+
} catch {}
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
// ../kit/src/cli.ts
|
|
1921
|
+
var LEVEL_OPTIONS = {
|
|
1922
|
+
...OUTPUT_OPTIONS,
|
|
1923
|
+
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1924
|
+
};
|
|
1925
|
+
var TOP_OPTIONS = {
|
|
1926
|
+
...LEVEL_OPTIONS,
|
|
1927
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1928
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1929
|
+
};
|
|
1930
|
+
function printError(prefix, message, hint, cause) {
|
|
1931
|
+
const colors = paint(process17.stderr);
|
|
1932
|
+
const styled = takesControlCodes(process17.stderr);
|
|
1933
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1934
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1935
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
1936
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1937
|
+
}
|
|
1938
|
+
function printJsonError(message, hint, cause) {
|
|
1939
|
+
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
1940
|
+
}
|
|
1941
|
+
function wantsJson(argv) {
|
|
1942
|
+
const end = argv.indexOf("--");
|
|
1943
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
1944
|
+
}
|
|
1945
|
+
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
1946
|
+
if (error instanceof HelpShown)
|
|
1947
|
+
return 0;
|
|
1948
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
1949
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
1950
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
1951
|
+
if (error instanceof Exit && error.code === 2)
|
|
1952
|
+
noteUsageError(error.message);
|
|
1953
|
+
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
1954
|
+
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
1955
|
+
return error instanceof Exit ? error.code : 1;
|
|
1956
|
+
}
|
|
1957
|
+
var COMPLETE = "__complete";
|
|
1958
|
+
var FILES = "__files__";
|
|
1959
|
+
async function completingOf(run) {
|
|
1960
|
+
completion.active = true;
|
|
1961
|
+
try {
|
|
1962
|
+
await run([]);
|
|
1963
|
+
} catch (error) {
|
|
1964
|
+
if (error instanceof Completing)
|
|
1965
|
+
return error;
|
|
1966
|
+
} finally {
|
|
1967
|
+
completion.active = false;
|
|
1968
|
+
}
|
|
1969
|
+
return new Completing({});
|
|
1970
|
+
}
|
|
1971
|
+
function candidateLine(candidate) {
|
|
1972
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
1973
|
+
}
|
|
1974
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
1975
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1976
|
+
const typed = [];
|
|
1977
|
+
let at = 0;
|
|
1978
|
+
while (at < before.length) {
|
|
1979
|
+
const word = before[at];
|
|
1980
|
+
if (word === "--") {
|
|
1981
|
+
typed.push(...before.slice(at + 1));
|
|
1982
|
+
break;
|
|
1765
1983
|
}
|
|
1766
|
-
if (
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1984
|
+
if (!word.startsWith("-"))
|
|
1985
|
+
typed.push(word);
|
|
1986
|
+
else if (takesValue(word))
|
|
1987
|
+
at++;
|
|
1988
|
+
at++;
|
|
1989
|
+
}
|
|
1990
|
+
const last = positionals.at(-1);
|
|
1991
|
+
if (typed.length < positionals.length)
|
|
1992
|
+
return { name: positionals[typed.length], typed };
|
|
1993
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1773
1994
|
}
|
|
1774
|
-
function
|
|
1775
|
-
const
|
|
1776
|
-
|
|
1995
|
+
async function leafCandidates(run, words) {
|
|
1996
|
+
const completing = await completingOf(run);
|
|
1997
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
1998
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1999
|
+
const flag = words.at(-2);
|
|
2000
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
2001
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
2002
|
+
if (option?.type === "string") {
|
|
2003
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
2004
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
2005
|
+
}
|
|
2006
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
2007
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1777
2008
|
}
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
const searchable = laid.map((row) => row.searchable);
|
|
1782
|
-
const matches = rank(state.query, searchable);
|
|
1783
|
-
return { ...state, rows: cells, items: laid.map((row) => row.text), styles: laid.map((row) => row.styles), searchable, header, matches, cursor: Math.max(0, Math.min(matches.length - 1, state.cursor)), marked: new Set };
|
|
2009
|
+
var COMPLETIONS = "--completions";
|
|
2010
|
+
function flagValue([flag = "", ...rest]) {
|
|
2011
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1784
2012
|
}
|
|
1785
|
-
function
|
|
1786
|
-
const
|
|
1787
|
-
|
|
2013
|
+
function printCompletionScript(name, args) {
|
|
2014
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
2015
|
+
if (shell === undefined || args.length !== 1) {
|
|
2016
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
2017
|
+
return 2;
|
|
2018
|
+
}
|
|
2019
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
2020
|
+
return 0;
|
|
1788
2021
|
}
|
|
1789
|
-
function
|
|
1790
|
-
|
|
2022
|
+
async function printCandidates(found) {
|
|
2023
|
+
for (const line of await found)
|
|
2024
|
+
console.log(line);
|
|
2025
|
+
return 0;
|
|
1791
2026
|
}
|
|
1792
|
-
function
|
|
1793
|
-
|
|
2027
|
+
function packageVersion(entry = Bun.main) {
|
|
2028
|
+
let resolved = entry;
|
|
2029
|
+
try {
|
|
2030
|
+
resolved = realpathSync2(entry);
|
|
2031
|
+
} catch {}
|
|
2032
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
2033
|
+
try {
|
|
2034
|
+
const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
|
|
2035
|
+
if (typeof version === "string")
|
|
2036
|
+
return version;
|
|
2037
|
+
} catch {}
|
|
2038
|
+
if (dirname3(dir) === dir)
|
|
2039
|
+
return "0.0.0";
|
|
2040
|
+
}
|
|
1794
2041
|
}
|
|
1795
|
-
function
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
return
|
|
2042
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
2043
|
+
const answered = await askpassClient(argv);
|
|
2044
|
+
if (answered !== undefined)
|
|
2045
|
+
return answered;
|
|
2046
|
+
if (argv[0] === COMPLETE)
|
|
2047
|
+
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
2048
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
2049
|
+
return printCompletionScript(name, flagValue(argv));
|
|
2050
|
+
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
2051
|
+
console.log(version ?? packageVersion());
|
|
2052
|
+
return 0;
|
|
1806
2053
|
}
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
2054
|
+
let code;
|
|
2055
|
+
const started = performance.now();
|
|
2056
|
+
try {
|
|
2057
|
+
code = await run(argv);
|
|
2058
|
+
} catch (error) {
|
|
2059
|
+
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
2060
|
+
}
|
|
2061
|
+
notifyEnd(name, code, performance.now() - started);
|
|
2062
|
+
if (usage !== false) {
|
|
2063
|
+
try {
|
|
2064
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
2065
|
+
} catch {}
|
|
2066
|
+
}
|
|
2067
|
+
return code;
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
// ../kit/src/index.ts
|
|
2071
|
+
init_config();
|
|
2072
|
+
|
|
2073
|
+
// ../kit/src/excerpt.ts
|
|
2074
|
+
init_text2();
|
|
2075
|
+
var BASH_ECHO = /^\$ /;
|
|
2076
|
+
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
2077
|
+
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
2078
|
+
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
2079
|
+
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
2080
|
+
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
2081
|
+
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
2082
|
+
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
2083
|
+
var TSC_ERROR = /\berror TS\d+/;
|
|
2084
|
+
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
2085
|
+
var TSC_FRAME = /^\s*[~^|]/;
|
|
2086
|
+
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
2087
|
+
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
2088
|
+
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
2089
|
+
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
2090
|
+
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
2091
|
+
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
2092
|
+
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
2093
|
+
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
2094
|
+
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
2095
|
+
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
2096
|
+
var MAX_TESTS = 10;
|
|
2097
|
+
var MAX_LINES = 100;
|
|
2098
|
+
var TAIL = 30;
|
|
2099
|
+
var bunTest = (lines) => {
|
|
2100
|
+
const seen = new Set;
|
|
2101
|
+
const blocks = [];
|
|
2102
|
+
for (const [index, line] of lines.entries()) {
|
|
2103
|
+
const name = line.replace(DURATION2, "");
|
|
2104
|
+
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
2105
|
+
continue;
|
|
2106
|
+
seen.add(name);
|
|
2107
|
+
if (blocks.length < MAX_TESTS)
|
|
2108
|
+
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
2109
|
+
`).trim());
|
|
2110
|
+
}
|
|
2111
|
+
if (blocks.length === 0)
|
|
2112
|
+
return;
|
|
2113
|
+
if (seen.size > MAX_TESTS)
|
|
2114
|
+
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
2115
|
+
return [...blocks.join(`
|
|
2116
|
+
|
|
2117
|
+
`).split(`
|
|
2118
|
+
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
2119
|
+
};
|
|
2120
|
+
var bunCheck = (lines) => {
|
|
2121
|
+
const text = lines.join(`
|
|
2122
|
+
`);
|
|
2123
|
+
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
2124
|
+
if (blocks === null)
|
|
2125
|
+
return;
|
|
2126
|
+
const errors = blocks.map((block) => {
|
|
2127
|
+
const { file, line, column, code, message } = bunCheckFields(block);
|
|
2128
|
+
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
2129
|
+
});
|
|
2130
|
+
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
2131
|
+
};
|
|
2132
|
+
function bunCheckFields(block) {
|
|
2133
|
+
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
2134
|
+
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
2135
|
+
return {
|
|
2136
|
+
file: attributes.file ?? "",
|
|
2137
|
+
line: attributes.line ?? "",
|
|
2138
|
+
column: attributes.column ?? "",
|
|
2139
|
+
code: attributes.code ?? "",
|
|
2140
|
+
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
2141
|
+
`).slice(1, -1).join(`
|
|
2142
|
+
`).trim()
|
|
2143
|
+
};
|
|
2144
|
+
}
|
|
2145
|
+
var tsc = (lines) => {
|
|
2146
|
+
const kept = [];
|
|
2147
|
+
let inError = false;
|
|
2148
|
+
for (const line of lines) {
|
|
2149
|
+
if (TSC_ERROR.test(line)) {
|
|
2150
|
+
inError = true;
|
|
2151
|
+
kept.push(line);
|
|
2152
|
+
} else if (TSC_SUMMARY.test(line)) {
|
|
2153
|
+
inError = false;
|
|
2154
|
+
kept.push(line);
|
|
2155
|
+
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
2156
|
+
kept.push(line);
|
|
2157
|
+
} else {
|
|
2158
|
+
inError = false;
|
|
1838
2159
|
}
|
|
1839
2160
|
}
|
|
2161
|
+
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
2162
|
+
};
|
|
2163
|
+
var eslint = (lines) => {
|
|
2164
|
+
const kept = [];
|
|
2165
|
+
let file = "";
|
|
2166
|
+
let shown = "";
|
|
2167
|
+
for (const line of lines) {
|
|
2168
|
+
if (ESLINT_PROBLEM.test(line)) {
|
|
2169
|
+
if (file !== shown) {
|
|
2170
|
+
kept.push(file);
|
|
2171
|
+
shown = file;
|
|
2172
|
+
}
|
|
2173
|
+
kept.push(line);
|
|
2174
|
+
} else if (ESLINT_SUMMARY.test(line)) {
|
|
2175
|
+
kept.push(line);
|
|
2176
|
+
} else if (line.trim() !== "") {
|
|
2177
|
+
file = line;
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
2181
|
+
};
|
|
2182
|
+
var phpstan = (lines) => {
|
|
2183
|
+
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
2184
|
+
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
2185
|
+
};
|
|
2186
|
+
var php = (lines) => {
|
|
2187
|
+
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
2188
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
2189
|
+
};
|
|
2190
|
+
var vitest = (lines) => {
|
|
2191
|
+
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
2192
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
2193
|
+
};
|
|
2194
|
+
var playwright = (lines) => {
|
|
2195
|
+
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
2196
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
2197
|
+
};
|
|
2198
|
+
var phpCsFixer = (lines) => {
|
|
2199
|
+
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
2200
|
+
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
2201
|
+
};
|
|
2202
|
+
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
2203
|
+
function squeeze(lines) {
|
|
2204
|
+
const out = [];
|
|
2205
|
+
for (const line of lines.map((text) => text.trimEnd())) {
|
|
2206
|
+
if (line !== "" || out.at(-1) !== "")
|
|
2207
|
+
out.push(line);
|
|
2208
|
+
}
|
|
2209
|
+
while (out.at(-1) === "")
|
|
2210
|
+
out.pop();
|
|
2211
|
+
return out;
|
|
1840
2212
|
}
|
|
1841
|
-
function
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
2213
|
+
function cut(shown) {
|
|
2214
|
+
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
2215
|
+
`) : shown.join(`
|
|
2216
|
+
`);
|
|
2217
|
+
}
|
|
2218
|
+
function recognised(lines, parsers) {
|
|
2219
|
+
return parsers.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
2220
|
+
}
|
|
2221
|
+
function failureExcerpt(output) {
|
|
2222
|
+
const lines = stripAnsi(output).split(`
|
|
2223
|
+
`);
|
|
2224
|
+
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
2225
|
+
lines.shift();
|
|
2226
|
+
return cut(squeeze(recognised(lines, PARSERS) ?? lines.slice(-TAIL)));
|
|
1846
2227
|
}
|
|
2228
|
+
var LOG_PATTERNS = { BASH_ECHO, DURATION: DURATION2, BOUNDARY, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_CONTINUATION, TSC_FRAME, TSC_SUMMARY, ESLINT_PROBLEM, ESLINT_SUMMARY };
|
|
2229
|
+
|
|
2230
|
+
// ../kit/src/index.ts
|
|
2231
|
+
init_folders();
|
|
2232
|
+
init_format();
|
|
2233
|
+
|
|
2234
|
+
// ../kit/src/git.ts
|
|
2235
|
+
init_args();
|
|
2236
|
+
// ../kit/src/limit.ts
|
|
2237
|
+
init_args();
|
|
2238
|
+
|
|
2239
|
+
// ../kit/src/index.ts
|
|
2240
|
+
init_mode();
|
|
2241
|
+
|
|
2242
|
+
// ../kit/src/report.ts
|
|
2243
|
+
init_style();
|
|
2244
|
+
init_text2();
|
|
2245
|
+
// ../kit/src/secrets.ts
|
|
2246
|
+
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
2247
|
+
// ../kit/src/sessions.ts
|
|
2248
|
+
var {Glob } = globalThis.Bun;
|
|
2249
|
+
var SESSION_FILES = new Glob("*.json");
|
|
2250
|
+
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
2251
|
+
|
|
2252
|
+
// ../kit/src/index.ts
|
|
2253
|
+
init_style();
|
|
2254
|
+
init_text2();
|
|
2255
|
+
init_theme();
|
|
2256
|
+
init_user_config();
|
|
2257
|
+
|
|
2258
|
+
// ../kit/src/watch.ts
|
|
2259
|
+
init_args();
|
|
2260
|
+
init_input();
|
|
2261
|
+
init_style();
|
|
2262
|
+
// ../kit/src/workspace-root.ts
|
|
2263
|
+
init_user_config();
|
|
2264
|
+
// package.json
|
|
2265
|
+
var version = "0.21.1";
|
|
2266
|
+
|
|
2267
|
+
// src/j.ts
|
|
2268
|
+
import process26 from "process";
|
|
2269
|
+
|
|
2270
|
+
// ../kit/src/picker.ts
|
|
2271
|
+
init_folders();
|
|
2272
|
+
init_state();
|
|
2273
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
2274
|
+
import { dirname as dirname4, join as join8 } from "path";
|
|
2275
|
+
import process23 from "process";
|
|
1847
2276
|
|
|
1848
2277
|
// ../kit/src/picker/terminal.ts
|
|
2278
|
+
init_args();
|
|
2279
|
+
init_job();
|
|
2280
|
+
init_redraw();
|
|
2281
|
+
init_style();
|
|
1849
2282
|
import { openSync as openSync2 } from "fs";
|
|
1850
|
-
import
|
|
2283
|
+
import process22 from "process";
|
|
1851
2284
|
import tty from "tty";
|
|
1852
2285
|
|
|
1853
|
-
// ../kit/src/job.ts
|
|
1854
|
-
import process19 from "process";
|
|
1855
|
-
function stopJob() {
|
|
1856
|
-
process19.kill(0, "SIGTSTP");
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
// ../kit/src/redraw.ts
|
|
1860
|
-
var SYNC_START = "\x1B[?2026h";
|
|
1861
|
-
var SYNC_END = "\x1B[?2026l";
|
|
1862
|
-
function overwrite(lines, columns) {
|
|
1863
|
-
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1864
|
-
`);
|
|
1865
|
-
}
|
|
1866
|
-
function rowsTaken(lines, columns) {
|
|
1867
|
-
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1868
|
-
}
|
|
1869
|
-
|
|
1870
2286
|
// ../kit/src/picker/preview.ts
|
|
1871
|
-
import
|
|
2287
|
+
import process21 from "process";
|
|
1872
2288
|
|
|
1873
2289
|
// ../kit/src/shell.ts
|
|
1874
2290
|
var SEPARATORS = new Set([`
|
|
@@ -1937,7 +2353,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
1937
2353
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
1938
2354
|
const stop = () => {
|
|
1939
2355
|
try {
|
|
1940
|
-
|
|
2356
|
+
process21.kill(-proc.pid, "SIGKILL");
|
|
1941
2357
|
} catch {
|
|
1942
2358
|
proc.kill();
|
|
1943
2359
|
}
|
|
@@ -1962,7 +2378,12 @@ ${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe",
|
|
|
1962
2378
|
return signal.aborted ? [] : previewLines(Buffer.concat(chunks).subarray(0, PREVIEW_BYTES).toString());
|
|
1963
2379
|
}
|
|
1964
2380
|
|
|
2381
|
+
// ../kit/src/picker/terminal.ts
|
|
2382
|
+
init_state();
|
|
2383
|
+
|
|
1965
2384
|
// ../kit/src/picker/view.ts
|
|
2385
|
+
init_line();
|
|
2386
|
+
init_state();
|
|
1966
2387
|
var MIN_HEIGHT = 4;
|
|
1967
2388
|
var PREVIEW_MIN_COLUMNS = 80;
|
|
1968
2389
|
var PREVIEW_MIN_ROWS = 10;
|
|
@@ -2095,7 +2516,7 @@ function openTerminal() {
|
|
|
2095
2516
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
2096
2517
|
}
|
|
2097
2518
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
2098
|
-
const out =
|
|
2519
|
+
const out = process22.stderr;
|
|
2099
2520
|
let resize;
|
|
2100
2521
|
async function read(onChunk) {
|
|
2101
2522
|
const decoder = new TextDecoder;
|
|
@@ -2284,9 +2705,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2284
2705
|
const ended = new Promise((resolve) => {
|
|
2285
2706
|
finish = resolve;
|
|
2286
2707
|
});
|
|
2287
|
-
|
|
2708
|
+
process22.once("exit", restore);
|
|
2288
2709
|
for (const signal of SIGNALS2)
|
|
2289
|
-
|
|
2710
|
+
process22.once(signal, stop);
|
|
2290
2711
|
try {
|
|
2291
2712
|
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
2292
2713
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -2299,8 +2720,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2299
2720
|
await ended;
|
|
2300
2721
|
} finally {
|
|
2301
2722
|
for (const signal of SIGNALS2)
|
|
2302
|
-
|
|
2303
|
-
|
|
2723
|
+
process22.off(signal, stop);
|
|
2724
|
+
process22.off("exit", restore);
|
|
2304
2725
|
restore();
|
|
2305
2726
|
}
|
|
2306
2727
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -2314,6 +2735,7 @@ async function previewOf(preview, hidden, signal) {
|
|
|
2314
2735
|
}
|
|
2315
2736
|
|
|
2316
2737
|
// ../kit/src/picker.ts
|
|
2738
|
+
init_score();
|
|
2317
2739
|
var REMEMBERED = 20;
|
|
2318
2740
|
async function pick(rows, options) {
|
|
2319
2741
|
const height = parseHeight(options.height ?? "100%");
|
|
@@ -2342,12 +2764,12 @@ function history(name) {
|
|
|
2342
2764
|
}
|
|
2343
2765
|
}
|
|
2344
2766
|
function runs(name) {
|
|
2345
|
-
return history(name)[
|
|
2767
|
+
return history(name)[process23.cwd()] ?? [];
|
|
2346
2768
|
}
|
|
2347
2769
|
function record(name, run) {
|
|
2348
2770
|
const all = history(name);
|
|
2349
2771
|
const file = historyFile(name);
|
|
2350
|
-
all[
|
|
2772
|
+
all[process23.cwd()] = [run, ...(all[process23.cwd()] ?? []).filter((earlier) => earlier.id !== run.id)].slice(0, REMEMBERED);
|
|
2351
2773
|
mkdirSync2(dirname4(file), { recursive: true });
|
|
2352
2774
|
writeFileSync(file, JSON.stringify(all));
|
|
2353
2775
|
}
|
|
@@ -2370,200 +2792,11 @@ function list(rows) {
|
|
|
2370
2792
|
console.log(JSON.stringify(rows));
|
|
2371
2793
|
}
|
|
2372
2794
|
|
|
2373
|
-
//
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
// ../kit/src/answers.ts
|
|
2377
|
-
import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync2 } from "fs";
|
|
2378
|
-
import { dirname as dirname5, join as join9 } from "path";
|
|
2379
|
-
var KEPT = 50;
|
|
2380
|
-
function answersFile() {
|
|
2381
|
-
return join9(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
2382
|
-
}
|
|
2383
|
-
function stored() {
|
|
2384
|
-
try {
|
|
2385
|
-
const parsed = JSON.parse(readFileSync6(answersFile(), "utf-8"));
|
|
2386
|
-
if (typeof parsed !== "object" || parsed === null)
|
|
2387
|
-
return {};
|
|
2388
|
-
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
2389
|
-
} catch {
|
|
2390
|
-
return {};
|
|
2391
|
-
}
|
|
2392
|
-
}
|
|
2393
|
-
function earlierAnswers(key) {
|
|
2394
|
-
return stored()[key] ?? [];
|
|
2395
|
-
}
|
|
2396
|
-
function rememberAnswer(key, answer) {
|
|
2397
|
-
const all = stored();
|
|
2398
|
-
const file = answersFile();
|
|
2399
|
-
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
2400
|
-
try {
|
|
2401
|
-
mkdirSync3(dirname5(file), { recursive: true });
|
|
2402
|
-
writeFileSync2(file, JSON.stringify(all));
|
|
2403
|
-
} catch {}
|
|
2404
|
-
}
|
|
2405
|
-
|
|
2406
|
-
// ../kit/src/prompt.ts
|
|
2407
|
-
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
2408
|
-
var MAX_LISTED = 12;
|
|
2409
|
-
function readKeys(input, paste = { active: false }) {
|
|
2410
|
-
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
2411
|
-
}
|
|
2412
|
-
function roomAfter(question, columns) {
|
|
2413
|
-
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
2414
|
-
}
|
|
2415
|
-
function withCaret(colors, line, room, dim = false) {
|
|
2416
|
-
const { before, at, after } = visible(line, room);
|
|
2417
|
-
const tone = dim ? colors.dim : (text) => text;
|
|
2418
|
-
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
2419
|
-
}
|
|
2420
|
-
function sharedStart(texts) {
|
|
2421
|
-
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
2422
|
-
let length = first.length;
|
|
2423
|
-
for (const chars of rest) {
|
|
2424
|
-
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
2425
|
-
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
2426
|
-
}
|
|
2427
|
-
return first.slice(0, length).join("");
|
|
2428
|
-
}
|
|
2429
|
-
function listed2(colors, found, columns) {
|
|
2430
|
-
const shared = sharedStart(found);
|
|
2431
|
-
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
2432
|
-
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
2433
|
-
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
2434
|
-
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
2435
|
-
}
|
|
2436
|
-
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
2437
|
-
let line = { text: "", caret: 0 };
|
|
2438
|
-
let invalid;
|
|
2439
|
-
let completions = [];
|
|
2440
|
-
const remembered = history === undefined || mask ? undefined : history;
|
|
2441
|
-
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
2442
|
-
let recalled = -1;
|
|
2443
|
-
let draft = line;
|
|
2444
|
-
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
2445
|
-
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
2446
|
-
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
2447
|
-
if (state !== "asking")
|
|
2448
|
-
return [answer(colors, question, state, shown())];
|
|
2449
|
-
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
2450
|
-
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
2451
|
-
}, (key) => {
|
|
2452
|
-
if (key === "cancel")
|
|
2453
|
-
return "cancel";
|
|
2454
|
-
invalid = undefined;
|
|
2455
|
-
completions = [];
|
|
2456
|
-
if (line.chained === true && endsKills(key))
|
|
2457
|
-
line = { ...line, chained: false };
|
|
2458
|
-
if (key === "tab") {
|
|
2459
|
-
const chars = [...line.text];
|
|
2460
|
-
const before = chars.slice(0, line.caret).join("");
|
|
2461
|
-
const found = complete?.(before) ?? [];
|
|
2462
|
-
const filled = sharedStart(found);
|
|
2463
|
-
if ([...filled].length > [...before].length)
|
|
2464
|
-
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
2465
|
-
else
|
|
2466
|
-
completions = found;
|
|
2467
|
-
return;
|
|
2468
|
-
}
|
|
2469
|
-
if (key === "enter") {
|
|
2470
|
-
invalid = validate?.(taken());
|
|
2471
|
-
return invalid === undefined ? "enter" : undefined;
|
|
2472
|
-
}
|
|
2473
|
-
if (key === "up" || key === "down") {
|
|
2474
|
-
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
2475
|
-
if (recalled === -1)
|
|
2476
|
-
draft = line;
|
|
2477
|
-
recalled = to;
|
|
2478
|
-
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
2479
|
-
line = { ...shown, killed: line.killed ?? "" };
|
|
2480
|
-
return;
|
|
2481
|
-
}
|
|
2482
|
-
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
2483
|
-
if (typeof edit === "object" || isEditKey(edit))
|
|
2484
|
-
line = editLine(line, edit);
|
|
2485
|
-
return;
|
|
2486
|
-
});
|
|
2487
|
-
if (!accepted)
|
|
2488
|
-
return;
|
|
2489
|
-
if (remembered !== undefined && taken() !== "")
|
|
2490
|
-
rememberAnswer(remembered, taken());
|
|
2491
|
-
return taken();
|
|
2492
|
-
}
|
|
2493
|
-
function answer(colors, question, state, picked) {
|
|
2494
|
-
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2495
|
-
}
|
|
2496
|
-
async function ask(question, { hint, terminal = process23 }, render, press) {
|
|
2497
|
-
const { stdin, stderr } = terminal;
|
|
2498
|
-
if (!isInteractive(terminal))
|
|
2499
|
-
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
2500
|
-
const colors = paint(stderr);
|
|
2501
|
-
let current = "asking";
|
|
2502
|
-
let outcome;
|
|
2503
|
-
const columns = () => stderr.columns || 80;
|
|
2504
|
-
const draw = (state, last = false) => {
|
|
2505
|
-
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
2506
|
-
const rows = rowsTaken(frame, columns());
|
|
2507
|
-
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
2508
|
-
current = state;
|
|
2509
|
-
};
|
|
2510
|
-
const redraw = () => draw(current);
|
|
2511
|
-
const paste = { active: false };
|
|
2512
|
-
const stop = terminal.stop ?? (terminal === process23 ? stopJob : undefined);
|
|
2513
|
-
const suspend = () => {
|
|
2514
|
-
if (stop === undefined)
|
|
2515
|
-
return;
|
|
2516
|
-
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
2517
|
-
stdin.setRawMode(false);
|
|
2518
|
-
stop();
|
|
2519
|
-
stdin.setRawMode(true);
|
|
2520
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2521
|
-
};
|
|
2522
|
-
try {
|
|
2523
|
-
stderr.on?.("resize", redraw);
|
|
2524
|
-
stdin.setRawMode(true);
|
|
2525
|
-
stdin.resume();
|
|
2526
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2527
|
-
draw("asking");
|
|
2528
|
-
return await new Promise((resolve) => {
|
|
2529
|
-
function onData(data) {
|
|
2530
|
-
for (const key of readKeys(data.toString(), paste)) {
|
|
2531
|
-
if (key === "suspend") {
|
|
2532
|
-
suspend();
|
|
2533
|
-
continue;
|
|
2534
|
-
}
|
|
2535
|
-
const pressed = press(key);
|
|
2536
|
-
if (pressed !== undefined) {
|
|
2537
|
-
settle(pressed);
|
|
2538
|
-
return;
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
draw("asking");
|
|
2542
|
-
}
|
|
2543
|
-
function onEnd() {
|
|
2544
|
-
settle("cancel");
|
|
2545
|
-
}
|
|
2546
|
-
function settle(settled) {
|
|
2547
|
-
outcome = settled;
|
|
2548
|
-
stdin.off("data", onData);
|
|
2549
|
-
stdin.off("end", onEnd);
|
|
2550
|
-
resolve(settled === "enter");
|
|
2551
|
-
}
|
|
2552
|
-
stdin.on("data", onData);
|
|
2553
|
-
stdin.on("end", onEnd);
|
|
2554
|
-
});
|
|
2555
|
-
} finally {
|
|
2556
|
-
stderr.off?.("resize", redraw);
|
|
2557
|
-
draw(outcome ?? "cancel", true);
|
|
2558
|
-
stderr.write(`
|
|
2559
|
-
\x1B[?25h\x1B[?2004l`);
|
|
2560
|
-
stdin.setRawMode(false);
|
|
2561
|
-
stdin.pause();
|
|
2562
|
-
}
|
|
2563
|
-
}
|
|
2795
|
+
// src/j.ts
|
|
2796
|
+
init_prompt();
|
|
2564
2797
|
|
|
2565
2798
|
// src/job-picker.ts
|
|
2566
|
-
import
|
|
2799
|
+
import process25 from "process";
|
|
2567
2800
|
|
|
2568
2801
|
// src/jobs.ts
|
|
2569
2802
|
import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync7 } from "fs";
|
|
@@ -2983,7 +3216,7 @@ function labelled(entries) {
|
|
|
2983
3216
|
return new Set(entries.map((entry) => entry.tag)).size > 1;
|
|
2984
3217
|
}
|
|
2985
3218
|
function row(entry, labels, signed) {
|
|
2986
|
-
const colors = paint(
|
|
3219
|
+
const colors = paint(process25.stderr);
|
|
2987
3220
|
const keyed = entry.dir === "." ? entry.name : `${colors.dim(`${entry.dir}/`)}${entry.name}`;
|
|
2988
3221
|
return {
|
|
2989
3222
|
hidden: [entry.kind, entry.dir, entry.name, id(entry)],
|
|
@@ -2997,7 +3230,7 @@ async function pickJob(entries, narrowed = false) {
|
|
|
2997
3230
|
prompt: `${[...new Set(entries.map((entry) => entry.tag))].join("/")}> `,
|
|
2998
3231
|
searched: labels ? 2 : 1,
|
|
2999
3232
|
...narrowed ? { height: heightFor(entries.length) } : {},
|
|
3000
|
-
preview: `${
|
|
3233
|
+
preview: `${process25.execPath} ${process25.argv[1]} --show {1} {2} {3}`
|
|
3001
3234
|
});
|
|
3002
3235
|
return entries.find((candidate) => id(candidate) === picked?.hidden[3]);
|
|
3003
3236
|
}
|
|
@@ -3006,10 +3239,9 @@ async function pickJob(entries, narrowed = false) {
|
|
|
3006
3239
|
var usage2 = `j [name] [args...]
|
|
3007
3240
|
j -
|
|
3008
3241
|
|
|
3009
|
-
Without a name, picks a recipe,
|
|
3010
|
-
\`j -\` runs the last one again with the same arguments, \`j <name> [args...]\` runs without the picker, the words after the name filling the parameters in order
|
|
3011
|
-
The sources are a Justfile, a Makefile,
|
|
3012
|
-
A name is the key behind the folder it runs from, \`api/test\`, bare for this folder. A name several entries share offers them, unless it comes qualified by its runner: \`just:check\`, \`bun:api/test\`.`;
|
|
3242
|
+
Without a name, picks a recipe, script or task of this folder, its parents and its child folders and runs it, the ones run last first; without a terminal it lists them instead.
|
|
3243
|
+
\`j -\` runs the last one again with the same arguments, \`j <name> [args...]\` runs without the picker, the words after the name filling the parameters in order.
|
|
3244
|
+
The sources are a Justfile, a Makefile, package.json and composer.json scripts, deno tasks, a Taskfile, mise tasks and a pyproject; a name several share offers them, unless qualified by its runner (\`just:check\`).`;
|
|
3013
3245
|
var EXITS = [["its own", "the code of the command it ran"], [1, "there is nothing to run here or nothing by that name"]];
|
|
3014
3246
|
var options = {
|
|
3015
3247
|
json: jsonOption("[{ id, key, runner, dir, name, doc, parameters }]")
|
|
@@ -3018,7 +3250,7 @@ function preview(kind, dir, name) {
|
|
|
3018
3250
|
const entry = readKind(kind, dir).find((candidate) => candidate.name === name);
|
|
3019
3251
|
if (entry === undefined)
|
|
3020
3252
|
return;
|
|
3021
|
-
const colors = paint(
|
|
3253
|
+
const colors = paint(process26.stdout);
|
|
3022
3254
|
console.log(`${colors.dim(`$ ${dir === "." ? "" : `env -C ${dir} `}`)}${colors.bold([...entry.runner, entry.name].join(" "))}
|
|
3023
3255
|
`);
|
|
3024
3256
|
if (entry.body !== undefined)
|
|
@@ -3051,7 +3283,7 @@ function listed3(found) {
|
|
|
3051
3283
|
}));
|
|
3052
3284
|
}
|
|
3053
3285
|
function listing(found) {
|
|
3054
|
-
const colors = paint(
|
|
3286
|
+
const colors = paint(process26.stdout);
|
|
3055
3287
|
const labels = labelled(found);
|
|
3056
3288
|
return table(found.map((entry) => [...labels ? [entry.tag] : [], key(entry), signature(entry), colors.dim(entry.doc ?? "")]));
|
|
3057
3289
|
}
|
|
@@ -3152,4 +3384,4 @@ async function j2(argv) {
|
|
|
3152
3384
|
}
|
|
3153
3385
|
|
|
3154
3386
|
// src/j-cli.ts
|
|
3155
|
-
|
|
3387
|
+
process27.exitCode = await runMain({ name: "j", version, run: j2 });
|