@kaynooo/cli-git 0.15.1 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/dist/gb.js +343 -62
- package/dist/gc.js +162 -35
- package/dist/gcl.js +151 -34
- package/dist/gd.js +158 -41
- package/dist/gf.js +155 -38
- package/dist/gm.js +2964 -0
- package/dist/gp.js +155 -38
- package/dist/gst.js +196 -52
- package/dist/gu.js +149 -31
- package/package.json +6 -4
package/dist/gb.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gb.ts
|
|
5
|
-
import
|
|
5
|
+
import process23 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -493,7 +493,7 @@ function printJson(value) {
|
|
|
493
493
|
|
|
494
494
|
// ../kit/src/help.ts
|
|
495
495
|
import process8 from "process";
|
|
496
|
-
var OPTIONAL =
|
|
496
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
497
497
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
498
498
|
var FULL_STOP = /\.$/;
|
|
499
499
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
@@ -532,29 +532,41 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
532
532
|
return [];
|
|
533
533
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
534
534
|
}
|
|
535
|
+
var MAX_INLINE_CHOICES = 24;
|
|
535
536
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
536
537
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
537
538
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
538
|
-
const
|
|
539
|
+
const choices = option.choices?.join("|");
|
|
540
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
541
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
539
542
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
540
543
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
541
|
-
|
|
544
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
545
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
542
546
|
});
|
|
543
547
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
544
548
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
545
549
|
}
|
|
546
550
|
|
|
547
551
|
// ../kit/src/text.ts
|
|
548
|
-
var ANSI =
|
|
552
|
+
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
549
553
|
function distance(a, b) {
|
|
550
|
-
|
|
551
|
-
|
|
554
|
+
const left = [...a];
|
|
555
|
+
const right = [...b];
|
|
556
|
+
let before = [];
|
|
557
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
558
|
+
for (const [i, x] of left.entries()) {
|
|
552
559
|
const current = [i + 1];
|
|
553
|
-
for (const [j,
|
|
554
|
-
|
|
560
|
+
for (const [j, y] of right.entries()) {
|
|
561
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
562
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
563
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
564
|
+
current.push(cost);
|
|
565
|
+
}
|
|
566
|
+
before = previous;
|
|
555
567
|
previous = current;
|
|
556
568
|
}
|
|
557
|
-
return previous[
|
|
569
|
+
return previous[right.length] ?? 0;
|
|
558
570
|
}
|
|
559
571
|
function closest(name, names) {
|
|
560
572
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -630,7 +642,7 @@ class Completing {
|
|
|
630
642
|
}
|
|
631
643
|
var completion = { active: false };
|
|
632
644
|
var OUTPUT_OPTIONS = {
|
|
633
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
645
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
634
646
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
635
647
|
};
|
|
636
648
|
function applyOutput(color, plain, env = process9.env) {
|
|
@@ -1138,13 +1150,91 @@ function interceptOutput(clear) {
|
|
|
1138
1150
|
// ../kit/src/cli.ts
|
|
1139
1151
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
1140
1152
|
import { dirname as dirname3, join as join5 } from "path";
|
|
1141
|
-
import
|
|
1153
|
+
import process15 from "process";
|
|
1154
|
+
|
|
1155
|
+
// ../kit/src/completions.ts
|
|
1156
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
1157
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
1158
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1159
|
+
set -l current (commandline -ct)
|
|
1160
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1161
|
+
if test "$line" = __files__
|
|
1162
|
+
__fish_complete_path $current
|
|
1163
|
+
else
|
|
1164
|
+
echo $line
|
|
1165
|
+
end
|
|
1166
|
+
end
|
|
1167
|
+
end`;
|
|
1168
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1169
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1170
|
+
local -a lines
|
|
1171
|
+
COMPREPLY=()
|
|
1172
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1173
|
+
for line in "\${lines[@]}"; do
|
|
1174
|
+
if [[ $line == __files__ ]]; then
|
|
1175
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1176
|
+
else
|
|
1177
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1178
|
+
fi
|
|
1179
|
+
done
|
|
1180
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1181
|
+
}`;
|
|
1182
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1183
|
+
local line
|
|
1184
|
+
local -a described plain
|
|
1185
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1186
|
+
if [[ $line == __files__ ]]; then
|
|
1187
|
+
_files
|
|
1188
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1189
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1190
|
+
else
|
|
1191
|
+
plain+=("$line")
|
|
1192
|
+
fi
|
|
1193
|
+
done
|
|
1194
|
+
(( \${#described} )) && _describe -V value described
|
|
1195
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1196
|
+
return 0
|
|
1197
|
+
}`;
|
|
1198
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1199
|
+
if (shell === "fish")
|
|
1200
|
+
return `${header}
|
|
1201
|
+
${FISH_FUNCTION}
|
|
1202
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1203
|
+
`).join("")}`;
|
|
1204
|
+
if (shell === "bash")
|
|
1205
|
+
return `${header}
|
|
1206
|
+
${BASH_FUNCTION}
|
|
1207
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1208
|
+
`;
|
|
1209
|
+
return `${header}
|
|
1210
|
+
${ZSH_FUNCTION}
|
|
1211
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1212
|
+
`;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
// ../kit/src/notify.ts
|
|
1216
|
+
import process13 from "process";
|
|
1217
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1218
|
+
var CANCELLED = 130;
|
|
1219
|
+
function base64(text) {
|
|
1220
|
+
return Buffer.from(text).toString("base64");
|
|
1221
|
+
}
|
|
1222
|
+
function notification(title, body, env = process13.env) {
|
|
1223
|
+
const id = `kit${process13.pid}`;
|
|
1224
|
+
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
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1226
|
+
}
|
|
1227
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1228
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1229
|
+
return;
|
|
1230
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1231
|
+
}
|
|
1142
1232
|
|
|
1143
1233
|
// ../kit/src/usage.ts
|
|
1144
1234
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1145
1235
|
import { homedir as homedir3 } from "os";
|
|
1146
1236
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1147
|
-
import
|
|
1237
|
+
import process14 from "process";
|
|
1148
1238
|
|
|
1149
1239
|
// ../kit/src/logs.ts
|
|
1150
1240
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1158,14 +1248,14 @@ var usageError;
|
|
|
1158
1248
|
function noteUsageError(message) {
|
|
1159
1249
|
usageError = message;
|
|
1160
1250
|
}
|
|
1161
|
-
function stateHome(env =
|
|
1251
|
+
function stateHome(env = process14.env) {
|
|
1162
1252
|
const dir = env.XDG_STATE_HOME;
|
|
1163
1253
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1164
1254
|
}
|
|
1165
|
-
function usagePath(env =
|
|
1255
|
+
function usagePath(env = process14.env) {
|
|
1166
1256
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1167
1257
|
}
|
|
1168
|
-
function usageRecorded(env =
|
|
1258
|
+
function usageRecorded(env = process14.env) {
|
|
1169
1259
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1170
1260
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1171
1261
|
}
|
|
@@ -1179,7 +1269,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1179
1269
|
usageError = undefined;
|
|
1180
1270
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1181
1271
|
}
|
|
1182
|
-
function recordUsage(entry, env =
|
|
1272
|
+
function recordUsage(entry, env = process14.env) {
|
|
1183
1273
|
if (!usageRecorded(env))
|
|
1184
1274
|
return;
|
|
1185
1275
|
try {
|
|
@@ -1195,10 +1285,14 @@ var LEVEL_OPTIONS = {
|
|
|
1195
1285
|
...OUTPUT_OPTIONS,
|
|
1196
1286
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1197
1287
|
};
|
|
1198
|
-
var TOP_OPTIONS = {
|
|
1288
|
+
var TOP_OPTIONS = {
|
|
1289
|
+
...LEVEL_OPTIONS,
|
|
1290
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1291
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1292
|
+
};
|
|
1199
1293
|
function printError(prefix, message, hint, cause) {
|
|
1200
|
-
const colors = paint(
|
|
1201
|
-
const styled = takesControlCodes(
|
|
1294
|
+
const colors = paint(process15.stderr);
|
|
1295
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1202
1296
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1203
1297
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1204
1298
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1278,6 +1372,19 @@ async function leafCandidates(run, words) {
|
|
|
1278
1372
|
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1279
1373
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1280
1374
|
}
|
|
1375
|
+
var COMPLETIONS = "--completions";
|
|
1376
|
+
function flagValue([flag = "", ...rest]) {
|
|
1377
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1378
|
+
}
|
|
1379
|
+
function printCompletionScript(name, args) {
|
|
1380
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1381
|
+
if (shell === undefined || args.length !== 1) {
|
|
1382
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1383
|
+
return 2;
|
|
1384
|
+
}
|
|
1385
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1386
|
+
return 0;
|
|
1387
|
+
}
|
|
1281
1388
|
async function printCandidates(found) {
|
|
1282
1389
|
for (const line of await found)
|
|
1283
1390
|
console.log(line);
|
|
@@ -1301,16 +1408,20 @@ function packageVersion(entry = Bun.main) {
|
|
|
1301
1408
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1302
1409
|
if (argv[0] === COMPLETE)
|
|
1303
1410
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1411
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1412
|
+
return printCompletionScript(name, flagValue(argv));
|
|
1304
1413
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1305
1414
|
console.log(version ?? packageVersion());
|
|
1306
1415
|
return 0;
|
|
1307
1416
|
}
|
|
1308
1417
|
let code;
|
|
1418
|
+
const started = performance.now();
|
|
1309
1419
|
try {
|
|
1310
1420
|
code = await run(argv);
|
|
1311
1421
|
} catch (error) {
|
|
1312
1422
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1313
1423
|
}
|
|
1424
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1314
1425
|
if (usage !== false) {
|
|
1315
1426
|
try {
|
|
1316
1427
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1327,7 +1438,7 @@ var {Glob } = globalThis.Bun;
|
|
|
1327
1438
|
var SESSION_FILES = new Glob("*.json");
|
|
1328
1439
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1329
1440
|
// ../kit/src/watch.ts
|
|
1330
|
-
import
|
|
1441
|
+
import process16 from "process";
|
|
1331
1442
|
import { format } from "util";
|
|
1332
1443
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1333
1444
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1349,7 +1460,7 @@ function withoutWatch(args) {
|
|
|
1349
1460
|
}
|
|
1350
1461
|
return rest;
|
|
1351
1462
|
}
|
|
1352
|
-
async function watching(value, step, stream =
|
|
1463
|
+
async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1353
1464
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1354
1465
|
if (!takesControlCodes(stream))
|
|
1355
1466
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1357,12 +1468,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1357
1468
|
for (let round = 0;round < rounds; round++) {
|
|
1358
1469
|
const held = [];
|
|
1359
1470
|
const { log, info } = console;
|
|
1360
|
-
const write =
|
|
1471
|
+
const write = process16.stdout.write.bind(process16.stdout);
|
|
1361
1472
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1362
1473
|
`);
|
|
1363
1474
|
console.log = hold;
|
|
1364
1475
|
console.info = hold;
|
|
1365
|
-
|
|
1476
|
+
process16.stdout.write = (text) => {
|
|
1366
1477
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1367
1478
|
return true;
|
|
1368
1479
|
};
|
|
@@ -1371,7 +1482,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1371
1482
|
} finally {
|
|
1372
1483
|
console.log = log;
|
|
1373
1484
|
console.info = info;
|
|
1374
|
-
|
|
1485
|
+
process16.stdout.write = write;
|
|
1375
1486
|
}
|
|
1376
1487
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1377
1488
|
await sleep(interval);
|
|
@@ -1381,7 +1492,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1381
1492
|
// ../kit/src/workspace-root.ts
|
|
1382
1493
|
import { homedir as homedir4 } from "os";
|
|
1383
1494
|
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1384
|
-
import
|
|
1495
|
+
import process17 from "process";
|
|
1385
1496
|
function expandHome(path, home) {
|
|
1386
1497
|
if (path === "~")
|
|
1387
1498
|
return home;
|
|
@@ -1391,13 +1502,126 @@ function configured(env, home) {
|
|
|
1391
1502
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1392
1503
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1393
1504
|
}
|
|
1394
|
-
function workspaceRoot({ given, env =
|
|
1505
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1395
1506
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1396
1507
|
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1397
1508
|
}
|
|
1398
1509
|
// src/branch.ts
|
|
1399
1510
|
import { basename } from "path";
|
|
1400
|
-
import
|
|
1511
|
+
import process22 from "process";
|
|
1512
|
+
|
|
1513
|
+
// ../kit/src/picker/line.ts
|
|
1514
|
+
var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1515
|
+
var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1516
|
+
var FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1517
|
+
function isEditKey(key) {
|
|
1518
|
+
return EDIT_KEYS.has(key);
|
|
1519
|
+
}
|
|
1520
|
+
function endsKills(key) {
|
|
1521
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
1522
|
+
}
|
|
1523
|
+
var WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
1524
|
+
var SPACE = /\s/;
|
|
1525
|
+
function isWord(char) {
|
|
1526
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
1527
|
+
}
|
|
1528
|
+
function wordStart(chars, from) {
|
|
1529
|
+
let at = from;
|
|
1530
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
1531
|
+
at--;
|
|
1532
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
1533
|
+
at--;
|
|
1534
|
+
return at;
|
|
1535
|
+
}
|
|
1536
|
+
function wordEnd(chars, from) {
|
|
1537
|
+
let at = from;
|
|
1538
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
1539
|
+
at++;
|
|
1540
|
+
while (at < chars.length && isWord(chars[at]))
|
|
1541
|
+
at++;
|
|
1542
|
+
return at;
|
|
1543
|
+
}
|
|
1544
|
+
function spacedStart(chars, from) {
|
|
1545
|
+
let at = from;
|
|
1546
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
1547
|
+
at--;
|
|
1548
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
1549
|
+
at--;
|
|
1550
|
+
return at;
|
|
1551
|
+
}
|
|
1552
|
+
function cut(chars, from, to) {
|
|
1553
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
1554
|
+
}
|
|
1555
|
+
function insert(chars, at, text) {
|
|
1556
|
+
const typed = [...text];
|
|
1557
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
1558
|
+
}
|
|
1559
|
+
function editLine(line, key) {
|
|
1560
|
+
const { killed = "", chained = false } = line;
|
|
1561
|
+
const chars = [...line.text];
|
|
1562
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
1563
|
+
const edited = edit(chars, at, key, killed);
|
|
1564
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
1565
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
1566
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
1567
|
+
if (taken === "")
|
|
1568
|
+
return { ...edited, killed, chained };
|
|
1569
|
+
if (!chained)
|
|
1570
|
+
return { ...edited, killed: taken, chained: true };
|
|
1571
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
1572
|
+
}
|
|
1573
|
+
function edit(chars, at, key, killed) {
|
|
1574
|
+
const text = chars.join("");
|
|
1575
|
+
if (typeof key === "object")
|
|
1576
|
+
return insert(chars, at, key.text);
|
|
1577
|
+
switch (key) {
|
|
1578
|
+
case "left":
|
|
1579
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
1580
|
+
case "right":
|
|
1581
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
1582
|
+
case "wordleft":
|
|
1583
|
+
return { text, caret: wordStart(chars, at) };
|
|
1584
|
+
case "wordright":
|
|
1585
|
+
return { text, caret: wordEnd(chars, at) };
|
|
1586
|
+
case "linestart":
|
|
1587
|
+
return { text, caret: 0 };
|
|
1588
|
+
case "lineend":
|
|
1589
|
+
return { text, caret: chars.length };
|
|
1590
|
+
case "erase":
|
|
1591
|
+
return cut(chars, Math.max(at - 1, 0), at);
|
|
1592
|
+
case "delete":
|
|
1593
|
+
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
1594
|
+
case "word":
|
|
1595
|
+
return cut(chars, spacedStart(chars, at), at);
|
|
1596
|
+
case "killword":
|
|
1597
|
+
return cut(chars, wordStart(chars, at), at);
|
|
1598
|
+
case "killnext":
|
|
1599
|
+
return cut(chars, at, wordEnd(chars, at));
|
|
1600
|
+
case "clear":
|
|
1601
|
+
return cut(chars, 0, at);
|
|
1602
|
+
case "killend":
|
|
1603
|
+
return cut(chars, at, chars.length);
|
|
1604
|
+
case "yank":
|
|
1605
|
+
return insert(chars, at, killed);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
function visible({ text, caret }, room) {
|
|
1609
|
+
const chars = [...text];
|
|
1610
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
1611
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
1612
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
1613
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
1614
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
1615
|
+
let start = at;
|
|
1616
|
+
let end = at + 1;
|
|
1617
|
+
while (start > 0 && fits(start - 1, end))
|
|
1618
|
+
start--;
|
|
1619
|
+
while (end < cells.length && fits(start, end + 1))
|
|
1620
|
+
end++;
|
|
1621
|
+
const left = start > 0 ? "\u2026" : "";
|
|
1622
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
1623
|
+
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
1624
|
+
}
|
|
1401
1625
|
|
|
1402
1626
|
// ../kit/src/picker/score.ts
|
|
1403
1627
|
var MATCH = 16;
|
|
@@ -1483,7 +1707,6 @@ function rank(query, lines) {
|
|
|
1483
1707
|
}
|
|
1484
1708
|
|
|
1485
1709
|
// ../kit/src/picker/state.ts
|
|
1486
|
-
var ANSI2 = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
1487
1710
|
var CONTROL2 = /[\x00-\x1F\x7F-\x9F]/g;
|
|
1488
1711
|
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1489
1712
|
var SGR = /^\x1B\[[0-9;]*m$/;
|
|
@@ -1491,7 +1714,6 @@ var RESET = /^\x1B\[0?m$/;
|
|
|
1491
1714
|
var COLUMN_GAP = 2;
|
|
1492
1715
|
var PASTE_START = "\x1B[200~";
|
|
1493
1716
|
var PASTE_END = "\x1B[201~";
|
|
1494
|
-
var LAST_WORD = /\S*\s*$/;
|
|
1495
1717
|
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1496
1718
|
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1497
1719
|
var WHEEL_LINES = 3;
|
|
@@ -1514,10 +1736,29 @@ var KEYS = {
|
|
|
1514
1736
|
"\n": "enter",
|
|
1515
1737
|
"\x03": "cancel",
|
|
1516
1738
|
"\x1B": "cancel",
|
|
1739
|
+
"\x1B[D": "left",
|
|
1740
|
+
"\x1BOD": "left",
|
|
1741
|
+
"\x1B[C": "right",
|
|
1742
|
+
"\x1BOC": "right",
|
|
1743
|
+
"\x1B[1;5D": "wordleft",
|
|
1744
|
+
"\x1B[1;3D": "wordleft",
|
|
1745
|
+
"\x1Bb": "wordleft",
|
|
1746
|
+
"\x1B[1;5C": "wordright",
|
|
1747
|
+
"\x1B[1;3C": "wordright",
|
|
1748
|
+
"\x1Bf": "wordright",
|
|
1749
|
+
"\x01": "linestart",
|
|
1750
|
+
"\x05": "lineend",
|
|
1517
1751
|
"\x7F": "erase",
|
|
1518
|
-
"\
|
|
1752
|
+
"\x1B[3~": "delete",
|
|
1753
|
+
"\b": "killword",
|
|
1754
|
+
"\x1B\x7F": "killword",
|
|
1755
|
+
"\x1B[3;5~": "killnext",
|
|
1756
|
+
"\x1Bd": "killnext",
|
|
1519
1757
|
"\x15": "clear",
|
|
1758
|
+
"\v": "killend",
|
|
1520
1759
|
"\x17": "word",
|
|
1760
|
+
"\x19": "yank",
|
|
1761
|
+
"\x1A": "suspend",
|
|
1521
1762
|
"\t": "tab",
|
|
1522
1763
|
"\x1F": "help",
|
|
1523
1764
|
"\x1BOP": "help",
|
|
@@ -1539,7 +1780,7 @@ function styled(line) {
|
|
|
1539
1780
|
colored ||= active !== "" && flat !== "";
|
|
1540
1781
|
styles.push(...repeat(active, flat.length));
|
|
1541
1782
|
}
|
|
1542
|
-
for (const found of line.matchAll(
|
|
1783
|
+
for (const found of line.matchAll(ANSI)) {
|
|
1543
1784
|
add(line.slice(last, found.index));
|
|
1544
1785
|
last = found.index + found[0].length;
|
|
1545
1786
|
if (SGR.test(found[0]))
|
|
@@ -1551,7 +1792,7 @@ function styled(line) {
|
|
|
1551
1792
|
function lay(rows, searched) {
|
|
1552
1793
|
const parsed = rows.map((row) => row.cells.map(styled));
|
|
1553
1794
|
const widths = (parsed[0] ?? []).map((_, column) => Math.max(...parsed.map((cells) => Bun.stringWidth(cells[column]?.text ?? ""))));
|
|
1554
|
-
return parsed.map((cells) => {
|
|
1795
|
+
return parsed.map((cells, at) => {
|
|
1555
1796
|
let text = "";
|
|
1556
1797
|
const styles = [];
|
|
1557
1798
|
let colored = false;
|
|
@@ -1570,7 +1811,7 @@ function lay(rows, searched) {
|
|
|
1570
1811
|
styles.push(...repeat("", pad));
|
|
1571
1812
|
}
|
|
1572
1813
|
}
|
|
1573
|
-
return { text, styles: colored ? styles : undefined, searchable: text.slice(0, searchEnd) };
|
|
1814
|
+
return { text, styles: colored ? styles : undefined, searchable: rows[at].search ?? text.slice(0, searchEnd) };
|
|
1574
1815
|
});
|
|
1575
1816
|
}
|
|
1576
1817
|
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
@@ -1594,7 +1835,7 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
1594
1835
|
});
|
|
1595
1836
|
}
|
|
1596
1837
|
function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
|
|
1597
|
-
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 };
|
|
1838
|
+
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 };
|
|
1598
1839
|
return withRows(state, rows);
|
|
1599
1840
|
}
|
|
1600
1841
|
function withRows(state, rows, header = state.header) {
|
|
@@ -1604,8 +1845,9 @@ function withRows(state, rows, header = state.header) {
|
|
|
1604
1845
|
const matches = rank(state.query, searchable);
|
|
1605
1846
|
return { ...state, rows: cells, items: laid.map((row) => row.text), styles: laid.map((row) => row.styles), searchable, header, matches, cursor: Math.max(0, Math.min(matches.length - 1, state.cursor)), marked: new Set };
|
|
1606
1847
|
}
|
|
1607
|
-
function withQuery(state,
|
|
1608
|
-
|
|
1848
|
+
function withQuery(state, key) {
|
|
1849
|
+
const { text, caret, killed = "", chained = false } = editLine({ text: state.query, caret: state.caret, killed: state.killed, chained: state.chained }, key);
|
|
1850
|
+
return text === state.query ? { ...state, caret, killed, chained } : { ...state, query: text, caret, killed, chained, matches: rank(text, state.searchable), cursor: 0 };
|
|
1609
1851
|
}
|
|
1610
1852
|
function move(state, by) {
|
|
1611
1853
|
return { ...state, cursor: Math.max(0, Math.min(state.matches.length - 1, state.cursor + by)) };
|
|
@@ -1616,13 +1858,17 @@ function highlighted(state) {
|
|
|
1616
1858
|
function press(state, key) {
|
|
1617
1859
|
if (state.done !== undefined)
|
|
1618
1860
|
return state;
|
|
1861
|
+
if (state.chained && endsKills(key))
|
|
1862
|
+
state = { ...state, chained: false };
|
|
1619
1863
|
if (state.help)
|
|
1620
1864
|
return { ...state, help: false };
|
|
1621
1865
|
if (typeof key === "object") {
|
|
1622
1866
|
if ("text" in key)
|
|
1623
|
-
return withQuery(state,
|
|
1867
|
+
return withQuery(state, key);
|
|
1624
1868
|
return state.expect.includes(key.ctrl) ? { ...state, done: "accept", key: key.ctrl } : state;
|
|
1625
1869
|
}
|
|
1870
|
+
if (isEditKey(key))
|
|
1871
|
+
return withQuery(state, key);
|
|
1626
1872
|
switch (key) {
|
|
1627
1873
|
case "up":
|
|
1628
1874
|
return move(state, -1);
|
|
@@ -1640,12 +1886,8 @@ function press(state, key) {
|
|
|
1640
1886
|
return { ...state, done: "cancel" };
|
|
1641
1887
|
case "help":
|
|
1642
1888
|
return { ...state, help: true };
|
|
1643
|
-
case "
|
|
1644
|
-
return
|
|
1645
|
-
case "clear":
|
|
1646
|
-
return withQuery(state, "");
|
|
1647
|
-
case "word":
|
|
1648
|
-
return withQuery(state, state.query.replace(LAST_WORD, ""));
|
|
1889
|
+
case "suspend":
|
|
1890
|
+
return state;
|
|
1649
1891
|
case "enter":
|
|
1650
1892
|
return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
|
|
1651
1893
|
case "tab": {
|
|
@@ -1668,11 +1910,25 @@ function chosen(state) {
|
|
|
1668
1910
|
|
|
1669
1911
|
// ../kit/src/picker/terminal.ts
|
|
1670
1912
|
import { openSync } from "fs";
|
|
1671
|
-
import
|
|
1913
|
+
import process21 from "process";
|
|
1672
1914
|
import tty from "tty";
|
|
1673
1915
|
|
|
1916
|
+
// ../kit/src/job.ts
|
|
1917
|
+
import process19 from "process";
|
|
1918
|
+
function stopJob() {
|
|
1919
|
+
process19.kill(0, "SIGTSTP");
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
// ../kit/src/redraw.ts
|
|
1923
|
+
var SYNC_START = "\x1B[?2026h";
|
|
1924
|
+
var SYNC_END = "\x1B[?2026l";
|
|
1925
|
+
function overwrite(lines, columns) {
|
|
1926
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1927
|
+
`);
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1674
1930
|
// ../kit/src/picker/preview.ts
|
|
1675
|
-
import
|
|
1931
|
+
import process20 from "process";
|
|
1676
1932
|
|
|
1677
1933
|
// ../kit/src/shell.ts
|
|
1678
1934
|
var SEPARATORS = new Set([`
|
|
@@ -1741,7 +1997,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
1741
1997
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
1742
1998
|
const stop = () => {
|
|
1743
1999
|
try {
|
|
1744
|
-
|
|
2000
|
+
process20.kill(-proc.pid, "SIGKILL");
|
|
1745
2001
|
} catch {
|
|
1746
2002
|
proc.kill();
|
|
1747
2003
|
}
|
|
@@ -1816,13 +2072,20 @@ function fitStyled(line, width, plain = identity) {
|
|
|
1816
2072
|
const { text, styles } = styled(line);
|
|
1817
2073
|
return fit(text, width, plain, plain, new Set, styles);
|
|
1818
2074
|
}
|
|
1819
|
-
function
|
|
1820
|
-
return
|
|
2075
|
+
function queryShown(state, layout) {
|
|
2076
|
+
return visible({ text: state.query, caret: state.caret }, Math.max(1, layout.listWidth - Bun.stringWidth(state.prompt)));
|
|
2077
|
+
}
|
|
2078
|
+
function caretCell(state, layout) {
|
|
2079
|
+
const shown = queryShown(state, layout);
|
|
2080
|
+
return { column: Math.min(layout.listWidth, Bun.stringWidth(state.prompt) + shown.column + 1), char: shown.at ?? " " };
|
|
1821
2081
|
}
|
|
1822
2082
|
function helpLines(state, layout, theme) {
|
|
1823
2083
|
const lines = [
|
|
1824
2084
|
"type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end, the wheel move",
|
|
1825
|
-
|
|
2085
|
+
"left, right, ctrl-a, ctrl-e move in the query, ctrl or alt with left or right by a word",
|
|
2086
|
+
"ctrl-w or ctrl-backspace erase a word, ctrl-u back to the start, ctrl-k to the end, del ahead",
|
|
2087
|
+
"ctrl-y puts back what they erased, ctrl-z suspends to the shell",
|
|
2088
|
+
`enter picks${state.multi ? ", tab marks" : ""}, esc or ctrl-c cancels`,
|
|
1826
2089
|
...state.expect.length > 0 ? [`${state.expect.join(", ")} end the pick as this command asks`] : []
|
|
1827
2090
|
];
|
|
1828
2091
|
const title = "keys, any key closes this help";
|
|
@@ -1838,7 +2101,9 @@ function listLines(state, layout, theme) {
|
|
|
1838
2101
|
const top = Math.max(0, Math.min(state.cursor - Math.floor(rows / 2), state.matches.length - rows));
|
|
1839
2102
|
const marks = (state.marked.size > 0 ? ` (${state.marked.size} marked)` : "") + (state.status === "" ? "" : ` ${state.status}`);
|
|
1840
2103
|
const promptWidth = Bun.stringWidth(state.prompt);
|
|
1841
|
-
const
|
|
2104
|
+
const shown = queryShown(state, layout);
|
|
2105
|
+
const text = `${shown.before}${shown.at ?? ""}${shown.after}`;
|
|
2106
|
+
const query = { text, width: Bun.stringWidth(text) };
|
|
1842
2107
|
const place = state.matches.length > rows ? ` (${state.cursor + 1} of ${state.matches.length})` : "";
|
|
1843
2108
|
const count = fit(` ${state.matches.length}/${state.items.length}${place}${marks} ctrl-/ keys`, layout.listWidth, theme.label);
|
|
1844
2109
|
const lines = [{ text: theme.accent(state.prompt) + query.text, width: promptWidth + query.width }, count, ...header];
|
|
@@ -1871,7 +2136,8 @@ var ESCAPE_WAIT_MS = 30;
|
|
|
1871
2136
|
var OPEN = { ctrl: "open" };
|
|
1872
2137
|
var HIDE_CURSOR = "\x1B[?25l";
|
|
1873
2138
|
var SHOW_CURSOR = "\x1B[?25h";
|
|
1874
|
-
var
|
|
2139
|
+
var REVERSE = "\x1B[7m";
|
|
2140
|
+
var REVERSE_END = "\x1B[27m";
|
|
1875
2141
|
var PASTE_ON = "\x1B[?2004h";
|
|
1876
2142
|
var PASTE_OFF = "\x1B[?2004l";
|
|
1877
2143
|
var MOUSE_ON = "\x1B[?1000h\x1B[?1006h";
|
|
@@ -1889,7 +2155,7 @@ function openTerminal() {
|
|
|
1889
2155
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
1890
2156
|
}
|
|
1891
2157
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
1892
|
-
const out =
|
|
2158
|
+
const out = process21.stderr;
|
|
1893
2159
|
let resize;
|
|
1894
2160
|
async function read(onChunk) {
|
|
1895
2161
|
const decoder = new TextDecoder;
|
|
@@ -1915,6 +2181,11 @@ function openTerminal() {
|
|
|
1915
2181
|
out.on("resize", onResize);
|
|
1916
2182
|
read(onChunk);
|
|
1917
2183
|
},
|
|
2184
|
+
suspend() {
|
|
2185
|
+
mode.setRawMode(false);
|
|
2186
|
+
stopJob();
|
|
2187
|
+
mode.setRawMode(true);
|
|
2188
|
+
},
|
|
1918
2189
|
close() {
|
|
1919
2190
|
if (resize !== undefined)
|
|
1920
2191
|
out.off("resize", resize);
|
|
@@ -1942,14 +2213,14 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1942
2213
|
if (restored)
|
|
1943
2214
|
return;
|
|
1944
2215
|
const layout = layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition);
|
|
1945
|
-
let frame = HIDE_CURSOR;
|
|
2216
|
+
let frame = SYNC_START + HIDE_CURSOR;
|
|
1946
2217
|
if (reserved !== layout.height || clear) {
|
|
1947
2218
|
frame += CLEAR_BELOW2 + `
|
|
1948
2219
|
`.repeat(layout.height - 1) + up(layout.height - 1);
|
|
1949
2220
|
reserved = layout.height;
|
|
1950
2221
|
}
|
|
1951
|
-
|
|
1952
|
-
|
|
2222
|
+
const caret = caretCell(state, layout);
|
|
2223
|
+
frame += `\r${overwrite(render(state, layout, theme, preview), terminal.columns)}${up(layout.height - 1)}\r\x1B[${caret.column}G${REVERSE}${caret.char}${REVERSE_END}\r${SYNC_END}`;
|
|
1953
2224
|
terminal.write(frame);
|
|
1954
2225
|
}
|
|
1955
2226
|
function pageSize() {
|
|
@@ -1991,6 +2262,14 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1991
2262
|
terminal.write(`${CLEAR_BELOW2}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
|
|
1992
2263
|
terminal.close();
|
|
1993
2264
|
}
|
|
2265
|
+
function suspend() {
|
|
2266
|
+
if (terminal.suspend === undefined)
|
|
2267
|
+
return;
|
|
2268
|
+
terminal.write(`${CLEAR_BELOW2}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
|
|
2269
|
+
terminal.suspend();
|
|
2270
|
+
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
2271
|
+
draw(true);
|
|
2272
|
+
}
|
|
1994
2273
|
const stop = () => {
|
|
1995
2274
|
state = { ...state, done: "cancel" };
|
|
1996
2275
|
finish?.();
|
|
@@ -2024,6 +2303,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2024
2303
|
for (let key = pending.shift();key !== undefined && state.done === undefined; key = pending.shift()) {
|
|
2025
2304
|
if (key === OPEN || typeof key === "object" && "ctrl" in key && key.ctrl === reload?.key)
|
|
2026
2305
|
await reloadRows();
|
|
2306
|
+
else if (key === "suspend")
|
|
2307
|
+
suspend();
|
|
2027
2308
|
else
|
|
2028
2309
|
state = press({ ...state, page: pageSize() }, key);
|
|
2029
2310
|
}
|
|
@@ -2063,9 +2344,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2063
2344
|
const ended = new Promise((resolve) => {
|
|
2064
2345
|
finish = resolve;
|
|
2065
2346
|
});
|
|
2066
|
-
|
|
2347
|
+
process21.once("exit", restore);
|
|
2067
2348
|
for (const signal of SIGNALS2)
|
|
2068
|
-
|
|
2349
|
+
process21.once(signal, stop);
|
|
2069
2350
|
try {
|
|
2070
2351
|
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
2071
2352
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -2078,8 +2359,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2078
2359
|
await ended;
|
|
2079
2360
|
} finally {
|
|
2080
2361
|
for (const signal of SIGNALS2)
|
|
2081
|
-
|
|
2082
|
-
|
|
2362
|
+
process21.off(signal, stop);
|
|
2363
|
+
process21.off("exit", restore);
|
|
2083
2364
|
restore();
|
|
2084
2365
|
}
|
|
2085
2366
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -2350,7 +2631,7 @@ async function gb(args) {
|
|
|
2350
2631
|
if (parsed.values.json === true)
|
|
2351
2632
|
printJson(all);
|
|
2352
2633
|
else
|
|
2353
|
-
console.log(table2(all.map(row)).map((line) => takesControlCodes(
|
|
2634
|
+
console.log(table2(all.map(row)).map((line) => takesControlCodes(process22.stdout) ? line : Bun.stripANSI(line)).join(`
|
|
2354
2635
|
`));
|
|
2355
2636
|
return 0;
|
|
2356
2637
|
}
|
|
@@ -2407,4 +2688,4 @@ async function finish(command, typed, emitting) {
|
|
|
2407
2688
|
}
|
|
2408
2689
|
|
|
2409
2690
|
// src/gb.ts
|
|
2410
|
-
|
|
2691
|
+
process23.exitCode = await runMain({ name: "gb", run: gb });
|