iubcli 4.2.15 → 4.2.16

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/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  // src/index.ts
4
4
  import fs8 from "fs";
5
5
  import path8 from "path";
6
- import readline from "readline";
7
6
  import { execSync as execSync3 } from "child_process";
8
7
  import { Command } from "commander";
9
8
  import chalk9 from "chalk";
@@ -2300,22 +2299,41 @@ function stripTerminalControlNoise(raw) {
2300
2299
  }
2301
2300
  function isIncompleteEscapePrefix(str) {
2302
2301
  if (str === "\x1B" || str === "\x1BO") return true;
2303
- return /^\x1b\[[0-9;?:]*$/.test(str);
2302
+ return /^\x1b\[[0-9;?:<>=]*$/.test(str);
2303
+ }
2304
+ function enterRawStdin() {
2305
+ const wasRaw = Boolean(process.stdin.isRaw);
2306
+ try {
2307
+ if (process.stdin.isTTY) {
2308
+ if (wasRaw) {
2309
+ process.stdin.setRawMode(false);
2310
+ }
2311
+ process.stdin.setRawMode(true);
2312
+ }
2313
+ } catch {
2314
+ }
2315
+ try {
2316
+ process.stdin.ref?.();
2317
+ process.stdin.resume();
2318
+ } catch {
2319
+ }
2320
+ return wasRaw;
2304
2321
  }
2305
2322
  function parseTerminalEscape(rest) {
2306
- const win32Match = rest.match(/^\x1b\[(\d+);(\d+);(\d+);([01]);(\d+);(\d+)_/);
2323
+ const win32Match = rest.match(/^\x1b\[([0-9;]*)_/);
2307
2324
  if (win32Match) {
2308
2325
  const length = win32Match[0].length;
2309
- const vk = Number(win32Match[1]);
2310
- const uc = Number(win32Match[3]);
2311
- const isKeyDown = win32Match[4] === "1";
2312
- const controlState = Number(win32Match[5]);
2326
+ const parts = win32Match[1].split(";");
2327
+ const vk = Number(parts[0] || 0);
2328
+ const uc = Number(parts[2] || 0);
2329
+ const isKeyDown = parts[3] === "1";
2330
+ const controlState = Number(parts[4] || 0);
2313
2331
  if (!isKeyDown) return { type: "noop", length };
2314
2332
  if (uc === 3 || vk === 67 && (controlState & 12) !== 0) return { type: "ctrl_c", length };
2315
- if (vk === 38) return { type: "up", length };
2316
- if (vk === 40) return { type: "down", length };
2317
- if (vk === 37) return { type: "left", length };
2318
- if (vk === 39) return { type: "right", length };
2333
+ if (vk === 38 || uc === 0 && vk === 104) return { type: "up", length };
2334
+ if (vk === 40 || uc === 0 && vk === 98) return { type: "down", length };
2335
+ if (vk === 37 || uc === 0 && vk === 100) return { type: "left", length };
2336
+ if (vk === 39 || uc === 0 && vk === 102) return { type: "right", length };
2319
2337
  if (vk === 33) return { type: "page_up", length };
2320
2338
  if (vk === 34) return { type: "page_down", length };
2321
2339
  if (vk === 36) return { type: "home", length };
@@ -2331,21 +2349,27 @@ function parseTerminalEscape(rest) {
2331
2349
  if (rest.startsWith("\x1B\r") || rest.startsWith("\x1B\r")) {
2332
2350
  return { type: "newline", length: 2 };
2333
2351
  }
2334
- const kittyEnterMatch = rest.match(/^\x1b\[13(?:;(\d+)(?::\d+)?)?u/);
2352
+ const kittyEnterMatch = rest.match(/^\x1b\[13(?:;(\d+)(?::(\d+))?)?u/);
2335
2353
  if (kittyEnterMatch) {
2354
+ if (kittyEnterMatch[2] === "3") return { type: "noop", length: kittyEnterMatch[0].length };
2336
2355
  const mod = kittyEnterMatch[1] ? Number(kittyEnterMatch[1]) : 1;
2337
2356
  return { type: mod > 1 ? "newline" : "enter", length: kittyEnterMatch[0].length };
2338
2357
  }
2339
2358
  const kittyEscMatch = rest.match(/^\x1b\[27(?:;[0-9:]+)?u/);
2340
2359
  if (kittyEscMatch) {
2360
+ if (/:3(?:$|;)/.test(kittyEscMatch[0])) return { type: "noop", length: kittyEscMatch[0].length };
2341
2361
  return { type: "escape", length: kittyEscMatch[0].length };
2342
2362
  }
2343
- const kittyTabMatch = rest.match(/^\x1b\[9(?:;1(?::\d+)?)?u/);
2363
+ const kittyTabMatch = rest.match(/^\x1b\[9(?:;1(?::(\d+))?)?u/);
2344
2364
  if (kittyTabMatch) {
2365
+ if (kittyTabMatch[1] === "3") return { type: "noop", length: kittyTabMatch[0].length };
2345
2366
  return { type: "tab", length: kittyTabMatch[0].length };
2346
2367
  }
2347
- const csiNavMatch = rest.match(/^\x1b\[[0-9;:]*([ABCDHF])/);
2368
+ const csiNavMatch = rest.match(/^\x1b\[([0-9;:]*)([ABCDHF])/);
2348
2369
  if (csiNavMatch) {
2370
+ if (/:3(?:$|;)/.test(csiNavMatch[1])) {
2371
+ return { type: "noop", length: csiNavMatch[0].length };
2372
+ }
2349
2373
  const dirMap = {
2350
2374
  A: "up",
2351
2375
  B: "down",
@@ -2354,7 +2378,7 @@ function parseTerminalEscape(rest) {
2354
2378
  H: "home",
2355
2379
  F: "end"
2356
2380
  };
2357
- return { type: dirMap[csiNavMatch[1]], length: csiNavMatch[0].length };
2381
+ return { type: dirMap[csiNavMatch[2]], length: csiNavMatch[0].length };
2358
2382
  }
2359
2383
  const rxvtNavMatch = rest.match(/^\x1b\[([abcd])/);
2360
2384
  if (rxvtNavMatch) {
@@ -2366,10 +2390,13 @@ function parseTerminalEscape(rest) {
2366
2390
  };
2367
2391
  return { type: dirMap[rxvtNavMatch[1]], length: 3 };
2368
2392
  }
2369
- const tildeMatch = rest.match(/^\x1b\[(\d+)(?:;[0-9:]+)?~/);
2393
+ const tildeMatch = rest.match(/^\x1b\[(\d+)(?:;([0-9:]+))?~/);
2370
2394
  if (tildeMatch) {
2371
2395
  const code = tildeMatch[1];
2372
2396
  const length = tildeMatch[0].length;
2397
+ if (tildeMatch[2] && /:3(?:$|;)/.test(tildeMatch[2])) {
2398
+ return { type: "noop", length };
2399
+ }
2373
2400
  if (code === "5") return { type: "page_up", length };
2374
2401
  if (code === "6") return { type: "page_down", length };
2375
2402
  if (code === "1" || code === "7") return { type: "home", length };
@@ -2398,7 +2425,7 @@ function parseTerminalEscape(rest) {
2398
2425
  };
2399
2426
  return { type: ss3Map[ch] || "noop", length: 3 };
2400
2427
  }
2401
- const genericCsi = rest.match(/^\x1b\[[0-9;?:]*[a-zA-Z~_]/);
2428
+ const genericCsi = rest.match(/^\x1b\[[0-9;?:<>=]*[a-zA-Z~_]/);
2402
2429
  if (genericCsi) {
2403
2430
  return { type: "noop", length: genericCsi[0].length };
2404
2431
  }
@@ -2450,12 +2477,7 @@ async function interactiveSelect(config) {
2450
2477
  _interactiveSelectActive = true;
2451
2478
  let cursor = config.options.findIndex((o) => o.value === config.initialValue);
2452
2479
  if (cursor === -1) cursor = 0;
2453
- const wasRaw = process.stdin.isRaw;
2454
- try {
2455
- process.stdin.setRawMode(true);
2456
- } catch {
2457
- }
2458
- process.stdin.resume();
2480
+ const wasRaw = enterRawStdin();
2459
2481
  process.stdout.write("\x1B[?25l");
2460
2482
  let termRows = process.stdout.rows || 24;
2461
2483
  let termCols = process.stdout.columns || 80;
@@ -2697,7 +2719,7 @@ async function interactiveSelect(config) {
2697
2719
  }
2698
2720
  };
2699
2721
  process.stdout.on("resize", onResize);
2700
- process.stdin.on("data", onData);
2722
+ process.stdin.prependListener("data", onData);
2701
2723
  draw();
2702
2724
  });
2703
2725
  }
@@ -2719,10 +2741,8 @@ async function interactiveInput(config) {
2719
2741
  let inBracketedPaste = false;
2720
2742
  let pasteBuf = "";
2721
2743
  let lastLines = 0;
2722
- const wasRaw = process.stdin.isRaw;
2744
+ const wasRaw = enterRawStdin();
2723
2745
  try {
2724
- process.stdin.setRawMode(true);
2725
- process.stdin.resume();
2726
2746
  process.stdout.write("\x1B[?2004h");
2727
2747
  } catch {
2728
2748
  }
@@ -2932,7 +2952,7 @@ async function interactiveInput(config) {
2932
2952
  lastLines = initLines.length;
2933
2953
  const initCol = Math.min(termCols - 2, 5 + (value.length === 0 ? 0 : cursorPos));
2934
2954
  process.stdout.write(`\x1B[${lastLines - 1}A\x1B[${initCol}G\x1B[?25h`);
2935
- process.stdin.on("data", onData);
2955
+ process.stdin.prependListener("data", onData);
2936
2956
  });
2937
2957
  }
2938
2958
  function updateDockedModel(provider, model, mode) {
@@ -3035,12 +3055,7 @@ async function readInlinePrompt(options) {
3035
3055
  process.stdout.write("\x1B[?2004h");
3036
3056
  } catch {
3037
3057
  }
3038
- const wasRaw = process.stdin.isRaw;
3039
- try {
3040
- process.stdin.setRawMode(true);
3041
- process.stdin.resume();
3042
- } catch {
3043
- }
3058
+ const wasRaw = enterRawStdin();
3044
3059
  let bufferLines = [""];
3045
3060
  let cursorLine = 0;
3046
3061
  let cursorCol = 0;
@@ -3482,7 +3497,7 @@ async function readInlinePrompt(options) {
3482
3497
  idx = printableEnd;
3483
3498
  }
3484
3499
  };
3485
- process.stdin.on("data", onData);
3500
+ process.stdin.prependListener("data", onData);
3486
3501
  });
3487
3502
  }
3488
3503
  async function readOpenCodePrompt(options) {
@@ -8514,18 +8529,14 @@ function attachEscapeListener(onEscape) {
8514
8529
  return () => {
8515
8530
  };
8516
8531
  }
8517
- readline.emitKeypressEvents(process.stdin);
8518
- const wasRaw = process.stdin.isRaw;
8519
- try {
8520
- process.stdin.setRawMode(true);
8521
- process.stdin.resume();
8522
- } catch {
8523
- }
8532
+ const wasRaw = enterRawStdin();
8524
8533
  let triggered = false;
8534
+ let escBuffer = "";
8525
8535
  let escTimer = null;
8526
8536
  const triggerEscape = () => {
8527
8537
  if (triggered) return;
8528
8538
  triggered = true;
8539
+ escBuffer = "";
8529
8540
  if (escTimer) {
8530
8541
  clearTimeout(escTimer);
8531
8542
  escTimer = null;
@@ -8533,52 +8544,58 @@ function attachEscapeListener(onEscape) {
8533
8544
  onEscape();
8534
8545
  };
8535
8546
  const onData = (chunk) => {
8536
- if (isInteractivePromptActive()) {
8537
- if (escTimer) {
8538
- clearTimeout(escTimer);
8539
- escTimer = null;
8540
- }
8541
- return;
8547
+ if (escTimer) {
8548
+ clearTimeout(escTimer);
8549
+ escTimer = null;
8542
8550
  }
8543
- const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
8544
- if (buf.length === 1 && buf[0] === 3) {
8545
- process.exit(0);
8551
+ if (isInteractivePromptActive() || wasInteractivePromptRecentlyActive(600)) {
8552
+ escBuffer = "";
8553
+ return;
8546
8554
  }
8547
- if (wasInteractivePromptRecentlyActive(600)) return;
8548
- if (buf.length === 1 && buf[0] === 27) {
8549
- if (escTimer) {
8550
- triggerEscape();
8551
- return;
8555
+ const incoming = typeof chunk === "string" ? chunk : chunk.toString("utf-8");
8556
+ const str = escBuffer + incoming;
8557
+ escBuffer = "";
8558
+ if (!str) return;
8559
+ let idx = 0;
8560
+ while (idx < str.length) {
8561
+ const rest = str.slice(idx);
8562
+ if (rest.startsWith("")) {
8563
+ process.exit(0);
8552
8564
  }
8553
- escTimer = setTimeout(() => {
8554
- escTimer = null;
8555
- if (!isInteractivePromptActive() && !wasInteractivePromptRecentlyActive(600)) {
8565
+ if (rest[0] === "\x1B") {
8566
+ const parsed = parseTerminalEscape(rest);
8567
+ if (parsed === null) {
8568
+ escBuffer = rest;
8569
+ escTimer = setTimeout(() => {
8570
+ escBuffer = "";
8571
+ escTimer = null;
8572
+ if (!isInteractivePromptActive() && !wasInteractivePromptRecentlyActive(600)) {
8573
+ triggerEscape();
8574
+ }
8575
+ }, 60);
8576
+ return;
8577
+ }
8578
+ if (parsed.type === "ctrl_c") {
8579
+ process.exit(0);
8580
+ }
8581
+ if (parsed.type === "escape") {
8556
8582
  triggerEscape();
8583
+ return;
8557
8584
  }
8558
- }, 60);
8559
- } else if (escTimer) {
8560
- clearTimeout(escTimer);
8561
- escTimer = null;
8562
- }
8563
- };
8564
- const keypressHandler = (str, key) => {
8565
- if (key && key.ctrl && key.name === "c") {
8566
- process.exit(0);
8567
- }
8568
- if (isInteractivePromptActive() || wasInteractivePromptRecentlyActive(600)) return;
8569
- if (key && key.name === "escape" || str === "\x1B" || str === "\x1B" || key && key.sequence === "\x1B") {
8570
- triggerEscape();
8585
+ idx += parsed.length;
8586
+ continue;
8587
+ }
8588
+ idx += 1;
8571
8589
  }
8572
8590
  };
8573
8591
  process.stdin.on("data", onData);
8574
- process.stdin.on("keypress", keypressHandler);
8575
8592
  return () => {
8593
+ escBuffer = "";
8576
8594
  if (escTimer) {
8577
8595
  clearTimeout(escTimer);
8578
8596
  escTimer = null;
8579
8597
  }
8580
8598
  process.stdin.removeListener("data", onData);
8581
- process.stdin.removeListener("keypress", keypressHandler);
8582
8599
  try {
8583
8600
  if (!wasRaw && process.stdin.isTTY) {
8584
8601
  process.stdin.setRawMode(false);