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