@kaynooo/cli-git 0.16.1 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/dist/gb.js +1728 -1143
- package/dist/gc.js +1173 -178
- package/dist/gcl.js +1165 -181
- package/dist/gd.js +1152 -183
- package/dist/gf.js +1172 -182
- package/dist/gm.js +1799 -1172
- package/dist/gp.js +1183 -188
- package/dist/gst.js +1149 -185
- package/dist/gu.js +1152 -178
- 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,15 +139,21 @@ 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";
|
|
134
148
|
import { homedir } from "os";
|
|
135
|
-
import { join as join2 } from "path";
|
|
149
|
+
import { isAbsolute, join as join2 } from "path";
|
|
136
150
|
import process4 from "process";
|
|
151
|
+
function xdgFolder(value, fallback) {
|
|
152
|
+
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
153
|
+
}
|
|
137
154
|
function configBase(where = {}) {
|
|
138
155
|
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
139
|
-
return xdg
|
|
156
|
+
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
140
157
|
}
|
|
141
158
|
function userConfigPath(bin, where = {}) {
|
|
142
159
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
@@ -159,13 +176,17 @@ function readUserConfig(bin, where = {}, legacy = []) {
|
|
|
159
176
|
return {};
|
|
160
177
|
}
|
|
161
178
|
}
|
|
179
|
+
var init_user_config = () => {};
|
|
162
180
|
|
|
163
181
|
// ../kit/src/theme.ts
|
|
182
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
183
|
+
import { homedir as homedir2 } from "os";
|
|
184
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
185
|
+
import process5 from "process";
|
|
164
186
|
function toLinear(channel) {
|
|
165
187
|
const value = channel / 255;
|
|
166
188
|
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
167
189
|
}
|
|
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
190
|
function toOklab(hex) {
|
|
170
191
|
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
171
192
|
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
@@ -180,7 +201,6 @@ function fromOklab([lightness, a, b]) {
|
|
|
180
201
|
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
202
|
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
182
203
|
}
|
|
183
|
-
var ENDS = new Map;
|
|
184
204
|
function gradientAt(theme, ratio) {
|
|
185
205
|
if (theme.gradient === undefined)
|
|
186
206
|
return;
|
|
@@ -194,33 +214,11 @@ function gradientAt(theme, ratio) {
|
|
|
194
214
|
const [from, to] = ends;
|
|
195
215
|
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
196
216
|
}
|
|
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
217
|
function isColorSpec(spec) {
|
|
219
218
|
if (typeof spec === "number")
|
|
220
219
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
221
220
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
222
221
|
}
|
|
223
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
224
222
|
function cubeLevel(channel) {
|
|
225
223
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
226
224
|
}
|
|
@@ -328,7 +326,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
328
326
|
function endsWalk(home) {
|
|
329
327
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
330
328
|
}
|
|
331
|
-
var warned = new Set;
|
|
332
329
|
function warnOnce(message) {
|
|
333
330
|
if (warned.has(message))
|
|
334
331
|
return;
|
|
@@ -365,8 +362,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
365
362
|
}
|
|
366
363
|
return { theme, sources, preset };
|
|
367
364
|
}
|
|
368
|
-
var current;
|
|
369
|
-
var currentKey = "";
|
|
370
365
|
function activeTheme() {
|
|
371
366
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
372
367
|
if (current === undefined || key !== currentKey) {
|
|
@@ -375,9 +370,38 @@ function activeTheme() {
|
|
|
375
370
|
}
|
|
376
371
|
return current;
|
|
377
372
|
}
|
|
373
|
+
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 = "";
|
|
374
|
+
var init_theme = __esm(() => {
|
|
375
|
+
init_config();
|
|
376
|
+
init_user_config();
|
|
377
|
+
ENDS = new Map;
|
|
378
|
+
DEFAULT = {
|
|
379
|
+
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" },
|
|
380
|
+
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" },
|
|
381
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
382
|
+
bins: {},
|
|
383
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
384
|
+
};
|
|
385
|
+
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" };
|
|
386
|
+
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" };
|
|
387
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
388
|
+
PRESETS = {
|
|
389
|
+
default: {},
|
|
390
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
391
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
392
|
+
ascii: { glyphs: ASCII }
|
|
393
|
+
};
|
|
394
|
+
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"]);
|
|
395
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
396
|
+
CONTROL = /\p{Cc}/u;
|
|
397
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
398
|
+
SPACES = /\s+/;
|
|
399
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
400
|
+
warned = new Set;
|
|
401
|
+
});
|
|
378
402
|
|
|
379
403
|
// ../kit/src/style.ts
|
|
380
|
-
|
|
404
|
+
import process6 from "process";
|
|
381
405
|
function takesControlCodes(stream, env = process6.env) {
|
|
382
406
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
383
407
|
}
|
|
@@ -397,17 +421,24 @@ function role(name, stream, env = process6.env) {
|
|
|
397
421
|
const colors = paint(stream, env);
|
|
398
422
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
399
423
|
}
|
|
400
|
-
var STATUS_WORDS
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
424
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
425
|
+
var init_style = __esm(() => {
|
|
426
|
+
init_colors();
|
|
427
|
+
init_mode();
|
|
428
|
+
init_theme();
|
|
429
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
430
|
+
STATUS_WORDS = {
|
|
431
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
432
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
433
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
434
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
435
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
436
|
+
};
|
|
437
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
438
|
+
});
|
|
408
439
|
|
|
409
440
|
// ../kit/src/format.ts
|
|
410
|
-
|
|
441
|
+
import process7 from "process";
|
|
411
442
|
function formatSeconds(total) {
|
|
412
443
|
let rest = Math.max(0, Math.round(total));
|
|
413
444
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -439,10 +470,8 @@ function formatAge(date, now = Date.now()) {
|
|
|
439
470
|
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
440
471
|
}
|
|
441
472
|
function truncate(text, width) {
|
|
442
|
-
return
|
|
473
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
443
474
|
}
|
|
444
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
445
|
-
var ESCAPE = String.fromCharCode(27);
|
|
446
475
|
function textWidth(text) {
|
|
447
476
|
return Bun.stringWidth(text);
|
|
448
477
|
}
|
|
@@ -491,14 +520,40 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
491
520
|
function printJson(value) {
|
|
492
521
|
console.log(jsonText(value));
|
|
493
522
|
}
|
|
523
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
524
|
+
var init_format = __esm(() => {
|
|
525
|
+
init_text();
|
|
526
|
+
init_mode();
|
|
527
|
+
init_style();
|
|
528
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
529
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
530
|
+
ESCAPE = String.fromCharCode(27);
|
|
531
|
+
});
|
|
494
532
|
|
|
495
533
|
// ../kit/src/help.ts
|
|
496
534
|
import process8 from "process";
|
|
497
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
498
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
499
|
-
var FULL_STOP = /\.$/;
|
|
500
535
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
501
|
-
|
|
536
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
537
|
+
`);
|
|
538
|
+
const blank = lines.indexOf("");
|
|
539
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
540
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
541
|
+
const colon = synopses[0].indexOf(": ");
|
|
542
|
+
const inline = synopses[0].slice(colon + 2);
|
|
543
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
544
|
+
if (colon !== -1)
|
|
545
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
546
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
547
|
+
`)}`;
|
|
548
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
549
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
550
|
+
return [head, ...lead, ...rest].join(`
|
|
551
|
+
`);
|
|
552
|
+
}
|
|
553
|
+
function prose(line, colors) {
|
|
554
|
+
if (colors.cyan("x") === "x")
|
|
555
|
+
return line;
|
|
556
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
502
557
|
}
|
|
503
558
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
504
559
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -533,7 +588,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
533
588
|
return [];
|
|
534
589
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
535
590
|
}
|
|
536
|
-
var MAX_INLINE_CHOICES = 24;
|
|
537
591
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
538
592
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
539
593
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -548,9 +602,17 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
548
602
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
549
603
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
550
604
|
}
|
|
605
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
606
|
+
var init_help = __esm(() => {
|
|
607
|
+
init_mode();
|
|
608
|
+
init_style();
|
|
609
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
610
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
611
|
+
FULL_STOP = /\.$/;
|
|
612
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
613
|
+
});
|
|
551
614
|
|
|
552
615
|
// ../kit/src/text.ts
|
|
553
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
554
616
|
function distance(a, b) {
|
|
555
617
|
const left = [...a];
|
|
556
618
|
const right = [...b];
|
|
@@ -576,8 +638,12 @@ function closest(name, names) {
|
|
|
576
638
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
577
639
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
578
640
|
}
|
|
641
|
+
var ANSI;
|
|
642
|
+
var init_text2 = __esm(() => {
|
|
643
|
+
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
644
|
+
});
|
|
645
|
+
|
|
579
646
|
// ../kit/src/input.ts
|
|
580
|
-
var WHOLE = /^\d+$/;
|
|
581
647
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
582
648
|
if (value === undefined)
|
|
583
649
|
return fallback;
|
|
@@ -586,8 +652,6 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
586
652
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
587
653
|
return number;
|
|
588
654
|
}
|
|
589
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
590
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
591
655
|
function duration(value, name, fallback, unit = "s") {
|
|
592
656
|
if (value === undefined)
|
|
593
657
|
return fallback;
|
|
@@ -597,40 +661,27 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
597
661
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
598
662
|
return ms;
|
|
599
663
|
}
|
|
664
|
+
var WHOLE, DURATION, UNIT_MS;
|
|
665
|
+
var init_input = __esm(() => {
|
|
666
|
+
init_args();
|
|
667
|
+
WHOLE = /^\d+$/;
|
|
668
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
669
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
670
|
+
});
|
|
600
671
|
|
|
601
672
|
// ../kit/src/args.ts
|
|
602
|
-
|
|
673
|
+
import process9 from "process";
|
|
674
|
+
import { parseArgs } from "util";
|
|
603
675
|
function jsonOption(holds) {
|
|
604
676
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
605
677
|
}
|
|
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
678
|
function fail(message, code = 2, hint) {
|
|
616
679
|
throw new Exit(message, code, hint);
|
|
617
680
|
}
|
|
618
|
-
|
|
619
|
-
class UsageError extends Exit {
|
|
620
|
-
constructor(message, hint) {
|
|
621
|
-
super(message, 2, hint);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
681
|
function badUsage(message) {
|
|
625
682
|
throw new UsageError(message);
|
|
626
683
|
}
|
|
627
684
|
|
|
628
|
-
class HelpShown extends Exit {
|
|
629
|
-
constructor() {
|
|
630
|
-
super("help shown", 0);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
685
|
class Completing {
|
|
635
686
|
options;
|
|
636
687
|
positionals;
|
|
@@ -641,11 +692,6 @@ class Completing {
|
|
|
641
692
|
this.candidates = candidates;
|
|
642
693
|
}
|
|
643
694
|
}
|
|
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
695
|
function applyOutput(color, plain, env = process9.env) {
|
|
650
696
|
const when = plain === true ? "never" : color ?? "auto";
|
|
651
697
|
if (when === "auto")
|
|
@@ -799,7 +845,6 @@ function parseError(error) {
|
|
|
799
845
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
800
846
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
801
847
|
}
|
|
802
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
803
848
|
function nearestOption(message, options, allowNegative) {
|
|
804
849
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
805
850
|
if (typed === undefined)
|
|
@@ -815,1117 +860,1633 @@ function nearestOption(message, options, allowNegative) {
|
|
|
815
860
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
816
861
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
817
862
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
863
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
864
|
+
var init_args = __esm(() => {
|
|
865
|
+
init_format();
|
|
866
|
+
init_help();
|
|
867
|
+
init_text2();
|
|
868
|
+
init_help();
|
|
869
|
+
init_input();
|
|
870
|
+
DASHES = /^-+/;
|
|
871
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
872
|
+
Exit = class Exit extends Error {
|
|
873
|
+
code;
|
|
874
|
+
hint;
|
|
875
|
+
[EXIT] = true;
|
|
876
|
+
constructor(message, code, hint) {
|
|
877
|
+
super(message);
|
|
878
|
+
this.code = code;
|
|
879
|
+
this.hint = hint;
|
|
880
|
+
}
|
|
881
|
+
static [Symbol.hasInstance](value) {
|
|
882
|
+
if (this !== Exit)
|
|
883
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
884
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
UsageError = class UsageError extends Exit {
|
|
888
|
+
constructor(message, hint) {
|
|
889
|
+
super(message, 2, hint);
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
HelpShown = class HelpShown extends Exit {
|
|
893
|
+
constructor() {
|
|
894
|
+
super("help shown", 0);
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
completion = { active: false };
|
|
898
|
+
OUTPUT_OPTIONS = {
|
|
899
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
900
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
901
|
+
};
|
|
902
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
// ../kit/src/folders.ts
|
|
906
|
+
import { homedir as homedir3 } from "os";
|
|
907
|
+
import { join as join4 } from "path";
|
|
908
|
+
import process13 from "process";
|
|
909
|
+
function cacheFolder({ home = homedir3(), env = process13.env } = {}) {
|
|
910
|
+
return xdgFolder(env.XDG_CACHE_HOME, join4(home, ".cache"));
|
|
911
|
+
}
|
|
912
|
+
var SKIPPED_FOLDERS;
|
|
913
|
+
var init_folders = __esm(() => {
|
|
914
|
+
init_user_config();
|
|
915
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
// ../kit/src/answers.ts
|
|
919
|
+
import { mkdirSync, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
920
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
921
|
+
function answersFile() {
|
|
922
|
+
return join5(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
923
|
+
}
|
|
924
|
+
function stored() {
|
|
823
925
|
try {
|
|
824
|
-
|
|
926
|
+
const parsed = JSON.parse(readFileSync5(answersFile(), "utf-8"));
|
|
927
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
928
|
+
return {};
|
|
929
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
825
930
|
} catch {
|
|
826
|
-
return;
|
|
931
|
+
return {};
|
|
827
932
|
}
|
|
828
933
|
}
|
|
829
|
-
function
|
|
934
|
+
function earlierAnswers(key) {
|
|
935
|
+
return stored()[key] ?? [];
|
|
936
|
+
}
|
|
937
|
+
function rememberAnswer(key, answer) {
|
|
938
|
+
const all = stored();
|
|
939
|
+
const file = answersFile();
|
|
940
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
830
941
|
try {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}
|
|
942
|
+
mkdirSync(dirname2(file), { recursive: true });
|
|
943
|
+
writeFileSync(file, JSON.stringify(all));
|
|
944
|
+
} catch {}
|
|
835
945
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
946
|
+
var KEPT = 50;
|
|
947
|
+
var init_answers = __esm(() => {
|
|
948
|
+
init_folders();
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
// ../kit/src/job.ts
|
|
952
|
+
import process14 from "process";
|
|
953
|
+
function stopJob() {
|
|
954
|
+
process14.kill(0, "SIGTSTP");
|
|
841
955
|
}
|
|
842
|
-
|
|
843
|
-
import process12 from "process";
|
|
956
|
+
var init_job = () => {};
|
|
844
957
|
|
|
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];
|
|
958
|
+
// ../kit/src/picker/line.ts
|
|
959
|
+
function isEditKey(key) {
|
|
960
|
+
return EDIT_KEYS.has(key);
|
|
856
961
|
}
|
|
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;
|
|
962
|
+
function endsKills(key) {
|
|
963
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
887
964
|
}
|
|
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
|
-
};
|
|
965
|
+
function isWord(char) {
|
|
966
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
965
967
|
}
|
|
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
|
-
};
|
|
968
|
+
function wordStart(chars, from) {
|
|
969
|
+
let at = from;
|
|
970
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
971
|
+
at--;
|
|
972
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
973
|
+
at--;
|
|
974
|
+
return at;
|
|
1040
975
|
}
|
|
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
|
-
};
|
|
976
|
+
function wordEnd(chars, from) {
|
|
977
|
+
let at = from;
|
|
978
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
979
|
+
at++;
|
|
980
|
+
while (at < chars.length && isWord(chars[at]))
|
|
981
|
+
at++;
|
|
982
|
+
return at;
|
|
1066
983
|
}
|
|
1067
|
-
function
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
984
|
+
function spacedStart(chars, from) {
|
|
985
|
+
let at = from;
|
|
986
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
987
|
+
at--;
|
|
988
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
989
|
+
at--;
|
|
990
|
+
return at;
|
|
991
|
+
}
|
|
992
|
+
function cut(chars, from, to) {
|
|
993
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
994
|
+
}
|
|
995
|
+
function insert(chars, at, text) {
|
|
996
|
+
const typed = [...text];
|
|
997
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
998
|
+
}
|
|
999
|
+
function editLine(line, key) {
|
|
1000
|
+
const { killed = "", chained = false } = line;
|
|
1001
|
+
const chars = [...line.text];
|
|
1002
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
1003
|
+
const edited = edit(chars, at, key, killed);
|
|
1004
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
1005
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
1006
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
1007
|
+
if (taken === "")
|
|
1008
|
+
return { ...edited, killed, chained };
|
|
1009
|
+
if (!chained)
|
|
1010
|
+
return { ...edited, killed: taken, chained: true };
|
|
1011
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
1012
|
+
}
|
|
1013
|
+
function edit(chars, at, key, killed) {
|
|
1014
|
+
const text = chars.join("");
|
|
1015
|
+
if (typeof key === "object")
|
|
1016
|
+
return insert(chars, at, key.text);
|
|
1017
|
+
switch (key) {
|
|
1018
|
+
case "left":
|
|
1019
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
1020
|
+
case "right":
|
|
1021
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
1022
|
+
case "wordleft":
|
|
1023
|
+
return { text, caret: wordStart(chars, at) };
|
|
1024
|
+
case "wordright":
|
|
1025
|
+
return { text, caret: wordEnd(chars, at) };
|
|
1026
|
+
case "linestart":
|
|
1027
|
+
return { text, caret: 0 };
|
|
1028
|
+
case "lineend":
|
|
1029
|
+
return { text, caret: chars.length };
|
|
1030
|
+
case "erase":
|
|
1031
|
+
return cut(chars, Math.max(at - 1, 0), at);
|
|
1032
|
+
case "delete":
|
|
1033
|
+
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
1034
|
+
case "word":
|
|
1035
|
+
return cut(chars, spacedStart(chars, at), at);
|
|
1036
|
+
case "killword":
|
|
1037
|
+
return cut(chars, wordStart(chars, at), at);
|
|
1038
|
+
case "killnext":
|
|
1039
|
+
return cut(chars, at, wordEnd(chars, at));
|
|
1040
|
+
case "clear":
|
|
1041
|
+
return cut(chars, 0, at);
|
|
1042
|
+
case "killend":
|
|
1043
|
+
return cut(chars, at, chars.length);
|
|
1044
|
+
case "yank":
|
|
1045
|
+
return insert(chars, at, killed);
|
|
1074
1046
|
}
|
|
1075
|
-
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1076
|
-
return parts;
|
|
1077
1047
|
}
|
|
1078
|
-
function
|
|
1079
|
-
|
|
1048
|
+
function visible({ text, caret }, room) {
|
|
1049
|
+
const chars = [...text];
|
|
1050
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
1051
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
1052
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
1053
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
1054
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
1055
|
+
let start = at;
|
|
1056
|
+
let end = at + 1;
|
|
1057
|
+
while (start > 0 && fits(start - 1, end))
|
|
1058
|
+
start--;
|
|
1059
|
+
while (end < cells.length && fits(start, end + 1))
|
|
1060
|
+
end++;
|
|
1061
|
+
const left = start > 0 ? "\u2026" : "";
|
|
1062
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
1063
|
+
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) };
|
|
1080
1064
|
}
|
|
1081
|
-
|
|
1082
|
-
|
|
1065
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
|
|
1066
|
+
var init_line = __esm(() => {
|
|
1067
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1068
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1069
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1070
|
+
WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
1071
|
+
SPACE = /\s/;
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
// ../kit/src/picker/score.ts
|
|
1075
|
+
function startsWord(text, index) {
|
|
1076
|
+
if (index === 0)
|
|
1077
|
+
return true;
|
|
1078
|
+
const before = text[index - 1];
|
|
1079
|
+
return BOUNDARY_AFTER.has(before) || LOWER.test(before) && UPPER.test(text[index]);
|
|
1083
1080
|
}
|
|
1084
|
-
function
|
|
1085
|
-
if (
|
|
1086
|
-
return
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1081
|
+
function fuzzy(query, text) {
|
|
1082
|
+
if (query === "")
|
|
1083
|
+
return { score: 0, positions: [] };
|
|
1084
|
+
const exact = query !== query.toLowerCase();
|
|
1085
|
+
const needle = exact ? query : query.toLowerCase();
|
|
1086
|
+
const haystack = exact ? text : text.toLowerCase();
|
|
1087
|
+
if (haystack.length !== text.length || needle.length > haystack.length)
|
|
1088
|
+
return;
|
|
1089
|
+
const width = haystack.length;
|
|
1090
|
+
const best = Array.from({ length: needle.length }, () => new Array(width).fill(NONE));
|
|
1091
|
+
const from = Array.from({ length: needle.length }, () => new Array(width).fill(-1));
|
|
1092
|
+
for (let j = 0;j < needle.length; j++) {
|
|
1093
|
+
let run = NONE;
|
|
1094
|
+
let runAt = -1;
|
|
1095
|
+
for (let i = j;i < width; i++) {
|
|
1096
|
+
if (j > 0 && i - 2 >= j - 1) {
|
|
1097
|
+
const candidate = best[j - 1][i - 2] + (i - 2) * GAP;
|
|
1098
|
+
if (candidate > run) {
|
|
1099
|
+
run = candidate;
|
|
1100
|
+
runAt = i - 2;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
if (haystack[i] !== needle[j])
|
|
1104
|
+
continue;
|
|
1105
|
+
const here = MATCH + (startsWord(text, i) ? BOUNDARY : 0) + (i === 0 ? PREFIX : 0);
|
|
1106
|
+
if (j === 0) {
|
|
1107
|
+
best[0][i] = here - i * GAP;
|
|
1108
|
+
continue;
|
|
1109
|
+
}
|
|
1110
|
+
const joined = best[j - 1][i - 1] + CONSECUTIVE;
|
|
1111
|
+
const skipped = run - (i - 1) * GAP;
|
|
1112
|
+
if (joined > NONE && joined >= skipped) {
|
|
1113
|
+
best[j][i] = joined + here;
|
|
1114
|
+
from[j][i] = i - 1;
|
|
1115
|
+
} else if (skipped > NONE) {
|
|
1116
|
+
best[j][i] = skipped + here;
|
|
1117
|
+
from[j][i] = runAt;
|
|
1118
|
+
}
|
|
1099
1119
|
}
|
|
1100
|
-
const char = String.fromCodePoint(line.codePointAt(index));
|
|
1101
|
-
const columns = Bun.stringWidth(char);
|
|
1102
|
-
if (columns > room)
|
|
1103
|
-
break;
|
|
1104
|
-
kept += char;
|
|
1105
|
-
room -= columns;
|
|
1106
|
-
index += char.length;
|
|
1107
1120
|
}
|
|
1108
|
-
|
|
1121
|
+
const last = best[needle.length - 1];
|
|
1122
|
+
let end = -1;
|
|
1123
|
+
for (let i = 0;i < width; i++) {
|
|
1124
|
+
if (last[i] > NONE && (end === -1 || last[i] > last[end]))
|
|
1125
|
+
end = i;
|
|
1126
|
+
}
|
|
1127
|
+
if (end === -1)
|
|
1128
|
+
return;
|
|
1129
|
+
const positions = [];
|
|
1130
|
+
for (let j = needle.length - 1, i = end;j >= 0; j--) {
|
|
1131
|
+
positions.unshift(i);
|
|
1132
|
+
i = from[j][i];
|
|
1133
|
+
}
|
|
1134
|
+
return { score: last[end], positions };
|
|
1109
1135
|
}
|
|
1110
|
-
function
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
input.setRawMode(true);
|
|
1121
|
-
input.on("data", onData);
|
|
1122
|
-
input.resume();
|
|
1123
|
-
let released = false;
|
|
1124
|
-
return () => {
|
|
1125
|
-
if (released)
|
|
1126
|
-
return;
|
|
1127
|
-
released = true;
|
|
1128
|
-
input.off("data", onData);
|
|
1129
|
-
input.pause();
|
|
1130
|
-
input.setRawMode(false);
|
|
1131
|
-
};
|
|
1136
|
+
function rank(query, lines) {
|
|
1137
|
+
if (query === "")
|
|
1138
|
+
return lines.map((_, index) => ({ index, positions: [] }));
|
|
1139
|
+
const found = [];
|
|
1140
|
+
for (const [index, line] of lines.entries()) {
|
|
1141
|
+
const match = fuzzy(query, line);
|
|
1142
|
+
if (match !== undefined)
|
|
1143
|
+
found.push({ index, positions: match.positions, score: match.score });
|
|
1144
|
+
}
|
|
1145
|
+
return found.sort((a, b) => b.score - a.score || lines[a.index].length - lines[b.index].length || a.index - b.index);
|
|
1132
1146
|
}
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1147
|
+
var MATCH = 16, CONSECUTIVE = 12, BOUNDARY = 10, PREFIX = 8, GAP = 1, BOUNDARY_AFTER, UPPER, LOWER, NONE;
|
|
1148
|
+
var init_score = __esm(() => {
|
|
1149
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1150
|
+
UPPER = /\p{Lu}/u;
|
|
1151
|
+
LOWER = /\p{Ll}/u;
|
|
1152
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
// ../kit/src/picker/state.ts
|
|
1156
|
+
function repeat(value, count) {
|
|
1157
|
+
return Array.from({ length: count }).fill(value);
|
|
1158
|
+
}
|
|
1159
|
+
function styled(line) {
|
|
1160
|
+
let text = "";
|
|
1161
|
+
const styles = [];
|
|
1162
|
+
let active = "";
|
|
1163
|
+
let colored = false;
|
|
1164
|
+
let last = 0;
|
|
1165
|
+
function add(chunk) {
|
|
1166
|
+
const flat = chunk.replace(CONTROL2, " ");
|
|
1167
|
+
text += flat;
|
|
1168
|
+
colored ||= active !== "" && flat !== "";
|
|
1169
|
+
styles.push(...repeat(active, flat.length));
|
|
1170
|
+
}
|
|
1171
|
+
for (const found of line.matchAll(ANSI)) {
|
|
1172
|
+
add(line.slice(last, found.index));
|
|
1173
|
+
last = found.index + found[0].length;
|
|
1174
|
+
if (SGR.test(found[0]))
|
|
1175
|
+
active = RESET.test(found[0]) ? "" : active + found[0];
|
|
1176
|
+
}
|
|
1177
|
+
add(line.slice(last));
|
|
1178
|
+
return { text, styles: colored ? styles : undefined };
|
|
1179
|
+
}
|
|
1180
|
+
function lay(rows, searched) {
|
|
1181
|
+
const parsed = rows.map((row) => row.cells.map(styled));
|
|
1182
|
+
const widths = (parsed[0] ?? []).map((_, column) => Math.max(...parsed.map((cells) => Bun.stringWidth(cells[column]?.text ?? ""))));
|
|
1183
|
+
return parsed.map((cells, at) => {
|
|
1184
|
+
let text = "";
|
|
1185
|
+
const styles = [];
|
|
1186
|
+
let colored = false;
|
|
1187
|
+
let searchEnd = 0;
|
|
1188
|
+
for (const [column, cell] of cells.entries()) {
|
|
1189
|
+
const last = column === cells.length - 1;
|
|
1190
|
+
const shown = cells.length > 1 && last ? cell.text.trimEnd() : cell.text;
|
|
1191
|
+
text += shown;
|
|
1192
|
+
colored ||= cell.styles !== undefined;
|
|
1193
|
+
styles.push(...cell.styles?.slice(0, shown.length) ?? repeat("", shown.length));
|
|
1194
|
+
if (column < searched)
|
|
1195
|
+
searchEnd = cells.length > 1 ? text.trimEnd().length : text.length;
|
|
1196
|
+
if (!last) {
|
|
1197
|
+
const pad = widths[column] - Bun.stringWidth(cell.text) + COLUMN_GAP;
|
|
1198
|
+
text += " ".repeat(pad);
|
|
1199
|
+
styles.push(...repeat("", pad));
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
return { text, styles: colored ? styles : undefined, searchable: rows[at].search ?? text.slice(0, searchEnd) };
|
|
1143
1203
|
});
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1204
|
+
}
|
|
1205
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1206
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1207
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1208
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1209
|
+
if (wheel !== undefined)
|
|
1210
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1211
|
+
const named = codes.get(sequence);
|
|
1212
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1213
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1214
|
+
paste.active = sequence === PASTE_START;
|
|
1215
|
+
return [];
|
|
1148
1216
|
}
|
|
1149
|
-
|
|
1217
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
1218
|
+
`))
|
|
1219
|
+
return [];
|
|
1220
|
+
if (key !== undefined)
|
|
1221
|
+
return [key];
|
|
1222
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1223
|
+
});
|
|
1150
1224
|
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1225
|
+
function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
|
|
1226
|
+
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 };
|
|
1227
|
+
return withRows(state, rows);
|
|
1228
|
+
}
|
|
1229
|
+
function withRows(state, rows, header = state.header) {
|
|
1230
|
+
const cells = rows.map((row) => typeof row === "string" ? { hidden: [], cells: [row] } : row);
|
|
1231
|
+
const laid = lay(cells, state.searched);
|
|
1232
|
+
const searchable = laid.map((row) => row.searchable);
|
|
1233
|
+
const matches = rank(state.query, searchable);
|
|
1234
|
+
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 };
|
|
1235
|
+
}
|
|
1236
|
+
function withQuery(state, key) {
|
|
1237
|
+
const { text, caret, killed = "", chained = false } = editLine({ text: state.query, caret: state.caret, killed: state.killed, chained: state.chained }, key);
|
|
1238
|
+
return text === state.query ? { ...state, caret, killed, chained } : { ...state, query: text, caret, killed, chained, matches: rank(text, state.searchable), cursor: 0 };
|
|
1239
|
+
}
|
|
1240
|
+
function move(state, by) {
|
|
1241
|
+
return { ...state, cursor: Math.max(0, Math.min(state.matches.length - 1, state.cursor + by)) };
|
|
1242
|
+
}
|
|
1243
|
+
function highlighted(state) {
|
|
1244
|
+
return state.matches[state.cursor]?.index;
|
|
1245
|
+
}
|
|
1246
|
+
function press(state, key) {
|
|
1247
|
+
if (state.done !== undefined)
|
|
1248
|
+
return state;
|
|
1249
|
+
if (state.chained && endsKills(key))
|
|
1250
|
+
state = { ...state, chained: false };
|
|
1251
|
+
if (state.help)
|
|
1252
|
+
return { ...state, help: false };
|
|
1253
|
+
if (typeof key === "object") {
|
|
1254
|
+
if ("text" in key)
|
|
1255
|
+
return withQuery(state, key);
|
|
1256
|
+
return state.expect.includes(key.ctrl) ? { ...state, done: "accept", key: key.ctrl } : state;
|
|
1257
|
+
}
|
|
1258
|
+
if (isEditKey(key))
|
|
1259
|
+
return withQuery(state, key);
|
|
1260
|
+
switch (key) {
|
|
1261
|
+
case "up":
|
|
1262
|
+
return move(state, -1);
|
|
1263
|
+
case "down":
|
|
1264
|
+
return move(state, 1);
|
|
1265
|
+
case "pageup":
|
|
1266
|
+
return move(state, -state.page);
|
|
1267
|
+
case "pagedown":
|
|
1268
|
+
return move(state, state.page);
|
|
1269
|
+
case "home":
|
|
1270
|
+
return move(state, -state.matches.length);
|
|
1271
|
+
case "end":
|
|
1272
|
+
return move(state, state.matches.length);
|
|
1273
|
+
case "cancel":
|
|
1274
|
+
return { ...state, done: "cancel" };
|
|
1275
|
+
case "help":
|
|
1276
|
+
return { ...state, help: true };
|
|
1277
|
+
case "suspend":
|
|
1278
|
+
return state;
|
|
1279
|
+
case "enter":
|
|
1280
|
+
return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
|
|
1281
|
+
case "tab": {
|
|
1282
|
+
const at = highlighted(state);
|
|
1283
|
+
if (!state.multi || at === undefined)
|
|
1284
|
+
return state;
|
|
1285
|
+
const marked = new Set(state.marked);
|
|
1286
|
+
if (!marked.delete(at))
|
|
1287
|
+
marked.add(at);
|
|
1288
|
+
return move({ ...state, marked }, 1);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
function chosen(state) {
|
|
1293
|
+
if (state.marked.size > 0)
|
|
1294
|
+
return state.rows.filter((_, index) => state.marked.has(index));
|
|
1295
|
+
const at = highlighted(state);
|
|
1296
|
+
return at === undefined ? [] : [state.rows[at]];
|
|
1214
1297
|
}
|
|
1298
|
+
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;
|
|
1299
|
+
var init_state = __esm(() => {
|
|
1300
|
+
init_text2();
|
|
1301
|
+
init_line();
|
|
1302
|
+
init_score();
|
|
1303
|
+
CONTROL2 = /[\x00-\x1F\x7F-\x9F]/g;
|
|
1304
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1305
|
+
SGR = /^\x1B\[[0-9;]*m$/;
|
|
1306
|
+
RESET = /^\x1B\[0?m$/;
|
|
1307
|
+
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1308
|
+
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1309
|
+
KEYS = {
|
|
1310
|
+
"\x1B[A": "up",
|
|
1311
|
+
"\x1BOA": "up",
|
|
1312
|
+
"\x10": "up",
|
|
1313
|
+
"\x1B[B": "down",
|
|
1314
|
+
"\x1BOB": "down",
|
|
1315
|
+
"\x0E": "down",
|
|
1316
|
+
"\x1B[5~": "pageup",
|
|
1317
|
+
"\x1B[6~": "pagedown",
|
|
1318
|
+
"\x1B[H": "home",
|
|
1319
|
+
"\x1B[1~": "home",
|
|
1320
|
+
"\x1BOH": "home",
|
|
1321
|
+
"\x1B[F": "end",
|
|
1322
|
+
"\x1B[4~": "end",
|
|
1323
|
+
"\x1BOF": "end",
|
|
1324
|
+
"\r": "enter",
|
|
1325
|
+
"\n": "enter",
|
|
1326
|
+
"\x03": "cancel",
|
|
1327
|
+
"\x1B": "cancel",
|
|
1328
|
+
"\x1B[D": "left",
|
|
1329
|
+
"\x1BOD": "left",
|
|
1330
|
+
"\x1B[C": "right",
|
|
1331
|
+
"\x1BOC": "right",
|
|
1332
|
+
"\x1B[1;5D": "wordleft",
|
|
1333
|
+
"\x1B[1;3D": "wordleft",
|
|
1334
|
+
"\x1Bb": "wordleft",
|
|
1335
|
+
"\x1B[1;5C": "wordright",
|
|
1336
|
+
"\x1B[1;3C": "wordright",
|
|
1337
|
+
"\x1Bf": "wordright",
|
|
1338
|
+
"\x01": "linestart",
|
|
1339
|
+
"\x05": "lineend",
|
|
1340
|
+
"\x7F": "erase",
|
|
1341
|
+
"\x1B[3~": "delete",
|
|
1342
|
+
"\b": "killword",
|
|
1343
|
+
"\x1B\x7F": "killword",
|
|
1344
|
+
"\x1B[3;5~": "killnext",
|
|
1345
|
+
"\x1Bd": "killnext",
|
|
1346
|
+
"\x15": "clear",
|
|
1347
|
+
"\v": "killend",
|
|
1348
|
+
"\x17": "word",
|
|
1349
|
+
"\x19": "yank",
|
|
1350
|
+
"\x1A": "suspend",
|
|
1351
|
+
"\t": "tab",
|
|
1352
|
+
"\x1F": "help",
|
|
1353
|
+
"\x1BOP": "help",
|
|
1354
|
+
"\x1B[11~": "help"
|
|
1355
|
+
};
|
|
1356
|
+
CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
|
|
1357
|
+
});
|
|
1215
1358
|
|
|
1216
|
-
// ../kit/src/
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
function base64(text) {
|
|
1221
|
-
return Buffer.from(text).toString("base64");
|
|
1359
|
+
// ../kit/src/redraw.ts
|
|
1360
|
+
function overwrite(lines, columns) {
|
|
1361
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1362
|
+
`);
|
|
1222
1363
|
}
|
|
1223
|
-
function
|
|
1224
|
-
|
|
1225
|
-
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\\`];
|
|
1226
|
-
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1364
|
+
function rowsTaken(lines, columns) {
|
|
1365
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1227
1366
|
}
|
|
1228
|
-
|
|
1229
|
-
|
|
1367
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
1368
|
+
var init_redraw = __esm(() => {
|
|
1369
|
+
init_format();
|
|
1370
|
+
});
|
|
1371
|
+
|
|
1372
|
+
// ../kit/src/prompt.ts
|
|
1373
|
+
import process15 from "process";
|
|
1374
|
+
function readKeys(input, paste = { active: false }) {
|
|
1375
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1376
|
+
}
|
|
1377
|
+
function roomAfter(question, columns) {
|
|
1378
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
1379
|
+
}
|
|
1380
|
+
function withCaret(colors, line, room, dim = false) {
|
|
1381
|
+
const { before, at, after } = visible(line, room);
|
|
1382
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
1383
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
1384
|
+
}
|
|
1385
|
+
function sharedStart(texts) {
|
|
1386
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
1387
|
+
let length = first.length;
|
|
1388
|
+
for (const chars of rest) {
|
|
1389
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
1390
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
1391
|
+
}
|
|
1392
|
+
return first.slice(0, length).join("");
|
|
1393
|
+
}
|
|
1394
|
+
function listed2(colors, found, columns) {
|
|
1395
|
+
const shared = sharedStart(found);
|
|
1396
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
1397
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
1398
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
1399
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
1400
|
+
}
|
|
1401
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
1402
|
+
let line = { text: "", caret: 0 };
|
|
1403
|
+
let invalid;
|
|
1404
|
+
let completions = [];
|
|
1405
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
1406
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
1407
|
+
let recalled = -1;
|
|
1408
|
+
let draft = line;
|
|
1409
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
1410
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
1411
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
1412
|
+
if (state !== "asking")
|
|
1413
|
+
return [answer(colors, question, state, shown())];
|
|
1414
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
1415
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
1416
|
+
}, (key) => {
|
|
1417
|
+
if (key === "cancel")
|
|
1418
|
+
return "cancel";
|
|
1419
|
+
invalid = undefined;
|
|
1420
|
+
completions = [];
|
|
1421
|
+
if (line.chained === true && endsKills(key))
|
|
1422
|
+
line = { ...line, chained: false };
|
|
1423
|
+
if (key === "tab") {
|
|
1424
|
+
const chars = [...line.text];
|
|
1425
|
+
const before = chars.slice(0, line.caret).join("");
|
|
1426
|
+
const found = complete?.(before) ?? [];
|
|
1427
|
+
const filled = sharedStart(found);
|
|
1428
|
+
if ([...filled].length > [...before].length)
|
|
1429
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
1430
|
+
else
|
|
1431
|
+
completions = found;
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
if (key === "enter") {
|
|
1435
|
+
invalid = validate?.(taken());
|
|
1436
|
+
return invalid === undefined ? "enter" : undefined;
|
|
1437
|
+
}
|
|
1438
|
+
if (key === "up" || key === "down") {
|
|
1439
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
1440
|
+
if (recalled === -1)
|
|
1441
|
+
draft = line;
|
|
1442
|
+
recalled = to;
|
|
1443
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
1444
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
1445
|
+
return;
|
|
1446
|
+
}
|
|
1447
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
1448
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
1449
|
+
line = editLine(line, edit);
|
|
1230
1450
|
return;
|
|
1231
|
-
|
|
1232
|
-
|
|
1451
|
+
});
|
|
1452
|
+
if (!accepted)
|
|
1453
|
+
return;
|
|
1454
|
+
if (remembered !== undefined && taken() !== "")
|
|
1455
|
+
rememberAnswer(remembered, taken());
|
|
1456
|
+
return taken();
|
|
1457
|
+
}
|
|
1458
|
+
function answer(colors, question, state, picked) {
|
|
1459
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1460
|
+
}
|
|
1461
|
+
async function ask(question, { hint, terminal = process15 }, render, press) {
|
|
1462
|
+
const { stdin, stderr } = terminal;
|
|
1463
|
+
if (!isInteractive(terminal))
|
|
1464
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1465
|
+
const colors = paint(stderr);
|
|
1466
|
+
let current = "asking";
|
|
1467
|
+
let outcome;
|
|
1468
|
+
const columns = () => stderr.columns || 80;
|
|
1469
|
+
const draw = (state, last = false) => {
|
|
1470
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1471
|
+
const rows = rowsTaken(frame, columns());
|
|
1472
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1473
|
+
current = state;
|
|
1474
|
+
};
|
|
1475
|
+
const redraw = () => draw(current);
|
|
1476
|
+
const paste = { active: false };
|
|
1477
|
+
const stop = terminal.stop ?? (terminal === process15 ? stopJob : undefined);
|
|
1478
|
+
const suspend = () => {
|
|
1479
|
+
if (stop === undefined)
|
|
1480
|
+
return;
|
|
1481
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1482
|
+
stdin.setRawMode(false);
|
|
1483
|
+
stop();
|
|
1484
|
+
stdin.setRawMode(true);
|
|
1485
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1486
|
+
};
|
|
1487
|
+
try {
|
|
1488
|
+
stderr.on?.("resize", redraw);
|
|
1489
|
+
stdin.setRawMode(true);
|
|
1490
|
+
stdin.resume();
|
|
1491
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1492
|
+
draw("asking");
|
|
1493
|
+
return await new Promise((resolve) => {
|
|
1494
|
+
function onData(data) {
|
|
1495
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
1496
|
+
if (key === "suspend") {
|
|
1497
|
+
suspend();
|
|
1498
|
+
continue;
|
|
1499
|
+
}
|
|
1500
|
+
const pressed = press(key);
|
|
1501
|
+
if (pressed !== undefined) {
|
|
1502
|
+
settle(pressed);
|
|
1503
|
+
return;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
draw("asking");
|
|
1507
|
+
}
|
|
1508
|
+
function onEnd() {
|
|
1509
|
+
settle("cancel");
|
|
1510
|
+
}
|
|
1511
|
+
function settle(settled) {
|
|
1512
|
+
outcome = settled;
|
|
1513
|
+
stdin.off("data", onData);
|
|
1514
|
+
stdin.off("end", onEnd);
|
|
1515
|
+
resolve(settled === "enter");
|
|
1516
|
+
}
|
|
1517
|
+
stdin.on("data", onData);
|
|
1518
|
+
stdin.on("end", onEnd);
|
|
1519
|
+
});
|
|
1520
|
+
} finally {
|
|
1521
|
+
stderr.off?.("resize", redraw);
|
|
1522
|
+
draw(outcome ?? "cancel", true);
|
|
1523
|
+
stderr.write(`
|
|
1524
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1525
|
+
stdin.setRawMode(false);
|
|
1526
|
+
stdin.pause();
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
var PROMPT_KEYS, MAX_LISTED = 12;
|
|
1530
|
+
var init_prompt = __esm(() => {
|
|
1531
|
+
init_answers();
|
|
1532
|
+
init_args();
|
|
1533
|
+
init_format();
|
|
1534
|
+
init_job();
|
|
1535
|
+
init_mode();
|
|
1536
|
+
init_line();
|
|
1537
|
+
init_state();
|
|
1538
|
+
init_redraw();
|
|
1539
|
+
init_style();
|
|
1540
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1541
|
+
});
|
|
1233
1542
|
|
|
1234
|
-
//
|
|
1235
|
-
import {
|
|
1236
|
-
import {
|
|
1237
|
-
import
|
|
1238
|
-
import process14 from "process";
|
|
1543
|
+
// src/gm.ts
|
|
1544
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
1545
|
+
import { join as join10, relative } from "path";
|
|
1546
|
+
import process26 from "process";
|
|
1239
1547
|
|
|
1240
|
-
// ../kit/src/
|
|
1241
|
-
|
|
1242
|
-
var CLI_FOLDER = "kaynooo-cli";
|
|
1548
|
+
// ../kit/src/index.ts
|
|
1549
|
+
init_args();
|
|
1243
1550
|
|
|
1244
|
-
// ../kit/src/
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
}
|
|
1252
|
-
function stateHome(env = process14.env) {
|
|
1253
|
-
const dir = env.XDG_STATE_HOME;
|
|
1254
|
-
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1255
|
-
}
|
|
1256
|
-
function usagePath(env = process14.env) {
|
|
1257
|
-
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1258
|
-
}
|
|
1259
|
-
function usageRecorded(env = process14.env) {
|
|
1260
|
-
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1261
|
-
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1262
|
-
}
|
|
1263
|
-
function flagNames(argv) {
|
|
1264
|
-
const end = argv.indexOf("--");
|
|
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));
|
|
1267
|
-
}
|
|
1268
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1269
|
-
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1270
|
-
usageError = undefined;
|
|
1271
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1272
|
-
}
|
|
1273
|
-
function recordUsage(entry, env = process14.env) {
|
|
1274
|
-
if (!usageRecorded(env))
|
|
1551
|
+
// ../kit/src/argv.ts
|
|
1552
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
1553
|
+
import { resolve as resolve3 } from "path";
|
|
1554
|
+
import process10 from "process";
|
|
1555
|
+
function commandLine() {
|
|
1556
|
+
try {
|
|
1557
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
1558
|
+
} catch {
|
|
1275
1559
|
return;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
function realPath(word) {
|
|
1276
1563
|
try {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
} catch {}
|
|
1564
|
+
return realpathSync(resolve3(word));
|
|
1565
|
+
} catch {
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1282
1568
|
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
};
|
|
1289
|
-
var TOP_OPTIONS = {
|
|
1290
|
-
...LEVEL_OPTIONS,
|
|
1291
|
-
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1292
|
-
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1293
|
-
};
|
|
1294
|
-
function printError(prefix, message, hint, cause) {
|
|
1295
|
-
const colors = paint(process15.stderr);
|
|
1296
|
-
const styled = takesControlCodes(process15.stderr);
|
|
1297
|
-
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1298
|
-
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1299
|
-
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
1300
|
-
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1569
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
1570
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
1571
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
1572
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
1573
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
1301
1574
|
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1575
|
+
// ../kit/src/chart.ts
|
|
1576
|
+
init_format();
|
|
1577
|
+
init_mode();
|
|
1578
|
+
init_style();
|
|
1579
|
+
init_theme();
|
|
1580
|
+
// ../kit/src/ci.ts
|
|
1581
|
+
init_args();
|
|
1582
|
+
init_format();
|
|
1583
|
+
|
|
1584
|
+
// ../kit/src/progress.ts
|
|
1585
|
+
init_format();
|
|
1586
|
+
import process12 from "process";
|
|
1587
|
+
|
|
1588
|
+
// ../kit/src/process.ts
|
|
1589
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
1590
|
+
import { constants } from "os";
|
|
1591
|
+
import process11 from "process";
|
|
1592
|
+
var KILL_GRACE_MS = 2000;
|
|
1593
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
1594
|
+
var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
|
|
1595
|
+
function exitCodeOf(code, signal) {
|
|
1596
|
+
if (code !== null)
|
|
1597
|
+
return code;
|
|
1598
|
+
if (typeof signal === "number")
|
|
1599
|
+
return 128 + signal;
|
|
1600
|
+
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
1304
1601
|
}
|
|
1305
|
-
function
|
|
1306
|
-
|
|
1602
|
+
function groupsOf(pid) {
|
|
1603
|
+
try {
|
|
1604
|
+
const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
|
|
1605
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
1606
|
+
return { group: Number(fields[2]), foreground: Number(fields[5]) };
|
|
1607
|
+
} catch {
|
|
1608
|
+
return;
|
|
1609
|
+
}
|
|
1307
1610
|
}
|
|
1308
|
-
function
|
|
1309
|
-
|
|
1310
|
-
|
|
1611
|
+
function heardTheTerminal(child) {
|
|
1612
|
+
if (child.pid === undefined)
|
|
1613
|
+
return false;
|
|
1614
|
+
const own = groupsOf("self");
|
|
1615
|
+
return own !== undefined && own.group === own.foreground && groupsOf(child.pid)?.group === own.group;
|
|
1311
1616
|
}
|
|
1312
|
-
function
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
const
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1617
|
+
function holdSignals(cleanup) {
|
|
1618
|
+
let received;
|
|
1619
|
+
let child;
|
|
1620
|
+
const held = {
|
|
1621
|
+
get signal() {
|
|
1622
|
+
return received;
|
|
1623
|
+
},
|
|
1624
|
+
forward: (to) => {
|
|
1625
|
+
child = to;
|
|
1626
|
+
},
|
|
1627
|
+
release: () => {
|
|
1628
|
+
for (const signal of SIGNALS)
|
|
1629
|
+
process11.off(signal, onSignal);
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
function onSignal(signal) {
|
|
1633
|
+
received = signal;
|
|
1634
|
+
if (child !== undefined) {
|
|
1635
|
+
if (!GROUP_SIGNALS.has(signal) || !heardTheTerminal(child))
|
|
1636
|
+
child.kill(signal);
|
|
1637
|
+
return;
|
|
1638
|
+
}
|
|
1639
|
+
if (cleanup === undefined)
|
|
1640
|
+
return;
|
|
1641
|
+
held.release();
|
|
1642
|
+
cleanup(signal);
|
|
1643
|
+
process11.kill(process11.pid, signal);
|
|
1644
|
+
}
|
|
1645
|
+
for (const signal of SIGNALS)
|
|
1646
|
+
process11.on(signal, onSignal);
|
|
1647
|
+
return held;
|
|
1323
1648
|
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1649
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
1650
|
+
const chunks = [];
|
|
1651
|
+
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
1652
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin: input === undefined ? stdin : new TextEncoder().encode(input), stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
1653
|
+
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
1654
|
+
const timers = [];
|
|
1655
|
+
const killGroup = (killing) => {
|
|
1656
|
+
if (state.done)
|
|
1657
|
+
return;
|
|
1658
|
+
try {
|
|
1659
|
+
if (grouped)
|
|
1660
|
+
process11.kill(-proc.pid, killing);
|
|
1661
|
+
else
|
|
1662
|
+
proc.kill(killing);
|
|
1663
|
+
} catch {}
|
|
1664
|
+
};
|
|
1665
|
+
const stop = () => {
|
|
1666
|
+
killGroup("SIGTERM");
|
|
1667
|
+
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
1668
|
+
};
|
|
1669
|
+
const onAbort = () => stop();
|
|
1670
|
+
if (timeoutMs !== undefined) {
|
|
1671
|
+
timers.push(setTimeout(() => {
|
|
1672
|
+
state.timedOut = true;
|
|
1673
|
+
stop();
|
|
1674
|
+
}, timeoutMs));
|
|
1675
|
+
}
|
|
1676
|
+
if (signal?.aborted === true)
|
|
1677
|
+
onAbort();
|
|
1678
|
+
else
|
|
1679
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1680
|
+
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
1681
|
+
const drain = async (stream, name) => {
|
|
1682
|
+
for await (const data of stream) {
|
|
1683
|
+
if (state.failure !== undefined)
|
|
1684
|
+
continue;
|
|
1685
|
+
try {
|
|
1686
|
+
onChunk?.({ stream: name, data });
|
|
1687
|
+
} catch (error) {
|
|
1688
|
+
state.failure = error;
|
|
1689
|
+
stop();
|
|
1690
|
+
continue;
|
|
1691
|
+
}
|
|
1692
|
+
if (state.truncated)
|
|
1693
|
+
continue;
|
|
1694
|
+
let kept = data;
|
|
1695
|
+
if (state.kept + data.length > maxBytes) {
|
|
1696
|
+
let cut = maxBytes - state.kept;
|
|
1697
|
+
while (cut > 0 && ((data[cut] ?? 0) & 192) === 128)
|
|
1698
|
+
cut--;
|
|
1699
|
+
kept = data.subarray(0, cut);
|
|
1700
|
+
state.truncated = true;
|
|
1701
|
+
}
|
|
1702
|
+
state.kept += kept.length;
|
|
1703
|
+
if (kept.length > 0)
|
|
1704
|
+
chunks.push({ stream: name, data: kept });
|
|
1705
|
+
}
|
|
1706
|
+
};
|
|
1328
1707
|
try {
|
|
1329
|
-
await
|
|
1330
|
-
|
|
1331
|
-
if (error instanceof Completing)
|
|
1332
|
-
return error;
|
|
1708
|
+
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
1709
|
+
await proc.exited;
|
|
1333
1710
|
} finally {
|
|
1334
|
-
|
|
1711
|
+
state.done = true;
|
|
1712
|
+
for (const timer of timers)
|
|
1713
|
+
clearTimeout(timer);
|
|
1714
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1335
1715
|
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1716
|
+
if (state.failure !== undefined)
|
|
1717
|
+
throw state.failure;
|
|
1718
|
+
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
1719
|
+
let output;
|
|
1720
|
+
let text;
|
|
1721
|
+
let stdout;
|
|
1722
|
+
return {
|
|
1723
|
+
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
1724
|
+
chunks,
|
|
1725
|
+
timedOut: state.timedOut,
|
|
1726
|
+
truncated: state.truncated,
|
|
1727
|
+
get output() {
|
|
1728
|
+
return output ??= joined();
|
|
1729
|
+
},
|
|
1730
|
+
get text() {
|
|
1731
|
+
return text ??= (output ??= joined()).toString();
|
|
1732
|
+
},
|
|
1733
|
+
get stdout() {
|
|
1734
|
+
return stdout ??= Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
|
|
1350
1735
|
}
|
|
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 };
|
|
1736
|
+
};
|
|
1361
1737
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1738
|
+
|
|
1739
|
+
// ../kit/src/progress.ts
|
|
1740
|
+
init_style();
|
|
1741
|
+
init_theme();
|
|
1742
|
+
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1743
|
+
var FRAME_MS = 200;
|
|
1744
|
+
var BAR_WIDTH = 20;
|
|
1745
|
+
var CLEAR_BELOW = "\r\x1B[J";
|
|
1746
|
+
var ESC = String.fromCharCode(27);
|
|
1747
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
1748
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
1749
|
+
var CTRL_C = 3;
|
|
1750
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1751
|
+
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
1752
|
+
function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
1753
|
+
if (!takesControlCodes(stream, env))
|
|
1754
|
+
return { redraw: () => {
|
|
1755
|
+
return;
|
|
1756
|
+
}, print: (text) => void stream.write(`${text}
|
|
1757
|
+
`), stop: () => {
|
|
1758
|
+
return;
|
|
1759
|
+
}, pause: () => () => {
|
|
1760
|
+
return;
|
|
1761
|
+
} };
|
|
1762
|
+
const write = stream.write.bind(stream);
|
|
1763
|
+
let frame = 0;
|
|
1764
|
+
let drawn = false;
|
|
1765
|
+
let paused = false;
|
|
1766
|
+
let stopped = false;
|
|
1767
|
+
const columns = () => {
|
|
1768
|
+
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
1769
|
+
return now === undefined || now === 0 ? 80 : now;
|
|
1770
|
+
};
|
|
1771
|
+
const clear = () => {
|
|
1772
|
+
if (drawn)
|
|
1773
|
+
write(CLEAR_BELOW);
|
|
1774
|
+
drawn = false;
|
|
1775
|
+
};
|
|
1776
|
+
const draw = () => {
|
|
1777
|
+
if (paused)
|
|
1778
|
+
return;
|
|
1779
|
+
const width = columns() - 1;
|
|
1780
|
+
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
1781
|
+
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
1782
|
+
if (lines.length === 0) {
|
|
1783
|
+
clear();
|
|
1784
|
+
return;
|
|
1785
|
+
}
|
|
1786
|
+
write(`${CLEAR_BELOW}${lines.join(`
|
|
1787
|
+
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
1788
|
+
drawn = true;
|
|
1789
|
+
};
|
|
1790
|
+
let timer = setInterval(draw, FRAME_MS);
|
|
1791
|
+
stream.on?.("resize", draw);
|
|
1792
|
+
let restore = interceptOutput(clear);
|
|
1793
|
+
let release = swallowInput();
|
|
1794
|
+
const onExit = () => {
|
|
1795
|
+
clear();
|
|
1796
|
+
release();
|
|
1797
|
+
};
|
|
1798
|
+
const signals = holdSignals(stop);
|
|
1799
|
+
function stop() {
|
|
1800
|
+
stopped = true;
|
|
1801
|
+
clearInterval(timer);
|
|
1802
|
+
stream.off?.("resize", draw);
|
|
1803
|
+
clear();
|
|
1804
|
+
restore();
|
|
1805
|
+
release();
|
|
1806
|
+
process12.off("exit", onExit);
|
|
1807
|
+
signals.release();
|
|
1372
1808
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
return
|
|
1809
|
+
function pause() {
|
|
1810
|
+
if (paused || stopped)
|
|
1811
|
+
return () => {
|
|
1812
|
+
return;
|
|
1813
|
+
};
|
|
1814
|
+
paused = true;
|
|
1815
|
+
clearInterval(timer);
|
|
1816
|
+
stream.off?.("resize", draw);
|
|
1817
|
+
clear();
|
|
1818
|
+
restore();
|
|
1819
|
+
release();
|
|
1820
|
+
return () => {
|
|
1821
|
+
if (!paused || stopped)
|
|
1822
|
+
return;
|
|
1823
|
+
paused = false;
|
|
1824
|
+
timer = setInterval(draw, FRAME_MS);
|
|
1825
|
+
timer.unref();
|
|
1826
|
+
stream.on?.("resize", draw);
|
|
1827
|
+
restore = interceptOutput(clear);
|
|
1828
|
+
release = swallowInput();
|
|
1829
|
+
draw();
|
|
1830
|
+
};
|
|
1385
1831
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1832
|
+
timer.unref();
|
|
1833
|
+
process12.on("exit", onExit);
|
|
1834
|
+
return {
|
|
1835
|
+
redraw: draw,
|
|
1836
|
+
print: (text) => {
|
|
1837
|
+
clear();
|
|
1838
|
+
write(`${text}
|
|
1839
|
+
`);
|
|
1840
|
+
draw();
|
|
1841
|
+
},
|
|
1842
|
+
stop,
|
|
1843
|
+
pause
|
|
1844
|
+
};
|
|
1393
1845
|
}
|
|
1394
|
-
function
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1846
|
+
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
1847
|
+
const colors = paint(stream, env);
|
|
1848
|
+
const write = stream.write.bind(stream);
|
|
1849
|
+
const begun = performance.now();
|
|
1850
|
+
let started = begun;
|
|
1851
|
+
let current;
|
|
1852
|
+
const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
|
|
1853
|
+
const end = (line) => {
|
|
1854
|
+
region.stop();
|
|
1855
|
+
write(`${line}
|
|
1856
|
+
`);
|
|
1857
|
+
};
|
|
1858
|
+
return {
|
|
1859
|
+
update: (progress) => {
|
|
1860
|
+
const step = current?.step;
|
|
1861
|
+
current = progress;
|
|
1862
|
+
if (progress.step !== step) {
|
|
1863
|
+
started = performance.now();
|
|
1864
|
+
region.redraw();
|
|
1865
|
+
}
|
|
1866
|
+
},
|
|
1867
|
+
stop: region.stop,
|
|
1868
|
+
pause: region.pause,
|
|
1869
|
+
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1870
|
+
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1871
|
+
};
|
|
1408
1872
|
}
|
|
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 {}
|
|
1873
|
+
function progressParts({ step, done, total, unit }, spinner, ms) {
|
|
1874
|
+
const { theme } = activeTheme();
|
|
1875
|
+
const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
|
|
1876
|
+
if (total !== undefined && total > 0) {
|
|
1877
|
+
const counted = Math.min(done ?? 0, total);
|
|
1878
|
+
const filled = Math.round(counted / total * BAR_WIDTH);
|
|
1879
|
+
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
1880
|
}
|
|
1431
|
-
|
|
1881
|
+
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1882
|
+
return parts;
|
|
1432
1883
|
}
|
|
1433
|
-
|
|
1434
|
-
|
|
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` };
|
|
1884
|
+
function plain(text) {
|
|
1885
|
+
return text;
|
|
1450
1886
|
}
|
|
1451
|
-
function
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1887
|
+
function tintedParts(parts, colors) {
|
|
1888
|
+
return parts.map(({ text, tint }) => tint(colors)(text)).join("");
|
|
1889
|
+
}
|
|
1890
|
+
function cutToWidth(line, width) {
|
|
1891
|
+
if (Bun.stringWidth(line) <= width)
|
|
1892
|
+
return line;
|
|
1893
|
+
let room = width;
|
|
1894
|
+
let kept = "";
|
|
1895
|
+
let index = 0;
|
|
1896
|
+
let linked = false;
|
|
1897
|
+
while (index < line.length) {
|
|
1898
|
+
ESCAPE_CODE.lastIndex = index;
|
|
1899
|
+
const escape = ESCAPE_CODE.exec(line);
|
|
1900
|
+
if (escape !== null) {
|
|
1901
|
+
kept += escape[0];
|
|
1902
|
+
linked ||= escape[0].startsWith(`${ESC}]`);
|
|
1903
|
+
index = ESCAPE_CODE.lastIndex;
|
|
1904
|
+
continue;
|
|
1460
1905
|
}
|
|
1906
|
+
const char = String.fromCodePoint(line.codePointAt(index));
|
|
1907
|
+
const columns = Bun.stringWidth(char);
|
|
1908
|
+
if (columns > room)
|
|
1909
|
+
break;
|
|
1910
|
+
kept += char;
|
|
1911
|
+
room -= columns;
|
|
1912
|
+
index += char.length;
|
|
1461
1913
|
}
|
|
1462
|
-
return
|
|
1914
|
+
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1463
1915
|
}
|
|
1464
|
-
|
|
1465
|
-
const
|
|
1466
|
-
if (!
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1916
|
+
function swallowInput() {
|
|
1917
|
+
const input = process12.stdin;
|
|
1918
|
+
if (!input.isTTY)
|
|
1919
|
+
return () => {
|
|
1920
|
+
return;
|
|
1921
|
+
};
|
|
1922
|
+
const onData = (data) => {
|
|
1923
|
+
if (data.includes(CTRL_C))
|
|
1924
|
+
process12.kill(process12.pid, "SIGINT");
|
|
1925
|
+
};
|
|
1926
|
+
input.setRawMode(true);
|
|
1927
|
+
input.on("data", onData);
|
|
1928
|
+
input.resume();
|
|
1929
|
+
let released = false;
|
|
1930
|
+
return () => {
|
|
1931
|
+
if (released)
|
|
1932
|
+
return;
|
|
1933
|
+
released = true;
|
|
1934
|
+
input.off("data", onData);
|
|
1935
|
+
input.pause();
|
|
1936
|
+
input.setRawMode(false);
|
|
1937
|
+
};
|
|
1938
|
+
}
|
|
1939
|
+
function interceptOutput(clear) {
|
|
1940
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
|
|
1941
|
+
const wrapped = targets.map(([target, name]) => {
|
|
1942
|
+
const original = Reflect.get(target, name);
|
|
1943
|
+
const wrapper = (...args) => {
|
|
1944
|
+
clear();
|
|
1945
|
+
return original.apply(target, args);
|
|
1480
1946
|
};
|
|
1947
|
+
Reflect.set(target, name, wrapper);
|
|
1948
|
+
return { target, name, original, wrapper };
|
|
1949
|
+
});
|
|
1950
|
+
return () => {
|
|
1951
|
+
for (const { target, name, original, wrapper } of wrapped) {
|
|
1952
|
+
if (Reflect.get(target, name) === wrapper)
|
|
1953
|
+
Reflect.set(target, name, original);
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
// ../kit/src/ci.ts
|
|
1959
|
+
init_style();
|
|
1960
|
+
|
|
1961
|
+
// ../kit/src/tool.ts
|
|
1962
|
+
init_format();
|
|
1963
|
+
// ../kit/src/cli.ts
|
|
1964
|
+
init_args();
|
|
1965
|
+
import { readFileSync as readFileSync6, realpathSync as realpathSync2 } from "fs";
|
|
1966
|
+
import { dirname as dirname4, join as join8 } from "path";
|
|
1967
|
+
import process19 from "process";
|
|
1968
|
+
|
|
1969
|
+
// ../kit/src/askpass.ts
|
|
1970
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
1971
|
+
import { tmpdir } from "os";
|
|
1972
|
+
import { join as join6 } from "path";
|
|
1973
|
+
import process16 from "process";
|
|
1974
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1975
|
+
var ECHOED = /username|yes\/no/i;
|
|
1976
|
+
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1977
|
+
function askpass(pause = () => () => {
|
|
1978
|
+
return;
|
|
1979
|
+
}) {
|
|
1980
|
+
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1981
|
+
return;
|
|
1982
|
+
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1983
|
+
const socketPath = join6(dir, "socket");
|
|
1984
|
+
const script = join6(dir, "askpass");
|
|
1985
|
+
let turn = Promise.resolve();
|
|
1986
|
+
const answer = async ({ prompt, notice }) => {
|
|
1987
|
+
const resume = pause();
|
|
1481
1988
|
try {
|
|
1482
|
-
|
|
1989
|
+
if (notice === true) {
|
|
1990
|
+
process16.stderr.write(`${prompt.trim()}
|
|
1991
|
+
`);
|
|
1992
|
+
return {};
|
|
1993
|
+
}
|
|
1994
|
+
await Promise.resolve().then(() => init_prompt());
|
|
1995
|
+
return { answer: await input2(prompt.trim(), { mask: !ECHOED.test(prompt) }) };
|
|
1483
1996
|
} finally {
|
|
1484
|
-
|
|
1485
|
-
console.info = info;
|
|
1486
|
-
process16.stdout.write = write;
|
|
1997
|
+
resume();
|
|
1487
1998
|
}
|
|
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
|
-
|
|
1999
|
+
};
|
|
2000
|
+
const respond = async (socket, request) => {
|
|
2001
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
2002
|
+
const previous = turn;
|
|
2003
|
+
let reply = {};
|
|
2004
|
+
turn = promise;
|
|
2005
|
+
await previous;
|
|
2006
|
+
try {
|
|
2007
|
+
reply = await answer(request);
|
|
2008
|
+
} catch {} finally {
|
|
2009
|
+
socket.end(`${JSON.stringify(reply)}
|
|
2010
|
+
`);
|
|
2011
|
+
resolve();
|
|
2012
|
+
}
|
|
2013
|
+
};
|
|
2014
|
+
const server = Bun.listen({
|
|
2015
|
+
unix: socketPath,
|
|
2016
|
+
socket: {
|
|
2017
|
+
open: (socket) => {
|
|
2018
|
+
socket.data = { buffered: "" };
|
|
2019
|
+
},
|
|
2020
|
+
data: (socket, chunk) => {
|
|
2021
|
+
const before = socket.data.buffered;
|
|
2022
|
+
socket.data.buffered += chunk.toString();
|
|
2023
|
+
if (before.includes(`
|
|
2024
|
+
`) || !socket.data.buffered.includes(`
|
|
2025
|
+
`))
|
|
2026
|
+
return;
|
|
2027
|
+
respond(socket, JSON.parse(socket.data.buffered));
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
});
|
|
2031
|
+
writeFileSync2(script, `#!/bin/sh
|
|
2032
|
+
${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no-env-file --config=/dev/null ${quoted(process16.argv[1])} "$@"
|
|
2033
|
+
`);
|
|
2034
|
+
chmodSync(script, 448);
|
|
2035
|
+
return {
|
|
2036
|
+
env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
|
|
2037
|
+
close: () => {
|
|
2038
|
+
server.stop(true);
|
|
2039
|
+
rmSync(dir, { recursive: true, force: true });
|
|
2040
|
+
}
|
|
2041
|
+
};
|
|
1516
2042
|
}
|
|
1517
|
-
function
|
|
1518
|
-
|
|
2043
|
+
async function askpassClient(argv) {
|
|
2044
|
+
const socketPath = process16.env[SOCKET_VARIABLE];
|
|
2045
|
+
if (socketPath === undefined)
|
|
2046
|
+
return;
|
|
2047
|
+
const request = { prompt: argv[0] ?? "", ...process16.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
2048
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
2049
|
+
let received = "";
|
|
2050
|
+
try {
|
|
2051
|
+
await Bun.connect({
|
|
2052
|
+
unix: socketPath,
|
|
2053
|
+
socket: {
|
|
2054
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
2055
|
+
`),
|
|
2056
|
+
data: (_, chunk) => {
|
|
2057
|
+
received += chunk.toString();
|
|
2058
|
+
},
|
|
2059
|
+
close: () => resolve(received),
|
|
2060
|
+
error: () => resolve("")
|
|
2061
|
+
}
|
|
2062
|
+
});
|
|
2063
|
+
} catch {
|
|
2064
|
+
return 1;
|
|
2065
|
+
}
|
|
2066
|
+
const reply = await promise;
|
|
2067
|
+
if (reply === "")
|
|
2068
|
+
return 1;
|
|
2069
|
+
const { answer } = JSON.parse(reply);
|
|
2070
|
+
if (request.notice === true)
|
|
2071
|
+
return 0;
|
|
2072
|
+
if (answer === undefined)
|
|
2073
|
+
return 1;
|
|
2074
|
+
process16.stdout.write(`${answer}
|
|
2075
|
+
`);
|
|
2076
|
+
return 0;
|
|
1519
2077
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
2078
|
+
|
|
2079
|
+
// ../kit/src/completions.ts
|
|
2080
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
2081
|
+
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'
|
|
2082
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
2083
|
+
set -l current (commandline -ct)
|
|
2084
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
2085
|
+
if test "$line" = __files__
|
|
2086
|
+
__fish_complete_path $current
|
|
2087
|
+
else
|
|
2088
|
+
echo $line
|
|
2089
|
+
end
|
|
2090
|
+
end
|
|
2091
|
+
end`;
|
|
2092
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
2093
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
2094
|
+
local -a lines
|
|
2095
|
+
COMPREPLY=()
|
|
2096
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
2097
|
+
for line in "\${lines[@]}"; do
|
|
2098
|
+
if [[ $line == __files__ ]]; then
|
|
2099
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
2100
|
+
else
|
|
2101
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
2102
|
+
fi
|
|
2103
|
+
done
|
|
2104
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
2105
|
+
}`;
|
|
2106
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
2107
|
+
local line
|
|
2108
|
+
local -a described plain
|
|
2109
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
2110
|
+
if [[ $line == __files__ ]]; then
|
|
2111
|
+
_files
|
|
2112
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
2113
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
2114
|
+
else
|
|
2115
|
+
plain+=("$line")
|
|
2116
|
+
fi
|
|
2117
|
+
done
|
|
2118
|
+
(( \${#described} )) && _describe -V value described
|
|
2119
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
2120
|
+
return 0
|
|
2121
|
+
}`;
|
|
2122
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
2123
|
+
if (shell === "fish")
|
|
2124
|
+
return `${header}
|
|
2125
|
+
${FISH_FUNCTION}
|
|
2126
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
2127
|
+
`).join("")}`;
|
|
2128
|
+
if (shell === "bash")
|
|
2129
|
+
return `${header}
|
|
2130
|
+
${BASH_FUNCTION}
|
|
2131
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
2132
|
+
`;
|
|
2133
|
+
return `${header}
|
|
2134
|
+
${ZSH_FUNCTION}
|
|
2135
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
2136
|
+
`;
|
|
1524
2137
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
2138
|
+
|
|
2139
|
+
// ../kit/src/notify.ts
|
|
2140
|
+
init_format();
|
|
2141
|
+
init_mode();
|
|
2142
|
+
import process17 from "process";
|
|
2143
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
2144
|
+
var CANCELLED = 130;
|
|
2145
|
+
function base64(text) {
|
|
2146
|
+
return Buffer.from(text).toString("base64");
|
|
1532
2147
|
}
|
|
1533
|
-
function
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
while (at < chars.length && isWord(chars[at]))
|
|
1538
|
-
at++;
|
|
1539
|
-
return at;
|
|
2148
|
+
function notification(title, body, env = process17.env) {
|
|
2149
|
+
const id = `kit${process17.pid}`;
|
|
2150
|
+
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\\`];
|
|
2151
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1540
2152
|
}
|
|
1541
|
-
function
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
1546
|
-
at--;
|
|
1547
|
-
return at;
|
|
2153
|
+
function notifyEnd(command, code, ms, { stream = process17.stderr, env = process17.env } = {}) {
|
|
2154
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
2155
|
+
return;
|
|
2156
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1548
2157
|
}
|
|
1549
|
-
|
|
1550
|
-
|
|
2158
|
+
|
|
2159
|
+
// ../kit/src/cli.ts
|
|
2160
|
+
init_style();
|
|
2161
|
+
init_text2();
|
|
2162
|
+
|
|
2163
|
+
// ../kit/src/usage.ts
|
|
2164
|
+
import { appendFileSync, mkdirSync as mkdirSync2 } from "fs";
|
|
2165
|
+
import { homedir as homedir4 } from "os";
|
|
2166
|
+
import { dirname as dirname3, join as join7 } from "path";
|
|
2167
|
+
import process18 from "process";
|
|
2168
|
+
|
|
2169
|
+
// ../kit/src/logs.ts
|
|
2170
|
+
init_user_config();
|
|
2171
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
2172
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
2173
|
+
|
|
2174
|
+
// ../kit/src/usage.ts
|
|
2175
|
+
init_user_config();
|
|
2176
|
+
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
2177
|
+
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
2178
|
+
var LONGEST_NAME = 40;
|
|
2179
|
+
var usageError;
|
|
2180
|
+
function noteUsageError(message) {
|
|
2181
|
+
usageError = message;
|
|
1551
2182
|
}
|
|
1552
|
-
function
|
|
1553
|
-
|
|
1554
|
-
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
2183
|
+
function stateHome(env = process18.env) {
|
|
2184
|
+
return xdgFolder(env.XDG_STATE_HOME, join7(homedir4(), ".local", "state"));
|
|
1555
2185
|
}
|
|
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 };
|
|
2186
|
+
function usagePath(env = process18.env) {
|
|
2187
|
+
return join7(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1569
2188
|
}
|
|
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
|
-
}
|
|
2189
|
+
function usageRecorded(env = process18.env) {
|
|
2190
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
2191
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1604
2192
|
}
|
|
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) };
|
|
2193
|
+
function flagNames(argv) {
|
|
2194
|
+
const end = argv.indexOf("--");
|
|
2195
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
2196
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1621
2197
|
}
|
|
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]);
|
|
2198
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
2199
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
2200
|
+
usageError = undefined;
|
|
2201
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1638
2202
|
}
|
|
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)
|
|
2203
|
+
function recordUsage(entry, env = process18.env) {
|
|
2204
|
+
if (!usageRecorded(env))
|
|
1686
2205
|
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);
|
|
2206
|
+
try {
|
|
2207
|
+
const path = usagePath(env);
|
|
2208
|
+
mkdirSync2(dirname3(path), { recursive: true, mode: 448 });
|
|
2209
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
2210
|
+
`, { mode: 384 });
|
|
2211
|
+
} catch {}
|
|
1704
2212
|
}
|
|
1705
2213
|
|
|
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"
|
|
2214
|
+
// ../kit/src/cli.ts
|
|
2215
|
+
var LEVEL_OPTIONS = {
|
|
2216
|
+
...OUTPUT_OPTIONS,
|
|
2217
|
+
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1763
2218
|
};
|
|
1764
|
-
var
|
|
1765
|
-
|
|
1766
|
-
|
|
2219
|
+
var TOP_OPTIONS = {
|
|
2220
|
+
...LEVEL_OPTIONS,
|
|
2221
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
2222
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
2223
|
+
};
|
|
2224
|
+
function printError(prefix, message, hint, cause) {
|
|
2225
|
+
const colors = paint(process19.stderr);
|
|
2226
|
+
const styled = takesControlCodes(process19.stderr);
|
|
2227
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
2228
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
2229
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
2230
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1767
2231
|
}
|
|
1768
|
-
function
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
2232
|
+
function runHint(command, effect) {
|
|
2233
|
+
return `run \`${command}\`${effect === undefined ? "" : ` to ${effect}`}`;
|
|
2234
|
+
}
|
|
2235
|
+
function printJsonError(message, hint, cause) {
|
|
2236
|
+
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
2237
|
+
}
|
|
2238
|
+
function wantsJson(argv) {
|
|
2239
|
+
const end = argv.indexOf("--");
|
|
2240
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
2241
|
+
}
|
|
2242
|
+
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
2243
|
+
if (error instanceof HelpShown)
|
|
2244
|
+
return 0;
|
|
2245
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
2246
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
2247
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
2248
|
+
if (error instanceof Exit && error.code === 2)
|
|
2249
|
+
noteUsageError(error.message);
|
|
2250
|
+
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
2251
|
+
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
2252
|
+
return error instanceof Exit ? error.code : 1;
|
|
2253
|
+
}
|
|
2254
|
+
var COMPLETE = "__complete";
|
|
2255
|
+
var FILES = "__files__";
|
|
2256
|
+
async function completingOf(run) {
|
|
2257
|
+
completion.active = true;
|
|
2258
|
+
try {
|
|
2259
|
+
await run([]);
|
|
2260
|
+
} catch (error) {
|
|
2261
|
+
if (error instanceof Completing)
|
|
2262
|
+
return error;
|
|
2263
|
+
} finally {
|
|
2264
|
+
completion.active = false;
|
|
1785
2265
|
}
|
|
1786
|
-
|
|
1787
|
-
return { text, styles: colored ? styles : undefined };
|
|
2266
|
+
return new Completing({});
|
|
1788
2267
|
}
|
|
1789
|
-
function
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
colored ||= cell.styles !== undefined;
|
|
1802
|
-
styles.push(...cell.styles?.slice(0, shown.length) ?? repeat("", shown.length));
|
|
1803
|
-
if (column < searched)
|
|
1804
|
-
searchEnd = cells.length > 1 ? text.trimEnd().length : text.length;
|
|
1805
|
-
if (!last) {
|
|
1806
|
-
const pad = widths[column] - Bun.stringWidth(cell.text) + COLUMN_GAP;
|
|
1807
|
-
text += " ".repeat(pad);
|
|
1808
|
-
styles.push(...repeat("", pad));
|
|
1809
|
-
}
|
|
2268
|
+
function candidateLine(candidate) {
|
|
2269
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
2270
|
+
}
|
|
2271
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
2272
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
2273
|
+
const typed = [];
|
|
2274
|
+
let at = 0;
|
|
2275
|
+
while (at < before.length) {
|
|
2276
|
+
const word = before[at];
|
|
2277
|
+
if (word === "--") {
|
|
2278
|
+
typed.push(...before.slice(at + 1));
|
|
2279
|
+
break;
|
|
1810
2280
|
}
|
|
1811
|
-
|
|
1812
|
-
|
|
2281
|
+
if (!word.startsWith("-"))
|
|
2282
|
+
typed.push(word);
|
|
2283
|
+
else if (takesValue(word))
|
|
2284
|
+
at++;
|
|
2285
|
+
at++;
|
|
2286
|
+
}
|
|
2287
|
+
const last = positionals.at(-1);
|
|
2288
|
+
if (typed.length < positionals.length)
|
|
2289
|
+
return { name: positionals[typed.length], typed };
|
|
2290
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1813
2291
|
}
|
|
1814
|
-
function
|
|
1815
|
-
const
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
`))
|
|
1828
|
-
return [];
|
|
1829
|
-
if (key !== undefined)
|
|
1830
|
-
return [key];
|
|
1831
|
-
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1832
|
-
});
|
|
2292
|
+
async function leafCandidates(run, words) {
|
|
2293
|
+
const completing = await completingOf(run);
|
|
2294
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
2295
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
2296
|
+
const flag = words.at(-2);
|
|
2297
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
2298
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
2299
|
+
if (option?.type === "string") {
|
|
2300
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
2301
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
2302
|
+
}
|
|
2303
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
2304
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1833
2305
|
}
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
return
|
|
2306
|
+
var COMPLETIONS = "--completions";
|
|
2307
|
+
function flagValue([flag = "", ...rest]) {
|
|
2308
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1837
2309
|
}
|
|
1838
|
-
function
|
|
1839
|
-
const
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
2310
|
+
function printCompletionScript(name, args) {
|
|
2311
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
2312
|
+
if (shell === undefined || args.length !== 1) {
|
|
2313
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
2314
|
+
return 2;
|
|
2315
|
+
}
|
|
2316
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
2317
|
+
return 0;
|
|
1844
2318
|
}
|
|
1845
|
-
function
|
|
1846
|
-
|
|
1847
|
-
|
|
2319
|
+
async function printCandidates(found) {
|
|
2320
|
+
for (const line of await found)
|
|
2321
|
+
console.log(line);
|
|
2322
|
+
return 0;
|
|
1848
2323
|
}
|
|
1849
|
-
function
|
|
1850
|
-
|
|
2324
|
+
function packageVersion(entry = Bun.main) {
|
|
2325
|
+
let resolved = entry;
|
|
2326
|
+
try {
|
|
2327
|
+
resolved = realpathSync2(entry);
|
|
2328
|
+
} catch {}
|
|
2329
|
+
for (let dir = dirname4(resolved);; dir = dirname4(dir)) {
|
|
2330
|
+
try {
|
|
2331
|
+
const { version } = JSON.parse(readFileSync6(join8(dir, "package.json"), "utf8"));
|
|
2332
|
+
if (typeof version === "string")
|
|
2333
|
+
return version;
|
|
2334
|
+
} catch {}
|
|
2335
|
+
if (dirname4(dir) === dir)
|
|
2336
|
+
return "0.0.0";
|
|
2337
|
+
}
|
|
1851
2338
|
}
|
|
1852
|
-
function
|
|
1853
|
-
|
|
2339
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
2340
|
+
const answered = await askpassClient(argv);
|
|
2341
|
+
if (answered !== undefined)
|
|
2342
|
+
return answered;
|
|
2343
|
+
if (argv[0] === COMPLETE)
|
|
2344
|
+
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
2345
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
2346
|
+
return printCompletionScript(name, flagValue(argv));
|
|
2347
|
+
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
2348
|
+
console.log(version ?? packageVersion());
|
|
2349
|
+
return 0;
|
|
2350
|
+
}
|
|
2351
|
+
let code;
|
|
2352
|
+
const started = performance.now();
|
|
2353
|
+
try {
|
|
2354
|
+
code = await run(argv);
|
|
2355
|
+
} catch (error) {
|
|
2356
|
+
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
2357
|
+
}
|
|
2358
|
+
notifyEnd(name, code, performance.now() - started);
|
|
2359
|
+
if (usage !== false) {
|
|
2360
|
+
try {
|
|
2361
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
2362
|
+
} catch {}
|
|
2363
|
+
}
|
|
2364
|
+
return code;
|
|
1854
2365
|
}
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
2366
|
+
|
|
2367
|
+
// ../kit/src/index.ts
|
|
2368
|
+
init_config();
|
|
2369
|
+
|
|
2370
|
+
// ../kit/src/excerpt.ts
|
|
2371
|
+
init_text2();
|
|
2372
|
+
|
|
2373
|
+
// ../kit/src/index.ts
|
|
2374
|
+
init_folders();
|
|
2375
|
+
init_format();
|
|
2376
|
+
|
|
2377
|
+
// ../kit/src/git.ts
|
|
2378
|
+
init_args();
|
|
2379
|
+
// ../kit/src/limit.ts
|
|
2380
|
+
init_args();
|
|
2381
|
+
|
|
2382
|
+
// ../kit/src/index.ts
|
|
2383
|
+
init_mode();
|
|
2384
|
+
|
|
2385
|
+
// ../kit/src/report.ts
|
|
2386
|
+
init_style();
|
|
2387
|
+
init_text2();
|
|
2388
|
+
// ../kit/src/secrets.ts
|
|
2389
|
+
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
2390
|
+
var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
|
|
2391
|
+
// ../kit/src/sessions.ts
|
|
2392
|
+
var {Glob } = globalThis.Bun;
|
|
2393
|
+
var SESSION_FILES = new Glob("*.json");
|
|
2394
|
+
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
2395
|
+
|
|
2396
|
+
// ../kit/src/index.ts
|
|
2397
|
+
init_style();
|
|
2398
|
+
init_text2();
|
|
2399
|
+
init_theme();
|
|
2400
|
+
init_user_config();
|
|
2401
|
+
|
|
2402
|
+
// ../kit/src/watch.ts
|
|
2403
|
+
init_args();
|
|
2404
|
+
init_input();
|
|
2405
|
+
init_style();
|
|
2406
|
+
import process20 from "process";
|
|
2407
|
+
import { format } from "util";
|
|
2408
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
2409
|
+
var DEFAULT_SECONDS = 2;
|
|
2410
|
+
var ATTACHED_SHORT = /^-w./;
|
|
2411
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
2412
|
+
function watchOption(what) {
|
|
2413
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
2414
|
+
}
|
|
2415
|
+
function withoutWatch(args) {
|
|
2416
|
+
const rest = [];
|
|
2417
|
+
for (let at = 0;at < args.length; at++) {
|
|
2418
|
+
const arg = args[at];
|
|
2419
|
+
if (arg === "--watch" || arg === "-w") {
|
|
2420
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
2421
|
+
at++;
|
|
2422
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
2423
|
+
rest.push(arg);
|
|
2424
|
+
}
|
|
1866
2425
|
}
|
|
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
|
-
if (!state.multi || at === undefined)
|
|
1893
|
-
return state;
|
|
1894
|
-
const marked = new Set(state.marked);
|
|
1895
|
-
if (!marked.delete(at))
|
|
1896
|
-
marked.add(at);
|
|
1897
|
-
return move({ ...state, marked }, 1);
|
|
2426
|
+
return rest;
|
|
2427
|
+
}
|
|
2428
|
+
async function watching(value, step, stream = process20.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
2429
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
2430
|
+
if (!takesControlCodes(stream))
|
|
2431
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
2432
|
+
let code = 0;
|
|
2433
|
+
for (let round = 0;round < rounds; round++) {
|
|
2434
|
+
const held = [];
|
|
2435
|
+
const { log, info } = console;
|
|
2436
|
+
const write = process20.stdout.write.bind(process20.stdout);
|
|
2437
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
2438
|
+
`);
|
|
2439
|
+
console.log = hold;
|
|
2440
|
+
console.info = hold;
|
|
2441
|
+
process20.stdout.write = (text) => {
|
|
2442
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
2443
|
+
return true;
|
|
2444
|
+
};
|
|
2445
|
+
try {
|
|
2446
|
+
code = await step();
|
|
2447
|
+
} finally {
|
|
2448
|
+
console.log = log;
|
|
2449
|
+
console.info = info;
|
|
2450
|
+
process20.stdout.write = write;
|
|
1898
2451
|
}
|
|
2452
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
2453
|
+
await sleep(interval);
|
|
1899
2454
|
}
|
|
2455
|
+
return code;
|
|
1900
2456
|
}
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
2457
|
+
// ../kit/src/workspace-root.ts
|
|
2458
|
+
init_user_config();
|
|
2459
|
+
import { homedir as homedir5 } from "os";
|
|
2460
|
+
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2461
|
+
import process21 from "process";
|
|
2462
|
+
function expandHome(path, home) {
|
|
2463
|
+
if (path === "~")
|
|
2464
|
+
return home;
|
|
2465
|
+
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2466
|
+
}
|
|
2467
|
+
function configured(env, home) {
|
|
2468
|
+
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2469
|
+
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2470
|
+
}
|
|
2471
|
+
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2472
|
+
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2473
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
1906
2474
|
}
|
|
2475
|
+
// ../kit/src/picker.ts
|
|
2476
|
+
init_folders();
|
|
2477
|
+
init_state();
|
|
1907
2478
|
|
|
1908
2479
|
// ../kit/src/picker/terminal.ts
|
|
2480
|
+
init_args();
|
|
2481
|
+
init_job();
|
|
2482
|
+
init_redraw();
|
|
2483
|
+
init_style();
|
|
1909
2484
|
import { openSync } from "fs";
|
|
1910
|
-
import
|
|
2485
|
+
import process24 from "process";
|
|
1911
2486
|
import tty from "tty";
|
|
1912
2487
|
|
|
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
2488
|
// ../kit/src/picker/preview.ts
|
|
1928
|
-
import
|
|
2489
|
+
import process23 from "process";
|
|
1929
2490
|
|
|
1930
2491
|
// ../kit/src/shell.ts
|
|
1931
2492
|
var SEPARATORS = new Set([`
|
|
@@ -1936,6 +2497,7 @@ var COMMENT_PREFIXES = new Set([";", "&", "|", "(", ")"]);
|
|
|
1936
2497
|
var SAFE_WORD = /^[\w@%+=:,./-]+$/;
|
|
1937
2498
|
var DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
|
|
1938
2499
|
var KEYWORDS = new Set(["then", "do", "else", "if", "elif", "while", "until", "!", "{", "}"]);
|
|
2500
|
+
var FISH_COMBINERS = new Set(["and", "or", "not"]);
|
|
1939
2501
|
var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh", "fish", "csh", "tcsh", "nu", "xonsh", "elvish", "pwsh", "powershell"]);
|
|
1940
2502
|
var SCANNED_PROGRAMS = new Set(["su", "runuser", "flock"]);
|
|
1941
2503
|
var COMMAND_STRING_PROGRAMS = new Set([...SHELLS, ...SCANNED_PROGRAMS]);
|
|
@@ -1947,6 +2509,7 @@ var FIND_EXEC = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
|
|
|
1947
2509
|
function wrapper(short = "", long = [], operands = 0, runsString = false) {
|
|
1948
2510
|
return { short, long, operands, runsString };
|
|
1949
2511
|
}
|
|
2512
|
+
var RUNNER = { ...wrapper(), afterDashes: true };
|
|
1950
2513
|
var WRAPPERS = new Map([
|
|
1951
2514
|
["command", wrapper()],
|
|
1952
2515
|
["builtin", wrapper()],
|
|
@@ -1968,7 +2531,23 @@ var WRAPPERS = new Map([
|
|
|
1968
2531
|
["parallel", wrapper("jnNSaIPlLdTsC", ["--jobs", "--max-args", "--max-replace-args", "--sshlogin", "--arg-file", "--delimiter", "--colsep"], 0, true)],
|
|
1969
2532
|
["unbuffer", wrapper()],
|
|
1970
2533
|
["systemd-run", wrapper("puEMH", ["--property", "--unit", "--description", "--slice", "--setenv", "--machine", "--host", "--uid", "--gid", "--working-directory", "--nice", "--service-type"])],
|
|
1971
|
-
["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])]
|
|
2534
|
+
["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])],
|
|
2535
|
+
["strace", wrapper("abeEIoOpPsSuUX", ["--trace", "--output", "--attach", "--string-limit", "--user", "--env", "--columns", "--trace-path", "--signal", "--status", "--summary-sort-by", "--summary-columns", "--const-print-style", "--interruptible", "--detach-on"])],
|
|
2536
|
+
["ltrace", wrapper("aeFlnopsuxX", ["--output", "--user", "--library", "--config", "--align", "--indent"])],
|
|
2537
|
+
["taskset", wrapper("", [], 1)],
|
|
2538
|
+
["fakeroot", wrapper("lsib", ["--lib", "--faked"])],
|
|
2539
|
+
["sshpass", wrapper("pfdP")],
|
|
2540
|
+
["coproc", wrapper()],
|
|
2541
|
+
["proxychains", wrapper("f")],
|
|
2542
|
+
["proxychains4", wrapper("f")],
|
|
2543
|
+
["torsocks", wrapper("upaP", ["--user", "--pass", "--address", "--port"])],
|
|
2544
|
+
["chrt", wrapper("TPD", ["--sched-runtime", "--sched-period", "--sched-deadline"], 1)],
|
|
2545
|
+
["unshare", wrapper("SGRw", ["--setuid", "--setgid", "--root", "--wd", "--map-user", "--map-group", "--map-users", "--map-groups", "--propagation", "--setgroups"])],
|
|
2546
|
+
["nsenter", wrapper("tSG", ["--target", "--setuid", "--setgid"])],
|
|
2547
|
+
["out", RUNNER],
|
|
2548
|
+
["slot", RUNNER],
|
|
2549
|
+
["waitfor", RUNNER],
|
|
2550
|
+
["base", RUNNER]
|
|
1972
2551
|
]);
|
|
1973
2552
|
function shellQuote(word) {
|
|
1974
2553
|
return SAFE_WORD.test(word) && !word.startsWith("=") ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
@@ -1994,7 +2573,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
1994
2573
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
1995
2574
|
const stop = () => {
|
|
1996
2575
|
try {
|
|
1997
|
-
|
|
2576
|
+
process23.kill(-proc.pid, "SIGKILL");
|
|
1998
2577
|
} catch {
|
|
1999
2578
|
proc.kill();
|
|
2000
2579
|
}
|
|
@@ -2019,7 +2598,12 @@ ${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe",
|
|
|
2019
2598
|
return signal.aborted ? [] : previewLines(Buffer.concat(chunks).subarray(0, PREVIEW_BYTES).toString());
|
|
2020
2599
|
}
|
|
2021
2600
|
|
|
2601
|
+
// ../kit/src/picker/terminal.ts
|
|
2602
|
+
init_state();
|
|
2603
|
+
|
|
2022
2604
|
// ../kit/src/picker/view.ts
|
|
2605
|
+
init_line();
|
|
2606
|
+
init_state();
|
|
2023
2607
|
var MIN_HEIGHT = 4;
|
|
2024
2608
|
var PREVIEW_MIN_COLUMNS = 80;
|
|
2025
2609
|
var PREVIEW_MIN_ROWS = 10;
|
|
@@ -2152,7 +2736,7 @@ function openTerminal() {
|
|
|
2152
2736
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
2153
2737
|
}
|
|
2154
2738
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
2155
|
-
const out =
|
|
2739
|
+
const out = process24.stderr;
|
|
2156
2740
|
let resize;
|
|
2157
2741
|
async function read(onChunk) {
|
|
2158
2742
|
const decoder = new TextDecoder;
|
|
@@ -2341,9 +2925,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2341
2925
|
const ended = new Promise((resolve) => {
|
|
2342
2926
|
finish = resolve;
|
|
2343
2927
|
});
|
|
2344
|
-
|
|
2928
|
+
process24.once("exit", restore);
|
|
2345
2929
|
for (const signal of SIGNALS2)
|
|
2346
|
-
|
|
2930
|
+
process24.once(signal, stop);
|
|
2347
2931
|
try {
|
|
2348
2932
|
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
2349
2933
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -2356,8 +2940,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2356
2940
|
await ended;
|
|
2357
2941
|
} finally {
|
|
2358
2942
|
for (const signal of SIGNALS2)
|
|
2359
|
-
|
|
2360
|
-
|
|
2943
|
+
process24.off(signal, stop);
|
|
2944
|
+
process24.off("exit", restore);
|
|
2361
2945
|
restore();
|
|
2362
2946
|
}
|
|
2363
2947
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -2369,7 +2953,9 @@ async function previewOf(preview, hidden, signal) {
|
|
|
2369
2953
|
return [error instanceof Error ? error.message : String(error)];
|
|
2370
2954
|
}
|
|
2371
2955
|
}
|
|
2956
|
+
|
|
2372
2957
|
// ../kit/src/picker.ts
|
|
2958
|
+
init_score();
|
|
2373
2959
|
function table2(rows) {
|
|
2374
2960
|
const widths = rows[0]?.cells.map((_, index) => Math.max(...rows.map((row) => Bun.stringWidth(row.cells[index])))) ?? [];
|
|
2375
2961
|
return rows.map((row) => [
|
|
@@ -2405,15 +2991,15 @@ function list(rows) {
|
|
|
2405
2991
|
|
|
2406
2992
|
// src/branch.ts
|
|
2407
2993
|
import { basename } from "path";
|
|
2408
|
-
import
|
|
2409
|
-
var usage2 = `gb [branch]
|
|
2994
|
+
import process25 from "process";
|
|
2995
|
+
var usage2 = `gb [branch]: picks a git branch and switches to it
|
|
2410
2996
|
gb -
|
|
2411
2997
|
gb -c <name>
|
|
2412
2998
|
gb -d <branch>
|
|
2413
2999
|
|
|
2414
|
-
Without a branch,
|
|
2415
|
-
\`gb <branch>\` switches without the picker,
|
|
2416
|
-
A branch checked out in another worktree cannot be switched to: gb prints that worktree's path
|
|
3000
|
+
Without a branch, on a terminal, picks one: the recently checked out first, then the other local ones, then the remote ones with no local branch yet (enter switches, ctrl-n creates, ctrl-d deletes a merged local branch with \`git branch -d\`, ctrl-r fetches and prunes); without a terminal it lists them.
|
|
3001
|
+
\`gb <branch>\` switches without the picker, \`gb -\` goes back to the previous branch, \`gb -c <name>\` creates one and switches to it, \`gb -d <branch>\` deletes a local one.
|
|
3002
|
+
A branch checked out in another worktree cannot be switched to: gb prints that worktree's path, since a command cannot change its shell's folder.`;
|
|
2417
3003
|
var EXITS = [[0, "it switched, created, deleted or listed"], ["git", "the code of the git command it ran, when that failed"], [1, "there is no branch by that name or nothing was picked"], [2, "outside a git repository or a usage error"]];
|
|
2418
3004
|
var options = {
|
|
2419
3005
|
create: { type: "boolean", short: "c", description: "create the branch named by the rest of the line and switch to it" },
|
|
@@ -2556,7 +3142,7 @@ async function fetched() {
|
|
|
2556
3142
|
const success = await proc.exited === 0;
|
|
2557
3143
|
return header(branches(base()), read(["branch", "--show-current"]), success ? "" : "fetch failed");
|
|
2558
3144
|
}
|
|
2559
|
-
function
|
|
3145
|
+
function listed3(all) {
|
|
2560
3146
|
list([
|
|
2561
3147
|
...all.map((branch) => ({
|
|
2562
3148
|
label: branch.name,
|
|
@@ -2583,7 +3169,7 @@ async function hidden(flag, rest) {
|
|
|
2583
3169
|
return 0;
|
|
2584
3170
|
}
|
|
2585
3171
|
if (flag === "--list") {
|
|
2586
|
-
|
|
3172
|
+
listed3(load().all);
|
|
2587
3173
|
return 0;
|
|
2588
3174
|
}
|
|
2589
3175
|
if (flag === "--names") {
|
|
@@ -2630,7 +3216,7 @@ async function gb(args) {
|
|
|
2630
3216
|
if (parsed.values.json === true)
|
|
2631
3217
|
printJson(all);
|
|
2632
3218
|
else
|
|
2633
|
-
console.log(table2(all.map(row)).map((line) => takesControlCodes(
|
|
3219
|
+
console.log(table2(all.map(row)).map((line) => takesControlCodes(process25.stdout) ? line : Bun.stripANSI(line)).join(`
|
|
2634
3220
|
`));
|
|
2635
3221
|
return 0;
|
|
2636
3222
|
}
|
|
@@ -2721,22 +3307,22 @@ async function git2(args, env) {
|
|
|
2721
3307
|
// src/gm.ts
|
|
2722
3308
|
var USAGE = `gm [branch]: merges the branch into the current one with git merge --no-edit, saying what came in
|
|
2723
3309
|
|
|
2724
|
-
Without a branch, on a terminal, picks one
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
A working tree with uncommitted changes is refused. 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
|
-
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.`;
|
|
3310
|
+
Without a branch, on a terminal, picks one with a preview of what merging it would do (enter merges, ctrl-s squashes); without a terminal it lists the branches with that verdict. A merge in progress is refused here: \`gm --continue\` or \`gm --abort\`.
|
|
3311
|
+
Staged changes are refused, and so are unstaged ones in files the merge changes; other unstaged edits stay as they are.
|
|
3312
|
+
On a conflict every conflicted file is listed with its conflict regions and the exit is 1.`;
|
|
2729
3313
|
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
3314
|
var OPTIONS = {
|
|
2731
3315
|
abort: { type: "boolean", description: "give up the merge in progress", conflicts: ["continue", "dry-run"] },
|
|
2732
|
-
continue: { type: "boolean", description: "commit the merge in progress once no conflict marker is left", conflicts: ["abort", "dry-run"] },
|
|
3316
|
+
continue: { type: "boolean", description: "commit the merge in progress once no conflict marker is left and a side is picked for each file git could not mark", conflicts: ["abort", "dry-run"] },
|
|
2733
3317
|
squash: { type: "boolean", short: "s", description: "stage the branch's changes without committing or recording a merge", conflicts: ["abort", "continue", "dry-run"] },
|
|
2734
3318
|
"dry-run": { type: "boolean", short: "n", description: "say whether the merge would conflict, and where, without touching the tree", conflicts: ["abort", "continue"] },
|
|
2735
3319
|
json: jsonOption("{outcome, branch, into, sha?, commits?, files?: [{status, path, from?}], conflicts?: [{path, hunks: [{from, to, lines: [{line, text}]}]}]}, outcome being fast-forward, merge, squashed, up-to-date, conflict, clean (dry run), aborted or refused; with no branch an array of {name, remote, ahead, behind, outcome, conflicts: [path], when, subject}")
|
|
2736
3320
|
};
|
|
2737
3321
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
2738
3322
|
var RENAME = /^[RC]\d*$/;
|
|
2739
|
-
var EDITOR_OFF = { ...
|
|
3323
|
+
var EDITOR_OFF = { ...process26.env, GIT_EDITOR: "true", GIT_MERGE_AUTOEDIT: "no" };
|
|
3324
|
+
var BINARY_PROBE = 8000;
|
|
3325
|
+
var SYMLINK_MODE = "120000";
|
|
2740
3326
|
async function ran(args, env) {
|
|
2741
3327
|
const { code, stdout, stderr } = await git2(args, env);
|
|
2742
3328
|
if (code !== 0)
|
|
@@ -2754,18 +3340,40 @@ async function currentBranch() {
|
|
|
2754
3340
|
async function merging() {
|
|
2755
3341
|
return succeeds(["rev-parse", "-q", "--verify", "MERGE_HEAD"]);
|
|
2756
3342
|
}
|
|
3343
|
+
async function unmergedStages() {
|
|
3344
|
+
const stages = new Map;
|
|
3345
|
+
for (const entry of (await ran(["ls-files", "-u", "-z", "--full-name", "--", ":/"])).split("\x00").filter(Boolean)) {
|
|
3346
|
+
const tab = entry.indexOf("\t");
|
|
3347
|
+
const path = entry.slice(tab + 1);
|
|
3348
|
+
const [mode = "", blob = "", stage = ""] = entry.slice(0, tab).split(" ");
|
|
3349
|
+
stages.set(path, (stages.get(path) ?? new Map).set(stage, { mode, blob }));
|
|
3350
|
+
}
|
|
3351
|
+
return stages;
|
|
3352
|
+
}
|
|
3353
|
+
async function isMarkable(path, bytes, stages) {
|
|
3354
|
+
const ours = stages.get("2");
|
|
3355
|
+
const theirs = stages.get("3");
|
|
3356
|
+
if (bytes.subarray(0, BINARY_PROBE).includes(0) || ours === undefined || theirs === undefined || ours.mode === SYMLINK_MODE || theirs.mode === SYMLINK_MODE)
|
|
3357
|
+
return false;
|
|
3358
|
+
const blob = (await ran(["hash-object", "--", path])).trim();
|
|
3359
|
+
return blob !== ours.blob && blob !== theirs.blob;
|
|
3360
|
+
}
|
|
2757
3361
|
async function conflicted() {
|
|
2758
|
-
const
|
|
2759
|
-
return
|
|
3362
|
+
const top = (await ran(["rev-parse", "--show-toplevel"])).trim();
|
|
3363
|
+
return Promise.all([...await unmergedStages()].map(async ([fromTop, stages]) => {
|
|
3364
|
+
const path = relative(process26.cwd(), join10(top, fromTop));
|
|
3365
|
+
let bytes;
|
|
2760
3366
|
try {
|
|
2761
|
-
|
|
3367
|
+
bytes = readFileSync7(path);
|
|
2762
3368
|
} catch {
|
|
2763
|
-
return { path, hunks: [] };
|
|
3369
|
+
return { path, hunks: [], isMarked: false };
|
|
2764
3370
|
}
|
|
2765
|
-
|
|
3371
|
+
const isText = !bytes.subarray(0, BINARY_PROBE).includes(0);
|
|
3372
|
+
return { path, hunks: isText ? conflictHunks(bytes.toString("utf8")) : [], isMarked: await isMarkable(path, bytes, stages) };
|
|
3373
|
+
}));
|
|
2766
3374
|
}
|
|
2767
3375
|
function conflictLines(conflicts) {
|
|
2768
|
-
return conflicts.flatMap(({ path, hunks }) => hunks.length === 0 ? [`${role("path",
|
|
3376
|
+
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
3377
|
}
|
|
2770
3378
|
function fileLine(line) {
|
|
2771
3379
|
const [letter = "", from = "", to] = line.split("\t");
|
|
@@ -2780,10 +3388,10 @@ function files(text) {
|
|
|
2780
3388
|
}
|
|
2781
3389
|
function conflictReport(branch, into, conflicts, json, squash = false) {
|
|
2782
3390
|
if (json) {
|
|
2783
|
-
printJson({ outcome: "conflict", branch, into, conflicts });
|
|
3391
|
+
printJson({ outcome: "conflict", branch, into, conflicts: conflicts.map(({ path, hunks }) => ({ path, hunks })) });
|
|
2784
3392
|
return 1;
|
|
2785
3393
|
}
|
|
2786
|
-
console.log([marked("problem", `merging ${branch} into ${into} left ${conflicts.length} conflicted ${conflicts.length === 1 ? "file" : "files"}`,
|
|
3394
|
+
console.log([marked("problem", `merging ${branch} into ${into} left ${conflicts.length} conflicted ${conflicts.length === 1 ? "file" : "files"}`, process26.stdout), ...conflictLines(conflicts)].join(`
|
|
2787
3395
|
`).trimEnd());
|
|
2788
3396
|
console.log(squash ? `
|
|
2789
3397
|
resolve the files and commit them with gc, or git reset --merge to give up` : `
|
|
@@ -2804,7 +3412,7 @@ async function mergedReport(before, branch, into, json) {
|
|
|
2804
3412
|
const how = outcome === "merge" ? `merge commit ${sha.slice(0, 7)}` : "fast-forward";
|
|
2805
3413
|
const list = changed.split(`
|
|
2806
3414
|
`).filter(Boolean);
|
|
2807
|
-
console.log([marked("ok", `${into} <- ${branch}, ${how}, ${count}, ${list.length} ${list.length === 1 ? "file" : "files"} changed`,
|
|
3415
|
+
console.log([marked("ok", `${into} <- ${branch}, ${how}, ${count}, ${list.length} ${list.length === 1 ? "file" : "files"} changed`, process26.stdout), ...list.map(fileLine)].join(`
|
|
2808
3416
|
`));
|
|
2809
3417
|
return 0;
|
|
2810
3418
|
}
|
|
@@ -2819,7 +3427,7 @@ ${(stderr || stdout).trim()}`);
|
|
|
2819
3427
|
`);
|
|
2820
3428
|
return { outcome: code === 0 ? "clean" : "conflict", conflicts: [...new Set(rest.slice(0, Math.max(0, rest.indexOf(""))))] };
|
|
2821
3429
|
}
|
|
2822
|
-
function verdictText(verdict, tint = paint(
|
|
3430
|
+
function verdictText(verdict, tint = paint(process26.stdout)) {
|
|
2823
3431
|
if (verdict.outcome === "up-to-date")
|
|
2824
3432
|
return tint.dim("merged already");
|
|
2825
3433
|
return verdict.outcome === "clean" ? tint.green("clean") : tint.red(`conflicts: ${verdict.conflicts.join(", ")}`);
|
|
@@ -2833,7 +3441,7 @@ async function squashedReport(before, branch, into, json) {
|
|
|
2833
3441
|
}
|
|
2834
3442
|
const list = changed.split(`
|
|
2835
3443
|
`).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`,
|
|
3444
|
+
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
3445
|
`));
|
|
2838
3446
|
return 0;
|
|
2839
3447
|
}
|
|
@@ -2847,9 +3455,9 @@ async function dryRun(branch, into, json) {
|
|
|
2847
3455
|
if (verdict.outcome === "up-to-date")
|
|
2848
3456
|
console.log(`${branch} is already merged into ${into}`);
|
|
2849
3457
|
else if (verdict.outcome === "clean")
|
|
2850
|
-
console.log(marked("ok", `merging ${branch} into ${into} would not conflict`,
|
|
3458
|
+
console.log(marked("ok", `merging ${branch} into ${into} would not conflict`, process26.stdout));
|
|
2851
3459
|
else
|
|
2852
|
-
console.log([marked("problem", `merging ${branch} into ${into} would conflict in ${verdict.conflicts.length} ${verdict.conflicts.length === 1 ? "file" : "files"}`,
|
|
3460
|
+
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
3461
|
`));
|
|
2854
3462
|
return code;
|
|
2855
3463
|
}
|
|
@@ -2883,6 +3491,19 @@ async function choose2(into) {
|
|
|
2883
3491
|
enter merge, ctrl-s merge --squash`, expect: ["ctrl-s"], searched: 1, preview: async (hidden) => preview2(hidden[0] ?? "") });
|
|
2884
3492
|
return picked === undefined || picked.hidden[0] === undefined ? undefined : { branch: picked.hidden[0], squash: picked.key === "ctrl-s" };
|
|
2885
3493
|
}
|
|
3494
|
+
async function refuseUnsafeChanges(branch) {
|
|
3495
|
+
const paths = async (args) => (await ran([...args, "--name-only", "-z"])).split("\x00").filter((path) => path !== "");
|
|
3496
|
+
const staged = await paths(["diff", "--cached"]);
|
|
3497
|
+
if (staged.length > 0)
|
|
3498
|
+
fail(`staged changes would go into the merge (${staged.join(", ")}): commit them first (gc), or unstage them (gu --staged)`, 1);
|
|
3499
|
+
const dirty = await paths(["diff"]);
|
|
3500
|
+
if (dirty.length === 0)
|
|
3501
|
+
return;
|
|
3502
|
+
const touched = new Set(await paths(["diff", "--no-renames", `HEAD...${branch}`]));
|
|
3503
|
+
const overlap = dirty.filter((path) => touched.has(path));
|
|
3504
|
+
if (overlap.length > 0)
|
|
3505
|
+
fail(`uncommitted changes in files the merge changes (${overlap.join(", ")}): commit them first (gc), or set them aside as a patch (gu)`, 1);
|
|
3506
|
+
}
|
|
2886
3507
|
async function main(argv) {
|
|
2887
3508
|
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
3509
|
const json = values.json === true;
|
|
@@ -2900,18 +3521,25 @@ async function main(argv) {
|
|
|
2900
3521
|
console.log(`merge into ${into} aborted`);
|
|
2901
3522
|
return 0;
|
|
2902
3523
|
}
|
|
2903
|
-
const
|
|
2904
|
-
|
|
3524
|
+
const conflicts = await conflicted();
|
|
3525
|
+
const left = conflicts.filter((conflict) => conflict.hunks.length > 0);
|
|
3526
|
+
const unpicked = conflicts.filter((conflict) => conflict.hunks.length === 0 && !conflict.isMarked);
|
|
3527
|
+
if (left.length > 0 || unpicked.length > 0) {
|
|
3528
|
+
const problems = [
|
|
3529
|
+
left.length > 0 ? `conflict markers remain in ${left.map((conflict) => conflict.path).join(", ")}` : undefined,
|
|
3530
|
+
unpicked.length > 0 ? `no side is picked yet in ${unpicked.map((conflict) => conflict.path).join(", ")}: keep one and git add it, or git rm it` : undefined
|
|
3531
|
+
].filter((problem) => problem !== undefined);
|
|
2905
3532
|
if (json)
|
|
2906
|
-
printJson({ outcome: "refused", into, conflicts: left });
|
|
3533
|
+
printJson({ outcome: "refused", into, conflicts: [...left, ...unpicked].map(({ path, hunks }) => ({ path, hunks })) });
|
|
2907
3534
|
else
|
|
2908
|
-
console.log([
|
|
3535
|
+
console.log([...problems.map((problem) => marked("problem", problem, process26.stdout)), ...conflictLines([...left, ...unpicked])].join(`
|
|
2909
3536
|
`).trimEnd());
|
|
2910
3537
|
return 1;
|
|
2911
3538
|
}
|
|
2912
3539
|
const before = (await ran(["rev-parse", "HEAD"])).trim();
|
|
2913
3540
|
const incoming = (await ran(["rev-parse", "MERGE_HEAD"])).trim();
|
|
2914
|
-
|
|
3541
|
+
if (conflicts.length > 0)
|
|
3542
|
+
await ran(["add", "-A", "--", ...conflicts.map((conflict) => conflict.path)]);
|
|
2915
3543
|
await ran(["commit", "--no-edit"], EDITOR_OFF);
|
|
2916
3544
|
return mergedReport(before, incoming.slice(0, 7), into, json);
|
|
2917
3545
|
}
|
|
@@ -2943,8 +3571,7 @@ ${USAGE}`);
|
|
|
2943
3571
|
return dryRun(branch, into, json);
|
|
2944
3572
|
if (await merging())
|
|
2945
3573
|
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);
|
|
3574
|
+
await refuseUnsafeChanges(branch);
|
|
2948
3575
|
if (await succeeds(["merge-base", "--is-ancestor", branch, "HEAD"])) {
|
|
2949
3576
|
if (json)
|
|
2950
3577
|
printJson({ outcome: "up-to-date", branch, into });
|
|
@@ -2961,4 +3588,4 @@ ${USAGE}`);
|
|
|
2961
3588
|
return fail(`git merge failed:
|
|
2962
3589
|
${(merged.stderr || merged.stdout).trim()}`, NOT_A_REPOSITORY.test(merged.stderr) ? 2 : 1);
|
|
2963
3590
|
}
|
|
2964
|
-
|
|
3591
|
+
process26.exitCode = await runMain({ name: "gm", run: main });
|