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