@kaynooo/cli-git 0.16.1 → 0.17.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 +1 -1
- package/dist/gb.js +1642 -1139
- package/dist/gc.js +1053 -153
- package/dist/gcl.js +1086 -166
- package/dist/gd.js +1064 -164
- package/dist/gf.js +1095 -169
- package/dist/gm.js +1667 -1152
- package/dist/gp.js +1073 -167
- package/dist/gst.js +1072 -172
- package/dist/gu.js +1059 -159
- package/package.json +5 -5
package/dist/gm.js
CHANGED
|
@@ -1,21 +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
|
-
import process23 from "process";
|
|
7
|
-
// ../kit/src/args.ts
|
|
8
|
-
import process9 from "process";
|
|
9
|
-
import { parseArgs } from "util";
|
|
10
|
-
|
|
11
|
-
// ../kit/src/format.ts
|
|
12
|
-
import process7 from "process";
|
|
13
|
-
|
|
14
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
15
|
-
var N = new Map;
|
|
16
|
-
var Nt = /\s+\S*$/;
|
|
17
|
-
var Y = /\s/;
|
|
18
|
-
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 = "...") {
|
|
19
17
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
20
18
|
if (t.length <= e)
|
|
21
19
|
return t;
|
|
@@ -26,13 +24,22 @@ function ko(t, e, r = "...") {
|
|
|
26
24
|
c = c.trimEnd();
|
|
27
25
|
return s ? (c + n).slice(0, l) : c + n;
|
|
28
26
|
}
|
|
29
|
-
var
|
|
30
|
-
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
|
+
});
|
|
31
40
|
|
|
32
41
|
// ../kit/src/mode.ts
|
|
33
42
|
import process2 from "process";
|
|
34
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
35
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
36
43
|
function isSet(value) {
|
|
37
44
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
38
45
|
}
|
|
@@ -49,12 +56,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
49
56
|
function isInteractive(streams = process2) {
|
|
50
57
|
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
51
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
|
+
});
|
|
52
64
|
|
|
53
|
-
//
|
|
54
|
-
import process6 from "process";
|
|
55
|
-
|
|
56
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
57
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
65
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
58
66
|
function b(r) {
|
|
59
67
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
60
68
|
if (!G2.test(e))
|
|
@@ -65,11 +73,6 @@ function b(r) {
|
|
|
65
73
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
66
74
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
67
75
|
}
|
|
68
|
-
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") => {
|
|
69
|
-
let [l, n, c] = b(r);
|
|
70
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
71
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
72
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
73
76
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
74
77
|
if (e.FORCE_COLOR !== undefined)
|
|
75
78
|
return h.has(e.FORCE_COLOR);
|
|
@@ -83,7 +86,7 @@ function f(r, e = []) {
|
|
|
83
86
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
84
87
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
85
88
|
return new Proxy(c, { get(t, i) {
|
|
86
|
-
let a =
|
|
89
|
+
let a = B[i];
|
|
87
90
|
if (Array.isArray(a)) {
|
|
88
91
|
let s = g.get(i);
|
|
89
92
|
if (s === undefined)
|
|
@@ -106,13 +109,21 @@ function f(r, e = []) {
|
|
|
106
109
|
function Fe(r = {}) {
|
|
107
110
|
return f(r);
|
|
108
111
|
}
|
|
109
|
-
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
|
+
});
|
|
110
122
|
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
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
|
+
});
|
|
116
127
|
|
|
117
128
|
// ../kit/src/config.ts
|
|
118
129
|
import { existsSync } from "fs";
|
|
@@ -128,6 +139,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
128
139
|
return;
|
|
129
140
|
}
|
|
130
141
|
}
|
|
142
|
+
var init_config = __esm(() => {
|
|
143
|
+
init_args();
|
|
144
|
+
});
|
|
131
145
|
|
|
132
146
|
// ../kit/src/user-config.ts
|
|
133
147
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
@@ -159,13 +173,17 @@ function readUserConfig(bin, where = {}, legacy = []) {
|
|
|
159
173
|
return {};
|
|
160
174
|
}
|
|
161
175
|
}
|
|
176
|
+
var init_user_config = () => {};
|
|
162
177
|
|
|
163
178
|
// ../kit/src/theme.ts
|
|
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";
|
|
164
183
|
function toLinear(channel) {
|
|
165
184
|
const value = channel / 255;
|
|
166
185
|
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
167
186
|
}
|
|
168
|
-
var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055)));
|
|
169
187
|
function toOklab(hex) {
|
|
170
188
|
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
171
189
|
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
@@ -180,7 +198,6 @@ function fromOklab([lightness, a, b]) {
|
|
|
180
198
|
const channels = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
|
|
181
199
|
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
182
200
|
}
|
|
183
|
-
var ENDS = new Map;
|
|
184
201
|
function gradientAt(theme, ratio) {
|
|
185
202
|
if (theme.gradient === undefined)
|
|
186
203
|
return;
|
|
@@ -194,33 +211,11 @@ function gradientAt(theme, ratio) {
|
|
|
194
211
|
const [from, to] = ends;
|
|
195
212
|
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
196
213
|
}
|
|
197
|
-
var DEFAULT = {
|
|
198
|
-
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" },
|
|
199
|
-
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" },
|
|
200
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
201
|
-
bins: {},
|
|
202
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
203
|
-
};
|
|
204
|
-
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" };
|
|
205
|
-
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" };
|
|
206
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
207
|
-
var PRESETS = {
|
|
208
|
-
default: {},
|
|
209
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
210
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
211
|
-
ascii: { glyphs: ASCII }
|
|
212
|
-
};
|
|
213
|
-
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"]);
|
|
214
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
215
|
-
var CONTROL = /\p{Cc}/u;
|
|
216
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
217
|
-
var SPACES = /\s+/;
|
|
218
214
|
function isColorSpec(spec) {
|
|
219
215
|
if (typeof spec === "number")
|
|
220
216
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
221
217
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
222
218
|
}
|
|
223
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
224
219
|
function cubeLevel(channel) {
|
|
225
220
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
226
221
|
}
|
|
@@ -328,7 +323,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
328
323
|
function endsWalk(home) {
|
|
329
324
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
330
325
|
}
|
|
331
|
-
var warned = new Set;
|
|
332
326
|
function warnOnce(message) {
|
|
333
327
|
if (warned.has(message))
|
|
334
328
|
return;
|
|
@@ -365,8 +359,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
365
359
|
}
|
|
366
360
|
return { theme, sources, preset };
|
|
367
361
|
}
|
|
368
|
-
var current;
|
|
369
|
-
var currentKey = "";
|
|
370
362
|
function activeTheme() {
|
|
371
363
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
372
364
|
if (current === undefined || key !== currentKey) {
|
|
@@ -375,9 +367,38 @@ function activeTheme() {
|
|
|
375
367
|
}
|
|
376
368
|
return current;
|
|
377
369
|
}
|
|
370
|
+
var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055))), ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
371
|
+
var init_theme = __esm(() => {
|
|
372
|
+
init_config();
|
|
373
|
+
init_user_config();
|
|
374
|
+
ENDS = new Map;
|
|
375
|
+
DEFAULT = {
|
|
376
|
+
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" },
|
|
377
|
+
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" },
|
|
378
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
379
|
+
bins: {},
|
|
380
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
381
|
+
};
|
|
382
|
+
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" };
|
|
383
|
+
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" };
|
|
384
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
385
|
+
PRESETS = {
|
|
386
|
+
default: {},
|
|
387
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
388
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
389
|
+
ascii: { glyphs: ASCII }
|
|
390
|
+
};
|
|
391
|
+
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"]);
|
|
392
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
393
|
+
CONTROL = /\p{Cc}/u;
|
|
394
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
395
|
+
SPACES = /\s+/;
|
|
396
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
397
|
+
warned = new Set;
|
|
398
|
+
});
|
|
378
399
|
|
|
379
400
|
// ../kit/src/style.ts
|
|
380
|
-
|
|
401
|
+
import process6 from "process";
|
|
381
402
|
function takesControlCodes(stream, env = process6.env) {
|
|
382
403
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
383
404
|
}
|
|
@@ -397,17 +418,24 @@ function role(name, stream, env = process6.env) {
|
|
|
397
418
|
const colors = paint(stream, env);
|
|
398
419
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
399
420
|
}
|
|
400
|
-
var STATUS_WORDS
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
421
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
422
|
+
var init_style = __esm(() => {
|
|
423
|
+
init_colors();
|
|
424
|
+
init_mode();
|
|
425
|
+
init_theme();
|
|
426
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
427
|
+
STATUS_WORDS = {
|
|
428
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
429
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
430
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
431
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
432
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
433
|
+
};
|
|
434
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
435
|
+
});
|
|
408
436
|
|
|
409
437
|
// ../kit/src/format.ts
|
|
410
|
-
|
|
438
|
+
import process7 from "process";
|
|
411
439
|
function formatSeconds(total) {
|
|
412
440
|
let rest = Math.max(0, Math.round(total));
|
|
413
441
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -439,10 +467,8 @@ function formatAge(date, now = Date.now()) {
|
|
|
439
467
|
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
440
468
|
}
|
|
441
469
|
function truncate(text, width) {
|
|
442
|
-
return
|
|
470
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
443
471
|
}
|
|
444
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
445
|
-
var ESCAPE = String.fromCharCode(27);
|
|
446
472
|
function textWidth(text) {
|
|
447
473
|
return Bun.stringWidth(text);
|
|
448
474
|
}
|
|
@@ -491,12 +517,18 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
491
517
|
function printJson(value) {
|
|
492
518
|
console.log(jsonText(value));
|
|
493
519
|
}
|
|
520
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
521
|
+
var init_format = __esm(() => {
|
|
522
|
+
init_text();
|
|
523
|
+
init_mode();
|
|
524
|
+
init_style();
|
|
525
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
526
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
527
|
+
ESCAPE = String.fromCharCode(27);
|
|
528
|
+
});
|
|
494
529
|
|
|
495
530
|
// ../kit/src/help.ts
|
|
496
531
|
import process8 from "process";
|
|
497
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
498
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
499
|
-
var FULL_STOP = /\.$/;
|
|
500
532
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
501
533
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
502
534
|
}
|
|
@@ -533,7 +565,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
533
565
|
return [];
|
|
534
566
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
535
567
|
}
|
|
536
|
-
var MAX_INLINE_CHOICES = 24;
|
|
537
568
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
538
569
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
539
570
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -548,9 +579,16 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
548
579
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
549
580
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
550
581
|
}
|
|
582
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, MAX_INLINE_CHOICES = 24;
|
|
583
|
+
var init_help = __esm(() => {
|
|
584
|
+
init_mode();
|
|
585
|
+
init_style();
|
|
586
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
587
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
588
|
+
FULL_STOP = /\.$/;
|
|
589
|
+
});
|
|
551
590
|
|
|
552
591
|
// ../kit/src/text.ts
|
|
553
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
554
592
|
function distance(a, b) {
|
|
555
593
|
const left = [...a];
|
|
556
594
|
const right = [...b];
|
|
@@ -576,8 +614,12 @@ function closest(name, names) {
|
|
|
576
614
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
577
615
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
578
616
|
}
|
|
617
|
+
var ANSI;
|
|
618
|
+
var init_text2 = __esm(() => {
|
|
619
|
+
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
620
|
+
});
|
|
621
|
+
|
|
579
622
|
// ../kit/src/input.ts
|
|
580
|
-
var WHOLE = /^\d+$/;
|
|
581
623
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
582
624
|
if (value === undefined)
|
|
583
625
|
return fallback;
|
|
@@ -586,8 +628,6 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
586
628
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
587
629
|
return number;
|
|
588
630
|
}
|
|
589
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
590
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
591
631
|
function duration(value, name, fallback, unit = "s") {
|
|
592
632
|
if (value === undefined)
|
|
593
633
|
return fallback;
|
|
@@ -597,40 +637,27 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
597
637
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
598
638
|
return ms;
|
|
599
639
|
}
|
|
640
|
+
var WHOLE, DURATION, UNIT_MS;
|
|
641
|
+
var init_input = __esm(() => {
|
|
642
|
+
init_args();
|
|
643
|
+
WHOLE = /^\d+$/;
|
|
644
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
645
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
646
|
+
});
|
|
600
647
|
|
|
601
648
|
// ../kit/src/args.ts
|
|
602
|
-
|
|
649
|
+
import process9 from "process";
|
|
650
|
+
import { parseArgs } from "util";
|
|
603
651
|
function jsonOption(holds) {
|
|
604
652
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
605
653
|
}
|
|
606
|
-
class Exit extends Error {
|
|
607
|
-
code;
|
|
608
|
-
hint;
|
|
609
|
-
constructor(message, code, hint) {
|
|
610
|
-
super(message);
|
|
611
|
-
this.code = code;
|
|
612
|
-
this.hint = hint;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
654
|
function fail(message, code = 2, hint) {
|
|
616
655
|
throw new Exit(message, code, hint);
|
|
617
656
|
}
|
|
618
|
-
|
|
619
|
-
class UsageError extends Exit {
|
|
620
|
-
constructor(message, hint) {
|
|
621
|
-
super(message, 2, hint);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
657
|
function badUsage(message) {
|
|
625
658
|
throw new UsageError(message);
|
|
626
659
|
}
|
|
627
660
|
|
|
628
|
-
class HelpShown extends Exit {
|
|
629
|
-
constructor() {
|
|
630
|
-
super("help shown", 0);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
661
|
class Completing {
|
|
635
662
|
options;
|
|
636
663
|
positionals;
|
|
@@ -641,11 +668,6 @@ class Completing {
|
|
|
641
668
|
this.candidates = candidates;
|
|
642
669
|
}
|
|
643
670
|
}
|
|
644
|
-
var completion = { active: false };
|
|
645
|
-
var OUTPUT_OPTIONS = {
|
|
646
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
647
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
648
|
-
};
|
|
649
671
|
function applyOutput(color, plain, env = process9.env) {
|
|
650
672
|
const when = plain === true ? "never" : color ?? "auto";
|
|
651
673
|
if (when === "auto")
|
|
@@ -799,7 +821,6 @@ function parseError(error) {
|
|
|
799
821
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
800
822
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
801
823
|
}
|
|
802
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
803
824
|
function nearestOption(message, options, allowNegative) {
|
|
804
825
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
805
826
|
if (typed === undefined)
|
|
@@ -815,1117 +836,1592 @@ function nearestOption(message, options, allowNegative) {
|
|
|
815
836
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
816
837
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
817
838
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
839
|
+
var DASHES, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
840
|
+
var init_args = __esm(() => {
|
|
841
|
+
init_format();
|
|
842
|
+
init_help();
|
|
843
|
+
init_text2();
|
|
844
|
+
init_help();
|
|
845
|
+
init_input();
|
|
846
|
+
DASHES = /^-+/;
|
|
847
|
+
Exit = class Exit extends Error {
|
|
848
|
+
code;
|
|
849
|
+
hint;
|
|
850
|
+
constructor(message, code, hint) {
|
|
851
|
+
super(message);
|
|
852
|
+
this.code = code;
|
|
853
|
+
this.hint = hint;
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
UsageError = class UsageError extends Exit {
|
|
857
|
+
constructor(message, hint) {
|
|
858
|
+
super(message, 2, hint);
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
HelpShown = class HelpShown extends Exit {
|
|
862
|
+
constructor() {
|
|
863
|
+
super("help shown", 0);
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
completion = { active: false };
|
|
867
|
+
OUTPUT_OPTIONS = {
|
|
868
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
869
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
870
|
+
};
|
|
871
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
// ../kit/src/folders.ts
|
|
875
|
+
import { homedir as homedir3 } from "os";
|
|
876
|
+
import { join as join4 } from "path";
|
|
877
|
+
import process13 from "process";
|
|
878
|
+
function cacheFolder({ home = homedir3(), env = process13.env } = {}) {
|
|
879
|
+
return env.XDG_CACHE_HOME ?? join4(home, ".cache");
|
|
880
|
+
}
|
|
881
|
+
var SKIPPED_FOLDERS;
|
|
882
|
+
var init_folders = __esm(() => {
|
|
883
|
+
init_user_config();
|
|
884
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
// ../kit/src/answers.ts
|
|
888
|
+
import { mkdirSync, readFileSync as readFileSync4, writeFileSync } from "fs";
|
|
889
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
890
|
+
function answersFile() {
|
|
891
|
+
return join5(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
892
|
+
}
|
|
893
|
+
function stored() {
|
|
823
894
|
try {
|
|
824
|
-
|
|
895
|
+
const parsed = JSON.parse(readFileSync4(answersFile(), "utf-8"));
|
|
896
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
897
|
+
return {};
|
|
898
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
825
899
|
} catch {
|
|
826
|
-
return;
|
|
900
|
+
return {};
|
|
827
901
|
}
|
|
828
902
|
}
|
|
829
|
-
function
|
|
903
|
+
function earlierAnswers(key) {
|
|
904
|
+
return stored()[key] ?? [];
|
|
905
|
+
}
|
|
906
|
+
function rememberAnswer(key, answer) {
|
|
907
|
+
const all = stored();
|
|
908
|
+
const file = answersFile();
|
|
909
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
830
910
|
try {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}
|
|
911
|
+
mkdirSync(dirname2(file), { recursive: true });
|
|
912
|
+
writeFileSync(file, JSON.stringify(all));
|
|
913
|
+
} catch {}
|
|
835
914
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
915
|
+
var KEPT = 50;
|
|
916
|
+
var init_answers = __esm(() => {
|
|
917
|
+
init_folders();
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
// ../kit/src/job.ts
|
|
921
|
+
import process14 from "process";
|
|
922
|
+
function stopJob() {
|
|
923
|
+
process14.kill(0, "SIGTSTP");
|
|
841
924
|
}
|
|
842
|
-
|
|
843
|
-
import process12 from "process";
|
|
925
|
+
var init_job = () => {};
|
|
844
926
|
|
|
845
|
-
// ../kit/src/
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
var KILL_GRACE_MS = 2000;
|
|
849
|
-
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
850
|
-
function exitCodeOf(code, signal) {
|
|
851
|
-
if (code !== null)
|
|
852
|
-
return code;
|
|
853
|
-
if (typeof signal === "number")
|
|
854
|
-
return 128 + signal;
|
|
855
|
-
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
927
|
+
// ../kit/src/picker/line.ts
|
|
928
|
+
function isEditKey(key) {
|
|
929
|
+
return EDIT_KEYS.has(key);
|
|
856
930
|
}
|
|
857
|
-
function
|
|
858
|
-
|
|
859
|
-
let child;
|
|
860
|
-
const held = {
|
|
861
|
-
get signal() {
|
|
862
|
-
return received;
|
|
863
|
-
},
|
|
864
|
-
forward: (to) => {
|
|
865
|
-
child = to;
|
|
866
|
-
},
|
|
867
|
-
release: () => {
|
|
868
|
-
for (const signal of SIGNALS)
|
|
869
|
-
process11.off(signal, onSignal);
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
function onSignal(signal) {
|
|
873
|
-
received = signal;
|
|
874
|
-
if (child !== undefined) {
|
|
875
|
-
child.kill(signal);
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
if (cleanup === undefined)
|
|
879
|
-
return;
|
|
880
|
-
held.release();
|
|
881
|
-
cleanup(signal);
|
|
882
|
-
process11.kill(process11.pid, signal);
|
|
883
|
-
}
|
|
884
|
-
for (const signal of SIGNALS)
|
|
885
|
-
process11.on(signal, onSignal);
|
|
886
|
-
return held;
|
|
931
|
+
function endsKills(key) {
|
|
932
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
887
933
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
891
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
892
|
-
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
893
|
-
const timers = [];
|
|
894
|
-
const killGroup = (killing) => {
|
|
895
|
-
if (state.done)
|
|
896
|
-
return;
|
|
897
|
-
try {
|
|
898
|
-
if (grouped)
|
|
899
|
-
process11.kill(-proc.pid, killing);
|
|
900
|
-
else
|
|
901
|
-
proc.kill(killing);
|
|
902
|
-
} catch {}
|
|
903
|
-
};
|
|
904
|
-
const stop = () => {
|
|
905
|
-
killGroup("SIGTERM");
|
|
906
|
-
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
907
|
-
};
|
|
908
|
-
const onAbort = () => stop();
|
|
909
|
-
if (timeoutMs !== undefined) {
|
|
910
|
-
timers.push(setTimeout(() => {
|
|
911
|
-
state.timedOut = true;
|
|
912
|
-
stop();
|
|
913
|
-
}, timeoutMs));
|
|
914
|
-
}
|
|
915
|
-
if (signal?.aborted === true)
|
|
916
|
-
onAbort();
|
|
917
|
-
else
|
|
918
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
919
|
-
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
920
|
-
const drain = async (stream, name) => {
|
|
921
|
-
for await (const data of stream) {
|
|
922
|
-
if (state.failure !== undefined)
|
|
923
|
-
continue;
|
|
924
|
-
try {
|
|
925
|
-
onChunk?.({ stream: name, data });
|
|
926
|
-
} catch (error) {
|
|
927
|
-
state.failure = error;
|
|
928
|
-
stop();
|
|
929
|
-
continue;
|
|
930
|
-
}
|
|
931
|
-
if (state.kept + data.length > maxBytes) {
|
|
932
|
-
state.truncated = true;
|
|
933
|
-
continue;
|
|
934
|
-
}
|
|
935
|
-
state.kept += data.length;
|
|
936
|
-
chunks.push({ stream: name, data });
|
|
937
|
-
}
|
|
938
|
-
};
|
|
939
|
-
try {
|
|
940
|
-
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
941
|
-
await proc.exited;
|
|
942
|
-
} finally {
|
|
943
|
-
state.done = true;
|
|
944
|
-
for (const timer of timers)
|
|
945
|
-
clearTimeout(timer);
|
|
946
|
-
signal?.removeEventListener("abort", onAbort);
|
|
947
|
-
}
|
|
948
|
-
if (state.failure !== undefined)
|
|
949
|
-
throw state.failure;
|
|
950
|
-
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
951
|
-
let output;
|
|
952
|
-
let text;
|
|
953
|
-
return {
|
|
954
|
-
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
955
|
-
chunks,
|
|
956
|
-
timedOut: state.timedOut,
|
|
957
|
-
truncated: state.truncated,
|
|
958
|
-
get output() {
|
|
959
|
-
return output ??= joined();
|
|
960
|
-
},
|
|
961
|
-
get text() {
|
|
962
|
-
return text ??= (output ??= joined()).toString();
|
|
963
|
-
}
|
|
964
|
-
};
|
|
934
|
+
function isWord(char) {
|
|
935
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
965
936
|
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
974
|
-
var RESET_STYLE = `${ESC}[0m`;
|
|
975
|
-
var CTRL_C = 3;
|
|
976
|
-
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
977
|
-
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
978
|
-
function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
979
|
-
if (!takesControlCodes(stream, env))
|
|
980
|
-
return { redraw: () => {
|
|
981
|
-
return;
|
|
982
|
-
}, print: (text) => void stream.write(`${text}
|
|
983
|
-
`), stop: () => {
|
|
984
|
-
return;
|
|
985
|
-
} };
|
|
986
|
-
const write = stream.write.bind(stream);
|
|
987
|
-
let frame = 0;
|
|
988
|
-
let drawn = false;
|
|
989
|
-
const columns = () => {
|
|
990
|
-
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
991
|
-
return now === undefined || now === 0 ? 80 : now;
|
|
992
|
-
};
|
|
993
|
-
const clear = () => {
|
|
994
|
-
if (drawn)
|
|
995
|
-
write(CLEAR_BELOW);
|
|
996
|
-
drawn = false;
|
|
997
|
-
};
|
|
998
|
-
const draw = () => {
|
|
999
|
-
const width = columns() - 1;
|
|
1000
|
-
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
1001
|
-
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
1002
|
-
if (lines.length === 0) {
|
|
1003
|
-
clear();
|
|
1004
|
-
return;
|
|
1005
|
-
}
|
|
1006
|
-
write(`${CLEAR_BELOW}${lines.join(`
|
|
1007
|
-
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
1008
|
-
drawn = true;
|
|
1009
|
-
};
|
|
1010
|
-
const timer = setInterval(draw, FRAME_MS);
|
|
1011
|
-
stream.on?.("resize", draw);
|
|
1012
|
-
const restore = interceptOutput(clear);
|
|
1013
|
-
const release = swallowInput();
|
|
1014
|
-
const onExit = () => {
|
|
1015
|
-
clear();
|
|
1016
|
-
release();
|
|
1017
|
-
};
|
|
1018
|
-
const signals = holdSignals(stop);
|
|
1019
|
-
function stop() {
|
|
1020
|
-
clearInterval(timer);
|
|
1021
|
-
stream.off?.("resize", draw);
|
|
1022
|
-
clear();
|
|
1023
|
-
restore();
|
|
1024
|
-
release();
|
|
1025
|
-
process12.off("exit", onExit);
|
|
1026
|
-
signals.release();
|
|
1027
|
-
}
|
|
1028
|
-
timer.unref();
|
|
1029
|
-
process12.on("exit", onExit);
|
|
1030
|
-
return {
|
|
1031
|
-
redraw: draw,
|
|
1032
|
-
print: (text) => {
|
|
1033
|
-
clear();
|
|
1034
|
-
write(`${text}
|
|
1035
|
-
`);
|
|
1036
|
-
draw();
|
|
1037
|
-
},
|
|
1038
|
-
stop
|
|
1039
|
-
};
|
|
937
|
+
function wordStart(chars, from) {
|
|
938
|
+
let at = from;
|
|
939
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
940
|
+
at--;
|
|
941
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
942
|
+
at--;
|
|
943
|
+
return at;
|
|
1040
944
|
}
|
|
1041
|
-
function
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
const end = (line) => {
|
|
1049
|
-
region.stop();
|
|
1050
|
-
write(`${line}
|
|
1051
|
-
`);
|
|
1052
|
-
};
|
|
1053
|
-
return {
|
|
1054
|
-
update: (progress) => {
|
|
1055
|
-
const step = current?.step;
|
|
1056
|
-
current = progress;
|
|
1057
|
-
if (progress.step !== step) {
|
|
1058
|
-
started = performance.now();
|
|
1059
|
-
region.redraw();
|
|
1060
|
-
}
|
|
1061
|
-
},
|
|
1062
|
-
stop: region.stop,
|
|
1063
|
-
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1064
|
-
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1065
|
-
};
|
|
945
|
+
function wordEnd(chars, from) {
|
|
946
|
+
let at = from;
|
|
947
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
948
|
+
at++;
|
|
949
|
+
while (at < chars.length && isWord(chars[at]))
|
|
950
|
+
at++;
|
|
951
|
+
return at;
|
|
1066
952
|
}
|
|
1067
|
-
function
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
}
|
|
1075
|
-
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1076
|
-
return parts;
|
|
953
|
+
function spacedStart(chars, from) {
|
|
954
|
+
let at = from;
|
|
955
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
956
|
+
at--;
|
|
957
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
958
|
+
at--;
|
|
959
|
+
return at;
|
|
1077
960
|
}
|
|
1078
|
-
function
|
|
1079
|
-
return text;
|
|
961
|
+
function cut(chars, from, to) {
|
|
962
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
1080
963
|
}
|
|
1081
|
-
function
|
|
1082
|
-
|
|
964
|
+
function insert(chars, at, text) {
|
|
965
|
+
const typed = [...text];
|
|
966
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
1083
967
|
}
|
|
1084
|
-
function
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
968
|
+
function editLine(line, key) {
|
|
969
|
+
const { killed = "", chained = false } = line;
|
|
970
|
+
const chars = [...line.text];
|
|
971
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
972
|
+
const edited = edit(chars, at, key, killed);
|
|
973
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
974
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
975
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
976
|
+
if (taken === "")
|
|
977
|
+
return { ...edited, killed, chained };
|
|
978
|
+
if (!chained)
|
|
979
|
+
return { ...edited, killed: taken, chained: true };
|
|
980
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
981
|
+
}
|
|
982
|
+
function edit(chars, at, key, killed) {
|
|
983
|
+
const text = chars.join("");
|
|
984
|
+
if (typeof key === "object")
|
|
985
|
+
return insert(chars, at, key.text);
|
|
986
|
+
switch (key) {
|
|
987
|
+
case "left":
|
|
988
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
989
|
+
case "right":
|
|
990
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
991
|
+
case "wordleft":
|
|
992
|
+
return { text, caret: wordStart(chars, at) };
|
|
993
|
+
case "wordright":
|
|
994
|
+
return { text, caret: wordEnd(chars, at) };
|
|
995
|
+
case "linestart":
|
|
996
|
+
return { text, caret: 0 };
|
|
997
|
+
case "lineend":
|
|
998
|
+
return { text, caret: chars.length };
|
|
999
|
+
case "erase":
|
|
1000
|
+
return cut(chars, Math.max(at - 1, 0), at);
|
|
1001
|
+
case "delete":
|
|
1002
|
+
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
1003
|
+
case "word":
|
|
1004
|
+
return cut(chars, spacedStart(chars, at), at);
|
|
1005
|
+
case "killword":
|
|
1006
|
+
return cut(chars, wordStart(chars, at), at);
|
|
1007
|
+
case "killnext":
|
|
1008
|
+
return cut(chars, at, wordEnd(chars, at));
|
|
1009
|
+
case "clear":
|
|
1010
|
+
return cut(chars, 0, at);
|
|
1011
|
+
case "killend":
|
|
1012
|
+
return cut(chars, at, chars.length);
|
|
1013
|
+
case "yank":
|
|
1014
|
+
return insert(chars, at, killed);
|
|
1107
1015
|
}
|
|
1108
|
-
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1109
1016
|
}
|
|
1110
|
-
function
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
return;
|
|
1127
|
-
released = true;
|
|
1128
|
-
input.off("data", onData);
|
|
1129
|
-
input.pause();
|
|
1130
|
-
input.setRawMode(false);
|
|
1131
|
-
};
|
|
1017
|
+
function visible({ text, caret }, room) {
|
|
1018
|
+
const chars = [...text];
|
|
1019
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
1020
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
1021
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
1022
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
1023
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
1024
|
+
let start = at;
|
|
1025
|
+
let end = at + 1;
|
|
1026
|
+
while (start > 0 && fits(start - 1, end))
|
|
1027
|
+
start--;
|
|
1028
|
+
while (end < cells.length && fits(start, end + 1))
|
|
1029
|
+
end++;
|
|
1030
|
+
const left = start > 0 ? "\u2026" : "";
|
|
1031
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
1032
|
+
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) };
|
|
1132
1033
|
}
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1034
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
|
|
1035
|
+
var init_line = __esm(() => {
|
|
1036
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1037
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1038
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1039
|
+
WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
1040
|
+
SPACE = /\s/;
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
// ../kit/src/picker/score.ts
|
|
1044
|
+
function startsWord(text, index) {
|
|
1045
|
+
if (index === 0)
|
|
1046
|
+
return true;
|
|
1047
|
+
const before = text[index - 1];
|
|
1048
|
+
return BOUNDARY_AFTER.has(before) || LOWER.test(before) && UPPER.test(text[index]);
|
|
1049
|
+
}
|
|
1050
|
+
function fuzzy(query, text) {
|
|
1051
|
+
if (query === "")
|
|
1052
|
+
return { score: 0, positions: [] };
|
|
1053
|
+
const exact = query !== query.toLowerCase();
|
|
1054
|
+
const needle = exact ? query : query.toLowerCase();
|
|
1055
|
+
const haystack = exact ? text : text.toLowerCase();
|
|
1056
|
+
if (haystack.length !== text.length || needle.length > haystack.length)
|
|
1057
|
+
return;
|
|
1058
|
+
const width = haystack.length;
|
|
1059
|
+
const best = Array.from({ length: needle.length }, () => new Array(width).fill(NONE));
|
|
1060
|
+
const from = Array.from({ length: needle.length }, () => new Array(width).fill(-1));
|
|
1061
|
+
for (let j = 0;j < needle.length; j++) {
|
|
1062
|
+
let run = NONE;
|
|
1063
|
+
let runAt = -1;
|
|
1064
|
+
for (let i = j;i < width; i++) {
|
|
1065
|
+
if (j > 0 && i - 2 >= j - 1) {
|
|
1066
|
+
const candidate = best[j - 1][i - 2] + (i - 2) * GAP;
|
|
1067
|
+
if (candidate > run) {
|
|
1068
|
+
run = candidate;
|
|
1069
|
+
runAt = i - 2;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
if (haystack[i] !== needle[j])
|
|
1073
|
+
continue;
|
|
1074
|
+
const here = MATCH + (startsWord(text, i) ? BOUNDARY : 0) + (i === 0 ? PREFIX : 0);
|
|
1075
|
+
if (j === 0) {
|
|
1076
|
+
best[0][i] = here - i * GAP;
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
const joined = best[j - 1][i - 1] + CONSECUTIVE;
|
|
1080
|
+
const skipped = run - (i - 1) * GAP;
|
|
1081
|
+
if (joined > NONE && joined >= skipped) {
|
|
1082
|
+
best[j][i] = joined + here;
|
|
1083
|
+
from[j][i] = i - 1;
|
|
1084
|
+
} else if (skipped > NONE) {
|
|
1085
|
+
best[j][i] = skipped + here;
|
|
1086
|
+
from[j][i] = runAt;
|
|
1087
|
+
}
|
|
1148
1088
|
}
|
|
1149
|
-
}
|
|
1089
|
+
}
|
|
1090
|
+
const last = best[needle.length - 1];
|
|
1091
|
+
let end = -1;
|
|
1092
|
+
for (let i = 0;i < width; i++) {
|
|
1093
|
+
if (last[i] > NONE && (end === -1 || last[i] > last[end]))
|
|
1094
|
+
end = i;
|
|
1095
|
+
}
|
|
1096
|
+
if (end === -1)
|
|
1097
|
+
return;
|
|
1098
|
+
const positions = [];
|
|
1099
|
+
for (let j = needle.length - 1, i = end;j >= 0; j--) {
|
|
1100
|
+
positions.unshift(i);
|
|
1101
|
+
i = from[j][i];
|
|
1102
|
+
}
|
|
1103
|
+
return { score: last[end], positions };
|
|
1150
1104
|
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1162
|
-
if test "$line" = __files__
|
|
1163
|
-
__fish_complete_path $current
|
|
1164
|
-
else
|
|
1165
|
-
echo $line
|
|
1166
|
-
end
|
|
1167
|
-
end
|
|
1168
|
-
end`;
|
|
1169
|
-
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1170
|
-
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1171
|
-
local -a lines
|
|
1172
|
-
COMPREPLY=()
|
|
1173
|
-
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1174
|
-
for line in "\${lines[@]}"; do
|
|
1175
|
-
if [[ $line == __files__ ]]; then
|
|
1176
|
-
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1177
|
-
else
|
|
1178
|
-
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1179
|
-
fi
|
|
1180
|
-
done
|
|
1181
|
-
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1182
|
-
}`;
|
|
1183
|
-
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1184
|
-
local line
|
|
1185
|
-
local -a described plain
|
|
1186
|
-
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1187
|
-
if [[ $line == __files__ ]]; then
|
|
1188
|
-
_files
|
|
1189
|
-
elif [[ $line == *$'\\t'* ]]; then
|
|
1190
|
-
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1191
|
-
else
|
|
1192
|
-
plain+=("$line")
|
|
1193
|
-
fi
|
|
1194
|
-
done
|
|
1195
|
-
(( \${#described} )) && _describe -V value described
|
|
1196
|
-
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1197
|
-
return 0
|
|
1198
|
-
}`;
|
|
1199
|
-
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1200
|
-
if (shell === "fish")
|
|
1201
|
-
return `${header}
|
|
1202
|
-
${FISH_FUNCTION}
|
|
1203
|
-
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1204
|
-
`).join("")}`;
|
|
1205
|
-
if (shell === "bash")
|
|
1206
|
-
return `${header}
|
|
1207
|
-
${BASH_FUNCTION}
|
|
1208
|
-
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1209
|
-
`;
|
|
1210
|
-
return `${header}
|
|
1211
|
-
${ZSH_FUNCTION}
|
|
1212
|
-
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1213
|
-
`;
|
|
1105
|
+
function rank(query, lines) {
|
|
1106
|
+
if (query === "")
|
|
1107
|
+
return lines.map((_, index) => ({ index, positions: [] }));
|
|
1108
|
+
const found = [];
|
|
1109
|
+
for (const [index, line] of lines.entries()) {
|
|
1110
|
+
const match = fuzzy(query, line);
|
|
1111
|
+
if (match !== undefined)
|
|
1112
|
+
found.push({ index, positions: match.positions, score: match.score });
|
|
1113
|
+
}
|
|
1114
|
+
return found.sort((a, b) => b.score - a.score || lines[a.index].length - lines[b.index].length || a.index - b.index);
|
|
1214
1115
|
}
|
|
1116
|
+
var MATCH = 16, CONSECUTIVE = 12, BOUNDARY = 10, PREFIX = 8, GAP = 1, BOUNDARY_AFTER, UPPER, LOWER, NONE;
|
|
1117
|
+
var init_score = __esm(() => {
|
|
1118
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1119
|
+
UPPER = /\p{Lu}/u;
|
|
1120
|
+
LOWER = /\p{Ll}/u;
|
|
1121
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
1122
|
+
});
|
|
1215
1123
|
|
|
1216
|
-
// ../kit/src/
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
var CANCELLED = 130;
|
|
1220
|
-
function base64(text) {
|
|
1221
|
-
return Buffer.from(text).toString("base64");
|
|
1124
|
+
// ../kit/src/picker/state.ts
|
|
1125
|
+
function repeat(value, count) {
|
|
1126
|
+
return Array.from({ length: count }).fill(value);
|
|
1222
1127
|
}
|
|
1223
|
-
function
|
|
1224
|
-
|
|
1225
|
-
const
|
|
1226
|
-
|
|
1128
|
+
function styled(line) {
|
|
1129
|
+
let text = "";
|
|
1130
|
+
const styles = [];
|
|
1131
|
+
let active = "";
|
|
1132
|
+
let colored = false;
|
|
1133
|
+
let last = 0;
|
|
1134
|
+
function add(chunk) {
|
|
1135
|
+
const flat = chunk.replace(CONTROL2, " ");
|
|
1136
|
+
text += flat;
|
|
1137
|
+
colored ||= active !== "" && flat !== "";
|
|
1138
|
+
styles.push(...repeat(active, flat.length));
|
|
1139
|
+
}
|
|
1140
|
+
for (const found of line.matchAll(ANSI)) {
|
|
1141
|
+
add(line.slice(last, found.index));
|
|
1142
|
+
last = found.index + found[0].length;
|
|
1143
|
+
if (SGR.test(found[0]))
|
|
1144
|
+
active = RESET.test(found[0]) ? "" : active + found[0];
|
|
1145
|
+
}
|
|
1146
|
+
add(line.slice(last));
|
|
1147
|
+
return { text, styles: colored ? styles : undefined };
|
|
1227
1148
|
}
|
|
1228
|
-
function
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1149
|
+
function lay(rows, searched) {
|
|
1150
|
+
const parsed = rows.map((row) => row.cells.map(styled));
|
|
1151
|
+
const widths = (parsed[0] ?? []).map((_, column) => Math.max(...parsed.map((cells) => Bun.stringWidth(cells[column]?.text ?? ""))));
|
|
1152
|
+
return parsed.map((cells, at) => {
|
|
1153
|
+
let text = "";
|
|
1154
|
+
const styles = [];
|
|
1155
|
+
let colored = false;
|
|
1156
|
+
let searchEnd = 0;
|
|
1157
|
+
for (const [column, cell] of cells.entries()) {
|
|
1158
|
+
const last = column === cells.length - 1;
|
|
1159
|
+
const shown = cells.length > 1 && last ? cell.text.trimEnd() : cell.text;
|
|
1160
|
+
text += shown;
|
|
1161
|
+
colored ||= cell.styles !== undefined;
|
|
1162
|
+
styles.push(...cell.styles?.slice(0, shown.length) ?? repeat("", shown.length));
|
|
1163
|
+
if (column < searched)
|
|
1164
|
+
searchEnd = cells.length > 1 ? text.trimEnd().length : text.length;
|
|
1165
|
+
if (!last) {
|
|
1166
|
+
const pad = widths[column] - Bun.stringWidth(cell.text) + COLUMN_GAP;
|
|
1167
|
+
text += " ".repeat(pad);
|
|
1168
|
+
styles.push(...repeat("", pad));
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
return { text, styles: colored ? styles : undefined, searchable: rows[at].search ?? text.slice(0, searchEnd) };
|
|
1172
|
+
});
|
|
1232
1173
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1174
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1175
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1176
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1177
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1178
|
+
if (wheel !== undefined)
|
|
1179
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1180
|
+
const named = codes.get(sequence);
|
|
1181
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1182
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1183
|
+
paste.active = sequence === PASTE_START;
|
|
1184
|
+
return [];
|
|
1185
|
+
}
|
|
1186
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
1187
|
+
`))
|
|
1188
|
+
return [];
|
|
1189
|
+
if (key !== undefined)
|
|
1190
|
+
return [key];
|
|
1191
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
|
|
1195
|
+
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 };
|
|
1196
|
+
return withRows(state, rows);
|
|
1251
1197
|
}
|
|
1252
|
-
function
|
|
1253
|
-
const
|
|
1254
|
-
|
|
1198
|
+
function withRows(state, rows, header = state.header) {
|
|
1199
|
+
const cells = rows.map((row) => typeof row === "string" ? { hidden: [], cells: [row] } : row);
|
|
1200
|
+
const laid = lay(cells, state.searched);
|
|
1201
|
+
const searchable = laid.map((row) => row.searchable);
|
|
1202
|
+
const matches = rank(state.query, searchable);
|
|
1203
|
+
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 };
|
|
1255
1204
|
}
|
|
1256
|
-
function
|
|
1257
|
-
|
|
1205
|
+
function withQuery(state, key) {
|
|
1206
|
+
const { text, caret, killed = "", chained = false } = editLine({ text: state.query, caret: state.caret, killed: state.killed, chained: state.chained }, key);
|
|
1207
|
+
return text === state.query ? { ...state, caret, killed, chained } : { ...state, query: text, caret, killed, chained, matches: rank(text, state.searchable), cursor: 0 };
|
|
1258
1208
|
}
|
|
1259
|
-
function
|
|
1260
|
-
|
|
1261
|
-
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1209
|
+
function move(state, by) {
|
|
1210
|
+
return { ...state, cursor: Math.max(0, Math.min(state.matches.length - 1, state.cursor + by)) };
|
|
1262
1211
|
}
|
|
1263
|
-
function
|
|
1264
|
-
|
|
1265
|
-
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1266
|
-
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1212
|
+
function highlighted(state) {
|
|
1213
|
+
return state.matches[state.cursor]?.index;
|
|
1267
1214
|
}
|
|
1268
|
-
function
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1215
|
+
function press(state, key) {
|
|
1216
|
+
if (state.done !== undefined)
|
|
1217
|
+
return state;
|
|
1218
|
+
if (state.chained && endsKills(key))
|
|
1219
|
+
state = { ...state, chained: false };
|
|
1220
|
+
if (state.help)
|
|
1221
|
+
return { ...state, help: false };
|
|
1222
|
+
if (typeof key === "object") {
|
|
1223
|
+
if ("text" in key)
|
|
1224
|
+
return withQuery(state, key);
|
|
1225
|
+
return state.expect.includes(key.ctrl) ? { ...state, done: "accept", key: key.ctrl } : state;
|
|
1226
|
+
}
|
|
1227
|
+
if (isEditKey(key))
|
|
1228
|
+
return withQuery(state, key);
|
|
1229
|
+
switch (key) {
|
|
1230
|
+
case "up":
|
|
1231
|
+
return move(state, -1);
|
|
1232
|
+
case "down":
|
|
1233
|
+
return move(state, 1);
|
|
1234
|
+
case "pageup":
|
|
1235
|
+
return move(state, -state.page);
|
|
1236
|
+
case "pagedown":
|
|
1237
|
+
return move(state, state.page);
|
|
1238
|
+
case "home":
|
|
1239
|
+
return move(state, -state.matches.length);
|
|
1240
|
+
case "end":
|
|
1241
|
+
return move(state, state.matches.length);
|
|
1242
|
+
case "cancel":
|
|
1243
|
+
return { ...state, done: "cancel" };
|
|
1244
|
+
case "help":
|
|
1245
|
+
return { ...state, help: true };
|
|
1246
|
+
case "suspend":
|
|
1247
|
+
return state;
|
|
1248
|
+
case "enter":
|
|
1249
|
+
return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
|
|
1250
|
+
case "tab": {
|
|
1251
|
+
const at = highlighted(state);
|
|
1252
|
+
if (!state.multi || at === undefined)
|
|
1253
|
+
return state;
|
|
1254
|
+
const marked = new Set(state.marked);
|
|
1255
|
+
if (!marked.delete(at))
|
|
1256
|
+
marked.add(at);
|
|
1257
|
+
return move({ ...state, marked }, 1);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1272
1260
|
}
|
|
1273
|
-
function
|
|
1274
|
-
if (
|
|
1261
|
+
function chosen(state) {
|
|
1262
|
+
if (state.marked.size > 0)
|
|
1263
|
+
return state.rows.filter((_, index) => state.marked.has(index));
|
|
1264
|
+
const at = highlighted(state);
|
|
1265
|
+
return at === undefined ? [] : [state.rows[at]];
|
|
1266
|
+
}
|
|
1267
|
+
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;
|
|
1268
|
+
var init_state = __esm(() => {
|
|
1269
|
+
init_text2();
|
|
1270
|
+
init_line();
|
|
1271
|
+
init_score();
|
|
1272
|
+
CONTROL2 = /[\x00-\x1F\x7F-\x9F]/g;
|
|
1273
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1274
|
+
SGR = /^\x1B\[[0-9;]*m$/;
|
|
1275
|
+
RESET = /^\x1B\[0?m$/;
|
|
1276
|
+
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1277
|
+
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1278
|
+
KEYS = {
|
|
1279
|
+
"\x1B[A": "up",
|
|
1280
|
+
"\x1BOA": "up",
|
|
1281
|
+
"\x10": "up",
|
|
1282
|
+
"\x1B[B": "down",
|
|
1283
|
+
"\x1BOB": "down",
|
|
1284
|
+
"\x0E": "down",
|
|
1285
|
+
"\x1B[5~": "pageup",
|
|
1286
|
+
"\x1B[6~": "pagedown",
|
|
1287
|
+
"\x1B[H": "home",
|
|
1288
|
+
"\x1B[1~": "home",
|
|
1289
|
+
"\x1BOH": "home",
|
|
1290
|
+
"\x1B[F": "end",
|
|
1291
|
+
"\x1B[4~": "end",
|
|
1292
|
+
"\x1BOF": "end",
|
|
1293
|
+
"\r": "enter",
|
|
1294
|
+
"\n": "enter",
|
|
1295
|
+
"\x03": "cancel",
|
|
1296
|
+
"\x1B": "cancel",
|
|
1297
|
+
"\x1B[D": "left",
|
|
1298
|
+
"\x1BOD": "left",
|
|
1299
|
+
"\x1B[C": "right",
|
|
1300
|
+
"\x1BOC": "right",
|
|
1301
|
+
"\x1B[1;5D": "wordleft",
|
|
1302
|
+
"\x1B[1;3D": "wordleft",
|
|
1303
|
+
"\x1Bb": "wordleft",
|
|
1304
|
+
"\x1B[1;5C": "wordright",
|
|
1305
|
+
"\x1B[1;3C": "wordright",
|
|
1306
|
+
"\x1Bf": "wordright",
|
|
1307
|
+
"\x01": "linestart",
|
|
1308
|
+
"\x05": "lineend",
|
|
1309
|
+
"\x7F": "erase",
|
|
1310
|
+
"\x1B[3~": "delete",
|
|
1311
|
+
"\b": "killword",
|
|
1312
|
+
"\x1B\x7F": "killword",
|
|
1313
|
+
"\x1B[3;5~": "killnext",
|
|
1314
|
+
"\x1Bd": "killnext",
|
|
1315
|
+
"\x15": "clear",
|
|
1316
|
+
"\v": "killend",
|
|
1317
|
+
"\x17": "word",
|
|
1318
|
+
"\x19": "yank",
|
|
1319
|
+
"\x1A": "suspend",
|
|
1320
|
+
"\t": "tab",
|
|
1321
|
+
"\x1F": "help",
|
|
1322
|
+
"\x1BOP": "help",
|
|
1323
|
+
"\x1B[11~": "help"
|
|
1324
|
+
};
|
|
1325
|
+
CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
|
|
1326
|
+
});
|
|
1327
|
+
|
|
1328
|
+
// ../kit/src/redraw.ts
|
|
1329
|
+
function overwrite(lines, columns) {
|
|
1330
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1331
|
+
`);
|
|
1332
|
+
}
|
|
1333
|
+
function rowsTaken(lines, columns) {
|
|
1334
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1335
|
+
}
|
|
1336
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
1337
|
+
var init_redraw = __esm(() => {
|
|
1338
|
+
init_format();
|
|
1339
|
+
});
|
|
1340
|
+
|
|
1341
|
+
// ../kit/src/prompt.ts
|
|
1342
|
+
import process15 from "process";
|
|
1343
|
+
function readKeys(input, paste = { active: false }) {
|
|
1344
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1345
|
+
}
|
|
1346
|
+
function roomAfter(question, columns) {
|
|
1347
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
1348
|
+
}
|
|
1349
|
+
function withCaret(colors, line, room, dim = false) {
|
|
1350
|
+
const { before, at, after } = visible(line, room);
|
|
1351
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
1352
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
1353
|
+
}
|
|
1354
|
+
function sharedStart(texts) {
|
|
1355
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
1356
|
+
let length = first.length;
|
|
1357
|
+
for (const chars of rest) {
|
|
1358
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
1359
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
1360
|
+
}
|
|
1361
|
+
return first.slice(0, length).join("");
|
|
1362
|
+
}
|
|
1363
|
+
function listed2(colors, found, columns) {
|
|
1364
|
+
const shared = sharedStart(found);
|
|
1365
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
1366
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
1367
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
1368
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
1369
|
+
}
|
|
1370
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
1371
|
+
let line = { text: "", caret: 0 };
|
|
1372
|
+
let invalid;
|
|
1373
|
+
let completions = [];
|
|
1374
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
1375
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
1376
|
+
let recalled = -1;
|
|
1377
|
+
let draft = line;
|
|
1378
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
1379
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
1380
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
1381
|
+
if (state !== "asking")
|
|
1382
|
+
return [answer(colors, question, state, shown())];
|
|
1383
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
1384
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
1385
|
+
}, (key) => {
|
|
1386
|
+
if (key === "cancel")
|
|
1387
|
+
return "cancel";
|
|
1388
|
+
invalid = undefined;
|
|
1389
|
+
completions = [];
|
|
1390
|
+
if (line.chained === true && endsKills(key))
|
|
1391
|
+
line = { ...line, chained: false };
|
|
1392
|
+
if (key === "tab") {
|
|
1393
|
+
const chars = [...line.text];
|
|
1394
|
+
const before = chars.slice(0, line.caret).join("");
|
|
1395
|
+
const found = complete?.(before) ?? [];
|
|
1396
|
+
const filled = sharedStart(found);
|
|
1397
|
+
if ([...filled].length > [...before].length)
|
|
1398
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
1399
|
+
else
|
|
1400
|
+
completions = found;
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
if (key === "enter") {
|
|
1404
|
+
invalid = validate?.(taken());
|
|
1405
|
+
return invalid === undefined ? "enter" : undefined;
|
|
1406
|
+
}
|
|
1407
|
+
if (key === "up" || key === "down") {
|
|
1408
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
1409
|
+
if (recalled === -1)
|
|
1410
|
+
draft = line;
|
|
1411
|
+
recalled = to;
|
|
1412
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
1413
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
1416
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
1417
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
1418
|
+
line = editLine(line, edit);
|
|
1419
|
+
return;
|
|
1420
|
+
});
|
|
1421
|
+
if (!accepted)
|
|
1275
1422
|
return;
|
|
1423
|
+
if (remembered !== undefined && taken() !== "")
|
|
1424
|
+
rememberAnswer(remembered, taken());
|
|
1425
|
+
return taken();
|
|
1426
|
+
}
|
|
1427
|
+
function answer(colors, question, state, picked) {
|
|
1428
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1429
|
+
}
|
|
1430
|
+
async function ask(question, { hint, terminal = process15 }, render, press) {
|
|
1431
|
+
const { stdin, stderr } = terminal;
|
|
1432
|
+
if (!isInteractive(terminal))
|
|
1433
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1434
|
+
const colors = paint(stderr);
|
|
1435
|
+
let current = "asking";
|
|
1436
|
+
let outcome;
|
|
1437
|
+
const columns = () => stderr.columns || 80;
|
|
1438
|
+
const draw = (state, last = false) => {
|
|
1439
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1440
|
+
const rows = rowsTaken(frame, columns());
|
|
1441
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1442
|
+
current = state;
|
|
1443
|
+
};
|
|
1444
|
+
const redraw = () => draw(current);
|
|
1445
|
+
const paste = { active: false };
|
|
1446
|
+
const stop = terminal.stop ?? (terminal === process15 ? stopJob : undefined);
|
|
1447
|
+
const suspend = () => {
|
|
1448
|
+
if (stop === undefined)
|
|
1449
|
+
return;
|
|
1450
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1451
|
+
stdin.setRawMode(false);
|
|
1452
|
+
stop();
|
|
1453
|
+
stdin.setRawMode(true);
|
|
1454
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1455
|
+
};
|
|
1276
1456
|
try {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1457
|
+
stderr.on?.("resize", redraw);
|
|
1458
|
+
stdin.setRawMode(true);
|
|
1459
|
+
stdin.resume();
|
|
1460
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1461
|
+
draw("asking");
|
|
1462
|
+
return await new Promise((resolve) => {
|
|
1463
|
+
function onData(data) {
|
|
1464
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
1465
|
+
if (key === "suspend") {
|
|
1466
|
+
suspend();
|
|
1467
|
+
continue;
|
|
1468
|
+
}
|
|
1469
|
+
const pressed = press(key);
|
|
1470
|
+
if (pressed !== undefined) {
|
|
1471
|
+
settle(pressed);
|
|
1472
|
+
return;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
draw("asking");
|
|
1476
|
+
}
|
|
1477
|
+
function onEnd() {
|
|
1478
|
+
settle("cancel");
|
|
1479
|
+
}
|
|
1480
|
+
function settle(settled) {
|
|
1481
|
+
outcome = settled;
|
|
1482
|
+
stdin.off("data", onData);
|
|
1483
|
+
stdin.off("end", onEnd);
|
|
1484
|
+
resolve(settled === "enter");
|
|
1485
|
+
}
|
|
1486
|
+
stdin.on("data", onData);
|
|
1487
|
+
stdin.on("end", onEnd);
|
|
1488
|
+
});
|
|
1489
|
+
} finally {
|
|
1490
|
+
stderr.off?.("resize", redraw);
|
|
1491
|
+
draw(outcome ?? "cancel", true);
|
|
1492
|
+
stderr.write(`
|
|
1493
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1494
|
+
stdin.setRawMode(false);
|
|
1495
|
+
stdin.pause();
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
var PROMPT_KEYS, MAX_LISTED = 12;
|
|
1499
|
+
var init_prompt = __esm(() => {
|
|
1500
|
+
init_answers();
|
|
1501
|
+
init_args();
|
|
1502
|
+
init_format();
|
|
1503
|
+
init_job();
|
|
1504
|
+
init_mode();
|
|
1505
|
+
init_line();
|
|
1506
|
+
init_state();
|
|
1507
|
+
init_redraw();
|
|
1508
|
+
init_style();
|
|
1509
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1510
|
+
});
|
|
1283
1511
|
|
|
1284
|
-
//
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
};
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1512
|
+
// src/gm.ts
|
|
1513
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
1514
|
+
import process26 from "process";
|
|
1515
|
+
|
|
1516
|
+
// ../kit/src/index.ts
|
|
1517
|
+
init_args();
|
|
1518
|
+
|
|
1519
|
+
// ../kit/src/argv.ts
|
|
1520
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
1521
|
+
import { resolve as resolve3 } from "path";
|
|
1522
|
+
import process10 from "process";
|
|
1523
|
+
function commandLine() {
|
|
1524
|
+
try {
|
|
1525
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
1526
|
+
} catch {
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1301
1529
|
}
|
|
1302
|
-
function
|
|
1303
|
-
|
|
1530
|
+
function realPath(word) {
|
|
1531
|
+
try {
|
|
1532
|
+
return realpathSync(resolve3(word));
|
|
1533
|
+
} catch {
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1304
1536
|
}
|
|
1305
|
-
function
|
|
1306
|
-
|
|
1537
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
1538
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
1539
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
1540
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
1541
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
1307
1542
|
}
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1543
|
+
// ../kit/src/chart.ts
|
|
1544
|
+
init_format();
|
|
1545
|
+
init_mode();
|
|
1546
|
+
init_style();
|
|
1547
|
+
init_theme();
|
|
1548
|
+
// ../kit/src/ci.ts
|
|
1549
|
+
init_args();
|
|
1550
|
+
init_format();
|
|
1551
|
+
|
|
1552
|
+
// ../kit/src/progress.ts
|
|
1553
|
+
init_format();
|
|
1554
|
+
import process12 from "process";
|
|
1555
|
+
|
|
1556
|
+
// ../kit/src/process.ts
|
|
1557
|
+
import { constants } from "os";
|
|
1558
|
+
import process11 from "process";
|
|
1559
|
+
var KILL_GRACE_MS = 2000;
|
|
1560
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
1561
|
+
function exitCodeOf(code, signal) {
|
|
1562
|
+
if (code !== null)
|
|
1563
|
+
return code;
|
|
1564
|
+
if (typeof signal === "number")
|
|
1565
|
+
return 128 + signal;
|
|
1566
|
+
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
1311
1567
|
}
|
|
1312
|
-
function
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
const
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1568
|
+
function holdSignals(cleanup) {
|
|
1569
|
+
let received;
|
|
1570
|
+
let child;
|
|
1571
|
+
const held = {
|
|
1572
|
+
get signal() {
|
|
1573
|
+
return received;
|
|
1574
|
+
},
|
|
1575
|
+
forward: (to) => {
|
|
1576
|
+
child = to;
|
|
1577
|
+
},
|
|
1578
|
+
release: () => {
|
|
1579
|
+
for (const signal of SIGNALS)
|
|
1580
|
+
process11.off(signal, onSignal);
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
function onSignal(signal) {
|
|
1584
|
+
received = signal;
|
|
1585
|
+
if (child !== undefined) {
|
|
1586
|
+
child.kill(signal);
|
|
1587
|
+
return;
|
|
1588
|
+
}
|
|
1589
|
+
if (cleanup === undefined)
|
|
1590
|
+
return;
|
|
1591
|
+
held.release();
|
|
1592
|
+
cleanup(signal);
|
|
1593
|
+
process11.kill(process11.pid, signal);
|
|
1594
|
+
}
|
|
1595
|
+
for (const signal of SIGNALS)
|
|
1596
|
+
process11.on(signal, onSignal);
|
|
1597
|
+
return held;
|
|
1323
1598
|
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1599
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
1600
|
+
const chunks = [];
|
|
1601
|
+
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
1602
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
1603
|
+
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
1604
|
+
const timers = [];
|
|
1605
|
+
const killGroup = (killing) => {
|
|
1606
|
+
if (state.done)
|
|
1607
|
+
return;
|
|
1608
|
+
try {
|
|
1609
|
+
if (grouped)
|
|
1610
|
+
process11.kill(-proc.pid, killing);
|
|
1611
|
+
else
|
|
1612
|
+
proc.kill(killing);
|
|
1613
|
+
} catch {}
|
|
1614
|
+
};
|
|
1615
|
+
const stop = () => {
|
|
1616
|
+
killGroup("SIGTERM");
|
|
1617
|
+
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
1618
|
+
};
|
|
1619
|
+
const onAbort = () => stop();
|
|
1620
|
+
if (timeoutMs !== undefined) {
|
|
1621
|
+
timers.push(setTimeout(() => {
|
|
1622
|
+
state.timedOut = true;
|
|
1623
|
+
stop();
|
|
1624
|
+
}, timeoutMs));
|
|
1625
|
+
}
|
|
1626
|
+
if (signal?.aborted === true)
|
|
1627
|
+
onAbort();
|
|
1628
|
+
else
|
|
1629
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1630
|
+
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
1631
|
+
const drain = async (stream, name) => {
|
|
1632
|
+
for await (const data of stream) {
|
|
1633
|
+
if (state.failure !== undefined)
|
|
1634
|
+
continue;
|
|
1635
|
+
try {
|
|
1636
|
+
onChunk?.({ stream: name, data });
|
|
1637
|
+
} catch (error) {
|
|
1638
|
+
state.failure = error;
|
|
1639
|
+
stop();
|
|
1640
|
+
continue;
|
|
1641
|
+
}
|
|
1642
|
+
if (state.kept + data.length > maxBytes) {
|
|
1643
|
+
state.truncated = true;
|
|
1644
|
+
continue;
|
|
1645
|
+
}
|
|
1646
|
+
state.kept += data.length;
|
|
1647
|
+
chunks.push({ stream: name, data });
|
|
1648
|
+
}
|
|
1649
|
+
};
|
|
1328
1650
|
try {
|
|
1329
|
-
await
|
|
1330
|
-
|
|
1331
|
-
if (error instanceof Completing)
|
|
1332
|
-
return error;
|
|
1651
|
+
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
1652
|
+
await proc.exited;
|
|
1333
1653
|
} finally {
|
|
1334
|
-
|
|
1654
|
+
state.done = true;
|
|
1655
|
+
for (const timer of timers)
|
|
1656
|
+
clearTimeout(timer);
|
|
1657
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1335
1658
|
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1659
|
+
if (state.failure !== undefined)
|
|
1660
|
+
throw state.failure;
|
|
1661
|
+
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
1662
|
+
let output;
|
|
1663
|
+
let text;
|
|
1664
|
+
return {
|
|
1665
|
+
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
1666
|
+
chunks,
|
|
1667
|
+
timedOut: state.timedOut,
|
|
1668
|
+
truncated: state.truncated,
|
|
1669
|
+
get output() {
|
|
1670
|
+
return output ??= joined();
|
|
1671
|
+
},
|
|
1672
|
+
get text() {
|
|
1673
|
+
return text ??= (output ??= joined()).toString();
|
|
1350
1674
|
}
|
|
1351
|
-
|
|
1352
|
-
typed.push(word);
|
|
1353
|
-
else if (takesValue(word))
|
|
1354
|
-
at++;
|
|
1355
|
-
at++;
|
|
1356
|
-
}
|
|
1357
|
-
const last = positionals.at(-1);
|
|
1358
|
-
if (typed.length < positionals.length)
|
|
1359
|
-
return { name: positionals[typed.length], typed };
|
|
1360
|
-
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1675
|
+
};
|
|
1361
1676
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1677
|
+
|
|
1678
|
+
// ../kit/src/progress.ts
|
|
1679
|
+
init_style();
|
|
1680
|
+
init_theme();
|
|
1681
|
+
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1682
|
+
var FRAME_MS = 200;
|
|
1683
|
+
var BAR_WIDTH = 20;
|
|
1684
|
+
var CLEAR_BELOW = "\r\x1B[J";
|
|
1685
|
+
var ESC = String.fromCharCode(27);
|
|
1686
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
1687
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
1688
|
+
var CTRL_C = 3;
|
|
1689
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1690
|
+
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
1691
|
+
function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
1692
|
+
if (!takesControlCodes(stream, env))
|
|
1693
|
+
return { redraw: () => {
|
|
1694
|
+
return;
|
|
1695
|
+
}, print: (text) => void stream.write(`${text}
|
|
1696
|
+
`), stop: () => {
|
|
1697
|
+
return;
|
|
1698
|
+
}, pause: () => () => {
|
|
1699
|
+
return;
|
|
1700
|
+
} };
|
|
1701
|
+
const write = stream.write.bind(stream);
|
|
1702
|
+
let frame = 0;
|
|
1703
|
+
let drawn = false;
|
|
1704
|
+
let paused = false;
|
|
1705
|
+
let stopped = false;
|
|
1706
|
+
const columns = () => {
|
|
1707
|
+
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
1708
|
+
return now === undefined || now === 0 ? 80 : now;
|
|
1709
|
+
};
|
|
1710
|
+
const clear = () => {
|
|
1711
|
+
if (drawn)
|
|
1712
|
+
write(CLEAR_BELOW);
|
|
1713
|
+
drawn = false;
|
|
1714
|
+
};
|
|
1715
|
+
const draw = () => {
|
|
1716
|
+
if (paused)
|
|
1717
|
+
return;
|
|
1718
|
+
const width = columns() - 1;
|
|
1719
|
+
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
1720
|
+
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
1721
|
+
if (lines.length === 0) {
|
|
1722
|
+
clear();
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1725
|
+
write(`${CLEAR_BELOW}${lines.join(`
|
|
1726
|
+
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
1727
|
+
drawn = true;
|
|
1728
|
+
};
|
|
1729
|
+
let timer = setInterval(draw, FRAME_MS);
|
|
1730
|
+
stream.on?.("resize", draw);
|
|
1731
|
+
let restore = interceptOutput(clear);
|
|
1732
|
+
let release = swallowInput();
|
|
1733
|
+
const onExit = () => {
|
|
1734
|
+
clear();
|
|
1735
|
+
release();
|
|
1736
|
+
};
|
|
1737
|
+
const signals = holdSignals(stop);
|
|
1738
|
+
function stop() {
|
|
1739
|
+
stopped = true;
|
|
1740
|
+
clearInterval(timer);
|
|
1741
|
+
stream.off?.("resize", draw);
|
|
1742
|
+
clear();
|
|
1743
|
+
restore();
|
|
1744
|
+
release();
|
|
1745
|
+
process12.off("exit", onExit);
|
|
1746
|
+
signals.release();
|
|
1372
1747
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
return
|
|
1748
|
+
function pause() {
|
|
1749
|
+
if (paused || stopped)
|
|
1750
|
+
return () => {
|
|
1751
|
+
return;
|
|
1752
|
+
};
|
|
1753
|
+
paused = true;
|
|
1754
|
+
clearInterval(timer);
|
|
1755
|
+
stream.off?.("resize", draw);
|
|
1756
|
+
clear();
|
|
1757
|
+
restore();
|
|
1758
|
+
release();
|
|
1759
|
+
return () => {
|
|
1760
|
+
if (!paused || stopped)
|
|
1761
|
+
return;
|
|
1762
|
+
paused = false;
|
|
1763
|
+
timer = setInterval(draw, FRAME_MS);
|
|
1764
|
+
timer.unref();
|
|
1765
|
+
stream.on?.("resize", draw);
|
|
1766
|
+
restore = interceptOutput(clear);
|
|
1767
|
+
release = swallowInput();
|
|
1768
|
+
draw();
|
|
1769
|
+
};
|
|
1385
1770
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1771
|
+
timer.unref();
|
|
1772
|
+
process12.on("exit", onExit);
|
|
1773
|
+
return {
|
|
1774
|
+
redraw: draw,
|
|
1775
|
+
print: (text) => {
|
|
1776
|
+
clear();
|
|
1777
|
+
write(`${text}
|
|
1778
|
+
`);
|
|
1779
|
+
draw();
|
|
1780
|
+
},
|
|
1781
|
+
stop,
|
|
1782
|
+
pause
|
|
1783
|
+
};
|
|
1393
1784
|
}
|
|
1394
|
-
function
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1785
|
+
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
1786
|
+
const colors = paint(stream, env);
|
|
1787
|
+
const write = stream.write.bind(stream);
|
|
1788
|
+
const begun = performance.now();
|
|
1789
|
+
let started = begun;
|
|
1790
|
+
let current;
|
|
1791
|
+
const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
|
|
1792
|
+
const end = (line) => {
|
|
1793
|
+
region.stop();
|
|
1794
|
+
write(`${line}
|
|
1795
|
+
`);
|
|
1796
|
+
};
|
|
1797
|
+
return {
|
|
1798
|
+
update: (progress) => {
|
|
1799
|
+
const step = current?.step;
|
|
1800
|
+
current = progress;
|
|
1801
|
+
if (progress.step !== step) {
|
|
1802
|
+
started = performance.now();
|
|
1803
|
+
region.redraw();
|
|
1804
|
+
}
|
|
1805
|
+
},
|
|
1806
|
+
stop: region.stop,
|
|
1807
|
+
pause: region.pause,
|
|
1808
|
+
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1809
|
+
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1810
|
+
};
|
|
1408
1811
|
}
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
if (
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
return 0;
|
|
1417
|
-
}
|
|
1418
|
-
let code;
|
|
1419
|
-
const started = performance.now();
|
|
1420
|
-
try {
|
|
1421
|
-
code = await run(argv);
|
|
1422
|
-
} catch (error) {
|
|
1423
|
-
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1424
|
-
}
|
|
1425
|
-
notifyEnd(name, code, performance.now() - started);
|
|
1426
|
-
if (usage !== false) {
|
|
1427
|
-
try {
|
|
1428
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1429
|
-
} catch {}
|
|
1812
|
+
function progressParts({ step, done, total, unit }, spinner, ms) {
|
|
1813
|
+
const { theme } = activeTheme();
|
|
1814
|
+
const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
|
|
1815
|
+
if (total !== undefined && total > 0) {
|
|
1816
|
+
const counted = Math.min(done ?? 0, total);
|
|
1817
|
+
const filled = Math.round(counted / total * BAR_WIDTH);
|
|
1818
|
+
parts.push({ text: " ", tint: () => plain }, { text: theme.glyphs.bar.repeat(filled), tint: (colors) => () => shaded(theme, colors, theme.glyphs.bar, filled, BAR_WIDTH) }, { text: theme.glyphs.bar.repeat(BAR_WIDTH - filled), tint: (colors) => colors.dim }, { text: ` ${counted}/${total}${unit === undefined ? "" : ` ${unit}`}`, tint: (colors) => colors.dim });
|
|
1430
1819
|
}
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
// ../kit/src/folders.ts
|
|
1434
|
-
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1435
|
-
// ../kit/src/secrets.ts
|
|
1436
|
-
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1437
|
-
// ../kit/src/sessions.ts
|
|
1438
|
-
var {Glob } = globalThis.Bun;
|
|
1439
|
-
var SESSION_FILES = new Glob("*.json");
|
|
1440
|
-
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1441
|
-
// ../kit/src/watch.ts
|
|
1442
|
-
import process16 from "process";
|
|
1443
|
-
import { format } from "util";
|
|
1444
|
-
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1445
|
-
var DEFAULT_SECONDS = 2;
|
|
1446
|
-
var ATTACHED_SHORT = /^-w./;
|
|
1447
|
-
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1448
|
-
function watchOption(what) {
|
|
1449
|
-
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1820
|
+
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1821
|
+
return parts;
|
|
1450
1822
|
}
|
|
1451
|
-
function
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1823
|
+
function plain(text) {
|
|
1824
|
+
return text;
|
|
1825
|
+
}
|
|
1826
|
+
function tintedParts(parts, colors) {
|
|
1827
|
+
return parts.map(({ text, tint }) => tint(colors)(text)).join("");
|
|
1828
|
+
}
|
|
1829
|
+
function cutToWidth(line, width) {
|
|
1830
|
+
if (Bun.stringWidth(line) <= width)
|
|
1831
|
+
return line;
|
|
1832
|
+
let room = width;
|
|
1833
|
+
let kept = "";
|
|
1834
|
+
let index = 0;
|
|
1835
|
+
let linked = false;
|
|
1836
|
+
while (index < line.length) {
|
|
1837
|
+
ESCAPE_CODE.lastIndex = index;
|
|
1838
|
+
const escape = ESCAPE_CODE.exec(line);
|
|
1839
|
+
if (escape !== null) {
|
|
1840
|
+
kept += escape[0];
|
|
1841
|
+
linked ||= escape[0].startsWith(`${ESC}]`);
|
|
1842
|
+
index = ESCAPE_CODE.lastIndex;
|
|
1843
|
+
continue;
|
|
1460
1844
|
}
|
|
1845
|
+
const char = String.fromCodePoint(line.codePointAt(index));
|
|
1846
|
+
const columns = Bun.stringWidth(char);
|
|
1847
|
+
if (columns > room)
|
|
1848
|
+
break;
|
|
1849
|
+
kept += char;
|
|
1850
|
+
room -= columns;
|
|
1851
|
+
index += char.length;
|
|
1461
1852
|
}
|
|
1462
|
-
return
|
|
1853
|
+
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1463
1854
|
}
|
|
1464
|
-
|
|
1465
|
-
const
|
|
1466
|
-
if (!
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1855
|
+
function swallowInput() {
|
|
1856
|
+
const input = process12.stdin;
|
|
1857
|
+
if (!input.isTTY)
|
|
1858
|
+
return () => {
|
|
1859
|
+
return;
|
|
1860
|
+
};
|
|
1861
|
+
const onData = (data) => {
|
|
1862
|
+
if (data.includes(CTRL_C))
|
|
1863
|
+
process12.kill(process12.pid, "SIGINT");
|
|
1864
|
+
};
|
|
1865
|
+
input.setRawMode(true);
|
|
1866
|
+
input.on("data", onData);
|
|
1867
|
+
input.resume();
|
|
1868
|
+
let released = false;
|
|
1869
|
+
return () => {
|
|
1870
|
+
if (released)
|
|
1871
|
+
return;
|
|
1872
|
+
released = true;
|
|
1873
|
+
input.off("data", onData);
|
|
1874
|
+
input.pause();
|
|
1875
|
+
input.setRawMode(false);
|
|
1876
|
+
};
|
|
1877
|
+
}
|
|
1878
|
+
function interceptOutput(clear) {
|
|
1879
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
|
|
1880
|
+
const wrapped = targets.map(([target, name]) => {
|
|
1881
|
+
const original = Reflect.get(target, name);
|
|
1882
|
+
const wrapper = (...args) => {
|
|
1883
|
+
clear();
|
|
1884
|
+
return original.apply(target, args);
|
|
1480
1885
|
};
|
|
1886
|
+
Reflect.set(target, name, wrapper);
|
|
1887
|
+
return { target, name, original, wrapper };
|
|
1888
|
+
});
|
|
1889
|
+
return () => {
|
|
1890
|
+
for (const { target, name, original, wrapper } of wrapped) {
|
|
1891
|
+
if (Reflect.get(target, name) === wrapper)
|
|
1892
|
+
Reflect.set(target, name, original);
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
// ../kit/src/ci.ts
|
|
1898
|
+
init_style();
|
|
1899
|
+
|
|
1900
|
+
// ../kit/src/tool.ts
|
|
1901
|
+
init_format();
|
|
1902
|
+
// ../kit/src/cli.ts
|
|
1903
|
+
init_args();
|
|
1904
|
+
import { readFileSync as readFileSync5, realpathSync as realpathSync2 } from "fs";
|
|
1905
|
+
import { dirname as dirname4, join as join8 } from "path";
|
|
1906
|
+
import process19 from "process";
|
|
1907
|
+
|
|
1908
|
+
// ../kit/src/askpass.ts
|
|
1909
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
1910
|
+
import { tmpdir } from "os";
|
|
1911
|
+
import { join as join6 } from "path";
|
|
1912
|
+
import process16 from "process";
|
|
1913
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1914
|
+
var ECHOED = /username|yes\/no/i;
|
|
1915
|
+
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1916
|
+
function askpass(pause) {
|
|
1917
|
+
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1918
|
+
return;
|
|
1919
|
+
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1920
|
+
const socketPath = join6(dir, "socket");
|
|
1921
|
+
const script = join6(dir, "askpass");
|
|
1922
|
+
let turn = Promise.resolve();
|
|
1923
|
+
const answer = async ({ prompt, notice }) => {
|
|
1924
|
+
const resume = pause();
|
|
1481
1925
|
try {
|
|
1482
|
-
|
|
1926
|
+
if (notice === true) {
|
|
1927
|
+
process16.stderr.write(`${prompt.trim()}
|
|
1928
|
+
`);
|
|
1929
|
+
return {};
|
|
1930
|
+
}
|
|
1931
|
+
await Promise.resolve().then(() => init_prompt());
|
|
1932
|
+
return { answer: await input2(prompt.trim(), { mask: !ECHOED.test(prompt) }) };
|
|
1483
1933
|
} finally {
|
|
1484
|
-
|
|
1485
|
-
console.info = info;
|
|
1486
|
-
process16.stdout.write = write;
|
|
1934
|
+
resume();
|
|
1487
1935
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
const
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1936
|
+
};
|
|
1937
|
+
const respond = async (socket, request) => {
|
|
1938
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1939
|
+
const previous = turn;
|
|
1940
|
+
let reply = {};
|
|
1941
|
+
turn = promise;
|
|
1942
|
+
await previous;
|
|
1943
|
+
try {
|
|
1944
|
+
reply = await answer(request);
|
|
1945
|
+
} catch {} finally {
|
|
1946
|
+
socket.end(`${JSON.stringify(reply)}
|
|
1947
|
+
`);
|
|
1948
|
+
resolve();
|
|
1949
|
+
}
|
|
1950
|
+
};
|
|
1951
|
+
const server = Bun.listen({
|
|
1952
|
+
unix: socketPath,
|
|
1953
|
+
socket: {
|
|
1954
|
+
open: (socket) => {
|
|
1955
|
+
socket.data = { buffered: "" };
|
|
1956
|
+
},
|
|
1957
|
+
data: (socket, chunk) => {
|
|
1958
|
+
const before = socket.data.buffered;
|
|
1959
|
+
socket.data.buffered += chunk.toString();
|
|
1960
|
+
if (before.includes(`
|
|
1961
|
+
`) || !socket.data.buffered.includes(`
|
|
1962
|
+
`))
|
|
1963
|
+
return;
|
|
1964
|
+
respond(socket, JSON.parse(socket.data.buffered));
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
});
|
|
1968
|
+
writeFileSync2(script, `#!/bin/sh
|
|
1969
|
+
${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no-env-file --config=/dev/null ${quoted(process16.argv[1])} "$@"
|
|
1970
|
+
`);
|
|
1971
|
+
chmodSync(script, 448);
|
|
1972
|
+
return {
|
|
1973
|
+
env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
|
|
1974
|
+
close: () => {
|
|
1975
|
+
server.stop(true);
|
|
1976
|
+
rmSync(dir, { recursive: true, force: true });
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1516
1979
|
}
|
|
1517
|
-
function
|
|
1518
|
-
|
|
1980
|
+
async function askpassClient(argv) {
|
|
1981
|
+
const socketPath = process16.env[SOCKET_VARIABLE];
|
|
1982
|
+
if (socketPath === undefined)
|
|
1983
|
+
return;
|
|
1984
|
+
const request = { prompt: argv[0] ?? "", ...process16.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1985
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1986
|
+
let received = "";
|
|
1987
|
+
try {
|
|
1988
|
+
await Bun.connect({
|
|
1989
|
+
unix: socketPath,
|
|
1990
|
+
socket: {
|
|
1991
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1992
|
+
`),
|
|
1993
|
+
data: (_, chunk) => {
|
|
1994
|
+
received += chunk.toString();
|
|
1995
|
+
},
|
|
1996
|
+
close: () => resolve(received),
|
|
1997
|
+
error: () => resolve("")
|
|
1998
|
+
}
|
|
1999
|
+
});
|
|
2000
|
+
} catch {
|
|
2001
|
+
return 1;
|
|
2002
|
+
}
|
|
2003
|
+
const reply = await promise;
|
|
2004
|
+
if (reply === "")
|
|
2005
|
+
return 1;
|
|
2006
|
+
const { answer } = JSON.parse(reply);
|
|
2007
|
+
if (request.notice === true)
|
|
2008
|
+
return 0;
|
|
2009
|
+
if (answer === undefined)
|
|
2010
|
+
return 1;
|
|
2011
|
+
process16.stdout.write(`${answer}
|
|
2012
|
+
`);
|
|
2013
|
+
return 0;
|
|
1519
2014
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
2015
|
+
|
|
2016
|
+
// ../kit/src/completions.ts
|
|
2017
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
2018
|
+
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'
|
|
2019
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
2020
|
+
set -l current (commandline -ct)
|
|
2021
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
2022
|
+
if test "$line" = __files__
|
|
2023
|
+
__fish_complete_path $current
|
|
2024
|
+
else
|
|
2025
|
+
echo $line
|
|
2026
|
+
end
|
|
2027
|
+
end
|
|
2028
|
+
end`;
|
|
2029
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
2030
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
2031
|
+
local -a lines
|
|
2032
|
+
COMPREPLY=()
|
|
2033
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
2034
|
+
for line in "\${lines[@]}"; do
|
|
2035
|
+
if [[ $line == __files__ ]]; then
|
|
2036
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
2037
|
+
else
|
|
2038
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
2039
|
+
fi
|
|
2040
|
+
done
|
|
2041
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
2042
|
+
}`;
|
|
2043
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
2044
|
+
local line
|
|
2045
|
+
local -a described plain
|
|
2046
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
2047
|
+
if [[ $line == __files__ ]]; then
|
|
2048
|
+
_files
|
|
2049
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
2050
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
2051
|
+
else
|
|
2052
|
+
plain+=("$line")
|
|
2053
|
+
fi
|
|
2054
|
+
done
|
|
2055
|
+
(( \${#described} )) && _describe -V value described
|
|
2056
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
2057
|
+
return 0
|
|
2058
|
+
}`;
|
|
2059
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
2060
|
+
if (shell === "fish")
|
|
2061
|
+
return `${header}
|
|
2062
|
+
${FISH_FUNCTION}
|
|
2063
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
2064
|
+
`).join("")}`;
|
|
2065
|
+
if (shell === "bash")
|
|
2066
|
+
return `${header}
|
|
2067
|
+
${BASH_FUNCTION}
|
|
2068
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
2069
|
+
`;
|
|
2070
|
+
return `${header}
|
|
2071
|
+
${ZSH_FUNCTION}
|
|
2072
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
2073
|
+
`;
|
|
1524
2074
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
2075
|
+
|
|
2076
|
+
// ../kit/src/notify.ts
|
|
2077
|
+
init_format();
|
|
2078
|
+
init_mode();
|
|
2079
|
+
import process17 from "process";
|
|
2080
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
2081
|
+
var CANCELLED = 130;
|
|
2082
|
+
function base64(text) {
|
|
2083
|
+
return Buffer.from(text).toString("base64");
|
|
1532
2084
|
}
|
|
1533
|
-
function
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
while (at < chars.length && isWord(chars[at]))
|
|
1538
|
-
at++;
|
|
1539
|
-
return at;
|
|
2085
|
+
function notification(title, body, env = process17.env) {
|
|
2086
|
+
const id = `kit${process17.pid}`;
|
|
2087
|
+
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\\`];
|
|
2088
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1540
2089
|
}
|
|
1541
|
-
function
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
1546
|
-
at--;
|
|
1547
|
-
return at;
|
|
2090
|
+
function notifyEnd(command, code, ms, { stream = process17.stderr, env = process17.env } = {}) {
|
|
2091
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
2092
|
+
return;
|
|
2093
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1548
2094
|
}
|
|
1549
|
-
|
|
1550
|
-
|
|
2095
|
+
|
|
2096
|
+
// ../kit/src/cli.ts
|
|
2097
|
+
init_style();
|
|
2098
|
+
init_text2();
|
|
2099
|
+
|
|
2100
|
+
// ../kit/src/usage.ts
|
|
2101
|
+
import { appendFileSync, mkdirSync as mkdirSync2 } from "fs";
|
|
2102
|
+
import { homedir as homedir4 } from "os";
|
|
2103
|
+
import { dirname as dirname3, isAbsolute, join as join7 } from "path";
|
|
2104
|
+
import process18 from "process";
|
|
2105
|
+
|
|
2106
|
+
// ../kit/src/logs.ts
|
|
2107
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
2108
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
2109
|
+
|
|
2110
|
+
// ../kit/src/usage.ts
|
|
2111
|
+
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
2112
|
+
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
2113
|
+
var LONGEST_NAME = 40;
|
|
2114
|
+
var usageError;
|
|
2115
|
+
function noteUsageError(message) {
|
|
2116
|
+
usageError = message;
|
|
1551
2117
|
}
|
|
1552
|
-
function
|
|
1553
|
-
const
|
|
1554
|
-
return
|
|
2118
|
+
function stateHome(env = process18.env) {
|
|
2119
|
+
const dir = env.XDG_STATE_HOME;
|
|
2120
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join7(homedir4(), ".local", "state");
|
|
1555
2121
|
}
|
|
1556
|
-
function
|
|
1557
|
-
|
|
1558
|
-
const chars = [...line.text];
|
|
1559
|
-
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
1560
|
-
const edited = edit(chars, at, key, killed);
|
|
1561
|
-
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
1562
|
-
return line.killed === undefined ? edited : { ...edited, killed };
|
|
1563
|
-
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
1564
|
-
if (taken === "")
|
|
1565
|
-
return { ...edited, killed, chained };
|
|
1566
|
-
if (!chained)
|
|
1567
|
-
return { ...edited, killed: taken, chained: true };
|
|
1568
|
-
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
2122
|
+
function usagePath(env = process18.env) {
|
|
2123
|
+
return join7(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1569
2124
|
}
|
|
1570
|
-
function
|
|
1571
|
-
const
|
|
1572
|
-
|
|
1573
|
-
return insert(chars, at, key.text);
|
|
1574
|
-
switch (key) {
|
|
1575
|
-
case "left":
|
|
1576
|
-
return { text, caret: Math.max(at - 1, 0) };
|
|
1577
|
-
case "right":
|
|
1578
|
-
return { text, caret: Math.min(at + 1, chars.length) };
|
|
1579
|
-
case "wordleft":
|
|
1580
|
-
return { text, caret: wordStart(chars, at) };
|
|
1581
|
-
case "wordright":
|
|
1582
|
-
return { text, caret: wordEnd(chars, at) };
|
|
1583
|
-
case "linestart":
|
|
1584
|
-
return { text, caret: 0 };
|
|
1585
|
-
case "lineend":
|
|
1586
|
-
return { text, caret: chars.length };
|
|
1587
|
-
case "erase":
|
|
1588
|
-
return cut(chars, Math.max(at - 1, 0), at);
|
|
1589
|
-
case "delete":
|
|
1590
|
-
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
1591
|
-
case "word":
|
|
1592
|
-
return cut(chars, spacedStart(chars, at), at);
|
|
1593
|
-
case "killword":
|
|
1594
|
-
return cut(chars, wordStart(chars, at), at);
|
|
1595
|
-
case "killnext":
|
|
1596
|
-
return cut(chars, at, wordEnd(chars, at));
|
|
1597
|
-
case "clear":
|
|
1598
|
-
return cut(chars, 0, at);
|
|
1599
|
-
case "killend":
|
|
1600
|
-
return cut(chars, at, chars.length);
|
|
1601
|
-
case "yank":
|
|
1602
|
-
return insert(chars, at, killed);
|
|
1603
|
-
}
|
|
2125
|
+
function usageRecorded(env = process18.env) {
|
|
2126
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
2127
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1604
2128
|
}
|
|
1605
|
-
function
|
|
1606
|
-
const
|
|
1607
|
-
const
|
|
1608
|
-
|
|
1609
|
-
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
1610
|
-
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
1611
|
-
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
1612
|
-
let start = at;
|
|
1613
|
-
let end = at + 1;
|
|
1614
|
-
while (start > 0 && fits(start - 1, end))
|
|
1615
|
-
start--;
|
|
1616
|
-
while (end < cells.length && fits(start, end + 1))
|
|
1617
|
-
end++;
|
|
1618
|
-
const left = start > 0 ? "\u2026" : "";
|
|
1619
|
-
const right = end < cells.length ? "\u2026" : "";
|
|
1620
|
-
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) };
|
|
2129
|
+
function flagNames(argv) {
|
|
2130
|
+
const end = argv.indexOf("--");
|
|
2131
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
2132
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1621
2133
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
var BOUNDARY = 10;
|
|
1627
|
-
var PREFIX = 8;
|
|
1628
|
-
var GAP = 1;
|
|
1629
|
-
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1630
|
-
var UPPER = /\p{Lu}/u;
|
|
1631
|
-
var LOWER = /\p{Ll}/u;
|
|
1632
|
-
var NONE = Number.NEGATIVE_INFINITY;
|
|
1633
|
-
function startsWord(text, index) {
|
|
1634
|
-
if (index === 0)
|
|
1635
|
-
return true;
|
|
1636
|
-
const before = text[index - 1];
|
|
1637
|
-
return BOUNDARY_AFTER.has(before) || LOWER.test(before) && UPPER.test(text[index]);
|
|
2134
|
+
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
2135
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
2136
|
+
usageError = undefined;
|
|
2137
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1638
2138
|
}
|
|
1639
|
-
function
|
|
1640
|
-
if (
|
|
1641
|
-
return { score: 0, positions: [] };
|
|
1642
|
-
const exact = query !== query.toLowerCase();
|
|
1643
|
-
const needle = exact ? query : query.toLowerCase();
|
|
1644
|
-
const haystack = exact ? text : text.toLowerCase();
|
|
1645
|
-
if (haystack.length !== text.length || needle.length > haystack.length)
|
|
1646
|
-
return;
|
|
1647
|
-
const width = haystack.length;
|
|
1648
|
-
const best = Array.from({ length: needle.length }, () => new Array(width).fill(NONE));
|
|
1649
|
-
const from = Array.from({ length: needle.length }, () => new Array(width).fill(-1));
|
|
1650
|
-
for (let j = 0;j < needle.length; j++) {
|
|
1651
|
-
let run = NONE;
|
|
1652
|
-
let runAt = -1;
|
|
1653
|
-
for (let i = j;i < width; i++) {
|
|
1654
|
-
if (j > 0 && i - 2 >= j - 1) {
|
|
1655
|
-
const candidate = best[j - 1][i - 2] + (i - 2) * GAP;
|
|
1656
|
-
if (candidate > run) {
|
|
1657
|
-
run = candidate;
|
|
1658
|
-
runAt = i - 2;
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
if (haystack[i] !== needle[j])
|
|
1662
|
-
continue;
|
|
1663
|
-
const here = MATCH + (startsWord(text, i) ? BOUNDARY : 0) + (i === 0 ? PREFIX : 0);
|
|
1664
|
-
if (j === 0) {
|
|
1665
|
-
best[0][i] = here - i * GAP;
|
|
1666
|
-
continue;
|
|
1667
|
-
}
|
|
1668
|
-
const joined = best[j - 1][i - 1] + CONSECUTIVE;
|
|
1669
|
-
const skipped = run - (i - 1) * GAP;
|
|
1670
|
-
if (joined > NONE && joined >= skipped) {
|
|
1671
|
-
best[j][i] = joined + here;
|
|
1672
|
-
from[j][i] = i - 1;
|
|
1673
|
-
} else if (skipped > NONE) {
|
|
1674
|
-
best[j][i] = skipped + here;
|
|
1675
|
-
from[j][i] = runAt;
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
const last = best[needle.length - 1];
|
|
1680
|
-
let end = -1;
|
|
1681
|
-
for (let i = 0;i < width; i++) {
|
|
1682
|
-
if (last[i] > NONE && (end === -1 || last[i] > last[end]))
|
|
1683
|
-
end = i;
|
|
1684
|
-
}
|
|
1685
|
-
if (end === -1)
|
|
2139
|
+
function recordUsage(entry, env = process18.env) {
|
|
2140
|
+
if (!usageRecorded(env))
|
|
1686
2141
|
return;
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
}
|
|
1694
|
-
function rank(query, lines) {
|
|
1695
|
-
if (query === "")
|
|
1696
|
-
return lines.map((_, index) => ({ index, positions: [] }));
|
|
1697
|
-
const found = [];
|
|
1698
|
-
for (const [index, line] of lines.entries()) {
|
|
1699
|
-
const match = fuzzy(query, line);
|
|
1700
|
-
if (match !== undefined)
|
|
1701
|
-
found.push({ index, positions: match.positions, score: match.score });
|
|
1702
|
-
}
|
|
1703
|
-
return found.sort((a, b) => b.score - a.score || lines[a.index].length - lines[b.index].length || a.index - b.index);
|
|
2142
|
+
try {
|
|
2143
|
+
const path = usagePath(env);
|
|
2144
|
+
mkdirSync2(dirname3(path), { recursive: true, mode: 448 });
|
|
2145
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
2146
|
+
`, { mode: 384 });
|
|
2147
|
+
} catch {}
|
|
1704
2148
|
}
|
|
1705
2149
|
|
|
1706
|
-
// ../kit/src/
|
|
1707
|
-
var
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
var RESET = /^\x1B\[0?m$/;
|
|
1711
|
-
var COLUMN_GAP = 2;
|
|
1712
|
-
var PASTE_START = "\x1B[200~";
|
|
1713
|
-
var PASTE_END = "\x1B[201~";
|
|
1714
|
-
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1715
|
-
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1716
|
-
var WHEEL_LINES = 3;
|
|
1717
|
-
var KEYS = {
|
|
1718
|
-
"\x1B[A": "up",
|
|
1719
|
-
"\x1BOA": "up",
|
|
1720
|
-
"\x10": "up",
|
|
1721
|
-
"\x1B[B": "down",
|
|
1722
|
-
"\x1BOB": "down",
|
|
1723
|
-
"\x0E": "down",
|
|
1724
|
-
"\x1B[5~": "pageup",
|
|
1725
|
-
"\x1B[6~": "pagedown",
|
|
1726
|
-
"\x1B[H": "home",
|
|
1727
|
-
"\x1B[1~": "home",
|
|
1728
|
-
"\x1BOH": "home",
|
|
1729
|
-
"\x1B[F": "end",
|
|
1730
|
-
"\x1B[4~": "end",
|
|
1731
|
-
"\x1BOF": "end",
|
|
1732
|
-
"\r": "enter",
|
|
1733
|
-
"\n": "enter",
|
|
1734
|
-
"\x03": "cancel",
|
|
1735
|
-
"\x1B": "cancel",
|
|
1736
|
-
"\x1B[D": "left",
|
|
1737
|
-
"\x1BOD": "left",
|
|
1738
|
-
"\x1B[C": "right",
|
|
1739
|
-
"\x1BOC": "right",
|
|
1740
|
-
"\x1B[1;5D": "wordleft",
|
|
1741
|
-
"\x1B[1;3D": "wordleft",
|
|
1742
|
-
"\x1Bb": "wordleft",
|
|
1743
|
-
"\x1B[1;5C": "wordright",
|
|
1744
|
-
"\x1B[1;3C": "wordright",
|
|
1745
|
-
"\x1Bf": "wordright",
|
|
1746
|
-
"\x01": "linestart",
|
|
1747
|
-
"\x05": "lineend",
|
|
1748
|
-
"\x7F": "erase",
|
|
1749
|
-
"\x1B[3~": "delete",
|
|
1750
|
-
"\b": "killword",
|
|
1751
|
-
"\x1B\x7F": "killword",
|
|
1752
|
-
"\x1B[3;5~": "killnext",
|
|
1753
|
-
"\x1Bd": "killnext",
|
|
1754
|
-
"\x15": "clear",
|
|
1755
|
-
"\v": "killend",
|
|
1756
|
-
"\x17": "word",
|
|
1757
|
-
"\x19": "yank",
|
|
1758
|
-
"\x1A": "suspend",
|
|
1759
|
-
"\t": "tab",
|
|
1760
|
-
"\x1F": "help",
|
|
1761
|
-
"\x1BOP": "help",
|
|
1762
|
-
"\x1B[11~": "help"
|
|
2150
|
+
// ../kit/src/cli.ts
|
|
2151
|
+
var LEVEL_OPTIONS = {
|
|
2152
|
+
...OUTPUT_OPTIONS,
|
|
2153
|
+
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1763
2154
|
};
|
|
1764
|
-
var
|
|
1765
|
-
|
|
1766
|
-
|
|
2155
|
+
var TOP_OPTIONS = {
|
|
2156
|
+
...LEVEL_OPTIONS,
|
|
2157
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
2158
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
2159
|
+
};
|
|
2160
|
+
function printError(prefix, message, hint, cause) {
|
|
2161
|
+
const colors = paint(process19.stderr);
|
|
2162
|
+
const styled = takesControlCodes(process19.stderr);
|
|
2163
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
2164
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
2165
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
2166
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1767
2167
|
}
|
|
1768
|
-
function
|
|
1769
|
-
|
|
1770
|
-
const styles = [];
|
|
1771
|
-
let active = "";
|
|
1772
|
-
let colored = false;
|
|
1773
|
-
let last = 0;
|
|
1774
|
-
function add(chunk) {
|
|
1775
|
-
const flat = chunk.replace(CONTROL2, " ");
|
|
1776
|
-
text += flat;
|
|
1777
|
-
colored ||= active !== "" && flat !== "";
|
|
1778
|
-
styles.push(...repeat(active, flat.length));
|
|
1779
|
-
}
|
|
1780
|
-
for (const found of line.matchAll(ANSI)) {
|
|
1781
|
-
add(line.slice(last, found.index));
|
|
1782
|
-
last = found.index + found[0].length;
|
|
1783
|
-
if (SGR.test(found[0]))
|
|
1784
|
-
active = RESET.test(found[0]) ? "" : active + found[0];
|
|
1785
|
-
}
|
|
1786
|
-
add(line.slice(last));
|
|
1787
|
-
return { text, styles: colored ? styles : undefined };
|
|
2168
|
+
function runHint(command, effect) {
|
|
2169
|
+
return `run \`${command}\`${effect === undefined ? "" : ` to ${effect}`}`;
|
|
1788
2170
|
}
|
|
1789
|
-
function
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
2171
|
+
function printJsonError(message, hint, cause) {
|
|
2172
|
+
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
2173
|
+
}
|
|
2174
|
+
function wantsJson(argv) {
|
|
2175
|
+
const end = argv.indexOf("--");
|
|
2176
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
2177
|
+
}
|
|
2178
|
+
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
2179
|
+
if (error instanceof HelpShown)
|
|
2180
|
+
return 0;
|
|
2181
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
2182
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
2183
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
2184
|
+
if (error instanceof Exit && error.code === 2)
|
|
2185
|
+
noteUsageError(error.message);
|
|
2186
|
+
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
2187
|
+
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
2188
|
+
return error instanceof Exit ? error.code : 1;
|
|
2189
|
+
}
|
|
2190
|
+
var COMPLETE = "__complete";
|
|
2191
|
+
var FILES = "__files__";
|
|
2192
|
+
async function completingOf(run) {
|
|
2193
|
+
completion.active = true;
|
|
2194
|
+
try {
|
|
2195
|
+
await run([]);
|
|
2196
|
+
} catch (error) {
|
|
2197
|
+
if (error instanceof Completing)
|
|
2198
|
+
return error;
|
|
2199
|
+
} finally {
|
|
2200
|
+
completion.active = false;
|
|
2201
|
+
}
|
|
2202
|
+
return new Completing({});
|
|
1813
2203
|
}
|
|
1814
|
-
function
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
2204
|
+
function candidateLine(candidate) {
|
|
2205
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
2206
|
+
}
|
|
2207
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
2208
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
2209
|
+
const typed = [];
|
|
2210
|
+
let at = 0;
|
|
2211
|
+
while (at < before.length) {
|
|
2212
|
+
const word = before[at];
|
|
2213
|
+
if (word === "--") {
|
|
2214
|
+
typed.push(...before.slice(at + 1));
|
|
2215
|
+
break;
|
|
1825
2216
|
}
|
|
1826
|
-
if (
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
2217
|
+
if (!word.startsWith("-"))
|
|
2218
|
+
typed.push(word);
|
|
2219
|
+
else if (takesValue(word))
|
|
2220
|
+
at++;
|
|
2221
|
+
at++;
|
|
2222
|
+
}
|
|
2223
|
+
const last = positionals.at(-1);
|
|
2224
|
+
if (typed.length < positionals.length)
|
|
2225
|
+
return { name: positionals[typed.length], typed };
|
|
2226
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1833
2227
|
}
|
|
1834
|
-
function
|
|
1835
|
-
const
|
|
1836
|
-
|
|
2228
|
+
async function leafCandidates(run, words) {
|
|
2229
|
+
const completing = await completingOf(run);
|
|
2230
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
2231
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
2232
|
+
const flag = words.at(-2);
|
|
2233
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
2234
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
2235
|
+
if (option?.type === "string") {
|
|
2236
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
2237
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
2238
|
+
}
|
|
2239
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
2240
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1837
2241
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
const searchable = laid.map((row) => row.searchable);
|
|
1842
|
-
const matches = rank(state.query, searchable);
|
|
1843
|
-
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 };
|
|
2242
|
+
var COMPLETIONS = "--completions";
|
|
2243
|
+
function flagValue([flag = "", ...rest]) {
|
|
2244
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1844
2245
|
}
|
|
1845
|
-
function
|
|
1846
|
-
const
|
|
1847
|
-
|
|
2246
|
+
function printCompletionScript(name, args) {
|
|
2247
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
2248
|
+
if (shell === undefined || args.length !== 1) {
|
|
2249
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
2250
|
+
return 2;
|
|
2251
|
+
}
|
|
2252
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
2253
|
+
return 0;
|
|
1848
2254
|
}
|
|
1849
|
-
function
|
|
1850
|
-
|
|
2255
|
+
async function printCandidates(found) {
|
|
2256
|
+
for (const line of await found)
|
|
2257
|
+
console.log(line);
|
|
2258
|
+
return 0;
|
|
1851
2259
|
}
|
|
1852
|
-
function
|
|
1853
|
-
|
|
2260
|
+
function packageVersion(entry = Bun.main) {
|
|
2261
|
+
let resolved = entry;
|
|
2262
|
+
try {
|
|
2263
|
+
resolved = realpathSync2(entry);
|
|
2264
|
+
} catch {}
|
|
2265
|
+
for (let dir = dirname4(resolved);; dir = dirname4(dir)) {
|
|
2266
|
+
try {
|
|
2267
|
+
const { version } = JSON.parse(readFileSync5(join8(dir, "package.json"), "utf8"));
|
|
2268
|
+
if (typeof version === "string")
|
|
2269
|
+
return version;
|
|
2270
|
+
} catch {}
|
|
2271
|
+
if (dirname4(dir) === dir)
|
|
2272
|
+
return "0.0.0";
|
|
2273
|
+
}
|
|
1854
2274
|
}
|
|
1855
|
-
function
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
return
|
|
2275
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
2276
|
+
const answered = await askpassClient(argv);
|
|
2277
|
+
if (answered !== undefined)
|
|
2278
|
+
return answered;
|
|
2279
|
+
if (argv[0] === COMPLETE)
|
|
2280
|
+
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
2281
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
2282
|
+
return printCompletionScript(name, flagValue(argv));
|
|
2283
|
+
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
2284
|
+
console.log(version ?? packageVersion());
|
|
2285
|
+
return 0;
|
|
1866
2286
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
2287
|
+
let code;
|
|
2288
|
+
const started = performance.now();
|
|
2289
|
+
try {
|
|
2290
|
+
code = await run(argv);
|
|
2291
|
+
} catch (error) {
|
|
2292
|
+
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
2293
|
+
}
|
|
2294
|
+
notifyEnd(name, code, performance.now() - started);
|
|
2295
|
+
if (usage !== false) {
|
|
2296
|
+
try {
|
|
2297
|
+
recordUsage(usageEntry(name, undefined, argv, code));
|
|
2298
|
+
} catch {}
|
|
2299
|
+
}
|
|
2300
|
+
return code;
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
// ../kit/src/index.ts
|
|
2304
|
+
init_config();
|
|
2305
|
+
|
|
2306
|
+
// ../kit/src/excerpt.ts
|
|
2307
|
+
init_text2();
|
|
2308
|
+
|
|
2309
|
+
// ../kit/src/index.ts
|
|
2310
|
+
init_folders();
|
|
2311
|
+
init_format();
|
|
2312
|
+
|
|
2313
|
+
// ../kit/src/git.ts
|
|
2314
|
+
init_args();
|
|
2315
|
+
// ../kit/src/limit.ts
|
|
2316
|
+
init_args();
|
|
2317
|
+
|
|
2318
|
+
// ../kit/src/index.ts
|
|
2319
|
+
init_mode();
|
|
2320
|
+
|
|
2321
|
+
// ../kit/src/report.ts
|
|
2322
|
+
init_style();
|
|
2323
|
+
init_text2();
|
|
2324
|
+
// ../kit/src/secrets.ts
|
|
2325
|
+
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
2326
|
+
// ../kit/src/sessions.ts
|
|
2327
|
+
var {Glob } = globalThis.Bun;
|
|
2328
|
+
var SESSION_FILES = new Glob("*.json");
|
|
2329
|
+
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
2330
|
+
|
|
2331
|
+
// ../kit/src/index.ts
|
|
2332
|
+
init_style();
|
|
2333
|
+
init_text2();
|
|
2334
|
+
init_theme();
|
|
2335
|
+
init_user_config();
|
|
2336
|
+
|
|
2337
|
+
// ../kit/src/watch.ts
|
|
2338
|
+
init_args();
|
|
2339
|
+
init_input();
|
|
2340
|
+
init_style();
|
|
2341
|
+
import process20 from "process";
|
|
2342
|
+
import { format } from "util";
|
|
2343
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
2344
|
+
var DEFAULT_SECONDS = 2;
|
|
2345
|
+
var ATTACHED_SHORT = /^-w./;
|
|
2346
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
2347
|
+
function watchOption(what) {
|
|
2348
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
2349
|
+
}
|
|
2350
|
+
function withoutWatch(args) {
|
|
2351
|
+
const rest = [];
|
|
2352
|
+
for (let at = 0;at < args.length; at++) {
|
|
2353
|
+
const arg = args[at];
|
|
2354
|
+
if (arg === "--watch" || arg === "-w") {
|
|
2355
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
2356
|
+
at++;
|
|
2357
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
2358
|
+
rest.push(arg);
|
|
1898
2359
|
}
|
|
1899
2360
|
}
|
|
2361
|
+
return rest;
|
|
1900
2362
|
}
|
|
1901
|
-
function
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
2363
|
+
async function watching(value, step, stream = process20.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
2364
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
2365
|
+
if (!takesControlCodes(stream))
|
|
2366
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
2367
|
+
let code = 0;
|
|
2368
|
+
for (let round = 0;round < rounds; round++) {
|
|
2369
|
+
const held = [];
|
|
2370
|
+
const { log, info } = console;
|
|
2371
|
+
const write = process20.stdout.write.bind(process20.stdout);
|
|
2372
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
2373
|
+
`);
|
|
2374
|
+
console.log = hold;
|
|
2375
|
+
console.info = hold;
|
|
2376
|
+
process20.stdout.write = (text) => {
|
|
2377
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
2378
|
+
return true;
|
|
2379
|
+
};
|
|
2380
|
+
try {
|
|
2381
|
+
code = await step();
|
|
2382
|
+
} finally {
|
|
2383
|
+
console.log = log;
|
|
2384
|
+
console.info = info;
|
|
2385
|
+
process20.stdout.write = write;
|
|
2386
|
+
}
|
|
2387
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
2388
|
+
await sleep(interval);
|
|
2389
|
+
}
|
|
2390
|
+
return code;
|
|
1906
2391
|
}
|
|
2392
|
+
// ../kit/src/workspace-root.ts
|
|
2393
|
+
init_user_config();
|
|
2394
|
+
import { homedir as homedir5 } from "os";
|
|
2395
|
+
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2396
|
+
import process21 from "process";
|
|
2397
|
+
function expandHome(path, home) {
|
|
2398
|
+
if (path === "~")
|
|
2399
|
+
return home;
|
|
2400
|
+
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2401
|
+
}
|
|
2402
|
+
function configured(env, home) {
|
|
2403
|
+
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2404
|
+
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2405
|
+
}
|
|
2406
|
+
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2407
|
+
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2408
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2409
|
+
}
|
|
2410
|
+
// ../kit/src/picker.ts
|
|
2411
|
+
init_folders();
|
|
2412
|
+
init_state();
|
|
1907
2413
|
|
|
1908
2414
|
// ../kit/src/picker/terminal.ts
|
|
2415
|
+
init_args();
|
|
2416
|
+
init_job();
|
|
2417
|
+
init_redraw();
|
|
2418
|
+
init_style();
|
|
1909
2419
|
import { openSync } from "fs";
|
|
1910
|
-
import
|
|
2420
|
+
import process24 from "process";
|
|
1911
2421
|
import tty from "tty";
|
|
1912
2422
|
|
|
1913
|
-
// ../kit/src/job.ts
|
|
1914
|
-
import process19 from "process";
|
|
1915
|
-
function stopJob() {
|
|
1916
|
-
process19.kill(0, "SIGTSTP");
|
|
1917
|
-
}
|
|
1918
|
-
|
|
1919
|
-
// ../kit/src/redraw.ts
|
|
1920
|
-
var SYNC_START = "\x1B[?2026h";
|
|
1921
|
-
var SYNC_END = "\x1B[?2026l";
|
|
1922
|
-
function overwrite(lines, columns) {
|
|
1923
|
-
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1924
|
-
`);
|
|
1925
|
-
}
|
|
1926
|
-
|
|
1927
2423
|
// ../kit/src/picker/preview.ts
|
|
1928
|
-
import
|
|
2424
|
+
import process23 from "process";
|
|
1929
2425
|
|
|
1930
2426
|
// ../kit/src/shell.ts
|
|
1931
2427
|
var SEPARATORS = new Set([`
|
|
@@ -1994,7 +2490,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
1994
2490
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
1995
2491
|
const stop = () => {
|
|
1996
2492
|
try {
|
|
1997
|
-
|
|
2493
|
+
process23.kill(-proc.pid, "SIGKILL");
|
|
1998
2494
|
} catch {
|
|
1999
2495
|
proc.kill();
|
|
2000
2496
|
}
|
|
@@ -2019,7 +2515,12 @@ ${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe",
|
|
|
2019
2515
|
return signal.aborted ? [] : previewLines(Buffer.concat(chunks).subarray(0, PREVIEW_BYTES).toString());
|
|
2020
2516
|
}
|
|
2021
2517
|
|
|
2518
|
+
// ../kit/src/picker/terminal.ts
|
|
2519
|
+
init_state();
|
|
2520
|
+
|
|
2022
2521
|
// ../kit/src/picker/view.ts
|
|
2522
|
+
init_line();
|
|
2523
|
+
init_state();
|
|
2023
2524
|
var MIN_HEIGHT = 4;
|
|
2024
2525
|
var PREVIEW_MIN_COLUMNS = 80;
|
|
2025
2526
|
var PREVIEW_MIN_ROWS = 10;
|
|
@@ -2152,7 +2653,7 @@ function openTerminal() {
|
|
|
2152
2653
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
2153
2654
|
}
|
|
2154
2655
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
2155
|
-
const out =
|
|
2656
|
+
const out = process24.stderr;
|
|
2156
2657
|
let resize;
|
|
2157
2658
|
async function read(onChunk) {
|
|
2158
2659
|
const decoder = new TextDecoder;
|
|
@@ -2341,9 +2842,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2341
2842
|
const ended = new Promise((resolve) => {
|
|
2342
2843
|
finish = resolve;
|
|
2343
2844
|
});
|
|
2344
|
-
|
|
2845
|
+
process24.once("exit", restore);
|
|
2345
2846
|
for (const signal of SIGNALS2)
|
|
2346
|
-
|
|
2847
|
+
process24.once(signal, stop);
|
|
2347
2848
|
try {
|
|
2348
2849
|
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
2349
2850
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -2356,8 +2857,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2356
2857
|
await ended;
|
|
2357
2858
|
} finally {
|
|
2358
2859
|
for (const signal of SIGNALS2)
|
|
2359
|
-
|
|
2360
|
-
|
|
2860
|
+
process24.off(signal, stop);
|
|
2861
|
+
process24.off("exit", restore);
|
|
2361
2862
|
restore();
|
|
2362
2863
|
}
|
|
2363
2864
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -2369,7 +2870,9 @@ async function previewOf(preview, hidden, signal) {
|
|
|
2369
2870
|
return [error instanceof Error ? error.message : String(error)];
|
|
2370
2871
|
}
|
|
2371
2872
|
}
|
|
2873
|
+
|
|
2372
2874
|
// ../kit/src/picker.ts
|
|
2875
|
+
init_score();
|
|
2373
2876
|
function table2(rows) {
|
|
2374
2877
|
const widths = rows[0]?.cells.map((_, index) => Math.max(...rows.map((row) => Bun.stringWidth(row.cells[index])))) ?? [];
|
|
2375
2878
|
return rows.map((row) => [
|
|
@@ -2405,7 +2908,7 @@ function list(rows) {
|
|
|
2405
2908
|
|
|
2406
2909
|
// src/branch.ts
|
|
2407
2910
|
import { basename } from "path";
|
|
2408
|
-
import
|
|
2911
|
+
import process25 from "process";
|
|
2409
2912
|
var usage2 = `gb [branch]
|
|
2410
2913
|
gb -
|
|
2411
2914
|
gb -c <name>
|
|
@@ -2556,7 +3059,7 @@ async function fetched() {
|
|
|
2556
3059
|
const success = await proc.exited === 0;
|
|
2557
3060
|
return header(branches(base()), read(["branch", "--show-current"]), success ? "" : "fetch failed");
|
|
2558
3061
|
}
|
|
2559
|
-
function
|
|
3062
|
+
function listed3(all) {
|
|
2560
3063
|
list([
|
|
2561
3064
|
...all.map((branch) => ({
|
|
2562
3065
|
label: branch.name,
|
|
@@ -2583,7 +3086,7 @@ async function hidden(flag, rest) {
|
|
|
2583
3086
|
return 0;
|
|
2584
3087
|
}
|
|
2585
3088
|
if (flag === "--list") {
|
|
2586
|
-
|
|
3089
|
+
listed3(load().all);
|
|
2587
3090
|
return 0;
|
|
2588
3091
|
}
|
|
2589
3092
|
if (flag === "--names") {
|
|
@@ -2630,7 +3133,7 @@ async function gb(args) {
|
|
|
2630
3133
|
if (parsed.values.json === true)
|
|
2631
3134
|
printJson(all);
|
|
2632
3135
|
else
|
|
2633
|
-
console.log(table2(all.map(row)).map((line) => takesControlCodes(
|
|
3136
|
+
console.log(table2(all.map(row)).map((line) => takesControlCodes(process25.stdout) ? line : Bun.stripANSI(line)).join(`
|
|
2634
3137
|
`));
|
|
2635
3138
|
return 0;
|
|
2636
3139
|
}
|
|
@@ -2724,7 +3227,7 @@ var USAGE = `gm [branch]: merges the branch into the current one with git merge
|
|
|
2724
3227
|
Without a branch, on a terminal, picks one: every branch but the current one with how far it is ahead of and behind it, a preview of what the merge would do (the commits coming in, the files they touch, whether it would conflict and where), enter to merge and ctrl-s to merge with --squash. Without a terminal it lists the branches with that verdict each, clean, conflicts with the files, or merged already. A merge in progress is refused here: gm --continue or gm --abort.
|
|
2725
3228
|
--squash stages the changes of the branch without committing them or recording a merge, to commit with gc; a conflict then leaves the files to resolve and git reset --merge to give up.
|
|
2726
3229
|
|
|
2727
|
-
|
|
3230
|
+
Staged changes are refused, and so are unstaged ones in files the merge changes; other unstaged edits stay as they are, through a conflict and gm --abort too. The output names the outcome (fast-forward, merge commit or already up to date), the commits and the files that came in. On a conflict every conflicted file is listed with its conflict regions (the <<<<<<<, ======= and >>>>>>> lines and two lines around them, line numbers included) and the exit is 1.
|
|
2728
3231
|
gm --dry-run <branch> says whether the merge would conflict and in which files, touching nothing (git merge-tree). gm --continue commits the merge once the markers are gone from the conflicted files, refusing while one remains; gm --abort gives the merge up.`;
|
|
2729
3232
|
var EXITS2 = [[0, "it merged, the branch was already merged, or --dry-run found no conflict"], [1, "a conflict, a dirty tree, an unknown branch, a refused step or git failed"], [2, "outside a git repository or a usage error"]];
|
|
2730
3233
|
var OPTIONS = {
|
|
@@ -2736,7 +3239,7 @@ var OPTIONS = {
|
|
|
2736
3239
|
};
|
|
2737
3240
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
2738
3241
|
var RENAME = /^[RC]\d*$/;
|
|
2739
|
-
var EDITOR_OFF = { ...
|
|
3242
|
+
var EDITOR_OFF = { ...process26.env, GIT_EDITOR: "true", GIT_MERGE_AUTOEDIT: "no" };
|
|
2740
3243
|
async function ran(args, env) {
|
|
2741
3244
|
const { code, stdout, stderr } = await git2(args, env);
|
|
2742
3245
|
if (code !== 0)
|
|
@@ -2758,14 +3261,14 @@ async function conflicted() {
|
|
|
2758
3261
|
const paths = (await ran(["diff", "--name-only", "--diff-filter=U", "--relative", "-z"])).split("\x00").filter(Boolean);
|
|
2759
3262
|
return paths.map((path) => {
|
|
2760
3263
|
try {
|
|
2761
|
-
return { path, hunks: conflictHunks(
|
|
3264
|
+
return { path, hunks: conflictHunks(readFileSync6(path, "utf8")) };
|
|
2762
3265
|
} catch {
|
|
2763
3266
|
return { path, hunks: [] };
|
|
2764
3267
|
}
|
|
2765
3268
|
});
|
|
2766
3269
|
}
|
|
2767
3270
|
function conflictLines(conflicts) {
|
|
2768
|
-
return conflicts.flatMap(({ path, hunks }) => hunks.length === 0 ? [`${role("path",
|
|
3271
|
+
return conflicts.flatMap(({ path, hunks }) => hunks.length === 0 ? [`${role("path", process26.stdout)(path)}: conflicted, no markers to show (deleted on a side, binary or a mode change)`] : hunks.flatMap((hunk) => [role("path", process26.stdout)(`${path}:${hunk.from}-${hunk.to}`), ...hunk.lines.map(({ line, text }) => `${line} ${text}`), ""]));
|
|
2769
3272
|
}
|
|
2770
3273
|
function fileLine(line) {
|
|
2771
3274
|
const [letter = "", from = "", to] = line.split("\t");
|
|
@@ -2783,7 +3286,7 @@ function conflictReport(branch, into, conflicts, json, squash = false) {
|
|
|
2783
3286
|
printJson({ outcome: "conflict", branch, into, conflicts });
|
|
2784
3287
|
return 1;
|
|
2785
3288
|
}
|
|
2786
|
-
console.log([marked("problem", `merging ${branch} into ${into} left ${conflicts.length} conflicted ${conflicts.length === 1 ? "file" : "files"}`,
|
|
3289
|
+
console.log([marked("problem", `merging ${branch} into ${into} left ${conflicts.length} conflicted ${conflicts.length === 1 ? "file" : "files"}`, process26.stdout), ...conflictLines(conflicts)].join(`
|
|
2787
3290
|
`).trimEnd());
|
|
2788
3291
|
console.log(squash ? `
|
|
2789
3292
|
resolve the files and commit them with gc, or git reset --merge to give up` : `
|
|
@@ -2804,7 +3307,7 @@ async function mergedReport(before, branch, into, json) {
|
|
|
2804
3307
|
const how = outcome === "merge" ? `merge commit ${sha.slice(0, 7)}` : "fast-forward";
|
|
2805
3308
|
const list = changed.split(`
|
|
2806
3309
|
`).filter(Boolean);
|
|
2807
|
-
console.log([marked("ok", `${into} <- ${branch}, ${how}, ${count}, ${list.length} ${list.length === 1 ? "file" : "files"} changed`,
|
|
3310
|
+
console.log([marked("ok", `${into} <- ${branch}, ${how}, ${count}, ${list.length} ${list.length === 1 ? "file" : "files"} changed`, process26.stdout), ...list.map(fileLine)].join(`
|
|
2808
3311
|
`));
|
|
2809
3312
|
return 0;
|
|
2810
3313
|
}
|
|
@@ -2819,7 +3322,7 @@ ${(stderr || stdout).trim()}`);
|
|
|
2819
3322
|
`);
|
|
2820
3323
|
return { outcome: code === 0 ? "clean" : "conflict", conflicts: [...new Set(rest.slice(0, Math.max(0, rest.indexOf(""))))] };
|
|
2821
3324
|
}
|
|
2822
|
-
function verdictText(verdict, tint = paint(
|
|
3325
|
+
function verdictText(verdict, tint = paint(process26.stdout)) {
|
|
2823
3326
|
if (verdict.outcome === "up-to-date")
|
|
2824
3327
|
return tint.dim("merged already");
|
|
2825
3328
|
return verdict.outcome === "clean" ? tint.green("clean") : tint.red(`conflicts: ${verdict.conflicts.join(", ")}`);
|
|
@@ -2833,7 +3336,7 @@ async function squashedReport(before, branch, into, json) {
|
|
|
2833
3336
|
}
|
|
2834
3337
|
const list = changed.split(`
|
|
2835
3338
|
`).filter(Boolean);
|
|
2836
|
-
console.log([marked("ok", `${branch} squashed into the index of ${into}: ${commits} ${commits === 1 ? "commit" : "commits"}, ${list.length} ${list.length === 1 ? "file" : "files"}, commit them with gc`,
|
|
3339
|
+
console.log([marked("ok", `${branch} squashed into the index of ${into}: ${commits} ${commits === 1 ? "commit" : "commits"}, ${list.length} ${list.length === 1 ? "file" : "files"}, commit them with gc`, process26.stdout), ...list.map(fileLine)].join(`
|
|
2837
3340
|
`));
|
|
2838
3341
|
return 0;
|
|
2839
3342
|
}
|
|
@@ -2847,9 +3350,9 @@ async function dryRun(branch, into, json) {
|
|
|
2847
3350
|
if (verdict.outcome === "up-to-date")
|
|
2848
3351
|
console.log(`${branch} is already merged into ${into}`);
|
|
2849
3352
|
else if (verdict.outcome === "clean")
|
|
2850
|
-
console.log(marked("ok", `merging ${branch} into ${into} would not conflict`,
|
|
3353
|
+
console.log(marked("ok", `merging ${branch} into ${into} would not conflict`, process26.stdout));
|
|
2851
3354
|
else
|
|
2852
|
-
console.log([marked("problem", `merging ${branch} into ${into} would conflict in ${verdict.conflicts.length} ${verdict.conflicts.length === 1 ? "file" : "files"}`,
|
|
3355
|
+
console.log([marked("problem", `merging ${branch} into ${into} would conflict in ${verdict.conflicts.length} ${verdict.conflicts.length === 1 ? "file" : "files"}`, process26.stdout), ...verdict.conflicts.map((path) => ` ${path}`)].join(`
|
|
2853
3356
|
`));
|
|
2854
3357
|
return code;
|
|
2855
3358
|
}
|
|
@@ -2883,6 +3386,19 @@ async function choose2(into) {
|
|
|
2883
3386
|
enter merge, ctrl-s merge --squash`, expect: ["ctrl-s"], searched: 1, preview: async (hidden) => preview2(hidden[0] ?? "") });
|
|
2884
3387
|
return picked === undefined || picked.hidden[0] === undefined ? undefined : { branch: picked.hidden[0], squash: picked.key === "ctrl-s" };
|
|
2885
3388
|
}
|
|
3389
|
+
async function refuseUnsafeChanges(branch) {
|
|
3390
|
+
const paths = async (args) => (await ran([...args, "--name-only", "-z"])).split("\x00").filter((path) => path !== "");
|
|
3391
|
+
const staged = await paths(["diff", "--cached"]);
|
|
3392
|
+
if (staged.length > 0)
|
|
3393
|
+
fail(`staged changes would go into the merge (${staged.join(", ")}): commit them first (gc), or unstage them (gu --staged)`, 1);
|
|
3394
|
+
const dirty = await paths(["diff"]);
|
|
3395
|
+
if (dirty.length === 0)
|
|
3396
|
+
return;
|
|
3397
|
+
const touched = new Set(await paths(["diff", "--no-renames", `HEAD...${branch}`]));
|
|
3398
|
+
const overlap = dirty.filter((path) => touched.has(path));
|
|
3399
|
+
if (overlap.length > 0)
|
|
3400
|
+
fail(`uncommitted changes in files the merge changes (${overlap.join(", ")}): commit them first (gc), or set them aside as a patch (gu)`, 1);
|
|
3401
|
+
}
|
|
2886
3402
|
async function main(argv) {
|
|
2887
3403
|
const { values, positionals } = parse(argv, USAGE, OPTIONS, { positionals: ["[branch]"], exits: EXITS2, replaces: "git merge and then git diff --name-only --diff-filter=U and reading each file for markers", examples: ["gm feature", ["gm --dry-run feature", "whether it would conflict, and where"], ["gm --continue", "commit once the conflicts are resolved"], ["gm --abort", "give the merge up"]] });
|
|
2888
3404
|
const json = values.json === true;
|
|
@@ -2905,7 +3421,7 @@ async function main(argv) {
|
|
|
2905
3421
|
if (json)
|
|
2906
3422
|
printJson({ outcome: "refused", into, conflicts: left });
|
|
2907
3423
|
else
|
|
2908
|
-
console.log([marked("problem", `conflict markers remain in ${left.map((conflict) => conflict.path).join(", ")}`,
|
|
3424
|
+
console.log([marked("problem", `conflict markers remain in ${left.map((conflict) => conflict.path).join(", ")}`, process26.stdout), ...conflictLines(left)].join(`
|
|
2909
3425
|
`).trimEnd());
|
|
2910
3426
|
return 1;
|
|
2911
3427
|
}
|
|
@@ -2943,8 +3459,7 @@ ${USAGE}`);
|
|
|
2943
3459
|
return dryRun(branch, into, json);
|
|
2944
3460
|
if (await merging())
|
|
2945
3461
|
fail("a merge is already in progress: gm --continue once the conflicts are resolved, or gm --abort", 1);
|
|
2946
|
-
|
|
2947
|
-
fail("the working tree has uncommitted changes, commit or stash them first (gc, git stash)", 1);
|
|
3462
|
+
await refuseUnsafeChanges(branch);
|
|
2948
3463
|
if (await succeeds(["merge-base", "--is-ancestor", branch, "HEAD"])) {
|
|
2949
3464
|
if (json)
|
|
2950
3465
|
printJson({ outcome: "up-to-date", branch, into });
|
|
@@ -2961,4 +3476,4 @@ ${USAGE}`);
|
|
|
2961
3476
|
return fail(`git merge failed:
|
|
2962
3477
|
${(merged.stderr || merged.stdout).trim()}`, NOT_A_REPOSITORY.test(merged.stderr) ? 2 : 1);
|
|
2963
3478
|
}
|
|
2964
|
-
|
|
3479
|
+
process26.exitCode = await runMain({ name: "gm", run: main });
|