@kaynooo/cli-git 0.17.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gb.js +1642 -1139
- package/dist/gc.js +1053 -153
- package/dist/gcl.js +1086 -166
- package/dist/gd.js +1064 -164
- package/dist/gf.js +1095 -169
- package/dist/gm.js +1648 -1145
- package/dist/gp.js +1073 -167
- package/dist/gst.js +1072 -172
- package/dist/gu.js +1059 -159
- package/package.json +2 -2
package/dist/gcl.js
CHANGED
|
@@ -1,23 +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 { homedir as homedir5 } from "os";
|
|
7
|
-
import { basename, join as join8, resolve as resolve6 } from "path";
|
|
8
|
-
import process20 from "process";
|
|
9
|
-
// ../kit/src/args.ts
|
|
10
|
-
import process9 from "process";
|
|
11
|
-
import { parseArgs } from "util";
|
|
12
|
-
|
|
13
|
-
// ../kit/src/format.ts
|
|
14
|
-
import process7 from "process";
|
|
15
|
-
|
|
16
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
17
|
-
var N = new Map;
|
|
18
|
-
var Nt = /\s+\S*$/;
|
|
19
|
-
var Y = /\s/;
|
|
20
|
-
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 = "...") {
|
|
21
17
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
22
18
|
if (t.length <= e)
|
|
23
19
|
return t;
|
|
@@ -28,13 +24,22 @@ function ko(t, e, r = "...") {
|
|
|
28
24
|
c = c.trimEnd();
|
|
29
25
|
return s ? (c + n).slice(0, l) : c + n;
|
|
30
26
|
}
|
|
31
|
-
var
|
|
32
|
-
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
|
+
});
|
|
33
40
|
|
|
34
41
|
// ../kit/src/mode.ts
|
|
35
42
|
import process2 from "process";
|
|
36
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
37
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
38
43
|
function isSet(value) {
|
|
39
44
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
40
45
|
}
|
|
@@ -51,12 +56,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
51
56
|
function isInteractive(streams = process2) {
|
|
52
57
|
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
53
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
|
+
});
|
|
54
64
|
|
|
55
|
-
//
|
|
56
|
-
import process6 from "process";
|
|
57
|
-
|
|
58
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
59
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
65
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
60
66
|
function b(r) {
|
|
61
67
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
62
68
|
if (!G2.test(e))
|
|
@@ -67,11 +73,6 @@ function b(r) {
|
|
|
67
73
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
68
74
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
69
75
|
}
|
|
70
|
-
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") => {
|
|
71
|
-
let [l, n, c] = b(r);
|
|
72
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
73
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
74
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
75
76
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
76
77
|
if (e.FORCE_COLOR !== undefined)
|
|
77
78
|
return h.has(e.FORCE_COLOR);
|
|
@@ -85,7 +86,7 @@ function f(r, e = []) {
|
|
|
85
86
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
86
87
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
87
88
|
return new Proxy(c, { get(t, i) {
|
|
88
|
-
let a =
|
|
89
|
+
let a = B[i];
|
|
89
90
|
if (Array.isArray(a)) {
|
|
90
91
|
let s = g.get(i);
|
|
91
92
|
if (s === undefined)
|
|
@@ -108,13 +109,21 @@ function f(r, e = []) {
|
|
|
108
109
|
function Fe(r = {}) {
|
|
109
110
|
return f(r);
|
|
110
111
|
}
|
|
111
|
-
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
|
+
});
|
|
112
122
|
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
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
|
+
});
|
|
118
127
|
|
|
119
128
|
// ../kit/src/config.ts
|
|
120
129
|
import { existsSync } from "fs";
|
|
@@ -130,6 +139,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
130
139
|
return;
|
|
131
140
|
}
|
|
132
141
|
}
|
|
142
|
+
var init_config = __esm(() => {
|
|
143
|
+
init_args();
|
|
144
|
+
});
|
|
133
145
|
|
|
134
146
|
// ../kit/src/user-config.ts
|
|
135
147
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
@@ -161,13 +173,17 @@ function readUserConfig(bin, where = {}, legacy = []) {
|
|
|
161
173
|
return {};
|
|
162
174
|
}
|
|
163
175
|
}
|
|
176
|
+
var init_user_config = () => {};
|
|
164
177
|
|
|
165
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";
|
|
166
183
|
function toLinear(channel) {
|
|
167
184
|
const value = channel / 255;
|
|
168
185
|
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
169
186
|
}
|
|
170
|
-
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)));
|
|
171
187
|
function toOklab(hex) {
|
|
172
188
|
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
173
189
|
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
@@ -182,7 +198,6 @@ function fromOklab([lightness, a, b]) {
|
|
|
182
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];
|
|
183
199
|
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
184
200
|
}
|
|
185
|
-
var ENDS = new Map;
|
|
186
201
|
function gradientAt(theme, ratio) {
|
|
187
202
|
if (theme.gradient === undefined)
|
|
188
203
|
return;
|
|
@@ -196,33 +211,11 @@ function gradientAt(theme, ratio) {
|
|
|
196
211
|
const [from, to] = ends;
|
|
197
212
|
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
198
213
|
}
|
|
199
|
-
var DEFAULT = {
|
|
200
|
-
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" },
|
|
201
|
-
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" },
|
|
202
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
203
|
-
bins: {},
|
|
204
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
205
|
-
};
|
|
206
|
-
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" };
|
|
207
|
-
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" };
|
|
208
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
209
|
-
var PRESETS = {
|
|
210
|
-
default: {},
|
|
211
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
212
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
213
|
-
ascii: { glyphs: ASCII }
|
|
214
|
-
};
|
|
215
|
-
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"]);
|
|
216
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
217
|
-
var CONTROL = /\p{Cc}/u;
|
|
218
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
219
|
-
var SPACES = /\s+/;
|
|
220
214
|
function isColorSpec(spec) {
|
|
221
215
|
if (typeof spec === "number")
|
|
222
216
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
223
217
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
224
218
|
}
|
|
225
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
226
219
|
function cubeLevel(channel) {
|
|
227
220
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
228
221
|
}
|
|
@@ -330,7 +323,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
330
323
|
function endsWalk(home) {
|
|
331
324
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
332
325
|
}
|
|
333
|
-
var warned = new Set;
|
|
334
326
|
function warnOnce(message) {
|
|
335
327
|
if (warned.has(message))
|
|
336
328
|
return;
|
|
@@ -367,8 +359,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
367
359
|
}
|
|
368
360
|
return { theme, sources, preset };
|
|
369
361
|
}
|
|
370
|
-
var current;
|
|
371
|
-
var currentKey = "";
|
|
372
362
|
function activeTheme() {
|
|
373
363
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
374
364
|
if (current === undefined || key !== currentKey) {
|
|
@@ -377,9 +367,38 @@ function activeTheme() {
|
|
|
377
367
|
}
|
|
378
368
|
return current;
|
|
379
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
|
+
});
|
|
380
399
|
|
|
381
400
|
// ../kit/src/style.ts
|
|
382
|
-
|
|
401
|
+
import process6 from "process";
|
|
383
402
|
function takesControlCodes(stream, env = process6.env) {
|
|
384
403
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
385
404
|
}
|
|
@@ -399,17 +418,24 @@ function role(name, stream, env = process6.env) {
|
|
|
399
418
|
const colors = paint(stream, env);
|
|
400
419
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
401
420
|
}
|
|
402
|
-
var STATUS_WORDS
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
+
});
|
|
410
436
|
|
|
411
437
|
// ../kit/src/format.ts
|
|
412
|
-
|
|
438
|
+
import process7 from "process";
|
|
413
439
|
function formatSeconds(total) {
|
|
414
440
|
let rest = Math.max(0, Math.round(total));
|
|
415
441
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -441,10 +467,8 @@ function formatAge(date, now = Date.now()) {
|
|
|
441
467
|
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
442
468
|
}
|
|
443
469
|
function truncate(text, width) {
|
|
444
|
-
return
|
|
470
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
445
471
|
}
|
|
446
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
447
|
-
var ESCAPE = String.fromCharCode(27);
|
|
448
472
|
function textWidth(text) {
|
|
449
473
|
return Bun.stringWidth(text);
|
|
450
474
|
}
|
|
@@ -493,12 +517,18 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
493
517
|
function printJson(value) {
|
|
494
518
|
console.log(jsonText(value));
|
|
495
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
|
+
});
|
|
496
529
|
|
|
497
530
|
// ../kit/src/help.ts
|
|
498
531
|
import process8 from "process";
|
|
499
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
500
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
501
|
-
var FULL_STOP = /\.$/;
|
|
502
532
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
503
533
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
504
534
|
}
|
|
@@ -535,7 +565,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
535
565
|
return [];
|
|
536
566
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
537
567
|
}
|
|
538
|
-
var MAX_INLINE_CHOICES = 24;
|
|
539
568
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
540
569
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
541
570
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -550,9 +579,16 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
550
579
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
551
580
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
552
581
|
}
|
|
582
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, MAX_INLINE_CHOICES = 24;
|
|
583
|
+
var init_help = __esm(() => {
|
|
584
|
+
init_mode();
|
|
585
|
+
init_style();
|
|
586
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
587
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
588
|
+
FULL_STOP = /\.$/;
|
|
589
|
+
});
|
|
553
590
|
|
|
554
591
|
// ../kit/src/text.ts
|
|
555
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
556
592
|
function distance(a, b) {
|
|
557
593
|
const left = [...a];
|
|
558
594
|
const right = [...b];
|
|
@@ -578,8 +614,12 @@ function closest(name, names) {
|
|
|
578
614
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
579
615
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
580
616
|
}
|
|
617
|
+
var ANSI;
|
|
618
|
+
var init_text2 = __esm(() => {
|
|
619
|
+
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
620
|
+
});
|
|
621
|
+
|
|
581
622
|
// ../kit/src/input.ts
|
|
582
|
-
var WHOLE = /^\d+$/;
|
|
583
623
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
584
624
|
if (value === undefined)
|
|
585
625
|
return fallback;
|
|
@@ -588,8 +628,6 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
588
628
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
589
629
|
return number;
|
|
590
630
|
}
|
|
591
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
592
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
593
631
|
function duration(value, name, fallback, unit = "s") {
|
|
594
632
|
if (value === undefined)
|
|
595
633
|
return fallback;
|
|
@@ -599,40 +637,27 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
599
637
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
600
638
|
return ms;
|
|
601
639
|
}
|
|
640
|
+
var WHOLE, DURATION, UNIT_MS;
|
|
641
|
+
var init_input = __esm(() => {
|
|
642
|
+
init_args();
|
|
643
|
+
WHOLE = /^\d+$/;
|
|
644
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
645
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
646
|
+
});
|
|
602
647
|
|
|
603
648
|
// ../kit/src/args.ts
|
|
604
|
-
|
|
649
|
+
import process9 from "process";
|
|
650
|
+
import { parseArgs } from "util";
|
|
605
651
|
function jsonOption(holds) {
|
|
606
652
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
607
653
|
}
|
|
608
|
-
class Exit extends Error {
|
|
609
|
-
code;
|
|
610
|
-
hint;
|
|
611
|
-
constructor(message, code, hint) {
|
|
612
|
-
super(message);
|
|
613
|
-
this.code = code;
|
|
614
|
-
this.hint = hint;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
654
|
function fail(message, code = 2, hint) {
|
|
618
655
|
throw new Exit(message, code, hint);
|
|
619
656
|
}
|
|
620
|
-
|
|
621
|
-
class UsageError extends Exit {
|
|
622
|
-
constructor(message, hint) {
|
|
623
|
-
super(message, 2, hint);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
657
|
function badUsage(message) {
|
|
627
658
|
throw new UsageError(message);
|
|
628
659
|
}
|
|
629
660
|
|
|
630
|
-
class HelpShown extends Exit {
|
|
631
|
-
constructor() {
|
|
632
|
-
super("help shown", 0);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
661
|
class Completing {
|
|
637
662
|
options;
|
|
638
663
|
positionals;
|
|
@@ -643,11 +668,6 @@ class Completing {
|
|
|
643
668
|
this.candidates = candidates;
|
|
644
669
|
}
|
|
645
670
|
}
|
|
646
|
-
var completion = { active: false };
|
|
647
|
-
var OUTPUT_OPTIONS = {
|
|
648
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
649
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
650
|
-
};
|
|
651
671
|
function applyOutput(color, plain, env = process9.env) {
|
|
652
672
|
const when = plain === true ? "never" : color ?? "auto";
|
|
653
673
|
if (when === "auto")
|
|
@@ -801,7 +821,6 @@ function parseError(error) {
|
|
|
801
821
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
802
822
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
803
823
|
}
|
|
804
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
805
824
|
function nearestOption(message, options, allowNegative) {
|
|
806
825
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
807
826
|
if (typed === undefined)
|
|
@@ -817,6 +836,688 @@ function nearestOption(message, options, allowNegative) {
|
|
|
817
836
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
818
837
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
819
838
|
}
|
|
839
|
+
var DASHES, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
840
|
+
var init_args = __esm(() => {
|
|
841
|
+
init_format();
|
|
842
|
+
init_help();
|
|
843
|
+
init_text2();
|
|
844
|
+
init_help();
|
|
845
|
+
init_input();
|
|
846
|
+
DASHES = /^-+/;
|
|
847
|
+
Exit = class Exit extends Error {
|
|
848
|
+
code;
|
|
849
|
+
hint;
|
|
850
|
+
constructor(message, code, hint) {
|
|
851
|
+
super(message);
|
|
852
|
+
this.code = code;
|
|
853
|
+
this.hint = hint;
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
UsageError = class UsageError extends Exit {
|
|
857
|
+
constructor(message, hint) {
|
|
858
|
+
super(message, 2, hint);
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
HelpShown = class HelpShown extends Exit {
|
|
862
|
+
constructor() {
|
|
863
|
+
super("help shown", 0);
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
completion = { active: false };
|
|
867
|
+
OUTPUT_OPTIONS = {
|
|
868
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
869
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
870
|
+
};
|
|
871
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
// ../kit/src/folders.ts
|
|
875
|
+
import { homedir as homedir3 } from "os";
|
|
876
|
+
import { join as join4 } from "path";
|
|
877
|
+
import process13 from "process";
|
|
878
|
+
function cacheFolder({ home = homedir3(), env = process13.env } = {}) {
|
|
879
|
+
return env.XDG_CACHE_HOME ?? join4(home, ".cache");
|
|
880
|
+
}
|
|
881
|
+
var SKIPPED_FOLDERS;
|
|
882
|
+
var init_folders = __esm(() => {
|
|
883
|
+
init_user_config();
|
|
884
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
// ../kit/src/answers.ts
|
|
888
|
+
import { mkdirSync, readFileSync as readFileSync4, writeFileSync } from "fs";
|
|
889
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
890
|
+
function answersFile() {
|
|
891
|
+
return join5(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
892
|
+
}
|
|
893
|
+
function stored() {
|
|
894
|
+
try {
|
|
895
|
+
const parsed = JSON.parse(readFileSync4(answersFile(), "utf-8"));
|
|
896
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
897
|
+
return {};
|
|
898
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
899
|
+
} catch {
|
|
900
|
+
return {};
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
function earlierAnswers(key) {
|
|
904
|
+
return stored()[key] ?? [];
|
|
905
|
+
}
|
|
906
|
+
function rememberAnswer(key, answer) {
|
|
907
|
+
const all = stored();
|
|
908
|
+
const file = answersFile();
|
|
909
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
910
|
+
try {
|
|
911
|
+
mkdirSync(dirname2(file), { recursive: true });
|
|
912
|
+
writeFileSync(file, JSON.stringify(all));
|
|
913
|
+
} catch {}
|
|
914
|
+
}
|
|
915
|
+
var KEPT = 50;
|
|
916
|
+
var init_answers = __esm(() => {
|
|
917
|
+
init_folders();
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
// ../kit/src/job.ts
|
|
921
|
+
import process14 from "process";
|
|
922
|
+
function stopJob() {
|
|
923
|
+
process14.kill(0, "SIGTSTP");
|
|
924
|
+
}
|
|
925
|
+
var init_job = () => {};
|
|
926
|
+
|
|
927
|
+
// ../kit/src/picker/line.ts
|
|
928
|
+
function isEditKey(key) {
|
|
929
|
+
return EDIT_KEYS.has(key);
|
|
930
|
+
}
|
|
931
|
+
function endsKills(key) {
|
|
932
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
933
|
+
}
|
|
934
|
+
function isWord(char) {
|
|
935
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
936
|
+
}
|
|
937
|
+
function wordStart(chars, from) {
|
|
938
|
+
let at = from;
|
|
939
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
940
|
+
at--;
|
|
941
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
942
|
+
at--;
|
|
943
|
+
return at;
|
|
944
|
+
}
|
|
945
|
+
function wordEnd(chars, from) {
|
|
946
|
+
let at = from;
|
|
947
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
948
|
+
at++;
|
|
949
|
+
while (at < chars.length && isWord(chars[at]))
|
|
950
|
+
at++;
|
|
951
|
+
return at;
|
|
952
|
+
}
|
|
953
|
+
function spacedStart(chars, from) {
|
|
954
|
+
let at = from;
|
|
955
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
956
|
+
at--;
|
|
957
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
958
|
+
at--;
|
|
959
|
+
return at;
|
|
960
|
+
}
|
|
961
|
+
function cut(chars, from, to) {
|
|
962
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
963
|
+
}
|
|
964
|
+
function insert(chars, at, text) {
|
|
965
|
+
const typed = [...text];
|
|
966
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
967
|
+
}
|
|
968
|
+
function editLine(line, key) {
|
|
969
|
+
const { killed = "", chained = false } = line;
|
|
970
|
+
const chars = [...line.text];
|
|
971
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
972
|
+
const edited = edit(chars, at, key, killed);
|
|
973
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
974
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
975
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
976
|
+
if (taken === "")
|
|
977
|
+
return { ...edited, killed, chained };
|
|
978
|
+
if (!chained)
|
|
979
|
+
return { ...edited, killed: taken, chained: true };
|
|
980
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
981
|
+
}
|
|
982
|
+
function edit(chars, at, key, killed) {
|
|
983
|
+
const text = chars.join("");
|
|
984
|
+
if (typeof key === "object")
|
|
985
|
+
return insert(chars, at, key.text);
|
|
986
|
+
switch (key) {
|
|
987
|
+
case "left":
|
|
988
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
989
|
+
case "right":
|
|
990
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
991
|
+
case "wordleft":
|
|
992
|
+
return { text, caret: wordStart(chars, at) };
|
|
993
|
+
case "wordright":
|
|
994
|
+
return { text, caret: wordEnd(chars, at) };
|
|
995
|
+
case "linestart":
|
|
996
|
+
return { text, caret: 0 };
|
|
997
|
+
case "lineend":
|
|
998
|
+
return { text, caret: chars.length };
|
|
999
|
+
case "erase":
|
|
1000
|
+
return cut(chars, Math.max(at - 1, 0), at);
|
|
1001
|
+
case "delete":
|
|
1002
|
+
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
1003
|
+
case "word":
|
|
1004
|
+
return cut(chars, spacedStart(chars, at), at);
|
|
1005
|
+
case "killword":
|
|
1006
|
+
return cut(chars, wordStart(chars, at), at);
|
|
1007
|
+
case "killnext":
|
|
1008
|
+
return cut(chars, at, wordEnd(chars, at));
|
|
1009
|
+
case "clear":
|
|
1010
|
+
return cut(chars, 0, at);
|
|
1011
|
+
case "killend":
|
|
1012
|
+
return cut(chars, at, chars.length);
|
|
1013
|
+
case "yank":
|
|
1014
|
+
return insert(chars, at, killed);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
function visible({ text, caret }, room) {
|
|
1018
|
+
const chars = [...text];
|
|
1019
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
1020
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
1021
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
1022
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
1023
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
1024
|
+
let start = at;
|
|
1025
|
+
let end = at + 1;
|
|
1026
|
+
while (start > 0 && fits(start - 1, end))
|
|
1027
|
+
start--;
|
|
1028
|
+
while (end < cells.length && fits(start, end + 1))
|
|
1029
|
+
end++;
|
|
1030
|
+
const left = start > 0 ? "\u2026" : "";
|
|
1031
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
1032
|
+
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
1033
|
+
}
|
|
1034
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
|
|
1035
|
+
var init_line = __esm(() => {
|
|
1036
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1037
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1038
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1039
|
+
WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
1040
|
+
SPACE = /\s/;
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
// ../kit/src/picker/score.ts
|
|
1044
|
+
function startsWord(text, index) {
|
|
1045
|
+
if (index === 0)
|
|
1046
|
+
return true;
|
|
1047
|
+
const before = text[index - 1];
|
|
1048
|
+
return BOUNDARY_AFTER.has(before) || LOWER.test(before) && UPPER.test(text[index]);
|
|
1049
|
+
}
|
|
1050
|
+
function fuzzy(query, text) {
|
|
1051
|
+
if (query === "")
|
|
1052
|
+
return { score: 0, positions: [] };
|
|
1053
|
+
const exact = query !== query.toLowerCase();
|
|
1054
|
+
const needle = exact ? query : query.toLowerCase();
|
|
1055
|
+
const haystack = exact ? text : text.toLowerCase();
|
|
1056
|
+
if (haystack.length !== text.length || needle.length > haystack.length)
|
|
1057
|
+
return;
|
|
1058
|
+
const width = haystack.length;
|
|
1059
|
+
const best = Array.from({ length: needle.length }, () => new Array(width).fill(NONE));
|
|
1060
|
+
const from = Array.from({ length: needle.length }, () => new Array(width).fill(-1));
|
|
1061
|
+
for (let j = 0;j < needle.length; j++) {
|
|
1062
|
+
let run = NONE;
|
|
1063
|
+
let runAt = -1;
|
|
1064
|
+
for (let i = j;i < width; i++) {
|
|
1065
|
+
if (j > 0 && i - 2 >= j - 1) {
|
|
1066
|
+
const candidate = best[j - 1][i - 2] + (i - 2) * GAP;
|
|
1067
|
+
if (candidate > run) {
|
|
1068
|
+
run = candidate;
|
|
1069
|
+
runAt = i - 2;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
if (haystack[i] !== needle[j])
|
|
1073
|
+
continue;
|
|
1074
|
+
const here = MATCH + (startsWord(text, i) ? BOUNDARY : 0) + (i === 0 ? PREFIX : 0);
|
|
1075
|
+
if (j === 0) {
|
|
1076
|
+
best[0][i] = here - i * GAP;
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
const joined = best[j - 1][i - 1] + CONSECUTIVE;
|
|
1080
|
+
const skipped = run - (i - 1) * GAP;
|
|
1081
|
+
if (joined > NONE && joined >= skipped) {
|
|
1082
|
+
best[j][i] = joined + here;
|
|
1083
|
+
from[j][i] = i - 1;
|
|
1084
|
+
} else if (skipped > NONE) {
|
|
1085
|
+
best[j][i] = skipped + here;
|
|
1086
|
+
from[j][i] = runAt;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
const last = best[needle.length - 1];
|
|
1091
|
+
let end = -1;
|
|
1092
|
+
for (let i = 0;i < width; i++) {
|
|
1093
|
+
if (last[i] > NONE && (end === -1 || last[i] > last[end]))
|
|
1094
|
+
end = i;
|
|
1095
|
+
}
|
|
1096
|
+
if (end === -1)
|
|
1097
|
+
return;
|
|
1098
|
+
const positions = [];
|
|
1099
|
+
for (let j = needle.length - 1, i = end;j >= 0; j--) {
|
|
1100
|
+
positions.unshift(i);
|
|
1101
|
+
i = from[j][i];
|
|
1102
|
+
}
|
|
1103
|
+
return { score: last[end], positions };
|
|
1104
|
+
}
|
|
1105
|
+
function rank(query, lines) {
|
|
1106
|
+
if (query === "")
|
|
1107
|
+
return lines.map((_, index) => ({ index, positions: [] }));
|
|
1108
|
+
const found = [];
|
|
1109
|
+
for (const [index, line] of lines.entries()) {
|
|
1110
|
+
const match = fuzzy(query, line);
|
|
1111
|
+
if (match !== undefined)
|
|
1112
|
+
found.push({ index, positions: match.positions, score: match.score });
|
|
1113
|
+
}
|
|
1114
|
+
return found.sort((a, b) => b.score - a.score || lines[a.index].length - lines[b.index].length || a.index - b.index);
|
|
1115
|
+
}
|
|
1116
|
+
var MATCH = 16, CONSECUTIVE = 12, BOUNDARY = 10, PREFIX = 8, GAP = 1, BOUNDARY_AFTER, UPPER, LOWER, NONE;
|
|
1117
|
+
var init_score = __esm(() => {
|
|
1118
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1119
|
+
UPPER = /\p{Lu}/u;
|
|
1120
|
+
LOWER = /\p{Ll}/u;
|
|
1121
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
// ../kit/src/picker/state.ts
|
|
1125
|
+
function repeat(value, count) {
|
|
1126
|
+
return Array.from({ length: count }).fill(value);
|
|
1127
|
+
}
|
|
1128
|
+
function styled(line) {
|
|
1129
|
+
let text = "";
|
|
1130
|
+
const styles = [];
|
|
1131
|
+
let active = "";
|
|
1132
|
+
let colored = false;
|
|
1133
|
+
let last = 0;
|
|
1134
|
+
function add(chunk) {
|
|
1135
|
+
const flat = chunk.replace(CONTROL2, " ");
|
|
1136
|
+
text += flat;
|
|
1137
|
+
colored ||= active !== "" && flat !== "";
|
|
1138
|
+
styles.push(...repeat(active, flat.length));
|
|
1139
|
+
}
|
|
1140
|
+
for (const found of line.matchAll(ANSI)) {
|
|
1141
|
+
add(line.slice(last, found.index));
|
|
1142
|
+
last = found.index + found[0].length;
|
|
1143
|
+
if (SGR.test(found[0]))
|
|
1144
|
+
active = RESET.test(found[0]) ? "" : active + found[0];
|
|
1145
|
+
}
|
|
1146
|
+
add(line.slice(last));
|
|
1147
|
+
return { text, styles: colored ? styles : undefined };
|
|
1148
|
+
}
|
|
1149
|
+
function lay(rows, searched) {
|
|
1150
|
+
const parsed = rows.map((row) => row.cells.map(styled));
|
|
1151
|
+
const widths = (parsed[0] ?? []).map((_, column) => Math.max(...parsed.map((cells) => Bun.stringWidth(cells[column]?.text ?? ""))));
|
|
1152
|
+
return parsed.map((cells, at) => {
|
|
1153
|
+
let text = "";
|
|
1154
|
+
const styles = [];
|
|
1155
|
+
let colored = false;
|
|
1156
|
+
let searchEnd = 0;
|
|
1157
|
+
for (const [column, cell] of cells.entries()) {
|
|
1158
|
+
const last = column === cells.length - 1;
|
|
1159
|
+
const shown = cells.length > 1 && last ? cell.text.trimEnd() : cell.text;
|
|
1160
|
+
text += shown;
|
|
1161
|
+
colored ||= cell.styles !== undefined;
|
|
1162
|
+
styles.push(...cell.styles?.slice(0, shown.length) ?? repeat("", shown.length));
|
|
1163
|
+
if (column < searched)
|
|
1164
|
+
searchEnd = cells.length > 1 ? text.trimEnd().length : text.length;
|
|
1165
|
+
if (!last) {
|
|
1166
|
+
const pad = widths[column] - Bun.stringWidth(cell.text) + COLUMN_GAP;
|
|
1167
|
+
text += " ".repeat(pad);
|
|
1168
|
+
styles.push(...repeat("", pad));
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
return { text, styles: colored ? styles : undefined, searchable: rows[at].search ?? text.slice(0, searchEnd) };
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1175
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1176
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1177
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1178
|
+
if (wheel !== undefined)
|
|
1179
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1180
|
+
const named = codes.get(sequence);
|
|
1181
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1182
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1183
|
+
paste.active = sequence === PASTE_START;
|
|
1184
|
+
return [];
|
|
1185
|
+
}
|
|
1186
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
1187
|
+
`))
|
|
1188
|
+
return [];
|
|
1189
|
+
if (key !== undefined)
|
|
1190
|
+
return [key];
|
|
1191
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
|
|
1195
|
+
const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, caret: [...query].length, killed: "", chained: false, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
|
|
1196
|
+
return withRows(state, rows);
|
|
1197
|
+
}
|
|
1198
|
+
function withRows(state, rows, header = state.header) {
|
|
1199
|
+
const cells = rows.map((row) => typeof row === "string" ? { hidden: [], cells: [row] } : row);
|
|
1200
|
+
const laid = lay(cells, state.searched);
|
|
1201
|
+
const searchable = laid.map((row) => row.searchable);
|
|
1202
|
+
const matches = rank(state.query, searchable);
|
|
1203
|
+
return { ...state, rows: cells, items: laid.map((row) => row.text), styles: laid.map((row) => row.styles), searchable, header, matches, cursor: Math.max(0, Math.min(matches.length - 1, state.cursor)), marked: new Set };
|
|
1204
|
+
}
|
|
1205
|
+
function withQuery(state, key) {
|
|
1206
|
+
const { text, caret, killed = "", chained = false } = editLine({ text: state.query, caret: state.caret, killed: state.killed, chained: state.chained }, key);
|
|
1207
|
+
return text === state.query ? { ...state, caret, killed, chained } : { ...state, query: text, caret, killed, chained, matches: rank(text, state.searchable), cursor: 0 };
|
|
1208
|
+
}
|
|
1209
|
+
function move(state, by) {
|
|
1210
|
+
return { ...state, cursor: Math.max(0, Math.min(state.matches.length - 1, state.cursor + by)) };
|
|
1211
|
+
}
|
|
1212
|
+
function highlighted(state) {
|
|
1213
|
+
return state.matches[state.cursor]?.index;
|
|
1214
|
+
}
|
|
1215
|
+
function press(state, key) {
|
|
1216
|
+
if (state.done !== undefined)
|
|
1217
|
+
return state;
|
|
1218
|
+
if (state.chained && endsKills(key))
|
|
1219
|
+
state = { ...state, chained: false };
|
|
1220
|
+
if (state.help)
|
|
1221
|
+
return { ...state, help: false };
|
|
1222
|
+
if (typeof key === "object") {
|
|
1223
|
+
if ("text" in key)
|
|
1224
|
+
return withQuery(state, key);
|
|
1225
|
+
return state.expect.includes(key.ctrl) ? { ...state, done: "accept", key: key.ctrl } : state;
|
|
1226
|
+
}
|
|
1227
|
+
if (isEditKey(key))
|
|
1228
|
+
return withQuery(state, key);
|
|
1229
|
+
switch (key) {
|
|
1230
|
+
case "up":
|
|
1231
|
+
return move(state, -1);
|
|
1232
|
+
case "down":
|
|
1233
|
+
return move(state, 1);
|
|
1234
|
+
case "pageup":
|
|
1235
|
+
return move(state, -state.page);
|
|
1236
|
+
case "pagedown":
|
|
1237
|
+
return move(state, state.page);
|
|
1238
|
+
case "home":
|
|
1239
|
+
return move(state, -state.matches.length);
|
|
1240
|
+
case "end":
|
|
1241
|
+
return move(state, state.matches.length);
|
|
1242
|
+
case "cancel":
|
|
1243
|
+
return { ...state, done: "cancel" };
|
|
1244
|
+
case "help":
|
|
1245
|
+
return { ...state, help: true };
|
|
1246
|
+
case "suspend":
|
|
1247
|
+
return state;
|
|
1248
|
+
case "enter":
|
|
1249
|
+
return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
|
|
1250
|
+
case "tab": {
|
|
1251
|
+
const at = highlighted(state);
|
|
1252
|
+
if (!state.multi || at === undefined)
|
|
1253
|
+
return state;
|
|
1254
|
+
const marked = new Set(state.marked);
|
|
1255
|
+
if (!marked.delete(at))
|
|
1256
|
+
marked.add(at);
|
|
1257
|
+
return move({ ...state, marked }, 1);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
function chosen(state) {
|
|
1262
|
+
if (state.marked.size > 0)
|
|
1263
|
+
return state.rows.filter((_, index) => state.marked.has(index));
|
|
1264
|
+
const at = highlighted(state);
|
|
1265
|
+
return at === undefined ? [] : [state.rows[at]];
|
|
1266
|
+
}
|
|
1267
|
+
var CONTROL2, IS_CONTROL, SGR, RESET, COLUMN_GAP = 2, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS, CTRL_KEY;
|
|
1268
|
+
var init_state = __esm(() => {
|
|
1269
|
+
init_text2();
|
|
1270
|
+
init_line();
|
|
1271
|
+
init_score();
|
|
1272
|
+
CONTROL2 = /[\x00-\x1F\x7F-\x9F]/g;
|
|
1273
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1274
|
+
SGR = /^\x1B\[[0-9;]*m$/;
|
|
1275
|
+
RESET = /^\x1B\[0?m$/;
|
|
1276
|
+
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1277
|
+
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1278
|
+
KEYS = {
|
|
1279
|
+
"\x1B[A": "up",
|
|
1280
|
+
"\x1BOA": "up",
|
|
1281
|
+
"\x10": "up",
|
|
1282
|
+
"\x1B[B": "down",
|
|
1283
|
+
"\x1BOB": "down",
|
|
1284
|
+
"\x0E": "down",
|
|
1285
|
+
"\x1B[5~": "pageup",
|
|
1286
|
+
"\x1B[6~": "pagedown",
|
|
1287
|
+
"\x1B[H": "home",
|
|
1288
|
+
"\x1B[1~": "home",
|
|
1289
|
+
"\x1BOH": "home",
|
|
1290
|
+
"\x1B[F": "end",
|
|
1291
|
+
"\x1B[4~": "end",
|
|
1292
|
+
"\x1BOF": "end",
|
|
1293
|
+
"\r": "enter",
|
|
1294
|
+
"\n": "enter",
|
|
1295
|
+
"\x03": "cancel",
|
|
1296
|
+
"\x1B": "cancel",
|
|
1297
|
+
"\x1B[D": "left",
|
|
1298
|
+
"\x1BOD": "left",
|
|
1299
|
+
"\x1B[C": "right",
|
|
1300
|
+
"\x1BOC": "right",
|
|
1301
|
+
"\x1B[1;5D": "wordleft",
|
|
1302
|
+
"\x1B[1;3D": "wordleft",
|
|
1303
|
+
"\x1Bb": "wordleft",
|
|
1304
|
+
"\x1B[1;5C": "wordright",
|
|
1305
|
+
"\x1B[1;3C": "wordright",
|
|
1306
|
+
"\x1Bf": "wordright",
|
|
1307
|
+
"\x01": "linestart",
|
|
1308
|
+
"\x05": "lineend",
|
|
1309
|
+
"\x7F": "erase",
|
|
1310
|
+
"\x1B[3~": "delete",
|
|
1311
|
+
"\b": "killword",
|
|
1312
|
+
"\x1B\x7F": "killword",
|
|
1313
|
+
"\x1B[3;5~": "killnext",
|
|
1314
|
+
"\x1Bd": "killnext",
|
|
1315
|
+
"\x15": "clear",
|
|
1316
|
+
"\v": "killend",
|
|
1317
|
+
"\x17": "word",
|
|
1318
|
+
"\x19": "yank",
|
|
1319
|
+
"\x1A": "suspend",
|
|
1320
|
+
"\t": "tab",
|
|
1321
|
+
"\x1F": "help",
|
|
1322
|
+
"\x1BOP": "help",
|
|
1323
|
+
"\x1B[11~": "help"
|
|
1324
|
+
};
|
|
1325
|
+
CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
|
|
1326
|
+
});
|
|
1327
|
+
|
|
1328
|
+
// ../kit/src/redraw.ts
|
|
1329
|
+
function overwrite(lines, columns) {
|
|
1330
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1331
|
+
`);
|
|
1332
|
+
}
|
|
1333
|
+
function rowsTaken(lines, columns) {
|
|
1334
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1335
|
+
}
|
|
1336
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
1337
|
+
var init_redraw = __esm(() => {
|
|
1338
|
+
init_format();
|
|
1339
|
+
});
|
|
1340
|
+
|
|
1341
|
+
// ../kit/src/prompt.ts
|
|
1342
|
+
import process15 from "process";
|
|
1343
|
+
function readKeys(input, paste = { active: false }) {
|
|
1344
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1345
|
+
}
|
|
1346
|
+
function roomAfter(question, columns) {
|
|
1347
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
1348
|
+
}
|
|
1349
|
+
function withCaret(colors, line, room, dim = false) {
|
|
1350
|
+
const { before, at, after } = visible(line, room);
|
|
1351
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
1352
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
1353
|
+
}
|
|
1354
|
+
function sharedStart(texts) {
|
|
1355
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
1356
|
+
let length = first.length;
|
|
1357
|
+
for (const chars of rest) {
|
|
1358
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
1359
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
1360
|
+
}
|
|
1361
|
+
return first.slice(0, length).join("");
|
|
1362
|
+
}
|
|
1363
|
+
function listed2(colors, found, columns) {
|
|
1364
|
+
const shared = sharedStart(found);
|
|
1365
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
1366
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
1367
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
1368
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
1369
|
+
}
|
|
1370
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
1371
|
+
let line = { text: "", caret: 0 };
|
|
1372
|
+
let invalid;
|
|
1373
|
+
let completions = [];
|
|
1374
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
1375
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
1376
|
+
let recalled = -1;
|
|
1377
|
+
let draft = line;
|
|
1378
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
1379
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
1380
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
1381
|
+
if (state !== "asking")
|
|
1382
|
+
return [answer(colors, question, state, shown())];
|
|
1383
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
1384
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
1385
|
+
}, (key) => {
|
|
1386
|
+
if (key === "cancel")
|
|
1387
|
+
return "cancel";
|
|
1388
|
+
invalid = undefined;
|
|
1389
|
+
completions = [];
|
|
1390
|
+
if (line.chained === true && endsKills(key))
|
|
1391
|
+
line = { ...line, chained: false };
|
|
1392
|
+
if (key === "tab") {
|
|
1393
|
+
const chars = [...line.text];
|
|
1394
|
+
const before = chars.slice(0, line.caret).join("");
|
|
1395
|
+
const found = complete?.(before) ?? [];
|
|
1396
|
+
const filled = sharedStart(found);
|
|
1397
|
+
if ([...filled].length > [...before].length)
|
|
1398
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
1399
|
+
else
|
|
1400
|
+
completions = found;
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
if (key === "enter") {
|
|
1404
|
+
invalid = validate?.(taken());
|
|
1405
|
+
return invalid === undefined ? "enter" : undefined;
|
|
1406
|
+
}
|
|
1407
|
+
if (key === "up" || key === "down") {
|
|
1408
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
1409
|
+
if (recalled === -1)
|
|
1410
|
+
draft = line;
|
|
1411
|
+
recalled = to;
|
|
1412
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
1413
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
1416
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
1417
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
1418
|
+
line = editLine(line, edit);
|
|
1419
|
+
return;
|
|
1420
|
+
});
|
|
1421
|
+
if (!accepted)
|
|
1422
|
+
return;
|
|
1423
|
+
if (remembered !== undefined && taken() !== "")
|
|
1424
|
+
rememberAnswer(remembered, taken());
|
|
1425
|
+
return taken();
|
|
1426
|
+
}
|
|
1427
|
+
function answer(colors, question, state, picked) {
|
|
1428
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1429
|
+
}
|
|
1430
|
+
async function ask(question, { hint, terminal = process15 }, render, press) {
|
|
1431
|
+
const { stdin, stderr } = terminal;
|
|
1432
|
+
if (!isInteractive(terminal))
|
|
1433
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1434
|
+
const colors = paint(stderr);
|
|
1435
|
+
let current = "asking";
|
|
1436
|
+
let outcome;
|
|
1437
|
+
const columns = () => stderr.columns || 80;
|
|
1438
|
+
const draw = (state, last = false) => {
|
|
1439
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1440
|
+
const rows = rowsTaken(frame, columns());
|
|
1441
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1442
|
+
current = state;
|
|
1443
|
+
};
|
|
1444
|
+
const redraw = () => draw(current);
|
|
1445
|
+
const paste = { active: false };
|
|
1446
|
+
const stop = terminal.stop ?? (terminal === process15 ? stopJob : undefined);
|
|
1447
|
+
const suspend = () => {
|
|
1448
|
+
if (stop === undefined)
|
|
1449
|
+
return;
|
|
1450
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1451
|
+
stdin.setRawMode(false);
|
|
1452
|
+
stop();
|
|
1453
|
+
stdin.setRawMode(true);
|
|
1454
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1455
|
+
};
|
|
1456
|
+
try {
|
|
1457
|
+
stderr.on?.("resize", redraw);
|
|
1458
|
+
stdin.setRawMode(true);
|
|
1459
|
+
stdin.resume();
|
|
1460
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1461
|
+
draw("asking");
|
|
1462
|
+
return await new Promise((resolve) => {
|
|
1463
|
+
function onData(data) {
|
|
1464
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
1465
|
+
if (key === "suspend") {
|
|
1466
|
+
suspend();
|
|
1467
|
+
continue;
|
|
1468
|
+
}
|
|
1469
|
+
const pressed = press(key);
|
|
1470
|
+
if (pressed !== undefined) {
|
|
1471
|
+
settle(pressed);
|
|
1472
|
+
return;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
draw("asking");
|
|
1476
|
+
}
|
|
1477
|
+
function onEnd() {
|
|
1478
|
+
settle("cancel");
|
|
1479
|
+
}
|
|
1480
|
+
function settle(settled) {
|
|
1481
|
+
outcome = settled;
|
|
1482
|
+
stdin.off("data", onData);
|
|
1483
|
+
stdin.off("end", onEnd);
|
|
1484
|
+
resolve(settled === "enter");
|
|
1485
|
+
}
|
|
1486
|
+
stdin.on("data", onData);
|
|
1487
|
+
stdin.on("end", onEnd);
|
|
1488
|
+
});
|
|
1489
|
+
} finally {
|
|
1490
|
+
stderr.off?.("resize", redraw);
|
|
1491
|
+
draw(outcome ?? "cancel", true);
|
|
1492
|
+
stderr.write(`
|
|
1493
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1494
|
+
stdin.setRawMode(false);
|
|
1495
|
+
stdin.pause();
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
var PROMPT_KEYS, MAX_LISTED = 12;
|
|
1499
|
+
var init_prompt = __esm(() => {
|
|
1500
|
+
init_answers();
|
|
1501
|
+
init_args();
|
|
1502
|
+
init_format();
|
|
1503
|
+
init_job();
|
|
1504
|
+
init_mode();
|
|
1505
|
+
init_line();
|
|
1506
|
+
init_state();
|
|
1507
|
+
init_redraw();
|
|
1508
|
+
init_style();
|
|
1509
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1510
|
+
});
|
|
1511
|
+
|
|
1512
|
+
// src/gcl.ts
|
|
1513
|
+
import { existsSync as existsSync4, readdirSync, realpathSync as realpathSync3, statSync as statSync2 } from "fs";
|
|
1514
|
+
import { homedir as homedir6 } from "os";
|
|
1515
|
+
import { basename, join as join11, resolve as resolve6 } from "path";
|
|
1516
|
+
import process24 from "process";
|
|
1517
|
+
|
|
1518
|
+
// ../kit/src/index.ts
|
|
1519
|
+
init_args();
|
|
1520
|
+
|
|
820
1521
|
// ../kit/src/argv.ts
|
|
821
1522
|
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
822
1523
|
import { resolve as resolve3 } from "path";
|
|
@@ -841,7 +1542,17 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
841
1542
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
842
1543
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
843
1544
|
}
|
|
1545
|
+
// ../kit/src/chart.ts
|
|
1546
|
+
init_format();
|
|
1547
|
+
init_mode();
|
|
1548
|
+
init_style();
|
|
1549
|
+
init_theme();
|
|
1550
|
+
// ../kit/src/ci.ts
|
|
1551
|
+
init_args();
|
|
1552
|
+
init_format();
|
|
1553
|
+
|
|
844
1554
|
// ../kit/src/progress.ts
|
|
1555
|
+
init_format();
|
|
845
1556
|
import process12 from "process";
|
|
846
1557
|
|
|
847
1558
|
// ../kit/src/process.ts
|
|
@@ -967,6 +1678,8 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
967
1678
|
}
|
|
968
1679
|
|
|
969
1680
|
// ../kit/src/progress.ts
|
|
1681
|
+
init_style();
|
|
1682
|
+
init_theme();
|
|
970
1683
|
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
971
1684
|
var FRAME_MS = 200;
|
|
972
1685
|
var BAR_WIDTH = 20;
|
|
@@ -984,10 +1697,14 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
984
1697
|
}, print: (text) => void stream.write(`${text}
|
|
985
1698
|
`), stop: () => {
|
|
986
1699
|
return;
|
|
1700
|
+
}, pause: () => () => {
|
|
1701
|
+
return;
|
|
987
1702
|
} };
|
|
988
1703
|
const write = stream.write.bind(stream);
|
|
989
1704
|
let frame = 0;
|
|
990
1705
|
let drawn = false;
|
|
1706
|
+
let paused = false;
|
|
1707
|
+
let stopped = false;
|
|
991
1708
|
const columns = () => {
|
|
992
1709
|
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
993
1710
|
return now === undefined || now === 0 ? 80 : now;
|
|
@@ -998,6 +1715,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
998
1715
|
drawn = false;
|
|
999
1716
|
};
|
|
1000
1717
|
const draw = () => {
|
|
1718
|
+
if (paused)
|
|
1719
|
+
return;
|
|
1001
1720
|
const width = columns() - 1;
|
|
1002
1721
|
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
1003
1722
|
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
@@ -1009,16 +1728,17 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1009
1728
|
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
1010
1729
|
drawn = true;
|
|
1011
1730
|
};
|
|
1012
|
-
|
|
1731
|
+
let timer = setInterval(draw, FRAME_MS);
|
|
1013
1732
|
stream.on?.("resize", draw);
|
|
1014
|
-
|
|
1015
|
-
|
|
1733
|
+
let restore = interceptOutput(clear);
|
|
1734
|
+
let release = swallowInput();
|
|
1016
1735
|
const onExit = () => {
|
|
1017
1736
|
clear();
|
|
1018
1737
|
release();
|
|
1019
1738
|
};
|
|
1020
1739
|
const signals = holdSignals(stop);
|
|
1021
1740
|
function stop() {
|
|
1741
|
+
stopped = true;
|
|
1022
1742
|
clearInterval(timer);
|
|
1023
1743
|
stream.off?.("resize", draw);
|
|
1024
1744
|
clear();
|
|
@@ -1027,6 +1747,29 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1027
1747
|
process12.off("exit", onExit);
|
|
1028
1748
|
signals.release();
|
|
1029
1749
|
}
|
|
1750
|
+
function pause() {
|
|
1751
|
+
if (paused || stopped)
|
|
1752
|
+
return () => {
|
|
1753
|
+
return;
|
|
1754
|
+
};
|
|
1755
|
+
paused = true;
|
|
1756
|
+
clearInterval(timer);
|
|
1757
|
+
stream.off?.("resize", draw);
|
|
1758
|
+
clear();
|
|
1759
|
+
restore();
|
|
1760
|
+
release();
|
|
1761
|
+
return () => {
|
|
1762
|
+
if (!paused || stopped)
|
|
1763
|
+
return;
|
|
1764
|
+
paused = false;
|
|
1765
|
+
timer = setInterval(draw, FRAME_MS);
|
|
1766
|
+
timer.unref();
|
|
1767
|
+
stream.on?.("resize", draw);
|
|
1768
|
+
restore = interceptOutput(clear);
|
|
1769
|
+
release = swallowInput();
|
|
1770
|
+
draw();
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1030
1773
|
timer.unref();
|
|
1031
1774
|
process12.on("exit", onExit);
|
|
1032
1775
|
return {
|
|
@@ -1037,7 +1780,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1037
1780
|
`);
|
|
1038
1781
|
draw();
|
|
1039
1782
|
},
|
|
1040
|
-
stop
|
|
1783
|
+
stop,
|
|
1784
|
+
pause
|
|
1041
1785
|
};
|
|
1042
1786
|
}
|
|
1043
1787
|
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
@@ -1062,6 +1806,7 @@ function progressLine(stream = process12.stderr, env = process12.env) {
|
|
|
1062
1806
|
}
|
|
1063
1807
|
},
|
|
1064
1808
|
stop: region.stop,
|
|
1809
|
+
pause: region.pause,
|
|
1065
1810
|
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1066
1811
|
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1067
1812
|
};
|
|
@@ -1150,10 +1895,125 @@ function interceptOutput(clear) {
|
|
|
1150
1895
|
}
|
|
1151
1896
|
};
|
|
1152
1897
|
}
|
|
1898
|
+
|
|
1899
|
+
// ../kit/src/ci.ts
|
|
1900
|
+
init_style();
|
|
1901
|
+
|
|
1902
|
+
// ../kit/src/tool.ts
|
|
1903
|
+
init_format();
|
|
1153
1904
|
// ../kit/src/cli.ts
|
|
1154
|
-
|
|
1155
|
-
import {
|
|
1156
|
-
import
|
|
1905
|
+
init_args();
|
|
1906
|
+
import { readFileSync as readFileSync5, realpathSync as realpathSync2 } from "fs";
|
|
1907
|
+
import { dirname as dirname4, join as join8 } from "path";
|
|
1908
|
+
import process19 from "process";
|
|
1909
|
+
|
|
1910
|
+
// ../kit/src/askpass.ts
|
|
1911
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
1912
|
+
import { tmpdir } from "os";
|
|
1913
|
+
import { join as join6 } from "path";
|
|
1914
|
+
import process16 from "process";
|
|
1915
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1916
|
+
var ECHOED = /username|yes\/no/i;
|
|
1917
|
+
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1918
|
+
function askpass(pause) {
|
|
1919
|
+
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1920
|
+
return;
|
|
1921
|
+
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1922
|
+
const socketPath = join6(dir, "socket");
|
|
1923
|
+
const script = join6(dir, "askpass");
|
|
1924
|
+
let turn = Promise.resolve();
|
|
1925
|
+
const answer = async ({ prompt, notice }) => {
|
|
1926
|
+
const resume = pause();
|
|
1927
|
+
try {
|
|
1928
|
+
if (notice === true) {
|
|
1929
|
+
process16.stderr.write(`${prompt.trim()}
|
|
1930
|
+
`);
|
|
1931
|
+
return {};
|
|
1932
|
+
}
|
|
1933
|
+
await Promise.resolve().then(() => init_prompt());
|
|
1934
|
+
return { answer: await input2(prompt.trim(), { mask: !ECHOED.test(prompt) }) };
|
|
1935
|
+
} finally {
|
|
1936
|
+
resume();
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
const respond = async (socket, request) => {
|
|
1940
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1941
|
+
const previous = turn;
|
|
1942
|
+
let reply = {};
|
|
1943
|
+
turn = promise;
|
|
1944
|
+
await previous;
|
|
1945
|
+
try {
|
|
1946
|
+
reply = await answer(request);
|
|
1947
|
+
} catch {} finally {
|
|
1948
|
+
socket.end(`${JSON.stringify(reply)}
|
|
1949
|
+
`);
|
|
1950
|
+
resolve();
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
const server = Bun.listen({
|
|
1954
|
+
unix: socketPath,
|
|
1955
|
+
socket: {
|
|
1956
|
+
open: (socket) => {
|
|
1957
|
+
socket.data = { buffered: "" };
|
|
1958
|
+
},
|
|
1959
|
+
data: (socket, chunk) => {
|
|
1960
|
+
const before = socket.data.buffered;
|
|
1961
|
+
socket.data.buffered += chunk.toString();
|
|
1962
|
+
if (before.includes(`
|
|
1963
|
+
`) || !socket.data.buffered.includes(`
|
|
1964
|
+
`))
|
|
1965
|
+
return;
|
|
1966
|
+
respond(socket, JSON.parse(socket.data.buffered));
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
});
|
|
1970
|
+
writeFileSync2(script, `#!/bin/sh
|
|
1971
|
+
${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no-env-file --config=/dev/null ${quoted(process16.argv[1])} "$@"
|
|
1972
|
+
`);
|
|
1973
|
+
chmodSync(script, 448);
|
|
1974
|
+
return {
|
|
1975
|
+
env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
|
|
1976
|
+
close: () => {
|
|
1977
|
+
server.stop(true);
|
|
1978
|
+
rmSync(dir, { recursive: true, force: true });
|
|
1979
|
+
}
|
|
1980
|
+
};
|
|
1981
|
+
}
|
|
1982
|
+
async function askpassClient(argv) {
|
|
1983
|
+
const socketPath = process16.env[SOCKET_VARIABLE];
|
|
1984
|
+
if (socketPath === undefined)
|
|
1985
|
+
return;
|
|
1986
|
+
const request = { prompt: argv[0] ?? "", ...process16.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1987
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1988
|
+
let received = "";
|
|
1989
|
+
try {
|
|
1990
|
+
await Bun.connect({
|
|
1991
|
+
unix: socketPath,
|
|
1992
|
+
socket: {
|
|
1993
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1994
|
+
`),
|
|
1995
|
+
data: (_, chunk) => {
|
|
1996
|
+
received += chunk.toString();
|
|
1997
|
+
},
|
|
1998
|
+
close: () => resolve(received),
|
|
1999
|
+
error: () => resolve("")
|
|
2000
|
+
}
|
|
2001
|
+
});
|
|
2002
|
+
} catch {
|
|
2003
|
+
return 1;
|
|
2004
|
+
}
|
|
2005
|
+
const reply = await promise;
|
|
2006
|
+
if (reply === "")
|
|
2007
|
+
return 1;
|
|
2008
|
+
const { answer } = JSON.parse(reply);
|
|
2009
|
+
if (request.notice === true)
|
|
2010
|
+
return 0;
|
|
2011
|
+
if (answer === undefined)
|
|
2012
|
+
return 1;
|
|
2013
|
+
process16.stdout.write(`${answer}
|
|
2014
|
+
`);
|
|
2015
|
+
return 0;
|
|
2016
|
+
}
|
|
1157
2017
|
|
|
1158
2018
|
// ../kit/src/completions.ts
|
|
1159
2019
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -1216,28 +2076,34 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
1216
2076
|
}
|
|
1217
2077
|
|
|
1218
2078
|
// ../kit/src/notify.ts
|
|
1219
|
-
|
|
2079
|
+
init_format();
|
|
2080
|
+
init_mode();
|
|
2081
|
+
import process17 from "process";
|
|
1220
2082
|
var NOTIFY_AFTER_MS = 1e4;
|
|
1221
2083
|
var CANCELLED = 130;
|
|
1222
2084
|
function base64(text) {
|
|
1223
2085
|
return Buffer.from(text).toString("base64");
|
|
1224
2086
|
}
|
|
1225
|
-
function notification(title, body, env =
|
|
1226
|
-
const id = `kit${
|
|
2087
|
+
function notification(title, body, env = process17.env) {
|
|
2088
|
+
const id = `kit${process17.pid}`;
|
|
1227
2089
|
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\\`];
|
|
1228
2090
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1229
2091
|
}
|
|
1230
|
-
function notifyEnd(command, code, ms, { stream =
|
|
2092
|
+
function notifyEnd(command, code, ms, { stream = process17.stderr, env = process17.env } = {}) {
|
|
1231
2093
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1232
2094
|
return;
|
|
1233
2095
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1234
2096
|
}
|
|
1235
2097
|
|
|
2098
|
+
// ../kit/src/cli.ts
|
|
2099
|
+
init_style();
|
|
2100
|
+
init_text2();
|
|
2101
|
+
|
|
1236
2102
|
// ../kit/src/usage.ts
|
|
1237
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
1238
|
-
import { homedir as
|
|
1239
|
-
import { dirname as
|
|
1240
|
-
import
|
|
2103
|
+
import { appendFileSync, mkdirSync as mkdirSync2 } from "fs";
|
|
2104
|
+
import { homedir as homedir4 } from "os";
|
|
2105
|
+
import { dirname as dirname3, isAbsolute, join as join7 } from "path";
|
|
2106
|
+
import process18 from "process";
|
|
1241
2107
|
|
|
1242
2108
|
// ../kit/src/logs.ts
|
|
1243
2109
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1251,14 +2117,14 @@ var usageError;
|
|
|
1251
2117
|
function noteUsageError(message) {
|
|
1252
2118
|
usageError = message;
|
|
1253
2119
|
}
|
|
1254
|
-
function stateHome(env =
|
|
2120
|
+
function stateHome(env = process18.env) {
|
|
1255
2121
|
const dir = env.XDG_STATE_HOME;
|
|
1256
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
2122
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join7(homedir4(), ".local", "state");
|
|
1257
2123
|
}
|
|
1258
|
-
function usagePath(env =
|
|
1259
|
-
return
|
|
2124
|
+
function usagePath(env = process18.env) {
|
|
2125
|
+
return join7(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1260
2126
|
}
|
|
1261
|
-
function usageRecorded(env =
|
|
2127
|
+
function usageRecorded(env = process18.env) {
|
|
1262
2128
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1263
2129
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1264
2130
|
}
|
|
@@ -1272,12 +2138,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1272
2138
|
usageError = undefined;
|
|
1273
2139
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1274
2140
|
}
|
|
1275
|
-
function recordUsage(entry, env =
|
|
2141
|
+
function recordUsage(entry, env = process18.env) {
|
|
1276
2142
|
if (!usageRecorded(env))
|
|
1277
2143
|
return;
|
|
1278
2144
|
try {
|
|
1279
2145
|
const path = usagePath(env);
|
|
1280
|
-
|
|
2146
|
+
mkdirSync2(dirname3(path), { recursive: true, mode: 448 });
|
|
1281
2147
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1282
2148
|
`, { mode: 384 });
|
|
1283
2149
|
} catch {}
|
|
@@ -1294,8 +2160,8 @@ var TOP_OPTIONS = {
|
|
|
1294
2160
|
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1295
2161
|
};
|
|
1296
2162
|
function printError(prefix, message, hint, cause) {
|
|
1297
|
-
const colors = paint(
|
|
1298
|
-
const styled = takesControlCodes(
|
|
2163
|
+
const colors = paint(process19.stderr);
|
|
2164
|
+
const styled = takesControlCodes(process19.stderr);
|
|
1299
2165
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1300
2166
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1301
2167
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1398,17 +2264,20 @@ function packageVersion(entry = Bun.main) {
|
|
|
1398
2264
|
try {
|
|
1399
2265
|
resolved = realpathSync2(entry);
|
|
1400
2266
|
} catch {}
|
|
1401
|
-
for (let dir =
|
|
2267
|
+
for (let dir = dirname4(resolved);; dir = dirname4(dir)) {
|
|
1402
2268
|
try {
|
|
1403
|
-
const { version } = JSON.parse(
|
|
2269
|
+
const { version } = JSON.parse(readFileSync5(join8(dir, "package.json"), "utf8"));
|
|
1404
2270
|
if (typeof version === "string")
|
|
1405
2271
|
return version;
|
|
1406
2272
|
} catch {}
|
|
1407
|
-
if (
|
|
2273
|
+
if (dirname4(dir) === dir)
|
|
1408
2274
|
return "0.0.0";
|
|
1409
2275
|
}
|
|
1410
2276
|
}
|
|
1411
2277
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
2278
|
+
const answered = await askpassClient(argv);
|
|
2279
|
+
if (answered !== undefined)
|
|
2280
|
+
return answered;
|
|
1412
2281
|
if (argv[0] === COMPLETE)
|
|
1413
2282
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1414
2283
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -1432,16 +2301,46 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1432
2301
|
}
|
|
1433
2302
|
return code;
|
|
1434
2303
|
}
|
|
1435
|
-
|
|
1436
|
-
|
|
2304
|
+
|
|
2305
|
+
// ../kit/src/index.ts
|
|
2306
|
+
init_config();
|
|
2307
|
+
|
|
2308
|
+
// ../kit/src/excerpt.ts
|
|
2309
|
+
init_text2();
|
|
2310
|
+
|
|
2311
|
+
// ../kit/src/index.ts
|
|
2312
|
+
init_folders();
|
|
2313
|
+
init_format();
|
|
2314
|
+
|
|
2315
|
+
// ../kit/src/git.ts
|
|
2316
|
+
init_args();
|
|
2317
|
+
// ../kit/src/limit.ts
|
|
2318
|
+
init_args();
|
|
2319
|
+
|
|
2320
|
+
// ../kit/src/index.ts
|
|
2321
|
+
init_mode();
|
|
2322
|
+
|
|
2323
|
+
// ../kit/src/report.ts
|
|
2324
|
+
init_style();
|
|
2325
|
+
init_text2();
|
|
1437
2326
|
// ../kit/src/secrets.ts
|
|
1438
2327
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1439
2328
|
// ../kit/src/sessions.ts
|
|
1440
2329
|
var {Glob } = globalThis.Bun;
|
|
1441
2330
|
var SESSION_FILES = new Glob("*.json");
|
|
1442
2331
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
2332
|
+
|
|
2333
|
+
// ../kit/src/index.ts
|
|
2334
|
+
init_style();
|
|
2335
|
+
init_text2();
|
|
2336
|
+
init_theme();
|
|
2337
|
+
init_user_config();
|
|
2338
|
+
|
|
1443
2339
|
// ../kit/src/watch.ts
|
|
1444
|
-
|
|
2340
|
+
init_args();
|
|
2341
|
+
init_input();
|
|
2342
|
+
init_style();
|
|
2343
|
+
import process20 from "process";
|
|
1445
2344
|
import { format } from "util";
|
|
1446
2345
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1447
2346
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1463,7 +2362,7 @@ function withoutWatch(args) {
|
|
|
1463
2362
|
}
|
|
1464
2363
|
return rest;
|
|
1465
2364
|
}
|
|
1466
|
-
async function watching(value, step, stream =
|
|
2365
|
+
async function watching(value, step, stream = process20.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1467
2366
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1468
2367
|
if (!takesControlCodes(stream))
|
|
1469
2368
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1471,12 +2370,12 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1471
2370
|
for (let round = 0;round < rounds; round++) {
|
|
1472
2371
|
const held = [];
|
|
1473
2372
|
const { log, info } = console;
|
|
1474
|
-
const write =
|
|
2373
|
+
const write = process20.stdout.write.bind(process20.stdout);
|
|
1475
2374
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1476
2375
|
`);
|
|
1477
2376
|
console.log = hold;
|
|
1478
2377
|
console.info = hold;
|
|
1479
|
-
|
|
2378
|
+
process20.stdout.write = (text) => {
|
|
1480
2379
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1481
2380
|
return true;
|
|
1482
2381
|
};
|
|
@@ -1485,7 +2384,7 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1485
2384
|
} finally {
|
|
1486
2385
|
console.log = log;
|
|
1487
2386
|
console.info = info;
|
|
1488
|
-
|
|
2387
|
+
process20.stdout.write = write;
|
|
1489
2388
|
}
|
|
1490
2389
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1491
2390
|
await sleep(interval);
|
|
@@ -1493,21 +2392,22 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1493
2392
|
return code;
|
|
1494
2393
|
}
|
|
1495
2394
|
// ../kit/src/workspace-root.ts
|
|
1496
|
-
|
|
1497
|
-
import {
|
|
1498
|
-
import
|
|
2395
|
+
init_user_config();
|
|
2396
|
+
import { homedir as homedir5 } from "os";
|
|
2397
|
+
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2398
|
+
import process21 from "process";
|
|
1499
2399
|
function expandHome(path, home) {
|
|
1500
2400
|
if (path === "~")
|
|
1501
2401
|
return home;
|
|
1502
|
-
return path.startsWith("~/") ?
|
|
2402
|
+
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
1503
2403
|
}
|
|
1504
2404
|
function configured(env, home) {
|
|
1505
2405
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1506
2406
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1507
2407
|
}
|
|
1508
|
-
function workspaceRoot({ given, env =
|
|
2408
|
+
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
1509
2409
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1510
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ??
|
|
2410
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
1511
2411
|
}
|
|
1512
2412
|
// src/git.ts
|
|
1513
2413
|
async function git2(args, env) {
|
|
@@ -1518,8 +2418,8 @@ async function git2(args, env) {
|
|
|
1518
2418
|
|
|
1519
2419
|
// src/repos.ts
|
|
1520
2420
|
import { readdir } from "fs/promises";
|
|
1521
|
-
import { join as
|
|
1522
|
-
import
|
|
2421
|
+
import { join as join10, relative, resolve as resolve5 } from "path";
|
|
2422
|
+
import process23 from "process";
|
|
1523
2423
|
|
|
1524
2424
|
// src/status.ts
|
|
1525
2425
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -1615,7 +2515,7 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
1615
2515
|
found.push(dir);
|
|
1616
2516
|
if (left === 0)
|
|
1617
2517
|
return;
|
|
1618
|
-
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(
|
|
2518
|
+
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join10(dir, entry.name), left - 1)));
|
|
1619
2519
|
}
|
|
1620
2520
|
await walk(resolve5(root), depth);
|
|
1621
2521
|
return found.sort();
|
|
@@ -1625,14 +2525,14 @@ async function toplevelOf(dir) {
|
|
|
1625
2525
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
1626
2526
|
}
|
|
1627
2527
|
async function reposOf(roots) {
|
|
1628
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2528
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process23.cwd()];
|
|
1629
2529
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
1630
2530
|
return [...new Set(found.flat())].sort();
|
|
1631
2531
|
}
|
|
1632
2532
|
async function repoState(dir) {
|
|
1633
2533
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
1634
2534
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
1635
|
-
return { path: relative(
|
|
2535
|
+
return { path: relative(process23.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
1636
2536
|
}
|
|
1637
2537
|
function trackingOf(status) {
|
|
1638
2538
|
if (status.upstream === null)
|
|
@@ -1669,15 +2569,35 @@ async function dirsOf(positionals, all) {
|
|
|
1669
2569
|
|
|
1670
2570
|
// src/sync.ts
|
|
1671
2571
|
var GIT_FAILURE = /^(?:error: |fatal: )/;
|
|
2572
|
+
var LISTED = /^\s/;
|
|
2573
|
+
var LOCAL_CHANGES = /local changes .* would be overwritten/;
|
|
2574
|
+
var UNTRACKED = /untracked working tree files would be overwritten/;
|
|
1672
2575
|
function whyFailed(stderr, fallback) {
|
|
1673
2576
|
const lines = stderr.split(`
|
|
1674
2577
|
`).map((line) => line.trimEnd()).filter(Boolean);
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
2578
|
+
const at = lines.findIndex((line) => GIT_FAILURE.test(line));
|
|
2579
|
+
if (at === -1)
|
|
2580
|
+
return (lines.at(-1) ?? fallback).trim();
|
|
2581
|
+
const line = lines[at].trim();
|
|
2582
|
+
const listed = [];
|
|
2583
|
+
for (const next of lines.slice(at + 1)) {
|
|
2584
|
+
if (!LISTED.test(next))
|
|
2585
|
+
break;
|
|
2586
|
+
listed.push(next.trim());
|
|
2587
|
+
}
|
|
2588
|
+
if (listed.length === 0)
|
|
2589
|
+
return line;
|
|
2590
|
+
const paths = listed.join(", ");
|
|
2591
|
+
if (LOCAL_CHANGES.test(line))
|
|
2592
|
+
return `uncommitted changes in files the fast-forward changes (${paths}): commit them first (gc), or set them aside as a patch (gu)`;
|
|
2593
|
+
if (UNTRACKED.test(line))
|
|
2594
|
+
return `untracked files the fast-forward would overwrite (${paths}): move them aside first`;
|
|
2595
|
+
return `${line} ${paths}`;
|
|
2596
|
+
}
|
|
2597
|
+
async function sync(repo, { pull, env }) {
|
|
1678
2598
|
const { path, dir } = repo;
|
|
1679
2599
|
const refused = (reason, branch = null, upstream = null) => ({ path, branch, upstream, commits: null, outcome: "refused", reason });
|
|
1680
|
-
const fetched = await git2(["-C", dir, "fetch", "--prune"]);
|
|
2600
|
+
const fetched = await git2(["-C", dir, "fetch", "--prune"], env);
|
|
1681
2601
|
if (fetched.code !== 0)
|
|
1682
2602
|
return refused(whyFailed(fetched.stderr, "git fetch failed"), repo.status?.branch ?? null);
|
|
1683
2603
|
const { status } = await repoState(dir);
|
|
@@ -1720,7 +2640,7 @@ var TRAILING_SLASH = /\/+$/;
|
|
|
1720
2640
|
var LAST_SEGMENT = /[/:]/;
|
|
1721
2641
|
function urlOf(repo, forge) {
|
|
1722
2642
|
if (repo.startsWith("~/"))
|
|
1723
|
-
return
|
|
2643
|
+
return join11(homedir6(), repo.slice(2));
|
|
1724
2644
|
if (SCHEME.test(repo) || SCP.test(repo) || repo.startsWith("/") || repo.startsWith("."))
|
|
1725
2645
|
return repo;
|
|
1726
2646
|
if (OWNER_NAME.test(repo))
|
|
@@ -1743,7 +2663,7 @@ async function main(argv) {
|
|
|
1743
2663
|
const name = nameOf(url);
|
|
1744
2664
|
if (name === "")
|
|
1745
2665
|
fail(`no folder name can be taken from ${url}, give one: gcl ${repo} <dir>`, 2);
|
|
1746
|
-
const path = given === undefined ?
|
|
2666
|
+
const path = given === undefined ? join11(workspaceRoot(), name) : resolve6(given);
|
|
1747
2667
|
let outcome = "cloned";
|
|
1748
2668
|
if (existsSync4(path) && (!statSync2(path).isDirectory() || readdirSync(path).length > 0)) {
|
|
1749
2669
|
if (!statSync2(path).isDirectory() || await toplevelOf(path) !== realpathSync3(path))
|
|
@@ -1772,7 +2692,7 @@ ${cloned.stderr.trim()}`, 1);
|
|
|
1772
2692
|
return 0;
|
|
1773
2693
|
}
|
|
1774
2694
|
if (import.meta.main)
|
|
1775
|
-
|
|
2695
|
+
process24.exitCode = await runMain({ name: "gcl", run: main });
|
|
1776
2696
|
export {
|
|
1777
2697
|
nameOf,
|
|
1778
2698
|
urlOf
|