@kaynooo/cli-git 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gb.js +231 -62
- package/dist/gc.js +156 -47
- package/dist/gst.js +164 -52
- package/package.json +2 -2
package/dist/gb.js
CHANGED
|
@@ -2,13 +2,37 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gb.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
|
+
// ../kit/src/format.ts
|
|
11
|
+
import process7 from "process";
|
|
12
|
+
|
|
13
|
+
// ../kit/src/mode.ts
|
|
14
|
+
import process2 from "process";
|
|
15
|
+
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
16
|
+
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
17
|
+
function isSet(value) {
|
|
18
|
+
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
19
|
+
}
|
|
20
|
+
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
21
|
+
const chosen = env.KIT_MODE;
|
|
22
|
+
if (chosen !== undefined && MODES.has(chosen))
|
|
23
|
+
return chosen;
|
|
24
|
+
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
25
|
+
return "agent";
|
|
26
|
+
if (stream.isTTY === true)
|
|
27
|
+
return "terminal";
|
|
28
|
+
return isSet(env.CI) ? "ci" : "pipe";
|
|
29
|
+
}
|
|
30
|
+
function isInteractive(streams = process2) {
|
|
31
|
+
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
32
|
+
}
|
|
33
|
+
|
|
10
34
|
// ../kit/src/style.ts
|
|
11
|
-
import
|
|
35
|
+
import process6 from "process";
|
|
12
36
|
|
|
13
37
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
14
38
|
function x(s) {
|
|
@@ -275,13 +299,13 @@ var t = le();
|
|
|
275
299
|
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
276
300
|
import { homedir as homedir2 } from "os";
|
|
277
301
|
import { join as join3, resolve as resolve2 } from "path";
|
|
278
|
-
import
|
|
302
|
+
import process5 from "process";
|
|
279
303
|
|
|
280
304
|
// ../kit/src/config.ts
|
|
281
305
|
import { existsSync } from "fs";
|
|
282
306
|
import { dirname, join, resolve } from "path";
|
|
283
|
-
import
|
|
284
|
-
function findUp(names, from =
|
|
307
|
+
import process3 from "process";
|
|
308
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
285
309
|
const wanted = typeof names === "string" ? [names] : names;
|
|
286
310
|
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
287
311
|
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
@@ -295,9 +319,9 @@ function findUp(names, from = process2.cwd(), stop = () => false) {
|
|
|
295
319
|
// ../kit/src/user-config.ts
|
|
296
320
|
import { homedir } from "os";
|
|
297
321
|
import { join as join2 } from "path";
|
|
298
|
-
import
|
|
322
|
+
import process4 from "process";
|
|
299
323
|
function configBase(where = {}) {
|
|
300
|
-
const xdg = where.xdg ?? (where.home === undefined ?
|
|
324
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
301
325
|
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
302
326
|
}
|
|
303
327
|
function userConfigPath(bin, where = {}) {
|
|
@@ -330,10 +354,30 @@ function isColorSpec(spec) {
|
|
|
330
354
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
331
355
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
332
356
|
}
|
|
333
|
-
|
|
357
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
358
|
+
function cubeLevel(channel) {
|
|
359
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
360
|
+
}
|
|
361
|
+
function nearest256(hex) {
|
|
362
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
363
|
+
const levels = rgb.map(cubeLevel);
|
|
364
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
365
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
366
|
+
const greyValue = 8 + grey * 10;
|
|
367
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
368
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
369
|
+
}
|
|
370
|
+
function hasTrueColor(env) {
|
|
371
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
372
|
+
}
|
|
373
|
+
function tinted(colors, spec, env = process5.env) {
|
|
334
374
|
if (typeof spec === "number")
|
|
335
375
|
return colors.ansi256(spec);
|
|
336
|
-
return spec.trim().split(SPACES).reduce((chain, token) =>
|
|
376
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
377
|
+
if (HEX.test(token))
|
|
378
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
379
|
+
return chain[token] ?? chain;
|
|
380
|
+
}, colors);
|
|
337
381
|
}
|
|
338
382
|
function isRecord(value) {
|
|
339
383
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -417,7 +461,7 @@ function warnOnce(message) {
|
|
|
417
461
|
function isPath(chosen) {
|
|
418
462
|
return chosen.includes("/") || chosen.endsWith(".json");
|
|
419
463
|
}
|
|
420
|
-
function loadTheme({ env =
|
|
464
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
421
465
|
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
|
|
422
466
|
const sources = [];
|
|
423
467
|
const chosen = env.KIT_THEME ?? "";
|
|
@@ -447,7 +491,7 @@ function loadTheme({ env = process4.env, from = process4.cwd(), home = homedir2(
|
|
|
447
491
|
var current;
|
|
448
492
|
var currentKey = "";
|
|
449
493
|
function activeTheme() {
|
|
450
|
-
const key = `${
|
|
494
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
451
495
|
if (current === undefined || key !== currentKey) {
|
|
452
496
|
current = loadTheme();
|
|
453
497
|
currentKey = key;
|
|
@@ -456,20 +500,20 @@ function activeTheme() {
|
|
|
456
500
|
}
|
|
457
501
|
|
|
458
502
|
// ../kit/src/style.ts
|
|
459
|
-
function takesControlCodes(stream, env =
|
|
460
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
503
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
504
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
461
505
|
}
|
|
462
|
-
function paint(stream, env =
|
|
506
|
+
function paint(stream, env = process6.env) {
|
|
463
507
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
464
508
|
}
|
|
465
|
-
function role(name, stream, env =
|
|
509
|
+
function role(name, stream, env = process6.env) {
|
|
466
510
|
const colors = paint(stream, env);
|
|
467
|
-
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name]) : colors;
|
|
511
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
468
512
|
}
|
|
469
513
|
var STATUS_WORDS = {
|
|
470
514
|
passed: ["passed", "success", "succeeded", "ok"],
|
|
471
515
|
failed: ["failed", "failure", "error", "errored"],
|
|
472
|
-
running: ["running", "in_progress", "started"],
|
|
516
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
473
517
|
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
474
518
|
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
475
519
|
};
|
|
@@ -481,32 +525,35 @@ function upTo(text, separator) {
|
|
|
481
525
|
return end === -1 ? text : text.slice(0, end);
|
|
482
526
|
}
|
|
483
527
|
var ESCAPE = String.fromCharCode(27);
|
|
528
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
529
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
530
|
+
}
|
|
484
531
|
function printJson(value) {
|
|
485
|
-
console.log(
|
|
532
|
+
console.log(jsonText(value));
|
|
486
533
|
}
|
|
487
534
|
|
|
488
535
|
// ../kit/src/help.ts
|
|
489
|
-
import
|
|
536
|
+
import process8 from "process";
|
|
490
537
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
491
538
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
492
539
|
var FULL_STOP = /\.$/;
|
|
493
|
-
function usageLine(usage, colors = paint(
|
|
540
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
494
541
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
495
542
|
}
|
|
496
|
-
function helpText(usage, options, colors = paint(
|
|
543
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
497
544
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
498
545
|
`);
|
|
499
546
|
}
|
|
500
|
-
function exitRows(exits, colors = paint(
|
|
547
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
501
548
|
if (exits.length === 0)
|
|
502
549
|
return [];
|
|
503
550
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
504
551
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
505
552
|
}
|
|
506
|
-
function replacesRows(replaces, colors = paint(
|
|
507
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
553
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
554
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
508
555
|
}
|
|
509
|
-
function wantsHelpJson(env =
|
|
556
|
+
function wantsHelpJson(env = process8.env) {
|
|
510
557
|
return env.KIT_HELP === "json";
|
|
511
558
|
}
|
|
512
559
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -525,12 +572,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
525
572
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
526
573
|
};
|
|
527
574
|
}
|
|
528
|
-
function exampleRows(examples, colors = paint(
|
|
529
|
-
if (examples.length === 0)
|
|
575
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
576
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
530
577
|
return [];
|
|
531
578
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
532
579
|
}
|
|
533
|
-
function optionRows(options, colors = paint(
|
|
580
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
534
581
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
535
582
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
536
583
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -571,13 +618,23 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
571
618
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
572
619
|
return number;
|
|
573
620
|
}
|
|
621
|
+
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
622
|
+
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
623
|
+
function duration(value, name, fallback, unit = "s") {
|
|
624
|
+
if (value === undefined)
|
|
625
|
+
return fallback;
|
|
626
|
+
const match = DURATION.exec(value.trim());
|
|
627
|
+
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
628
|
+
if (ms < 1)
|
|
629
|
+
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
630
|
+
return ms;
|
|
631
|
+
}
|
|
574
632
|
|
|
575
633
|
// ../kit/src/args.ts
|
|
576
634
|
var DASHES = /^-+/;
|
|
577
635
|
function jsonOption(holds) {
|
|
578
636
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
579
637
|
}
|
|
580
|
-
|
|
581
638
|
class Exit extends Error {
|
|
582
639
|
code;
|
|
583
640
|
hint;
|
|
@@ -621,7 +678,7 @@ var OUTPUT_OPTIONS = {
|
|
|
621
678
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
622
679
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
623
680
|
};
|
|
624
|
-
function applyOutput(color, plain, env =
|
|
681
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
625
682
|
const when = plain === true ? "never" : color ?? "auto";
|
|
626
683
|
if (when === "auto")
|
|
627
684
|
return;
|
|
@@ -792,7 +849,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
792
849
|
}
|
|
793
850
|
// ../kit/src/process.ts
|
|
794
851
|
import { constants } from "os";
|
|
795
|
-
import
|
|
852
|
+
import process10 from "process";
|
|
796
853
|
var KILL_GRACE_MS = 2000;
|
|
797
854
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
798
855
|
function exitCodeOf(code, signal) {
|
|
@@ -814,7 +871,7 @@ function holdSignals(cleanup) {
|
|
|
814
871
|
},
|
|
815
872
|
release: () => {
|
|
816
873
|
for (const signal of SIGNALS)
|
|
817
|
-
|
|
874
|
+
process10.off(signal, onSignal);
|
|
818
875
|
}
|
|
819
876
|
};
|
|
820
877
|
function onSignal(signal) {
|
|
@@ -827,10 +884,10 @@ function holdSignals(cleanup) {
|
|
|
827
884
|
return;
|
|
828
885
|
held.release();
|
|
829
886
|
cleanup(signal);
|
|
830
|
-
|
|
887
|
+
process10.kill(process10.pid, signal);
|
|
831
888
|
}
|
|
832
889
|
for (const signal of SIGNALS)
|
|
833
|
-
|
|
890
|
+
process10.on(signal, onSignal);
|
|
834
891
|
return held;
|
|
835
892
|
}
|
|
836
893
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -844,7 +901,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
844
901
|
return;
|
|
845
902
|
try {
|
|
846
903
|
if (grouped)
|
|
847
|
-
|
|
904
|
+
process10.kill(-proc.pid, killing);
|
|
848
905
|
else
|
|
849
906
|
proc.kill(killing);
|
|
850
907
|
} catch {}
|
|
@@ -920,13 +977,13 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
|
920
977
|
// ../kit/src/cli.ts
|
|
921
978
|
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
922
979
|
import { dirname as dirname3, join as join5 } from "path";
|
|
923
|
-
import
|
|
980
|
+
import process12 from "process";
|
|
924
981
|
|
|
925
982
|
// ../kit/src/usage.ts
|
|
926
983
|
import { appendFileSync, mkdirSync } from "fs";
|
|
927
984
|
import { homedir as homedir3 } from "os";
|
|
928
985
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
929
|
-
import
|
|
986
|
+
import process11 from "process";
|
|
930
987
|
|
|
931
988
|
// ../kit/src/logs.ts
|
|
932
989
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -940,14 +997,14 @@ var usageError;
|
|
|
940
997
|
function noteUsageError(message) {
|
|
941
998
|
usageError = message;
|
|
942
999
|
}
|
|
943
|
-
function stateHome(env =
|
|
1000
|
+
function stateHome(env = process11.env) {
|
|
944
1001
|
const dir = env.XDG_STATE_HOME;
|
|
945
1002
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
946
1003
|
}
|
|
947
|
-
function usagePath(env =
|
|
1004
|
+
function usagePath(env = process11.env) {
|
|
948
1005
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
949
1006
|
}
|
|
950
|
-
function usageRecorded(env =
|
|
1007
|
+
function usageRecorded(env = process11.env) {
|
|
951
1008
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
952
1009
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
953
1010
|
}
|
|
@@ -961,7 +1018,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
961
1018
|
usageError = undefined;
|
|
962
1019
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
963
1020
|
}
|
|
964
|
-
function recordUsage(entry, env =
|
|
1021
|
+
function recordUsage(entry, env = process11.env) {
|
|
965
1022
|
if (!usageRecorded(env))
|
|
966
1023
|
return;
|
|
967
1024
|
try {
|
|
@@ -979,8 +1036,8 @@ var LEVEL_OPTIONS = {
|
|
|
979
1036
|
};
|
|
980
1037
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
981
1038
|
function printError(prefix, message, hint, cause) {
|
|
982
|
-
const colors = paint(
|
|
983
|
-
const styled = takesControlCodes(
|
|
1039
|
+
const colors = paint(process12.stderr);
|
|
1040
|
+
const styled = takesControlCodes(process12.stderr);
|
|
984
1041
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
985
1042
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
986
1043
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1076,7 +1133,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1076
1133
|
return "0.0.0";
|
|
1077
1134
|
}
|
|
1078
1135
|
}
|
|
1079
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1136
|
+
async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
|
|
1080
1137
|
if (argv[0] === COMPLETE)
|
|
1081
1138
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1082
1139
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1102,9 +1159,61 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
|
|
|
1102
1159
|
var {Glob } = globalThis.Bun;
|
|
1103
1160
|
var SESSION_FILES = new Glob("*.json");
|
|
1104
1161
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1162
|
+
// ../kit/src/watch.ts
|
|
1163
|
+
import process13 from "process";
|
|
1164
|
+
import { format } from "util";
|
|
1165
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1166
|
+
var DEFAULT_SECONDS = 2;
|
|
1167
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1168
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1169
|
+
function watchOption(what) {
|
|
1170
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1171
|
+
}
|
|
1172
|
+
function withoutWatch(args) {
|
|
1173
|
+
const rest = [];
|
|
1174
|
+
for (let at = 0;at < args.length; at++) {
|
|
1175
|
+
const arg = args[at];
|
|
1176
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1177
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1178
|
+
at++;
|
|
1179
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1180
|
+
rest.push(arg);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
return rest;
|
|
1184
|
+
}
|
|
1185
|
+
async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1186
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1187
|
+
if (!takesControlCodes(stream))
|
|
1188
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1189
|
+
let code = 0;
|
|
1190
|
+
for (let round = 0;round < rounds; round++) {
|
|
1191
|
+
const held = [];
|
|
1192
|
+
const { log, info } = console;
|
|
1193
|
+
const write = process13.stdout.write.bind(process13.stdout);
|
|
1194
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1195
|
+
`);
|
|
1196
|
+
console.log = hold;
|
|
1197
|
+
console.info = hold;
|
|
1198
|
+
process13.stdout.write = (text) => {
|
|
1199
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1200
|
+
return true;
|
|
1201
|
+
};
|
|
1202
|
+
try {
|
|
1203
|
+
code = await step();
|
|
1204
|
+
} finally {
|
|
1205
|
+
console.log = log;
|
|
1206
|
+
console.info = info;
|
|
1207
|
+
process13.stdout.write = write;
|
|
1208
|
+
}
|
|
1209
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1210
|
+
await sleep(interval);
|
|
1211
|
+
}
|
|
1212
|
+
return code;
|
|
1213
|
+
}
|
|
1105
1214
|
// src/branch.ts
|
|
1106
1215
|
import { basename } from "path";
|
|
1107
|
-
import
|
|
1216
|
+
import process17 from "process";
|
|
1108
1217
|
|
|
1109
1218
|
// ../kit/src/picker/score.ts
|
|
1110
1219
|
var MATCH = 16;
|
|
@@ -1207,6 +1316,14 @@ var KEYS = {
|
|
|
1207
1316
|
"\x1B[B": "down",
|
|
1208
1317
|
"\x1BOB": "down",
|
|
1209
1318
|
"\x0E": "down",
|
|
1319
|
+
"\x1B[5~": "pageup",
|
|
1320
|
+
"\x1B[6~": "pagedown",
|
|
1321
|
+
"\x1B[H": "home",
|
|
1322
|
+
"\x1B[1~": "home",
|
|
1323
|
+
"\x1BOH": "home",
|
|
1324
|
+
"\x1B[F": "end",
|
|
1325
|
+
"\x1B[4~": "end",
|
|
1326
|
+
"\x1BOF": "end",
|
|
1210
1327
|
"\r": "enter",
|
|
1211
1328
|
"\n": "enter",
|
|
1212
1329
|
"\x03": "cancel",
|
|
@@ -1215,7 +1332,10 @@ var KEYS = {
|
|
|
1215
1332
|
"\b": "erase",
|
|
1216
1333
|
"\x15": "clear",
|
|
1217
1334
|
"\x17": "word",
|
|
1218
|
-
"\t": "tab"
|
|
1335
|
+
"\t": "tab",
|
|
1336
|
+
"\x1F": "help",
|
|
1337
|
+
"\x1BOP": "help",
|
|
1338
|
+
"\x1B[11~": "help"
|
|
1219
1339
|
};
|
|
1220
1340
|
var CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
|
|
1221
1341
|
function repeat(value, count) {
|
|
@@ -1285,7 +1405,7 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
1285
1405
|
});
|
|
1286
1406
|
}
|
|
1287
1407
|
function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
|
|
1288
|
-
const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, matches: [], cursor: 0, marked: new Set, multi, prompt, done: undefined };
|
|
1408
|
+
const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
|
|
1289
1409
|
return withRows(state, rows);
|
|
1290
1410
|
}
|
|
1291
1411
|
function withRows(state, rows, header = state.header) {
|
|
@@ -1307,6 +1427,8 @@ function highlighted(state) {
|
|
|
1307
1427
|
function press(state, key) {
|
|
1308
1428
|
if (state.done !== undefined)
|
|
1309
1429
|
return state;
|
|
1430
|
+
if (state.help)
|
|
1431
|
+
return { ...state, help: false };
|
|
1310
1432
|
if (typeof key === "object") {
|
|
1311
1433
|
if ("text" in key)
|
|
1312
1434
|
return withQuery(state, state.query + key.text);
|
|
@@ -1317,8 +1439,18 @@ function press(state, key) {
|
|
|
1317
1439
|
return move(state, -1);
|
|
1318
1440
|
case "down":
|
|
1319
1441
|
return move(state, 1);
|
|
1442
|
+
case "pageup":
|
|
1443
|
+
return move(state, -state.page);
|
|
1444
|
+
case "pagedown":
|
|
1445
|
+
return move(state, state.page);
|
|
1446
|
+
case "home":
|
|
1447
|
+
return move(state, -state.matches.length);
|
|
1448
|
+
case "end":
|
|
1449
|
+
return move(state, state.matches.length);
|
|
1320
1450
|
case "cancel":
|
|
1321
1451
|
return { ...state, done: "cancel" };
|
|
1452
|
+
case "help":
|
|
1453
|
+
return { ...state, help: true };
|
|
1322
1454
|
case "erase":
|
|
1323
1455
|
return withQuery(state, [...state.query].slice(0, -1).join(""));
|
|
1324
1456
|
case "clear":
|
|
@@ -1347,11 +1479,11 @@ function chosen(state) {
|
|
|
1347
1479
|
|
|
1348
1480
|
// ../kit/src/picker/terminal.ts
|
|
1349
1481
|
import { openSync } from "fs";
|
|
1350
|
-
import
|
|
1482
|
+
import process16 from "process";
|
|
1351
1483
|
import tty from "tty";
|
|
1352
1484
|
|
|
1353
1485
|
// ../kit/src/picker/preview.ts
|
|
1354
|
-
import
|
|
1486
|
+
import process15 from "process";
|
|
1355
1487
|
|
|
1356
1488
|
// ../kit/src/shell.ts
|
|
1357
1489
|
var SEPARATORS = new Set([`
|
|
@@ -1420,7 +1552,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
1420
1552
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
1421
1553
|
const stop = () => {
|
|
1422
1554
|
try {
|
|
1423
|
-
|
|
1555
|
+
process15.kill(-proc.pid, "SIGKILL");
|
|
1424
1556
|
} catch {
|
|
1425
1557
|
proc.kill();
|
|
1426
1558
|
}
|
|
@@ -1498,7 +1630,18 @@ function fitStyled(line, width, plain = identity) {
|
|
|
1498
1630
|
function caretColumn(state, layout) {
|
|
1499
1631
|
return Math.min(layout.listWidth, Bun.stringWidth(state.prompt) + Bun.stringWidth(state.query) + 1);
|
|
1500
1632
|
}
|
|
1633
|
+
function helpLines(state, layout, theme) {
|
|
1634
|
+
const lines = [
|
|
1635
|
+
"type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end move",
|
|
1636
|
+
`enter picks${state.multi ? ", tab marks" : ""}, ctrl-u clears the query, ctrl-w a word, esc or ctrl-c cancels`,
|
|
1637
|
+
...state.expect.length > 0 ? [`${state.expect.join(", ")} end the pick as this command asks`] : []
|
|
1638
|
+
];
|
|
1639
|
+
const title = "keys, any key closes this help";
|
|
1640
|
+
return [{ text: theme.accent(title), width: title.length }, ...lines.map((line) => fit(` ${line}`, layout.listWidth, theme.label))];
|
|
1641
|
+
}
|
|
1501
1642
|
function listLines(state, layout, theme) {
|
|
1643
|
+
if (state.help)
|
|
1644
|
+
return helpLines(state, layout, theme);
|
|
1502
1645
|
const header = state.header === "" ? [] : state.header.split(`
|
|
1503
1646
|
`).map((line) => fitStyled(line, layout.listWidth, theme.label));
|
|
1504
1647
|
const rows = Math.max(1, layout.listHeight - 2 - header.length);
|
|
@@ -1507,7 +1650,8 @@ function listLines(state, layout, theme) {
|
|
|
1507
1650
|
const marks = (state.marked.size > 0 ? ` (${state.marked.size} marked)` : "") + (state.status === "" ? "" : ` ${state.status}`);
|
|
1508
1651
|
const promptWidth = Bun.stringWidth(state.prompt);
|
|
1509
1652
|
const query = fit(state.query, Math.max(1, layout.listWidth - promptWidth), identity);
|
|
1510
|
-
const
|
|
1653
|
+
const place = state.matches.length > rows ? ` (${state.cursor + 1} of ${state.matches.length})` : "";
|
|
1654
|
+
const count = fit(` ${state.matches.length}/${state.items.length}${place}${marks}`, layout.listWidth, theme.label);
|
|
1511
1655
|
const lines = [{ text: theme.accent(state.prompt) + query.text, width: promptWidth + query.width }, count, ...header];
|
|
1512
1656
|
if (state.matches.length === 0)
|
|
1513
1657
|
lines.push(fit(" no match", layout.listWidth, theme.label));
|
|
@@ -1534,6 +1678,7 @@ function render(state, layout, theme, preview = []) {
|
|
|
1534
1678
|
|
|
1535
1679
|
// ../kit/src/picker/terminal.ts
|
|
1536
1680
|
var PREVIEW_DELAY_MS = 120;
|
|
1681
|
+
var ESCAPE_WAIT_MS = 30;
|
|
1537
1682
|
var OPEN = { ctrl: "open" };
|
|
1538
1683
|
var HIDE_CURSOR = "\x1B[?25l";
|
|
1539
1684
|
var SHOW_CURSOR = "\x1B[?25h";
|
|
@@ -1551,7 +1696,7 @@ function openTerminal() {
|
|
|
1551
1696
|
} catch {
|
|
1552
1697
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
1553
1698
|
}
|
|
1554
|
-
const out =
|
|
1699
|
+
const out = process16.stderr;
|
|
1555
1700
|
let resize;
|
|
1556
1701
|
return {
|
|
1557
1702
|
get columns() {
|
|
@@ -1589,20 +1734,29 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1589
1734
|
let shownLine;
|
|
1590
1735
|
let finish;
|
|
1591
1736
|
let restored = false;
|
|
1737
|
+
let escape;
|
|
1738
|
+
let caret;
|
|
1592
1739
|
function draw(clear = false) {
|
|
1593
1740
|
if (restored)
|
|
1594
1741
|
return;
|
|
1595
1742
|
const layout = layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition);
|
|
1596
1743
|
let frame = HIDE_CURSOR;
|
|
1597
1744
|
if (reserved !== layout.height || clear) {
|
|
1745
|
+
frame += clear && caret !== undefined ? up(Math.floor((caret - 1) / terminal.columns)) : "";
|
|
1598
1746
|
frame += CLEAR_BELOW + `
|
|
1599
1747
|
`.repeat(layout.height - 1) + up(layout.height - 1);
|
|
1600
1748
|
reserved = layout.height;
|
|
1601
1749
|
}
|
|
1750
|
+
caret = caretColumn(state, layout);
|
|
1602
1751
|
frame += `\r${render(state, layout, theme, preview).map((line) => `\x1B[2K${line}`).join(`
|
|
1603
|
-
`)}${up(layout.height - 1)}\r\x1B[${
|
|
1752
|
+
`)}${up(layout.height - 1)}\r\x1B[${caret}G${SHOW_CURSOR}`;
|
|
1604
1753
|
terminal.write(frame);
|
|
1605
1754
|
}
|
|
1755
|
+
function pageSize() {
|
|
1756
|
+
const headerLines = state.header === "" ? 0 : state.header.split(`
|
|
1757
|
+
`).length;
|
|
1758
|
+
return Math.max(1, layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition).listHeight - 2 - headerLines);
|
|
1759
|
+
}
|
|
1606
1760
|
function refreshPreview() {
|
|
1607
1761
|
const at = highlighted(state);
|
|
1608
1762
|
if (settings.preview === undefined || at === shownLine)
|
|
@@ -1632,6 +1786,7 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1632
1786
|
return;
|
|
1633
1787
|
restored = true;
|
|
1634
1788
|
clearTimeout(previewTimer);
|
|
1789
|
+
clearTimeout(escape);
|
|
1635
1790
|
previewing.abort();
|
|
1636
1791
|
terminal.write(`${CLEAR_BELOW}${PASTE_OFF}${SHOW_CURSOR}`);
|
|
1637
1792
|
terminal.close();
|
|
@@ -1670,7 +1825,7 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1670
1825
|
if (key === OPEN || typeof key === "object" && "ctrl" in key && key.ctrl === reload?.key)
|
|
1671
1826
|
await reloadRows();
|
|
1672
1827
|
else
|
|
1673
|
-
state = press(state, key);
|
|
1828
|
+
state = press({ ...state, page: pageSize() }, key);
|
|
1674
1829
|
}
|
|
1675
1830
|
} finally {
|
|
1676
1831
|
draining = false;
|
|
@@ -1683,6 +1838,20 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1683
1838
|
draw();
|
|
1684
1839
|
}
|
|
1685
1840
|
function onChunk(chunk) {
|
|
1841
|
+
if (escape !== undefined) {
|
|
1842
|
+
clearTimeout(escape);
|
|
1843
|
+
escape = undefined;
|
|
1844
|
+
chunk = `\x1B${chunk}`;
|
|
1845
|
+
} else if (chunk === "\x1B") {
|
|
1846
|
+
escape = setTimeout(() => {
|
|
1847
|
+
escape = undefined;
|
|
1848
|
+
takeKeys("\x1B");
|
|
1849
|
+
}, ESCAPE_WAIT_MS);
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
takeKeys(chunk);
|
|
1853
|
+
}
|
|
1854
|
+
function takeKeys(chunk) {
|
|
1686
1855
|
const keys = parseKeys(chunk, paste, [...settings.expect ?? [], ...reload?.key === undefined ? [] : [reload.key]]);
|
|
1687
1856
|
if (busy && keys.includes("cancel")) {
|
|
1688
1857
|
stop();
|
|
@@ -1694,9 +1863,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1694
1863
|
const ended = new Promise((resolve) => {
|
|
1695
1864
|
finish = resolve;
|
|
1696
1865
|
});
|
|
1697
|
-
|
|
1866
|
+
process16.once("exit", restore);
|
|
1698
1867
|
for (const signal of SIGNALS2)
|
|
1699
|
-
|
|
1868
|
+
process16.once(signal, stop);
|
|
1700
1869
|
try {
|
|
1701
1870
|
terminal.write(PASTE_ON);
|
|
1702
1871
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -1709,8 +1878,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1709
1878
|
await ended;
|
|
1710
1879
|
} finally {
|
|
1711
1880
|
for (const signal of SIGNALS2)
|
|
1712
|
-
|
|
1713
|
-
|
|
1881
|
+
process16.off(signal, stop);
|
|
1882
|
+
process16.off("exit", restore);
|
|
1714
1883
|
restore();
|
|
1715
1884
|
}
|
|
1716
1885
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -1974,14 +2143,14 @@ async function gb(args) {
|
|
|
1974
2143
|
let branch;
|
|
1975
2144
|
let key = "";
|
|
1976
2145
|
if (named === undefined) {
|
|
1977
|
-
const interactive =
|
|
2146
|
+
const interactive = isInteractive() && parsed.values.json !== true;
|
|
1978
2147
|
if (!interactive) {
|
|
1979
2148
|
if (emitting)
|
|
1980
2149
|
fail("the picker needs a terminal", 1);
|
|
1981
2150
|
if (parsed.values.json === true)
|
|
1982
2151
|
printJson(all);
|
|
1983
2152
|
else
|
|
1984
|
-
console.log(table(all.map(row)).map((line) => takesControlCodes(
|
|
2153
|
+
console.log(table(all.map(row)).map((line) => takesControlCodes(process17.stdout) ? line : Bun.stripANSI(line)).join(`
|
|
1985
2154
|
`));
|
|
1986
2155
|
return 0;
|
|
1987
2156
|
}
|
|
@@ -2038,4 +2207,4 @@ async function finish(command, typed, emitting) {
|
|
|
2038
2207
|
}
|
|
2039
2208
|
|
|
2040
2209
|
// src/gb.ts
|
|
2041
|
-
|
|
2210
|
+
process18.exitCode = await runMain({ name: "gb", run: gb });
|