@kaynooo/cli-git 0.17.0 → 0.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/gb.js +1674 -1141
- package/dist/gc.js +1089 -159
- package/dist/gcl.js +1124 -174
- package/dist/gd.js +1100 -170
- package/dist/gf.js +1131 -175
- package/dist/gm.js +1686 -1155
- package/dist/gp.js +1110 -174
- package/dist/gst.js +1108 -178
- package/dist/gu.js +1097 -167
- package/package.json +2 -2
package/dist/gp.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,14 +517,40 @@ 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
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
534
|
+
`);
|
|
535
|
+
const blank = lines.indexOf("");
|
|
536
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
537
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
538
|
+
const colon = synopses[0].indexOf(": ");
|
|
539
|
+
const inline = synopses[0].slice(colon + 2);
|
|
540
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
541
|
+
if (colon !== -1)
|
|
542
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
543
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
544
|
+
`)}`;
|
|
545
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
546
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
547
|
+
return [head, ...lead, ...rest].join(`
|
|
548
|
+
`);
|
|
549
|
+
}
|
|
550
|
+
function prose(line, colors) {
|
|
551
|
+
if (colors.cyan("x") === "x")
|
|
552
|
+
return line;
|
|
553
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
501
554
|
}
|
|
502
555
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
503
556
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -532,7 +585,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
532
585
|
return [];
|
|
533
586
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
534
587
|
}
|
|
535
|
-
var MAX_INLINE_CHOICES = 24;
|
|
536
588
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
537
589
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
538
590
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -547,9 +599,17 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
547
599
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
548
600
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
549
601
|
}
|
|
602
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
603
|
+
var init_help = __esm(() => {
|
|
604
|
+
init_mode();
|
|
605
|
+
init_style();
|
|
606
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
607
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
608
|
+
FULL_STOP = /\.$/;
|
|
609
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
610
|
+
});
|
|
550
611
|
|
|
551
612
|
// ../kit/src/text.ts
|
|
552
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
553
613
|
function distance(a, b) {
|
|
554
614
|
const left = [...a];
|
|
555
615
|
const right = [...b];
|
|
@@ -575,8 +635,12 @@ function closest(name, names) {
|
|
|
575
635
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
576
636
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
577
637
|
}
|
|
638
|
+
var ANSI;
|
|
639
|
+
var init_text2 = __esm(() => {
|
|
640
|
+
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
641
|
+
});
|
|
642
|
+
|
|
578
643
|
// ../kit/src/input.ts
|
|
579
|
-
var WHOLE = /^\d+$/;
|
|
580
644
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
581
645
|
if (value === undefined)
|
|
582
646
|
return fallback;
|
|
@@ -585,8 +649,6 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
585
649
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
586
650
|
return number;
|
|
587
651
|
}
|
|
588
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
589
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
590
652
|
function duration(value, name, fallback, unit = "s") {
|
|
591
653
|
if (value === undefined)
|
|
592
654
|
return fallback;
|
|
@@ -596,40 +658,27 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
596
658
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
597
659
|
return ms;
|
|
598
660
|
}
|
|
661
|
+
var WHOLE, DURATION, UNIT_MS;
|
|
662
|
+
var init_input = __esm(() => {
|
|
663
|
+
init_args();
|
|
664
|
+
WHOLE = /^\d+$/;
|
|
665
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
666
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
667
|
+
});
|
|
599
668
|
|
|
600
669
|
// ../kit/src/args.ts
|
|
601
|
-
|
|
670
|
+
import process9 from "process";
|
|
671
|
+
import { parseArgs } from "util";
|
|
602
672
|
function jsonOption(holds) {
|
|
603
673
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
604
674
|
}
|
|
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
675
|
function fail(message, code = 2, hint) {
|
|
615
676
|
throw new Exit(message, code, hint);
|
|
616
677
|
}
|
|
617
|
-
|
|
618
|
-
class UsageError extends Exit {
|
|
619
|
-
constructor(message, hint) {
|
|
620
|
-
super(message, 2, hint);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
678
|
function badUsage(message) {
|
|
624
679
|
throw new UsageError(message);
|
|
625
680
|
}
|
|
626
681
|
|
|
627
|
-
class HelpShown extends Exit {
|
|
628
|
-
constructor() {
|
|
629
|
-
super("help shown", 0);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
682
|
class Completing {
|
|
634
683
|
options;
|
|
635
684
|
positionals;
|
|
@@ -640,11 +689,6 @@ class Completing {
|
|
|
640
689
|
this.candidates = candidates;
|
|
641
690
|
}
|
|
642
691
|
}
|
|
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
692
|
function applyOutput(color, plain, env = process9.env) {
|
|
649
693
|
const when = plain === true ? "never" : color ?? "auto";
|
|
650
694
|
if (when === "auto")
|
|
@@ -798,7 +842,6 @@ function parseError(error) {
|
|
|
798
842
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
799
843
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
800
844
|
}
|
|
801
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
802
845
|
function nearestOption(message, options, allowNegative) {
|
|
803
846
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
804
847
|
if (typed === undefined)
|
|
@@ -814,6 +857,692 @@ function nearestOption(message, options, allowNegative) {
|
|
|
814
857
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
815
858
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
816
859
|
}
|
|
860
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
861
|
+
var init_args = __esm(() => {
|
|
862
|
+
init_format();
|
|
863
|
+
init_help();
|
|
864
|
+
init_text2();
|
|
865
|
+
init_help();
|
|
866
|
+
init_input();
|
|
867
|
+
DASHES = /^-+/;
|
|
868
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
869
|
+
Exit = class Exit extends Error {
|
|
870
|
+
code;
|
|
871
|
+
hint;
|
|
872
|
+
[EXIT] = true;
|
|
873
|
+
constructor(message, code, hint) {
|
|
874
|
+
super(message);
|
|
875
|
+
this.code = code;
|
|
876
|
+
this.hint = hint;
|
|
877
|
+
}
|
|
878
|
+
static [Symbol.hasInstance](value) {
|
|
879
|
+
if (this !== Exit)
|
|
880
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
881
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
UsageError = class UsageError extends Exit {
|
|
885
|
+
constructor(message, hint) {
|
|
886
|
+
super(message, 2, hint);
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
HelpShown = class HelpShown extends Exit {
|
|
890
|
+
constructor() {
|
|
891
|
+
super("help shown", 0);
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
completion = { active: false };
|
|
895
|
+
OUTPUT_OPTIONS = {
|
|
896
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
897
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
898
|
+
};
|
|
899
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
// ../kit/src/folders.ts
|
|
903
|
+
import { homedir as homedir3 } from "os";
|
|
904
|
+
import { join as join4 } from "path";
|
|
905
|
+
import process13 from "process";
|
|
906
|
+
function cacheFolder({ home = homedir3(), env = process13.env } = {}) {
|
|
907
|
+
return env.XDG_CACHE_HOME ?? join4(home, ".cache");
|
|
908
|
+
}
|
|
909
|
+
var SKIPPED_FOLDERS;
|
|
910
|
+
var init_folders = __esm(() => {
|
|
911
|
+
init_user_config();
|
|
912
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
// ../kit/src/answers.ts
|
|
916
|
+
import { mkdirSync, readFileSync as readFileSync4, writeFileSync } from "fs";
|
|
917
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
918
|
+
function answersFile() {
|
|
919
|
+
return join5(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
920
|
+
}
|
|
921
|
+
function stored() {
|
|
922
|
+
try {
|
|
923
|
+
const parsed = JSON.parse(readFileSync4(answersFile(), "utf-8"));
|
|
924
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
925
|
+
return {};
|
|
926
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
927
|
+
} catch {
|
|
928
|
+
return {};
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
function earlierAnswers(key) {
|
|
932
|
+
return stored()[key] ?? [];
|
|
933
|
+
}
|
|
934
|
+
function rememberAnswer(key, answer) {
|
|
935
|
+
const all = stored();
|
|
936
|
+
const file = answersFile();
|
|
937
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
938
|
+
try {
|
|
939
|
+
mkdirSync(dirname2(file), { recursive: true });
|
|
940
|
+
writeFileSync(file, JSON.stringify(all));
|
|
941
|
+
} catch {}
|
|
942
|
+
}
|
|
943
|
+
var KEPT = 50;
|
|
944
|
+
var init_answers = __esm(() => {
|
|
945
|
+
init_folders();
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
// ../kit/src/job.ts
|
|
949
|
+
import process14 from "process";
|
|
950
|
+
function stopJob() {
|
|
951
|
+
process14.kill(0, "SIGTSTP");
|
|
952
|
+
}
|
|
953
|
+
var init_job = () => {};
|
|
954
|
+
|
|
955
|
+
// ../kit/src/picker/line.ts
|
|
956
|
+
function isEditKey(key) {
|
|
957
|
+
return EDIT_KEYS.has(key);
|
|
958
|
+
}
|
|
959
|
+
function endsKills(key) {
|
|
960
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
961
|
+
}
|
|
962
|
+
function isWord(char) {
|
|
963
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
964
|
+
}
|
|
965
|
+
function wordStart(chars, from) {
|
|
966
|
+
let at = from;
|
|
967
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
968
|
+
at--;
|
|
969
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
970
|
+
at--;
|
|
971
|
+
return at;
|
|
972
|
+
}
|
|
973
|
+
function wordEnd(chars, from) {
|
|
974
|
+
let at = from;
|
|
975
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
976
|
+
at++;
|
|
977
|
+
while (at < chars.length && isWord(chars[at]))
|
|
978
|
+
at++;
|
|
979
|
+
return at;
|
|
980
|
+
}
|
|
981
|
+
function spacedStart(chars, from) {
|
|
982
|
+
let at = from;
|
|
983
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
984
|
+
at--;
|
|
985
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
986
|
+
at--;
|
|
987
|
+
return at;
|
|
988
|
+
}
|
|
989
|
+
function cut(chars, from, to) {
|
|
990
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
991
|
+
}
|
|
992
|
+
function insert(chars, at, text) {
|
|
993
|
+
const typed = [...text];
|
|
994
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
995
|
+
}
|
|
996
|
+
function editLine(line, key) {
|
|
997
|
+
const { killed = "", chained = false } = line;
|
|
998
|
+
const chars = [...line.text];
|
|
999
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
1000
|
+
const edited = edit(chars, at, key, killed);
|
|
1001
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
1002
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
1003
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
1004
|
+
if (taken === "")
|
|
1005
|
+
return { ...edited, killed, chained };
|
|
1006
|
+
if (!chained)
|
|
1007
|
+
return { ...edited, killed: taken, chained: true };
|
|
1008
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
1009
|
+
}
|
|
1010
|
+
function edit(chars, at, key, killed) {
|
|
1011
|
+
const text = chars.join("");
|
|
1012
|
+
if (typeof key === "object")
|
|
1013
|
+
return insert(chars, at, key.text);
|
|
1014
|
+
switch (key) {
|
|
1015
|
+
case "left":
|
|
1016
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
1017
|
+
case "right":
|
|
1018
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
1019
|
+
case "wordleft":
|
|
1020
|
+
return { text, caret: wordStart(chars, at) };
|
|
1021
|
+
case "wordright":
|
|
1022
|
+
return { text, caret: wordEnd(chars, at) };
|
|
1023
|
+
case "linestart":
|
|
1024
|
+
return { text, caret: 0 };
|
|
1025
|
+
case "lineend":
|
|
1026
|
+
return { text, caret: chars.length };
|
|
1027
|
+
case "erase":
|
|
1028
|
+
return cut(chars, Math.max(at - 1, 0), at);
|
|
1029
|
+
case "delete":
|
|
1030
|
+
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
1031
|
+
case "word":
|
|
1032
|
+
return cut(chars, spacedStart(chars, at), at);
|
|
1033
|
+
case "killword":
|
|
1034
|
+
return cut(chars, wordStart(chars, at), at);
|
|
1035
|
+
case "killnext":
|
|
1036
|
+
return cut(chars, at, wordEnd(chars, at));
|
|
1037
|
+
case "clear":
|
|
1038
|
+
return cut(chars, 0, at);
|
|
1039
|
+
case "killend":
|
|
1040
|
+
return cut(chars, at, chars.length);
|
|
1041
|
+
case "yank":
|
|
1042
|
+
return insert(chars, at, killed);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
function visible({ text, caret }, room) {
|
|
1046
|
+
const chars = [...text];
|
|
1047
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
1048
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
1049
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
1050
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
1051
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
1052
|
+
let start = at;
|
|
1053
|
+
let end = at + 1;
|
|
1054
|
+
while (start > 0 && fits(start - 1, end))
|
|
1055
|
+
start--;
|
|
1056
|
+
while (end < cells.length && fits(start, end + 1))
|
|
1057
|
+
end++;
|
|
1058
|
+
const left = start > 0 ? "\u2026" : "";
|
|
1059
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
1060
|
+
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
1061
|
+
}
|
|
1062
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
|
|
1063
|
+
var init_line = __esm(() => {
|
|
1064
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1065
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1066
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1067
|
+
WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
1068
|
+
SPACE = /\s/;
|
|
1069
|
+
});
|
|
1070
|
+
|
|
1071
|
+
// ../kit/src/picker/score.ts
|
|
1072
|
+
function startsWord(text, index) {
|
|
1073
|
+
if (index === 0)
|
|
1074
|
+
return true;
|
|
1075
|
+
const before = text[index - 1];
|
|
1076
|
+
return BOUNDARY_AFTER.has(before) || LOWER.test(before) && UPPER.test(text[index]);
|
|
1077
|
+
}
|
|
1078
|
+
function fuzzy(query, text) {
|
|
1079
|
+
if (query === "")
|
|
1080
|
+
return { score: 0, positions: [] };
|
|
1081
|
+
const exact = query !== query.toLowerCase();
|
|
1082
|
+
const needle = exact ? query : query.toLowerCase();
|
|
1083
|
+
const haystack = exact ? text : text.toLowerCase();
|
|
1084
|
+
if (haystack.length !== text.length || needle.length > haystack.length)
|
|
1085
|
+
return;
|
|
1086
|
+
const width = haystack.length;
|
|
1087
|
+
const best = Array.from({ length: needle.length }, () => new Array(width).fill(NONE));
|
|
1088
|
+
const from = Array.from({ length: needle.length }, () => new Array(width).fill(-1));
|
|
1089
|
+
for (let j = 0;j < needle.length; j++) {
|
|
1090
|
+
let run = NONE;
|
|
1091
|
+
let runAt = -1;
|
|
1092
|
+
for (let i = j;i < width; i++) {
|
|
1093
|
+
if (j > 0 && i - 2 >= j - 1) {
|
|
1094
|
+
const candidate = best[j - 1][i - 2] + (i - 2) * GAP;
|
|
1095
|
+
if (candidate > run) {
|
|
1096
|
+
run = candidate;
|
|
1097
|
+
runAt = i - 2;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
if (haystack[i] !== needle[j])
|
|
1101
|
+
continue;
|
|
1102
|
+
const here = MATCH + (startsWord(text, i) ? BOUNDARY : 0) + (i === 0 ? PREFIX : 0);
|
|
1103
|
+
if (j === 0) {
|
|
1104
|
+
best[0][i] = here - i * GAP;
|
|
1105
|
+
continue;
|
|
1106
|
+
}
|
|
1107
|
+
const joined = best[j - 1][i - 1] + CONSECUTIVE;
|
|
1108
|
+
const skipped = run - (i - 1) * GAP;
|
|
1109
|
+
if (joined > NONE && joined >= skipped) {
|
|
1110
|
+
best[j][i] = joined + here;
|
|
1111
|
+
from[j][i] = i - 1;
|
|
1112
|
+
} else if (skipped > NONE) {
|
|
1113
|
+
best[j][i] = skipped + here;
|
|
1114
|
+
from[j][i] = runAt;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
const last = best[needle.length - 1];
|
|
1119
|
+
let end = -1;
|
|
1120
|
+
for (let i = 0;i < width; i++) {
|
|
1121
|
+
if (last[i] > NONE && (end === -1 || last[i] > last[end]))
|
|
1122
|
+
end = i;
|
|
1123
|
+
}
|
|
1124
|
+
if (end === -1)
|
|
1125
|
+
return;
|
|
1126
|
+
const positions = [];
|
|
1127
|
+
for (let j = needle.length - 1, i = end;j >= 0; j--) {
|
|
1128
|
+
positions.unshift(i);
|
|
1129
|
+
i = from[j][i];
|
|
1130
|
+
}
|
|
1131
|
+
return { score: last[end], positions };
|
|
1132
|
+
}
|
|
1133
|
+
function rank(query, lines) {
|
|
1134
|
+
if (query === "")
|
|
1135
|
+
return lines.map((_, index) => ({ index, positions: [] }));
|
|
1136
|
+
const found = [];
|
|
1137
|
+
for (const [index, line] of lines.entries()) {
|
|
1138
|
+
const match = fuzzy(query, line);
|
|
1139
|
+
if (match !== undefined)
|
|
1140
|
+
found.push({ index, positions: match.positions, score: match.score });
|
|
1141
|
+
}
|
|
1142
|
+
return found.sort((a, b) => b.score - a.score || lines[a.index].length - lines[b.index].length || a.index - b.index);
|
|
1143
|
+
}
|
|
1144
|
+
var MATCH = 16, CONSECUTIVE = 12, BOUNDARY = 10, PREFIX = 8, GAP = 1, BOUNDARY_AFTER, UPPER, LOWER, NONE;
|
|
1145
|
+
var init_score = __esm(() => {
|
|
1146
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1147
|
+
UPPER = /\p{Lu}/u;
|
|
1148
|
+
LOWER = /\p{Ll}/u;
|
|
1149
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
1150
|
+
});
|
|
1151
|
+
|
|
1152
|
+
// ../kit/src/picker/state.ts
|
|
1153
|
+
function repeat(value, count) {
|
|
1154
|
+
return Array.from({ length: count }).fill(value);
|
|
1155
|
+
}
|
|
1156
|
+
function styled(line) {
|
|
1157
|
+
let text = "";
|
|
1158
|
+
const styles = [];
|
|
1159
|
+
let active = "";
|
|
1160
|
+
let colored = false;
|
|
1161
|
+
let last = 0;
|
|
1162
|
+
function add(chunk) {
|
|
1163
|
+
const flat = chunk.replace(CONTROL2, " ");
|
|
1164
|
+
text += flat;
|
|
1165
|
+
colored ||= active !== "" && flat !== "";
|
|
1166
|
+
styles.push(...repeat(active, flat.length));
|
|
1167
|
+
}
|
|
1168
|
+
for (const found of line.matchAll(ANSI)) {
|
|
1169
|
+
add(line.slice(last, found.index));
|
|
1170
|
+
last = found.index + found[0].length;
|
|
1171
|
+
if (SGR.test(found[0]))
|
|
1172
|
+
active = RESET.test(found[0]) ? "" : active + found[0];
|
|
1173
|
+
}
|
|
1174
|
+
add(line.slice(last));
|
|
1175
|
+
return { text, styles: colored ? styles : undefined };
|
|
1176
|
+
}
|
|
1177
|
+
function lay(rows, searched) {
|
|
1178
|
+
const parsed = rows.map((row) => row.cells.map(styled));
|
|
1179
|
+
const widths = (parsed[0] ?? []).map((_, column) => Math.max(...parsed.map((cells) => Bun.stringWidth(cells[column]?.text ?? ""))));
|
|
1180
|
+
return parsed.map((cells, at) => {
|
|
1181
|
+
let text = "";
|
|
1182
|
+
const styles = [];
|
|
1183
|
+
let colored = false;
|
|
1184
|
+
let searchEnd = 0;
|
|
1185
|
+
for (const [column, cell] of cells.entries()) {
|
|
1186
|
+
const last = column === cells.length - 1;
|
|
1187
|
+
const shown = cells.length > 1 && last ? cell.text.trimEnd() : cell.text;
|
|
1188
|
+
text += shown;
|
|
1189
|
+
colored ||= cell.styles !== undefined;
|
|
1190
|
+
styles.push(...cell.styles?.slice(0, shown.length) ?? repeat("", shown.length));
|
|
1191
|
+
if (column < searched)
|
|
1192
|
+
searchEnd = cells.length > 1 ? text.trimEnd().length : text.length;
|
|
1193
|
+
if (!last) {
|
|
1194
|
+
const pad = widths[column] - Bun.stringWidth(cell.text) + COLUMN_GAP;
|
|
1195
|
+
text += " ".repeat(pad);
|
|
1196
|
+
styles.push(...repeat("", pad));
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
return { text, styles: colored ? styles : undefined, searchable: rows[at].search ?? text.slice(0, searchEnd) };
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1203
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1204
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1205
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1206
|
+
if (wheel !== undefined)
|
|
1207
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1208
|
+
const named = codes.get(sequence);
|
|
1209
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1210
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1211
|
+
paste.active = sequence === PASTE_START;
|
|
1212
|
+
return [];
|
|
1213
|
+
}
|
|
1214
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
1215
|
+
`))
|
|
1216
|
+
return [];
|
|
1217
|
+
if (key !== undefined)
|
|
1218
|
+
return [key];
|
|
1219
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
|
|
1223
|
+
const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, caret: [...query].length, killed: "", chained: false, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
|
|
1224
|
+
return withRows(state, rows);
|
|
1225
|
+
}
|
|
1226
|
+
function withRows(state, rows, header = state.header) {
|
|
1227
|
+
const cells = rows.map((row) => typeof row === "string" ? { hidden: [], cells: [row] } : row);
|
|
1228
|
+
const laid = lay(cells, state.searched);
|
|
1229
|
+
const searchable = laid.map((row) => row.searchable);
|
|
1230
|
+
const matches = rank(state.query, searchable);
|
|
1231
|
+
return { ...state, rows: cells, items: laid.map((row) => row.text), styles: laid.map((row) => row.styles), searchable, header, matches, cursor: Math.max(0, Math.min(matches.length - 1, state.cursor)), marked: new Set };
|
|
1232
|
+
}
|
|
1233
|
+
function withQuery(state, key) {
|
|
1234
|
+
const { text, caret, killed = "", chained = false } = editLine({ text: state.query, caret: state.caret, killed: state.killed, chained: state.chained }, key);
|
|
1235
|
+
return text === state.query ? { ...state, caret, killed, chained } : { ...state, query: text, caret, killed, chained, matches: rank(text, state.searchable), cursor: 0 };
|
|
1236
|
+
}
|
|
1237
|
+
function move(state, by) {
|
|
1238
|
+
return { ...state, cursor: Math.max(0, Math.min(state.matches.length - 1, state.cursor + by)) };
|
|
1239
|
+
}
|
|
1240
|
+
function highlighted(state) {
|
|
1241
|
+
return state.matches[state.cursor]?.index;
|
|
1242
|
+
}
|
|
1243
|
+
function press(state, key) {
|
|
1244
|
+
if (state.done !== undefined)
|
|
1245
|
+
return state;
|
|
1246
|
+
if (state.chained && endsKills(key))
|
|
1247
|
+
state = { ...state, chained: false };
|
|
1248
|
+
if (state.help)
|
|
1249
|
+
return { ...state, help: false };
|
|
1250
|
+
if (typeof key === "object") {
|
|
1251
|
+
if ("text" in key)
|
|
1252
|
+
return withQuery(state, key);
|
|
1253
|
+
return state.expect.includes(key.ctrl) ? { ...state, done: "accept", key: key.ctrl } : state;
|
|
1254
|
+
}
|
|
1255
|
+
if (isEditKey(key))
|
|
1256
|
+
return withQuery(state, key);
|
|
1257
|
+
switch (key) {
|
|
1258
|
+
case "up":
|
|
1259
|
+
return move(state, -1);
|
|
1260
|
+
case "down":
|
|
1261
|
+
return move(state, 1);
|
|
1262
|
+
case "pageup":
|
|
1263
|
+
return move(state, -state.page);
|
|
1264
|
+
case "pagedown":
|
|
1265
|
+
return move(state, state.page);
|
|
1266
|
+
case "home":
|
|
1267
|
+
return move(state, -state.matches.length);
|
|
1268
|
+
case "end":
|
|
1269
|
+
return move(state, state.matches.length);
|
|
1270
|
+
case "cancel":
|
|
1271
|
+
return { ...state, done: "cancel" };
|
|
1272
|
+
case "help":
|
|
1273
|
+
return { ...state, help: true };
|
|
1274
|
+
case "suspend":
|
|
1275
|
+
return state;
|
|
1276
|
+
case "enter":
|
|
1277
|
+
return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
|
|
1278
|
+
case "tab": {
|
|
1279
|
+
const at = highlighted(state);
|
|
1280
|
+
if (!state.multi || at === undefined)
|
|
1281
|
+
return state;
|
|
1282
|
+
const marked = new Set(state.marked);
|
|
1283
|
+
if (!marked.delete(at))
|
|
1284
|
+
marked.add(at);
|
|
1285
|
+
return move({ ...state, marked }, 1);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
function chosen(state) {
|
|
1290
|
+
if (state.marked.size > 0)
|
|
1291
|
+
return state.rows.filter((_, index) => state.marked.has(index));
|
|
1292
|
+
const at = highlighted(state);
|
|
1293
|
+
return at === undefined ? [] : [state.rows[at]];
|
|
1294
|
+
}
|
|
1295
|
+
var CONTROL2, IS_CONTROL, SGR, RESET, COLUMN_GAP = 2, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS, CTRL_KEY;
|
|
1296
|
+
var init_state = __esm(() => {
|
|
1297
|
+
init_text2();
|
|
1298
|
+
init_line();
|
|
1299
|
+
init_score();
|
|
1300
|
+
CONTROL2 = /[\x00-\x1F\x7F-\x9F]/g;
|
|
1301
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1302
|
+
SGR = /^\x1B\[[0-9;]*m$/;
|
|
1303
|
+
RESET = /^\x1B\[0?m$/;
|
|
1304
|
+
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1305
|
+
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1306
|
+
KEYS = {
|
|
1307
|
+
"\x1B[A": "up",
|
|
1308
|
+
"\x1BOA": "up",
|
|
1309
|
+
"\x10": "up",
|
|
1310
|
+
"\x1B[B": "down",
|
|
1311
|
+
"\x1BOB": "down",
|
|
1312
|
+
"\x0E": "down",
|
|
1313
|
+
"\x1B[5~": "pageup",
|
|
1314
|
+
"\x1B[6~": "pagedown",
|
|
1315
|
+
"\x1B[H": "home",
|
|
1316
|
+
"\x1B[1~": "home",
|
|
1317
|
+
"\x1BOH": "home",
|
|
1318
|
+
"\x1B[F": "end",
|
|
1319
|
+
"\x1B[4~": "end",
|
|
1320
|
+
"\x1BOF": "end",
|
|
1321
|
+
"\r": "enter",
|
|
1322
|
+
"\n": "enter",
|
|
1323
|
+
"\x03": "cancel",
|
|
1324
|
+
"\x1B": "cancel",
|
|
1325
|
+
"\x1B[D": "left",
|
|
1326
|
+
"\x1BOD": "left",
|
|
1327
|
+
"\x1B[C": "right",
|
|
1328
|
+
"\x1BOC": "right",
|
|
1329
|
+
"\x1B[1;5D": "wordleft",
|
|
1330
|
+
"\x1B[1;3D": "wordleft",
|
|
1331
|
+
"\x1Bb": "wordleft",
|
|
1332
|
+
"\x1B[1;5C": "wordright",
|
|
1333
|
+
"\x1B[1;3C": "wordright",
|
|
1334
|
+
"\x1Bf": "wordright",
|
|
1335
|
+
"\x01": "linestart",
|
|
1336
|
+
"\x05": "lineend",
|
|
1337
|
+
"\x7F": "erase",
|
|
1338
|
+
"\x1B[3~": "delete",
|
|
1339
|
+
"\b": "killword",
|
|
1340
|
+
"\x1B\x7F": "killword",
|
|
1341
|
+
"\x1B[3;5~": "killnext",
|
|
1342
|
+
"\x1Bd": "killnext",
|
|
1343
|
+
"\x15": "clear",
|
|
1344
|
+
"\v": "killend",
|
|
1345
|
+
"\x17": "word",
|
|
1346
|
+
"\x19": "yank",
|
|
1347
|
+
"\x1A": "suspend",
|
|
1348
|
+
"\t": "tab",
|
|
1349
|
+
"\x1F": "help",
|
|
1350
|
+
"\x1BOP": "help",
|
|
1351
|
+
"\x1B[11~": "help"
|
|
1352
|
+
};
|
|
1353
|
+
CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
|
|
1354
|
+
});
|
|
1355
|
+
|
|
1356
|
+
// ../kit/src/redraw.ts
|
|
1357
|
+
function overwrite(lines, columns) {
|
|
1358
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1359
|
+
`);
|
|
1360
|
+
}
|
|
1361
|
+
function rowsTaken(lines, columns) {
|
|
1362
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1363
|
+
}
|
|
1364
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
1365
|
+
var init_redraw = __esm(() => {
|
|
1366
|
+
init_format();
|
|
1367
|
+
});
|
|
1368
|
+
|
|
1369
|
+
// ../kit/src/prompt.ts
|
|
1370
|
+
import process15 from "process";
|
|
1371
|
+
function readKeys(input, paste = { active: false }) {
|
|
1372
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1373
|
+
}
|
|
1374
|
+
function roomAfter(question, columns) {
|
|
1375
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
1376
|
+
}
|
|
1377
|
+
function withCaret(colors, line, room, dim = false) {
|
|
1378
|
+
const { before, at, after } = visible(line, room);
|
|
1379
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
1380
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
1381
|
+
}
|
|
1382
|
+
function sharedStart(texts) {
|
|
1383
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
1384
|
+
let length = first.length;
|
|
1385
|
+
for (const chars of rest) {
|
|
1386
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
1387
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
1388
|
+
}
|
|
1389
|
+
return first.slice(0, length).join("");
|
|
1390
|
+
}
|
|
1391
|
+
function listed2(colors, found, columns) {
|
|
1392
|
+
const shared = sharedStart(found);
|
|
1393
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
1394
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
1395
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
1396
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
1397
|
+
}
|
|
1398
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
1399
|
+
let line = { text: "", caret: 0 };
|
|
1400
|
+
let invalid;
|
|
1401
|
+
let completions = [];
|
|
1402
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
1403
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
1404
|
+
let recalled = -1;
|
|
1405
|
+
let draft = line;
|
|
1406
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
1407
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
1408
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
1409
|
+
if (state !== "asking")
|
|
1410
|
+
return [answer(colors, question, state, shown())];
|
|
1411
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
1412
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
1413
|
+
}, (key) => {
|
|
1414
|
+
if (key === "cancel")
|
|
1415
|
+
return "cancel";
|
|
1416
|
+
invalid = undefined;
|
|
1417
|
+
completions = [];
|
|
1418
|
+
if (line.chained === true && endsKills(key))
|
|
1419
|
+
line = { ...line, chained: false };
|
|
1420
|
+
if (key === "tab") {
|
|
1421
|
+
const chars = [...line.text];
|
|
1422
|
+
const before = chars.slice(0, line.caret).join("");
|
|
1423
|
+
const found = complete?.(before) ?? [];
|
|
1424
|
+
const filled = sharedStart(found);
|
|
1425
|
+
if ([...filled].length > [...before].length)
|
|
1426
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
1427
|
+
else
|
|
1428
|
+
completions = found;
|
|
1429
|
+
return;
|
|
1430
|
+
}
|
|
1431
|
+
if (key === "enter") {
|
|
1432
|
+
invalid = validate?.(taken());
|
|
1433
|
+
return invalid === undefined ? "enter" : undefined;
|
|
1434
|
+
}
|
|
1435
|
+
if (key === "up" || key === "down") {
|
|
1436
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
1437
|
+
if (recalled === -1)
|
|
1438
|
+
draft = line;
|
|
1439
|
+
recalled = to;
|
|
1440
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
1441
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1444
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
1445
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
1446
|
+
line = editLine(line, edit);
|
|
1447
|
+
return;
|
|
1448
|
+
});
|
|
1449
|
+
if (!accepted)
|
|
1450
|
+
return;
|
|
1451
|
+
if (remembered !== undefined && taken() !== "")
|
|
1452
|
+
rememberAnswer(remembered, taken());
|
|
1453
|
+
return taken();
|
|
1454
|
+
}
|
|
1455
|
+
function answer(colors, question, state, picked) {
|
|
1456
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1457
|
+
}
|
|
1458
|
+
async function ask(question, { hint, terminal = process15 }, render, press) {
|
|
1459
|
+
const { stdin, stderr } = terminal;
|
|
1460
|
+
if (!isInteractive(terminal))
|
|
1461
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1462
|
+
const colors = paint(stderr);
|
|
1463
|
+
let current = "asking";
|
|
1464
|
+
let outcome;
|
|
1465
|
+
const columns = () => stderr.columns || 80;
|
|
1466
|
+
const draw = (state, last = false) => {
|
|
1467
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1468
|
+
const rows = rowsTaken(frame, columns());
|
|
1469
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1470
|
+
current = state;
|
|
1471
|
+
};
|
|
1472
|
+
const redraw = () => draw(current);
|
|
1473
|
+
const paste = { active: false };
|
|
1474
|
+
const stop = terminal.stop ?? (terminal === process15 ? stopJob : undefined);
|
|
1475
|
+
const suspend = () => {
|
|
1476
|
+
if (stop === undefined)
|
|
1477
|
+
return;
|
|
1478
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1479
|
+
stdin.setRawMode(false);
|
|
1480
|
+
stop();
|
|
1481
|
+
stdin.setRawMode(true);
|
|
1482
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1483
|
+
};
|
|
1484
|
+
try {
|
|
1485
|
+
stderr.on?.("resize", redraw);
|
|
1486
|
+
stdin.setRawMode(true);
|
|
1487
|
+
stdin.resume();
|
|
1488
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1489
|
+
draw("asking");
|
|
1490
|
+
return await new Promise((resolve) => {
|
|
1491
|
+
function onData(data) {
|
|
1492
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
1493
|
+
if (key === "suspend") {
|
|
1494
|
+
suspend();
|
|
1495
|
+
continue;
|
|
1496
|
+
}
|
|
1497
|
+
const pressed = press(key);
|
|
1498
|
+
if (pressed !== undefined) {
|
|
1499
|
+
settle(pressed);
|
|
1500
|
+
return;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
draw("asking");
|
|
1504
|
+
}
|
|
1505
|
+
function onEnd() {
|
|
1506
|
+
settle("cancel");
|
|
1507
|
+
}
|
|
1508
|
+
function settle(settled) {
|
|
1509
|
+
outcome = settled;
|
|
1510
|
+
stdin.off("data", onData);
|
|
1511
|
+
stdin.off("end", onEnd);
|
|
1512
|
+
resolve(settled === "enter");
|
|
1513
|
+
}
|
|
1514
|
+
stdin.on("data", onData);
|
|
1515
|
+
stdin.on("end", onEnd);
|
|
1516
|
+
});
|
|
1517
|
+
} finally {
|
|
1518
|
+
stderr.off?.("resize", redraw);
|
|
1519
|
+
draw(outcome ?? "cancel", true);
|
|
1520
|
+
stderr.write(`
|
|
1521
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1522
|
+
stdin.setRawMode(false);
|
|
1523
|
+
stdin.pause();
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
var PROMPT_KEYS, MAX_LISTED = 12;
|
|
1527
|
+
var init_prompt = __esm(() => {
|
|
1528
|
+
init_answers();
|
|
1529
|
+
init_args();
|
|
1530
|
+
init_format();
|
|
1531
|
+
init_job();
|
|
1532
|
+
init_mode();
|
|
1533
|
+
init_line();
|
|
1534
|
+
init_state();
|
|
1535
|
+
init_redraw();
|
|
1536
|
+
init_style();
|
|
1537
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1538
|
+
});
|
|
1539
|
+
|
|
1540
|
+
// src/gp.ts
|
|
1541
|
+
import process24 from "process";
|
|
1542
|
+
|
|
1543
|
+
// ../kit/src/index.ts
|
|
1544
|
+
init_args();
|
|
1545
|
+
|
|
817
1546
|
// ../kit/src/argv.ts
|
|
818
1547
|
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
819
1548
|
import { resolve as resolve3 } from "path";
|
|
@@ -838,7 +1567,17 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
838
1567
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
839
1568
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
840
1569
|
}
|
|
1570
|
+
// ../kit/src/chart.ts
|
|
1571
|
+
init_format();
|
|
1572
|
+
init_mode();
|
|
1573
|
+
init_style();
|
|
1574
|
+
init_theme();
|
|
1575
|
+
// ../kit/src/ci.ts
|
|
1576
|
+
init_args();
|
|
1577
|
+
init_format();
|
|
1578
|
+
|
|
841
1579
|
// ../kit/src/progress.ts
|
|
1580
|
+
init_format();
|
|
842
1581
|
import process12 from "process";
|
|
843
1582
|
|
|
844
1583
|
// ../kit/src/process.ts
|
|
@@ -884,10 +1623,10 @@ function holdSignals(cleanup) {
|
|
|
884
1623
|
process11.on(signal, onSignal);
|
|
885
1624
|
return held;
|
|
886
1625
|
}
|
|
887
|
-
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
1626
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
888
1627
|
const chunks = [];
|
|
889
1628
|
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 } : {} });
|
|
1629
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin: input === undefined ? stdin : new TextEncoder().encode(input), stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
891
1630
|
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
892
1631
|
const timers = [];
|
|
893
1632
|
const killGroup = (killing) => {
|
|
@@ -964,6 +1703,8 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
964
1703
|
}
|
|
965
1704
|
|
|
966
1705
|
// ../kit/src/progress.ts
|
|
1706
|
+
init_style();
|
|
1707
|
+
init_theme();
|
|
967
1708
|
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
968
1709
|
var FRAME_MS = 200;
|
|
969
1710
|
var BAR_WIDTH = 20;
|
|
@@ -981,10 +1722,14 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
981
1722
|
}, print: (text) => void stream.write(`${text}
|
|
982
1723
|
`), stop: () => {
|
|
983
1724
|
return;
|
|
1725
|
+
}, pause: () => () => {
|
|
1726
|
+
return;
|
|
984
1727
|
} };
|
|
985
1728
|
const write = stream.write.bind(stream);
|
|
986
1729
|
let frame = 0;
|
|
987
1730
|
let drawn = false;
|
|
1731
|
+
let paused = false;
|
|
1732
|
+
let stopped = false;
|
|
988
1733
|
const columns = () => {
|
|
989
1734
|
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
990
1735
|
return now === undefined || now === 0 ? 80 : now;
|
|
@@ -995,6 +1740,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
995
1740
|
drawn = false;
|
|
996
1741
|
};
|
|
997
1742
|
const draw = () => {
|
|
1743
|
+
if (paused)
|
|
1744
|
+
return;
|
|
998
1745
|
const width = columns() - 1;
|
|
999
1746
|
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
1000
1747
|
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
@@ -1006,16 +1753,17 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1006
1753
|
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
1007
1754
|
drawn = true;
|
|
1008
1755
|
};
|
|
1009
|
-
|
|
1756
|
+
let timer = setInterval(draw, FRAME_MS);
|
|
1010
1757
|
stream.on?.("resize", draw);
|
|
1011
|
-
|
|
1012
|
-
|
|
1758
|
+
let restore = interceptOutput(clear);
|
|
1759
|
+
let release = swallowInput();
|
|
1013
1760
|
const onExit = () => {
|
|
1014
1761
|
clear();
|
|
1015
1762
|
release();
|
|
1016
1763
|
};
|
|
1017
1764
|
const signals = holdSignals(stop);
|
|
1018
1765
|
function stop() {
|
|
1766
|
+
stopped = true;
|
|
1019
1767
|
clearInterval(timer);
|
|
1020
1768
|
stream.off?.("resize", draw);
|
|
1021
1769
|
clear();
|
|
@@ -1024,6 +1772,29 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1024
1772
|
process12.off("exit", onExit);
|
|
1025
1773
|
signals.release();
|
|
1026
1774
|
}
|
|
1775
|
+
function pause() {
|
|
1776
|
+
if (paused || stopped)
|
|
1777
|
+
return () => {
|
|
1778
|
+
return;
|
|
1779
|
+
};
|
|
1780
|
+
paused = true;
|
|
1781
|
+
clearInterval(timer);
|
|
1782
|
+
stream.off?.("resize", draw);
|
|
1783
|
+
clear();
|
|
1784
|
+
restore();
|
|
1785
|
+
release();
|
|
1786
|
+
return () => {
|
|
1787
|
+
if (!paused || stopped)
|
|
1788
|
+
return;
|
|
1789
|
+
paused = false;
|
|
1790
|
+
timer = setInterval(draw, FRAME_MS);
|
|
1791
|
+
timer.unref();
|
|
1792
|
+
stream.on?.("resize", draw);
|
|
1793
|
+
restore = interceptOutput(clear);
|
|
1794
|
+
release = swallowInput();
|
|
1795
|
+
draw();
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1027
1798
|
timer.unref();
|
|
1028
1799
|
process12.on("exit", onExit);
|
|
1029
1800
|
return {
|
|
@@ -1034,7 +1805,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1034
1805
|
`);
|
|
1035
1806
|
draw();
|
|
1036
1807
|
},
|
|
1037
|
-
stop
|
|
1808
|
+
stop,
|
|
1809
|
+
pause
|
|
1038
1810
|
};
|
|
1039
1811
|
}
|
|
1040
1812
|
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
@@ -1059,6 +1831,7 @@ function progressLine(stream = process12.stderr, env = process12.env) {
|
|
|
1059
1831
|
}
|
|
1060
1832
|
},
|
|
1061
1833
|
stop: region.stop,
|
|
1834
|
+
pause: region.pause,
|
|
1062
1835
|
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1063
1836
|
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1064
1837
|
};
|
|
@@ -1147,10 +1920,127 @@ function interceptOutput(clear) {
|
|
|
1147
1920
|
}
|
|
1148
1921
|
};
|
|
1149
1922
|
}
|
|
1923
|
+
|
|
1924
|
+
// ../kit/src/ci.ts
|
|
1925
|
+
init_style();
|
|
1926
|
+
|
|
1927
|
+
// ../kit/src/tool.ts
|
|
1928
|
+
init_format();
|
|
1150
1929
|
// ../kit/src/cli.ts
|
|
1151
|
-
|
|
1152
|
-
import {
|
|
1153
|
-
import
|
|
1930
|
+
init_args();
|
|
1931
|
+
import { readFileSync as readFileSync5, realpathSync as realpathSync2 } from "fs";
|
|
1932
|
+
import { dirname as dirname4, join as join8 } from "path";
|
|
1933
|
+
import process19 from "process";
|
|
1934
|
+
|
|
1935
|
+
// ../kit/src/askpass.ts
|
|
1936
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
1937
|
+
import { tmpdir } from "os";
|
|
1938
|
+
import { join as join6 } from "path";
|
|
1939
|
+
import process16 from "process";
|
|
1940
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1941
|
+
var ECHOED = /username|yes\/no/i;
|
|
1942
|
+
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1943
|
+
function askpass(pause = () => () => {
|
|
1944
|
+
return;
|
|
1945
|
+
}) {
|
|
1946
|
+
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1947
|
+
return;
|
|
1948
|
+
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1949
|
+
const socketPath = join6(dir, "socket");
|
|
1950
|
+
const script = join6(dir, "askpass");
|
|
1951
|
+
let turn = Promise.resolve();
|
|
1952
|
+
const answer = async ({ prompt, notice }) => {
|
|
1953
|
+
const resume = pause();
|
|
1954
|
+
try {
|
|
1955
|
+
if (notice === true) {
|
|
1956
|
+
process16.stderr.write(`${prompt.trim()}
|
|
1957
|
+
`);
|
|
1958
|
+
return {};
|
|
1959
|
+
}
|
|
1960
|
+
await Promise.resolve().then(() => init_prompt());
|
|
1961
|
+
return { answer: await input2(prompt.trim(), { mask: !ECHOED.test(prompt) }) };
|
|
1962
|
+
} finally {
|
|
1963
|
+
resume();
|
|
1964
|
+
}
|
|
1965
|
+
};
|
|
1966
|
+
const respond = async (socket, request) => {
|
|
1967
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1968
|
+
const previous = turn;
|
|
1969
|
+
let reply = {};
|
|
1970
|
+
turn = promise;
|
|
1971
|
+
await previous;
|
|
1972
|
+
try {
|
|
1973
|
+
reply = await answer(request);
|
|
1974
|
+
} catch {} finally {
|
|
1975
|
+
socket.end(`${JSON.stringify(reply)}
|
|
1976
|
+
`);
|
|
1977
|
+
resolve();
|
|
1978
|
+
}
|
|
1979
|
+
};
|
|
1980
|
+
const server = Bun.listen({
|
|
1981
|
+
unix: socketPath,
|
|
1982
|
+
socket: {
|
|
1983
|
+
open: (socket) => {
|
|
1984
|
+
socket.data = { buffered: "" };
|
|
1985
|
+
},
|
|
1986
|
+
data: (socket, chunk) => {
|
|
1987
|
+
const before = socket.data.buffered;
|
|
1988
|
+
socket.data.buffered += chunk.toString();
|
|
1989
|
+
if (before.includes(`
|
|
1990
|
+
`) || !socket.data.buffered.includes(`
|
|
1991
|
+
`))
|
|
1992
|
+
return;
|
|
1993
|
+
respond(socket, JSON.parse(socket.data.buffered));
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
});
|
|
1997
|
+
writeFileSync2(script, `#!/bin/sh
|
|
1998
|
+
${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no-env-file --config=/dev/null ${quoted(process16.argv[1])} "$@"
|
|
1999
|
+
`);
|
|
2000
|
+
chmodSync(script, 448);
|
|
2001
|
+
return {
|
|
2002
|
+
env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
|
|
2003
|
+
close: () => {
|
|
2004
|
+
server.stop(true);
|
|
2005
|
+
rmSync(dir, { recursive: true, force: true });
|
|
2006
|
+
}
|
|
2007
|
+
};
|
|
2008
|
+
}
|
|
2009
|
+
async function askpassClient(argv) {
|
|
2010
|
+
const socketPath = process16.env[SOCKET_VARIABLE];
|
|
2011
|
+
if (socketPath === undefined)
|
|
2012
|
+
return;
|
|
2013
|
+
const request = { prompt: argv[0] ?? "", ...process16.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
2014
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
2015
|
+
let received = "";
|
|
2016
|
+
try {
|
|
2017
|
+
await Bun.connect({
|
|
2018
|
+
unix: socketPath,
|
|
2019
|
+
socket: {
|
|
2020
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
2021
|
+
`),
|
|
2022
|
+
data: (_, chunk) => {
|
|
2023
|
+
received += chunk.toString();
|
|
2024
|
+
},
|
|
2025
|
+
close: () => resolve(received),
|
|
2026
|
+
error: () => resolve("")
|
|
2027
|
+
}
|
|
2028
|
+
});
|
|
2029
|
+
} catch {
|
|
2030
|
+
return 1;
|
|
2031
|
+
}
|
|
2032
|
+
const reply = await promise;
|
|
2033
|
+
if (reply === "")
|
|
2034
|
+
return 1;
|
|
2035
|
+
const { answer } = JSON.parse(reply);
|
|
2036
|
+
if (request.notice === true)
|
|
2037
|
+
return 0;
|
|
2038
|
+
if (answer === undefined)
|
|
2039
|
+
return 1;
|
|
2040
|
+
process16.stdout.write(`${answer}
|
|
2041
|
+
`);
|
|
2042
|
+
return 0;
|
|
2043
|
+
}
|
|
1154
2044
|
|
|
1155
2045
|
// ../kit/src/completions.ts
|
|
1156
2046
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -1213,28 +2103,34 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
1213
2103
|
}
|
|
1214
2104
|
|
|
1215
2105
|
// ../kit/src/notify.ts
|
|
1216
|
-
|
|
2106
|
+
init_format();
|
|
2107
|
+
init_mode();
|
|
2108
|
+
import process17 from "process";
|
|
1217
2109
|
var NOTIFY_AFTER_MS = 1e4;
|
|
1218
2110
|
var CANCELLED = 130;
|
|
1219
2111
|
function base64(text) {
|
|
1220
2112
|
return Buffer.from(text).toString("base64");
|
|
1221
2113
|
}
|
|
1222
|
-
function notification(title, body, env =
|
|
1223
|
-
const id = `kit${
|
|
2114
|
+
function notification(title, body, env = process17.env) {
|
|
2115
|
+
const id = `kit${process17.pid}`;
|
|
1224
2116
|
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\\`];
|
|
1225
2117
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1226
2118
|
}
|
|
1227
|
-
function notifyEnd(command, code, ms, { stream =
|
|
2119
|
+
function notifyEnd(command, code, ms, { stream = process17.stderr, env = process17.env } = {}) {
|
|
1228
2120
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1229
2121
|
return;
|
|
1230
2122
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1231
2123
|
}
|
|
1232
2124
|
|
|
2125
|
+
// ../kit/src/cli.ts
|
|
2126
|
+
init_style();
|
|
2127
|
+
init_text2();
|
|
2128
|
+
|
|
1233
2129
|
// ../kit/src/usage.ts
|
|
1234
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
1235
|
-
import { homedir as
|
|
1236
|
-
import { dirname as
|
|
1237
|
-
import
|
|
2130
|
+
import { appendFileSync, mkdirSync as mkdirSync2 } from "fs";
|
|
2131
|
+
import { homedir as homedir4 } from "os";
|
|
2132
|
+
import { dirname as dirname3, isAbsolute, join as join7 } from "path";
|
|
2133
|
+
import process18 from "process";
|
|
1238
2134
|
|
|
1239
2135
|
// ../kit/src/logs.ts
|
|
1240
2136
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1248,14 +2144,14 @@ var usageError;
|
|
|
1248
2144
|
function noteUsageError(message) {
|
|
1249
2145
|
usageError = message;
|
|
1250
2146
|
}
|
|
1251
|
-
function stateHome(env =
|
|
2147
|
+
function stateHome(env = process18.env) {
|
|
1252
2148
|
const dir = env.XDG_STATE_HOME;
|
|
1253
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
2149
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join7(homedir4(), ".local", "state");
|
|
1254
2150
|
}
|
|
1255
|
-
function usagePath(env =
|
|
1256
|
-
return
|
|
2151
|
+
function usagePath(env = process18.env) {
|
|
2152
|
+
return join7(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1257
2153
|
}
|
|
1258
|
-
function usageRecorded(env =
|
|
2154
|
+
function usageRecorded(env = process18.env) {
|
|
1259
2155
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1260
2156
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1261
2157
|
}
|
|
@@ -1264,17 +2160,17 @@ function flagNames(argv) {
|
|
|
1264
2160
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1265
2161
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1266
2162
|
}
|
|
1267
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
2163
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
1268
2164
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1269
2165
|
usageError = undefined;
|
|
1270
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
2166
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1271
2167
|
}
|
|
1272
|
-
function recordUsage(entry, env =
|
|
2168
|
+
function recordUsage(entry, env = process18.env) {
|
|
1273
2169
|
if (!usageRecorded(env))
|
|
1274
2170
|
return;
|
|
1275
2171
|
try {
|
|
1276
2172
|
const path = usagePath(env);
|
|
1277
|
-
|
|
2173
|
+
mkdirSync2(dirname3(path), { recursive: true, mode: 448 });
|
|
1278
2174
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1279
2175
|
`, { mode: 384 });
|
|
1280
2176
|
} catch {}
|
|
@@ -1291,8 +2187,8 @@ var TOP_OPTIONS = {
|
|
|
1291
2187
|
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1292
2188
|
};
|
|
1293
2189
|
function printError(prefix, message, hint, cause) {
|
|
1294
|
-
const colors = paint(
|
|
1295
|
-
const styled = takesControlCodes(
|
|
2190
|
+
const colors = paint(process19.stderr);
|
|
2191
|
+
const styled = takesControlCodes(process19.stderr);
|
|
1296
2192
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1297
2193
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1298
2194
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1395,17 +2291,20 @@ function packageVersion(entry = Bun.main) {
|
|
|
1395
2291
|
try {
|
|
1396
2292
|
resolved = realpathSync2(entry);
|
|
1397
2293
|
} catch {}
|
|
1398
|
-
for (let dir =
|
|
2294
|
+
for (let dir = dirname4(resolved);; dir = dirname4(dir)) {
|
|
1399
2295
|
try {
|
|
1400
|
-
const { version } = JSON.parse(
|
|
2296
|
+
const { version } = JSON.parse(readFileSync5(join8(dir, "package.json"), "utf8"));
|
|
1401
2297
|
if (typeof version === "string")
|
|
1402
2298
|
return version;
|
|
1403
2299
|
} catch {}
|
|
1404
|
-
if (
|
|
2300
|
+
if (dirname4(dir) === dir)
|
|
1405
2301
|
return "0.0.0";
|
|
1406
2302
|
}
|
|
1407
2303
|
}
|
|
1408
2304
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
2305
|
+
const answered = await askpassClient(argv);
|
|
2306
|
+
if (answered !== undefined)
|
|
2307
|
+
return answered;
|
|
1409
2308
|
if (argv[0] === COMPLETE)
|
|
1410
2309
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1411
2310
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -1424,21 +2323,51 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1424
2323
|
notifyEnd(name, code, performance.now() - started);
|
|
1425
2324
|
if (usage !== false) {
|
|
1426
2325
|
try {
|
|
1427
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
2326
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
1428
2327
|
} catch {}
|
|
1429
2328
|
}
|
|
1430
2329
|
return code;
|
|
1431
2330
|
}
|
|
1432
|
-
|
|
1433
|
-
|
|
2331
|
+
|
|
2332
|
+
// ../kit/src/index.ts
|
|
2333
|
+
init_config();
|
|
2334
|
+
|
|
2335
|
+
// ../kit/src/excerpt.ts
|
|
2336
|
+
init_text2();
|
|
2337
|
+
|
|
2338
|
+
// ../kit/src/index.ts
|
|
2339
|
+
init_folders();
|
|
2340
|
+
init_format();
|
|
2341
|
+
|
|
2342
|
+
// ../kit/src/git.ts
|
|
2343
|
+
init_args();
|
|
2344
|
+
// ../kit/src/limit.ts
|
|
2345
|
+
init_args();
|
|
2346
|
+
|
|
2347
|
+
// ../kit/src/index.ts
|
|
2348
|
+
init_mode();
|
|
2349
|
+
|
|
2350
|
+
// ../kit/src/report.ts
|
|
2351
|
+
init_style();
|
|
2352
|
+
init_text2();
|
|
1434
2353
|
// ../kit/src/secrets.ts
|
|
1435
2354
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1436
2355
|
// ../kit/src/sessions.ts
|
|
1437
2356
|
var {Glob } = globalThis.Bun;
|
|
1438
2357
|
var SESSION_FILES = new Glob("*.json");
|
|
1439
2358
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
2359
|
+
|
|
2360
|
+
// ../kit/src/index.ts
|
|
2361
|
+
init_style();
|
|
2362
|
+
init_text2();
|
|
2363
|
+
init_theme();
|
|
2364
|
+
init_user_config();
|
|
2365
|
+
|
|
1440
2366
|
// ../kit/src/watch.ts
|
|
1441
|
-
|
|
2367
|
+
init_args();
|
|
2368
|
+
init_input();
|
|
2369
|
+
init_style();
|
|
2370
|
+
import process20 from "process";
|
|
1442
2371
|
import { format } from "util";
|
|
1443
2372
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1444
2373
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1460,7 +2389,7 @@ function withoutWatch(args) {
|
|
|
1460
2389
|
}
|
|
1461
2390
|
return rest;
|
|
1462
2391
|
}
|
|
1463
|
-
async function watching(value, step, stream =
|
|
2392
|
+
async function watching(value, step, stream = process20.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1464
2393
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1465
2394
|
if (!takesControlCodes(stream))
|
|
1466
2395
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1468,12 +2397,12 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1468
2397
|
for (let round = 0;round < rounds; round++) {
|
|
1469
2398
|
const held = [];
|
|
1470
2399
|
const { log, info } = console;
|
|
1471
|
-
const write =
|
|
2400
|
+
const write = process20.stdout.write.bind(process20.stdout);
|
|
1472
2401
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1473
2402
|
`);
|
|
1474
2403
|
console.log = hold;
|
|
1475
2404
|
console.info = hold;
|
|
1476
|
-
|
|
2405
|
+
process20.stdout.write = (text) => {
|
|
1477
2406
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1478
2407
|
return true;
|
|
1479
2408
|
};
|
|
@@ -1482,7 +2411,7 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1482
2411
|
} finally {
|
|
1483
2412
|
console.log = log;
|
|
1484
2413
|
console.info = info;
|
|
1485
|
-
|
|
2414
|
+
process20.stdout.write = write;
|
|
1486
2415
|
}
|
|
1487
2416
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1488
2417
|
await sleep(interval);
|
|
@@ -1490,21 +2419,22 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1490
2419
|
return code;
|
|
1491
2420
|
}
|
|
1492
2421
|
// ../kit/src/workspace-root.ts
|
|
1493
|
-
|
|
1494
|
-
import {
|
|
1495
|
-
import
|
|
2422
|
+
init_user_config();
|
|
2423
|
+
import { homedir as homedir5 } from "os";
|
|
2424
|
+
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2425
|
+
import process21 from "process";
|
|
1496
2426
|
function expandHome(path, home) {
|
|
1497
2427
|
if (path === "~")
|
|
1498
2428
|
return home;
|
|
1499
|
-
return path.startsWith("~/") ?
|
|
2429
|
+
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
1500
2430
|
}
|
|
1501
2431
|
function configured(env, home) {
|
|
1502
2432
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1503
2433
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1504
2434
|
}
|
|
1505
|
-
function workspaceRoot({ given, env =
|
|
2435
|
+
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
1506
2436
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1507
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ??
|
|
2437
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
1508
2438
|
}
|
|
1509
2439
|
// src/git.ts
|
|
1510
2440
|
async function git2(args, env) {
|
|
@@ -1515,8 +2445,8 @@ async function git2(args, env) {
|
|
|
1515
2445
|
|
|
1516
2446
|
// src/repos.ts
|
|
1517
2447
|
import { readdir } from "fs/promises";
|
|
1518
|
-
import { join as
|
|
1519
|
-
import
|
|
2448
|
+
import { join as join10, relative, resolve as resolve5 } from "path";
|
|
2449
|
+
import process23 from "process";
|
|
1520
2450
|
|
|
1521
2451
|
// src/status.ts
|
|
1522
2452
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -1612,7 +2542,7 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
1612
2542
|
found.push(dir);
|
|
1613
2543
|
if (left === 0)
|
|
1614
2544
|
return;
|
|
1615
|
-
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(
|
|
2545
|
+
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join10(dir, entry.name), left - 1)));
|
|
1616
2546
|
}
|
|
1617
2547
|
await walk(resolve5(root), depth);
|
|
1618
2548
|
return found.sort();
|
|
@@ -1622,14 +2552,14 @@ async function toplevelOf(dir) {
|
|
|
1622
2552
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
1623
2553
|
}
|
|
1624
2554
|
async function reposOf(roots) {
|
|
1625
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2555
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process23.cwd()];
|
|
1626
2556
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
1627
2557
|
return [...new Set(found.flat())].sort();
|
|
1628
2558
|
}
|
|
1629
2559
|
async function repoState(dir) {
|
|
1630
2560
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
1631
2561
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
1632
|
-
return { path: relative(
|
|
2562
|
+
return { path: relative(process23.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
1633
2563
|
}
|
|
1634
2564
|
function trackingOf(status) {
|
|
1635
2565
|
if (status.upstream === null)
|
|
@@ -1665,7 +2595,7 @@ async function dirsOf(positionals, all) {
|
|
|
1665
2595
|
}
|
|
1666
2596
|
|
|
1667
2597
|
// src/gp.ts
|
|
1668
|
-
var USAGE = `gp [dir]...: pushes the current branch of the repository, or of each dir
|
|
2598
|
+
var USAGE = `gp [dir]...: pushes the current branch of the repository, or of each dir, when it is ahead of its upstream or has none yet
|
|
1669
2599
|
|
|
1670
2600
|
--repos pushes every repository at and below the current one's toplevel, or below each dir given, the way gst --repos lists them. A detached HEAD, a branch with nothing to push and a repository with no remote are skipped, saying so; the pushes run one after another.
|
|
1671
2601
|
What follows -- goes to every git push as is (gp -- --tags, gp -- --force-with-lease), and a branch with nothing ahead is then pushed too.`;
|
|
@@ -1692,7 +2622,7 @@ async function unpushed(dir, branch) {
|
|
|
1692
2622
|
const count = await git2(["-C", dir, "rev-list", "--count", branch, "--not", "--remotes"]);
|
|
1693
2623
|
return count.code === 0 ? Number(count.stdout.trim()) : null;
|
|
1694
2624
|
}
|
|
1695
|
-
async function push(repo, { dryRun, extra }) {
|
|
2625
|
+
async function push(repo, { dryRun, extra, env }) {
|
|
1696
2626
|
const { path, dir, status } = repo;
|
|
1697
2627
|
const skipped = (reason, branch = null) => ({ path, branch, remote: null, commits: null, outcome: "skipped", reason });
|
|
1698
2628
|
if (status === null)
|
|
@@ -1719,20 +2649,20 @@ async function push(repo, { dryRun, extra }) {
|
|
|
1719
2649
|
}
|
|
1720
2650
|
if (dryRun)
|
|
1721
2651
|
return { path, branch, remote, commits, outcome: "would-push" };
|
|
1722
|
-
const pushed = await git2(["-C", dir, ...args]);
|
|
2652
|
+
const pushed = await git2(["-C", dir, ...args], env);
|
|
1723
2653
|
return pushed.code === 0 ? { path, branch, remote, commits, outcome: "pushed" } : { path, branch, remote, commits, outcome: "refused", reason: whyRefused(pushed.stderr) };
|
|
1724
2654
|
}
|
|
1725
2655
|
function line(result) {
|
|
1726
|
-
const { dim } = paint(
|
|
2656
|
+
const { dim } = paint(process24.stdout);
|
|
1727
2657
|
const sent = result.commits === null ? "" : `, ${result.commits} ${result.commits === 1 ? "commit" : "commits"}`;
|
|
1728
2658
|
const what = `${result.branch} -> ${result.remote}${sent}`;
|
|
1729
2659
|
const said = {
|
|
1730
|
-
pushed: () => marked("ok", `pushed ${what}`,
|
|
2660
|
+
pushed: () => marked("ok", `pushed ${what}`, process24.stdout),
|
|
1731
2661
|
"would-push": () => `would push ${what}`,
|
|
1732
2662
|
skipped: () => dim(result.reason ?? "skipped"),
|
|
1733
|
-
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`,
|
|
2663
|
+
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process24.stdout)
|
|
1734
2664
|
}[result.outcome];
|
|
1735
|
-
return [role("path",
|
|
2665
|
+
return [role("path", process24.stdout)(result.path), said()];
|
|
1736
2666
|
}
|
|
1737
2667
|
async function main(argv) {
|
|
1738
2668
|
const { values, positionals, rest = [] } = parse(argv, USAGE, OPTIONS, { positionals: ["[dir]..."], rest: true, exits: EXITS, replaces: "git push, git push -u origin <branch> and a git -C <repo> push per nested repository", examples: ["gp", ["gp --repos", "every repository nested in this one"], ["gp --repos --dry-run", "what would go out"], ["gp . ../other", "this repository and a sibling"], ["gp -- --force-with-lease", "flags for git push"]] });
|
|
@@ -1740,15 +2670,21 @@ async function main(argv) {
|
|
|
1740
2670
|
const repos = await Promise.all(dirs.map(repoState));
|
|
1741
2671
|
const results = [];
|
|
1742
2672
|
const progress = progressLine();
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
2673
|
+
const prompts = askpass(progress.pause);
|
|
2674
|
+
const env = prompts === undefined ? undefined : { ...process24.env, ...prompts.env };
|
|
2675
|
+
try {
|
|
2676
|
+
for (const [at, repo] of repos.entries()) {
|
|
2677
|
+
progress.update(repos.length > 1 ? { step: `pushing ${repo.path}`, done: at, total: repos.length, unit: "repositories" } : { step: `pushing ${repo.path}` });
|
|
2678
|
+
results.push(await push(repo, { dryRun: values["dry-run"] === true, extra: rest, env }));
|
|
2679
|
+
}
|
|
2680
|
+
} finally {
|
|
2681
|
+
prompts?.close();
|
|
2682
|
+
progress.stop();
|
|
1746
2683
|
}
|
|
1747
|
-
progress.stop();
|
|
1748
2684
|
if (values.json === true)
|
|
1749
2685
|
printJson(results);
|
|
1750
2686
|
else
|
|
1751
2687
|
console.log(table(results.map(line)));
|
|
1752
2688
|
return results.some((result) => result.outcome === "refused") ? 1 : 0;
|
|
1753
2689
|
}
|
|
1754
|
-
|
|
2690
|
+
process24.exitCode = await runMain({ name: "gp", run: main });
|