@uncarved/jade 0.1.2 → 0.1.3

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.
Files changed (151) hide show
  1. package/README.md +204 -198
  2. package/bin/jade.js +23 -0
  3. package/dist/commands.d.ts +20 -0
  4. package/dist/commands.js +20 -0
  5. package/dist/commands.js.map +1 -1
  6. package/dist/distro.d.ts +43 -6
  7. package/dist/distro.js +198 -48
  8. package/dist/distro.js.map +1 -1
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.js +2 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/main.js +436 -300
  13. package/dist/main.js.map +1 -1
  14. package/dist/plugin-cli.d.ts +1 -1
  15. package/dist/plugin-cli.js +79 -36
  16. package/dist/plugin-cli.js.map +1 -1
  17. package/dist/plugins/budget.d.ts +2 -2
  18. package/dist/plugins/budget.js +2 -2
  19. package/dist/plugins/budget.js.map +1 -1
  20. package/dist/plugins/builtins.js +6 -3
  21. package/dist/plugins/builtins.js.map +1 -1
  22. package/dist/plugins/checks.d.ts +2 -1
  23. package/dist/plugins/checks.js +25 -5
  24. package/dist/plugins/checks.js.map +1 -1
  25. package/dist/plugins/compact.js +45 -1
  26. package/dist/plugins/compact.js.map +1 -1
  27. package/dist/plugins/core.d.ts +5 -0
  28. package/dist/plugins/core.js +39 -0
  29. package/dist/plugins/core.js.map +1 -1
  30. package/dist/plugins/host.d.ts +52 -0
  31. package/dist/plugins/host.js +115 -0
  32. package/dist/plugins/host.js.map +1 -0
  33. package/dist/plugins/install.d.ts +1 -1
  34. package/dist/plugins/loader.d.ts +238 -10
  35. package/dist/plugins/loader.js +175 -21
  36. package/dist/plugins/loader.js.map +1 -1
  37. package/dist/plugins/policy.d.ts +2 -0
  38. package/dist/plugins/policy.js +17 -1
  39. package/dist/plugins/policy.js.map +1 -1
  40. package/dist/plugins/prompts.d.ts +6 -1
  41. package/dist/plugins/prompts.js +103 -15
  42. package/dist/plugins/prompts.js.map +1 -1
  43. package/dist/plugins/repeats.d.ts +7 -0
  44. package/dist/plugins/repeats.js +74 -13
  45. package/dist/plugins/repeats.js.map +1 -1
  46. package/dist/plugins/review.d.ts +2 -0
  47. package/dist/plugins/review.js +41 -3
  48. package/dist/plugins/review.js.map +1 -1
  49. package/dist/plugins/sessions.d.ts +7 -0
  50. package/dist/plugins/sessions.js +110 -0
  51. package/dist/plugins/sessions.js.map +1 -0
  52. package/dist/provider.d.ts +56 -2
  53. package/dist/provider.js +73 -7
  54. package/dist/provider.js.map +1 -1
  55. package/dist/session-lifecycle.d.ts +61 -0
  56. package/dist/session-lifecycle.js +167 -0
  57. package/dist/session-lifecycle.js.map +1 -0
  58. package/dist/session-scope.d.ts +53 -0
  59. package/dist/session-scope.js +116 -0
  60. package/dist/session-scope.js.map +1 -0
  61. package/dist/sessions.d.ts +6 -0
  62. package/dist/sessions.js +20 -0
  63. package/dist/sessions.js.map +1 -1
  64. package/dist/sys.d.ts +4 -1
  65. package/dist/sys.js +18 -1
  66. package/dist/sys.js.map +1 -1
  67. package/dist/tools/ask.d.ts +11 -0
  68. package/dist/tools/ask.js +62 -0
  69. package/dist/tools/ask.js.map +1 -0
  70. package/dist/tools/fs.d.ts +4 -0
  71. package/dist/tools/fs.js +53 -12
  72. package/dist/tools/fs.js.map +1 -1
  73. package/dist/tools/grep.js +3 -2
  74. package/dist/tools/grep.js.map +1 -1
  75. package/dist/tools/shell.js +5 -1
  76. package/dist/tools/shell.js.map +1 -1
  77. package/dist/tools/task.d.ts +6 -2
  78. package/dist/tools/task.js +36 -8
  79. package/dist/tools/task.js.map +1 -1
  80. package/dist/tools/web.d.ts +33 -3
  81. package/dist/tools/web.js +351 -143
  82. package/dist/tools/web.js.map +1 -1
  83. package/dist/ui/configure.js +91 -22
  84. package/dist/ui/configure.js.map +1 -1
  85. package/dist/ui/diff.d.ts +1 -1
  86. package/dist/ui/diff.js +1 -2
  87. package/dist/ui/diff.js.map +1 -1
  88. package/dist/ui/editor.d.ts +8 -0
  89. package/dist/ui/editor.js +50 -1
  90. package/dist/ui/editor.js.map +1 -1
  91. package/dist/ui/markdown.d.ts +6 -1
  92. package/dist/ui/markdown.js +57 -19
  93. package/dist/ui/markdown.js.map +1 -1
  94. package/dist/ui/render.d.ts +9 -10
  95. package/dist/ui/render.js +35 -72
  96. package/dist/ui/render.js.map +1 -1
  97. package/dist/ui/renderers.d.ts +8 -0
  98. package/dist/ui/renderers.js +169 -0
  99. package/dist/ui/renderers.js.map +1 -0
  100. package/dist/ui/screen.d.ts +22 -2
  101. package/dist/ui/screen.js +104 -15
  102. package/dist/ui/screen.js.map +1 -1
  103. package/dist/ui/transcript.d.ts +13 -0
  104. package/dist/ui/transcript.js +105 -15
  105. package/dist/ui/transcript.js.map +1 -1
  106. package/dist/ui/tui.d.ts +2 -0
  107. package/dist/ui/tui.js +309 -58
  108. package/dist/ui/tui.js.map +1 -1
  109. package/dist/update.d.ts +53 -0
  110. package/dist/update.js +255 -0
  111. package/dist/update.js.map +1 -0
  112. package/package.json +6 -5
  113. package/src/commands.ts +24 -0
  114. package/src/distro.ts +228 -51
  115. package/src/index.ts +2 -0
  116. package/src/main.ts +413 -292
  117. package/src/plugin-cli.ts +73 -34
  118. package/src/plugins/budget.ts +4 -4
  119. package/src/plugins/builtins.ts +6 -3
  120. package/src/plugins/checks.ts +25 -6
  121. package/src/plugins/compact.ts +40 -1
  122. package/src/plugins/core.ts +40 -0
  123. package/src/plugins/host.ts +146 -0
  124. package/src/plugins/install.ts +1 -1
  125. package/src/plugins/loader.ts +379 -23
  126. package/src/plugins/policy.ts +17 -1
  127. package/src/plugins/prompts.ts +108 -15
  128. package/src/plugins/repeats.ts +75 -14
  129. package/src/plugins/review.ts +40 -3
  130. package/src/plugins/sessions.ts +109 -0
  131. package/src/provider.ts +109 -10
  132. package/src/session-lifecycle.ts +194 -0
  133. package/src/session-scope.ts +135 -0
  134. package/src/sessions.ts +17 -0
  135. package/src/sys.ts +18 -1
  136. package/src/tools/ask.ts +72 -0
  137. package/src/tools/fs.ts +53 -12
  138. package/src/tools/grep.ts +3 -2
  139. package/src/tools/shell.ts +5 -1
  140. package/src/tools/task.ts +51 -11
  141. package/src/tools/web.ts +370 -140
  142. package/src/ui/configure.ts +90 -27
  143. package/src/ui/diff.ts +1 -2
  144. package/src/ui/editor.ts +50 -1
  145. package/src/ui/markdown.ts +258 -219
  146. package/src/ui/render.ts +35 -57
  147. package/src/ui/renderers.ts +183 -0
  148. package/src/ui/screen.ts +113 -19
  149. package/src/ui/transcript.ts +109 -16
  150. package/src/ui/tui.tsx +353 -58
  151. package/src/update.ts +262 -0
package/dist/ui/tui.js CHANGED
@@ -4,12 +4,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  // 运行中也能输入:提交的内容由宿主决定立即执行还是排队。
5
5
  import { writeSync } from "node:fs";
6
6
  import { Box, render, Text, useBoxMetrics, useCursor, useInput, usePaste, useWindowSize, } from "ink";
7
- import { useEffect, useReducer, useRef, useState, useSyncExternalStore, } from "react";
7
+ import { createContext, useContext, useEffect, useReducer, useRef, useState, useSyncExternalStore, } from "react";
8
8
  import stringWidth from "string-width";
9
9
  import wrapAnsi from "wrap-ansi";
10
10
  import { mentionAt, mentionText, rankPaths } from "../mentions.js";
11
- import { edit, empty, layout } from "./editor.js";
12
- import { markdownStream } from "./markdown.js";
11
+ import { charWidth, edit, empty, layout, moveRow, offsetAt } from "./editor.js";
12
+ import { expandTabs, markdownStream } from "./markdown.js";
13
13
  import { dim, } from "./screen.js";
14
14
  /**
15
15
  * 界面可用的尺寸:宽度比终端少一列。
@@ -20,10 +20,21 @@ function useScreenSize() {
20
20
  const { columns, rows } = useWindowSize();
21
21
  return { columns: Math.max(1, columns - 1), rows };
22
22
  }
23
+ /** 按键写成 "ctrl+g"、"alt+v"(小写);别的键返回 undefined */
24
+ function keySpec(input, key) {
25
+ if (input.length !== 1)
26
+ return undefined;
27
+ const c = input.toLowerCase();
28
+ if (key.ctrl && !key.meta && /^[a-z]$/.test(c))
29
+ return `ctrl+${c}`;
30
+ if (key.meta && !key.ctrl && /^[a-z0-9]$/.test(c))
31
+ return `alt+${c}`;
32
+ return undefined;
33
+ }
23
34
  /** 对话最多保留这么多行(折行前),超出时丢掉最早的一段 */
24
35
  const MAX_LINES = 10_000;
25
- /** 按显示宽度折行,保留颜色;每一项是屏幕上的一行 */
26
- const wrap = (text, width) => wrapAnsi(text, width, { hard: true, trim: false }).split("\n");
36
+ /** 按显示宽度折行,保留颜色;每一项是屏幕上的一行。制表符先换成空格:按 0 列算宽度会对不齐、超宽 */
37
+ const wrap = (text, width) => wrapAnsi(expandTabs(text), width, { hard: true, trim: false }).split("\n");
27
38
  /** Markdown 排好的一行折成屏幕上的行 */
28
39
  const mdRows = (l, width) => typeof l === "string" ? wrap(l, width) : l.render(width);
29
40
  /** 按宽度截成一行,截掉了内容时以 … 结尾;留出两列给 … 和展开标记 */
@@ -233,6 +244,13 @@ class Store {
233
244
  this.#named.clear();
234
245
  this.update({ version: this.state.version + 1, live: undefined, progress: [], scroll: 0 }, true);
235
246
  }
247
+ /** 展开或收起最后一个可折叠的项(Ctrl+O);start、view 同 toggle */
248
+ toggleLatest(start, view) {
249
+ for (let r = this.#owners.length - 1; r >= 0; r--) {
250
+ if (foldable(this.#owners[r], this.#width))
251
+ return this.toggle(r, start, view);
252
+ }
253
+ }
236
254
  /** 往上(正数)或往下滚 n 行,不超过 max */
237
255
  scrollBy(n, max) {
238
256
  const scroll = Math.max(0, Math.min(max, this.state.scroll + n));
@@ -240,18 +258,40 @@ class Store {
240
258
  this.update({ scroll }, true);
241
259
  }
242
260
  }
243
- /** 开关鼠标事件上报(SGR 格式),用来接收滚轮和点击;开着时终端里选中文字要按住 Shift */
244
- const MOUSE_ON = "\x1b[?1000h\x1b[?1006h";
245
- const MOUSE_OFF = "\x1b[?1006l\x1b[?1000l";
261
+ /**
262
+ * 开关鼠标事件上报(SGR 格式),用来接收滚轮、点击和按住左键拖动(1002)。
263
+ * 开着时终端自己不再处理点击,所以对话区的文字由 jade 自己选中和复制(见 Selection)
264
+ */
265
+ const MOUSE_ON = "\x1b[?1000h\x1b[?1002h\x1b[?1006h";
266
+ const MOUSE_OFF = "\x1b[?1006l\x1b[?1002l\x1b[?1000l";
246
267
  /**
247
268
  * 光标样式:闪烁的竖线(DECSCUSR 5,再加上 ATT610 的"开始闪烁"给只认它的终端),一眼能看出输入框有焦点;
248
269
  * 退出时还原成终端自己的默认样式。光标什么时候显示仍由 Ink 管(只有输入框或输入对话框有焦点时才显示)
249
270
  */
250
271
  const CURSOR_BLINK = "\x1b[5 q\x1b[?12h";
251
272
  const CURSOR_RESET = "\x1b[0 q";
273
+ /** 工作超过这么久后结束,或者这时弹出要用户选择的对话框,用户多半去做别的了:提醒一下 */
274
+ const NOTIFY_AFTER = 10_000;
275
+ /** 支持 OSC 9 桌面通知的终端;其他终端只响铃(不认识的 OSC 9 在有的终端里会弹别的东西) */
276
+ const OSC9_TERMINALS = new Set(["iTerm.app", "WezTerm", "ghostty"]);
277
+ /** 响铃,支持的终端再发一条桌面通知。JADE_NOTIFY=off 关闭 */
278
+ function notifier(stdout, env = process.env) {
279
+ if (env.JADE_NOTIFY === "off")
280
+ return () => { };
281
+ const osc9 = OSC9_TERMINALS.has(env.TERM_PROGRAM ?? "");
282
+ return (message) => stdout.write(osc9 ? `\x1b]9;jade: ${message.replace(/[\x00-\x1f\x7f]/g, " ")}\x07` : "\x07");
283
+ }
252
284
  export function tuiScreen(opts) {
253
285
  const stdout = opts.io?.stdout ?? process.stdout;
254
286
  const store = new Store(opts.status);
287
+ const draft = {};
288
+ const notify = notifier(stdout);
289
+ /** 已经工作了很久(见 NOTIFY_AFTER) */
290
+ const longBusy = () => {
291
+ const since = store.state.busy?.since;
292
+ return since !== undefined && Date.now() - since >= NOTIFY_AFTER;
293
+ };
294
+ let doneTimer;
255
295
  /**
256
296
  * 正在进行的思考:一开始就作为一项放进对话(可以点击展开),之后的增量攒起来,每隔一小段时间改写一次那一项。
257
297
  * 收起时只占一行,显示模型最新想到了哪里;结束时换成用了多久
@@ -293,27 +333,33 @@ export function tuiScreen(opts) {
293
333
  const rest = all ? "" : lines.pop();
294
334
  if (all && lines.at(-1) === "")
295
335
  lines.pop();
296
- appendMd(lines.flatMap((l) => md.push(l)));
336
+ appendMd(lines.flatMap((l) => md.push(expandTabs(l))));
297
337
  if (all) {
298
338
  appendMd(md.flush());
299
339
  md = markdownStream();
300
340
  }
301
341
  store.update({ live: rest || !all ? { text: rest, pending: md.pending() } : undefined });
302
342
  };
303
- const ask = (dialog) => new Promise((resolve) => {
343
+ /** signal 中止时关掉对话框,返回 undefined */
344
+ const ask = (dialog, signal) => new Promise((resolve) => {
345
+ if (signal?.aborted)
346
+ return resolve(undefined);
347
+ const close = () => d.resolve(undefined);
304
348
  const d = {
305
349
  ...dialog,
306
350
  resolve: (v) => {
351
+ signal?.removeEventListener("abort", close);
307
352
  store.update({ dialogs: store.state.dialogs.filter((x) => x !== d) }, true);
308
353
  resolve(v);
309
354
  },
310
355
  };
356
+ signal?.addEventListener("abort", close, { once: true });
311
357
  store.update({ dialogs: [...store.state.dialogs, d] }, true);
312
358
  });
313
359
  // 切到备用屏幕后光标还停在原来的位置(不少终端不会自动归位),Ink 从那里往下画第一帧会让屏幕滚动,
314
360
  // 之后每帧只重写变化的行,整个界面就错位了。所以先自己切过去、清屏、把光标移到左上角
315
361
  stdout.write("\x1b[?1049h\x1b[2J\x1b[H");
316
- const instance = render(_jsx(App, { store: store, version: opts.version, commands: opts.commands, handlers: opts.handlers, history: opts.history ?? [] }), {
362
+ const instance = render(_jsx(App, { store: store, copy: (text) => stdout.write(osc52(text)), version: opts.version, commands: opts.commands, handlers: opts.handlers, history: opts.history ?? [], draft: draft }), {
317
363
  exitOnCtrlC: false,
318
364
  alternateScreen: true,
319
365
  // 全屏每帧只重写变化的行
@@ -391,10 +437,16 @@ export function tuiScreen(opts) {
391
437
  },
392
438
  busy(label) {
393
439
  const current = store.state.busy;
394
- if (label === undefined)
440
+ if (label === undefined) {
441
+ // 稍等一下再提醒:排队的消息接着开始时(马上又 busy)不算结束
442
+ if (longBusy())
443
+ doneTimer ??= setTimeout(() => notify("done"), 300);
395
444
  store.update({ busy: undefined });
396
- else
397
- store.update({ busy: { label, since: current?.since ?? Date.now() } });
445
+ return;
446
+ }
447
+ clearTimeout(doneTimer);
448
+ doneTimer = undefined;
449
+ store.update({ busy: { label, since: current?.since ?? Date.now() } });
398
450
  },
399
451
  status(info) {
400
452
  store.update({ status: { ...store.state.status, ...info } });
@@ -402,19 +454,31 @@ export function tuiScreen(opts) {
402
454
  queued(items) {
403
455
  store.update({ queued: [...items] });
404
456
  },
405
- select: (title, choices, o) => ask({
406
- kind: "select",
407
- title,
408
- body: o?.body,
409
- choices: choices,
410
- resolve: () => { },
411
- }),
412
- input: (title, o) => ask({
457
+ draft: {
458
+ text: () => draft.current?.get() ?? "",
459
+ insert: (text) => draft.current?.apply((s) => edit.insert(s, text.replace(/\r\n?/g, "\n"))),
460
+ set: (text) => {
461
+ const value = text.replace(/\r\n?/g, "\n");
462
+ draft.current?.apply(() => ({ value, cursor: value.length }));
463
+ },
464
+ },
465
+ select: (title, choices, o) => {
466
+ if (longBusy())
467
+ notify(title);
468
+ return ask({
469
+ kind: "select",
470
+ title,
471
+ body: o?.body,
472
+ choices: choices,
473
+ resolve: () => { },
474
+ }, o?.signal);
475
+ },
476
+ input: (title, { signal, ...o } = {}) => ask({
413
477
  kind: "input",
414
478
  title,
415
479
  ...o,
416
480
  resolve: () => { },
417
- }),
481
+ }, signal),
418
482
  clear() {
419
483
  clearTimeout(thinking?.timer);
420
484
  thinking = undefined;
@@ -422,6 +486,7 @@ export function tuiScreen(opts) {
422
486
  store.clear();
423
487
  },
424
488
  async close() {
489
+ clearTimeout(doneTimer);
425
490
  flushLive(true);
426
491
  store.update({ live: undefined, busy: undefined, progress: [] }, true);
427
492
  // 等最后一帧画完再卸载;卸载时 Ink 退出备用屏幕
@@ -438,8 +503,84 @@ export function tuiScreen(opts) {
438
503
  * SGR 鼠标事件(Ink 去掉了开头的 ESC):按钮号、列、行(从 1 开始),M 是按下、m 是松开。
439
504
  * 按钮号去掉 Shift/Alt/Ctrl 位后 0 是左键,64 是滚轮向上,65 向下
440
505
  */
441
- const MOUSE = /^\[<(\d+);\d+;(\d+)([Mm])$/;
506
+ const MOUSE = /^\[<(\d+);(\d+);(\d+)([Mm])$/;
507
+ /** 解析鼠标事件:button 是去掉 Shift/Alt/Ctrl 位的按钮号,press 表示按下;x、y 是屏幕上的列和行(从 0 开始) */
508
+ function mouseEvent(input) {
509
+ const m = MOUSE.exec(input);
510
+ if (!m)
511
+ return undefined;
512
+ return { button: Number(m[1]) & ~0b11100, press: m[4] === "M", x: Number(m[2]) - 1, y: Number(m[3]) - 1 };
513
+ }
442
514
  const WHEEL_LINES = 3;
515
+ /** 按住左键拖动时的按钮号(左键 0 加上移动位 32) */
516
+ const DRAG = 32;
517
+ /** "已复制"的提示显示多久 */
518
+ const COPIED_MS = 2000;
519
+ const same = (a, b) => a.row === b.row && a.col === b.col;
520
+ /** 第 row 行选中的列 [from, to);这一行不在选区里时 undefined */
521
+ function selectedCols(s, row) {
522
+ const { anchor: a, focus: f } = s;
523
+ const [first, last] = a.row < f.row || (a.row === f.row && a.col <= f.col) ? [a, f] : [f, a];
524
+ if (row < first.row || row > last.row)
525
+ return undefined;
526
+ return [row === first.row ? first.col : 0, row === last.row ? last.col + 1 : Infinity];
527
+ }
528
+ /** ANSI 转义序列(CSI,和以 BEL 或 ST 结束的 OSC,例如超链接) */
529
+ const ANSI = /\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/y;
530
+ const INVERSE = "\x1b[7m";
531
+ const INVERSE_OFF = "\x1b[27m";
532
+ /**
533
+ * 逐个走过一行里的字符:visit 收到每个字符和它是否落在列 [from, to) 里(宽字符跨进去一半也算)。
534
+ * 转义序列原样交给 escape
535
+ */
536
+ function walk(line, from, to, visit, escape) {
537
+ let col = 0;
538
+ for (let i = 0; i < line.length;) {
539
+ ANSI.lastIndex = i;
540
+ const m = ANSI.exec(line);
541
+ if (m) {
542
+ escape?.(m[0]);
543
+ i += m[0].length;
544
+ continue;
545
+ }
546
+ const ch = String.fromCodePoint(line.codePointAt(i));
547
+ const w = charWidth(ch);
548
+ visit(ch, col < to && col + Math.max(w, 1) > from);
549
+ col += w;
550
+ i += ch.length;
551
+ }
552
+ }
553
+ /** 给一行里选中的部分加上反色;中间的转义序列可能关掉反色,之后重新打开 */
554
+ function highlight(line, from, to) {
555
+ let out = "";
556
+ let on = false;
557
+ walk(line, from, to, (ch, inside) => {
558
+ if (inside !== on)
559
+ out += inside ? INVERSE : INVERSE_OFF;
560
+ on = inside;
561
+ out += ch;
562
+ }, (seq) => (out += seq + (on ? INVERSE : "")));
563
+ return out + (on ? INVERSE_OFF : "");
564
+ }
565
+ /** 选中的纯文字:每行去掉行尾空白,用换行连起来(自动折行的地方也是换行) */
566
+ function selectedText(s, row) {
567
+ const lines = [];
568
+ const { anchor: a, focus: f } = s;
569
+ for (let r = Math.min(a.row, f.row); r <= Math.max(a.row, f.row); r++) {
570
+ const [from, to] = selectedCols(s, r);
571
+ let text = "";
572
+ walk(row(r) ?? "", from, to, (ch, inside) => void (inside && (text += ch)));
573
+ lines.push(text.trimEnd());
574
+ }
575
+ return lines.join("\n");
576
+ }
577
+ /** OSC 52:让终端把文字放进系统剪贴板(Windows Terminal、iTerm2、kitty、WezTerm 等支持) */
578
+ const osc52 = (text) => `\x1b]52;c;${Buffer.from(text, "utf8").toString("base64")}\x07`;
579
+ /**
580
+ * 输入框和对话框用:有选中的文字时 Ctrl+C 只取消选中(很多人选完习惯按 Ctrl+C 复制),
581
+ * 不中断模型、不清空输入、不取消对话框
582
+ */
583
+ const SelectionContext = createContext({ active: () => false, clear: () => { } });
443
584
  /** 终端矮于这么多行时标题只占一行 */
444
585
  const COMPACT_ROWS = 24;
445
586
  /**
@@ -447,7 +588,7 @@ const COMPACT_ROWS = 24;
447
588
  * 超出的部分被裁掉,输入框的边框和状态栏就显示不全了
448
589
  */
449
590
  const roomFor = (rows, max) => Math.max(3, Math.min(max, Math.floor((rows - 10) / 2)));
450
- function App({ store, version, commands, handlers, history, }) {
591
+ function App({ store, copy, version, commands, handlers, history, draft, }) {
451
592
  const state = useSyncExternalStore(store.subscribe, store.get);
452
593
  const dialog = state.dialogs[0];
453
594
  // 运行中每 100ms 整体重画一次,推动转圈动画。不能让 Spinner 自己重画:
@@ -485,6 +626,30 @@ function App({ store, version, commands, handlers, history, }) {
485
626
  ...live.slice(Math.max(0, start - done.length), Math.max(0, end - done.length)),
486
627
  ];
487
628
  const page = Math.max(1, view - 2);
629
+ // 选中文字:按下左键记下位置,拖动时更新,松开时复制;点一下(没拖动)还是展开或收起那一项。
630
+ // 几个事件可能在同一块输入里连着到达,来不及重画,所以另外用 ref 记着最新的值
631
+ const [selection, setSelectionState] = useState();
632
+ const selected = useRef(undefined);
633
+ const pressed = useRef(undefined);
634
+ const setSelection = (s) => {
635
+ selected.current = s;
636
+ setSelectionState(s);
637
+ };
638
+ const [selectionApi] = useState(() => ({ active: () => selected.current !== undefined, clear: () => setSelection(undefined) }));
639
+ // 宽度变了,行重新折过,原来的位置对不上了
640
+ useEffect(() => setSelection(undefined), [width]);
641
+ const rowAt = (i) => (i < done.length ? done[i] : live[i - done.length]);
642
+ // 复制之后在输入框下面提示一会儿
643
+ const [copied, setCopied] = useState();
644
+ const copiedTimer = useRef(undefined);
645
+ useEffect(() => () => clearTimeout(copiedTimer.current), []);
646
+ const copySelection = (s) => {
647
+ const text = selectedText(s, rowAt);
648
+ copy(text);
649
+ clearTimeout(copiedTimer.current);
650
+ setCopied(`Copied ${[...text].length} characters to the clipboard`);
651
+ copiedTimer.current = setTimeout(() => setCopied(undefined), COPIED_MS);
652
+ };
488
653
  // Ink 增量渲染只用相对光标移动,第一帧起点一旦偏了(启动时终端尺寸还没稳定、窗口缩放、别的输出插进来),
489
654
  // 之后每帧都会画错行。启动后、尺寸变化后和按 Ctrl+L 时让一帧比终端高,Ink 会清屏从左上角整帧重画(包在同步输出里),下一帧再恢复
490
655
  const [redraws, setRedraws] = useState(0);
@@ -503,21 +668,49 @@ function App({ store, version, commands, handlers, history, }) {
503
668
  useInput((input, key) => {
504
669
  if (key.ctrl && input === "l")
505
670
  return setRedraws((n) => n + 1);
506
- const mouse = MOUSE.exec(input);
671
+ // 展开或收起最近的一项(工具结果、思考、检查报告),鼠标点不了时也能看完整内容
672
+ if (key.ctrl && input === "o")
673
+ return store.toggleLatest(start, view);
674
+ const mouse = mouseEvent(input);
507
675
  if (mouse) {
508
- const button = Number(mouse[1]) & ~0b11100;
509
- if (button === 64)
676
+ // 对话区里的位置;clamp 时拖出对话区停在第一行或最后一行,否则在对话区外返回 undefined
677
+ const at = (clamp) => {
678
+ const i = mouse.y - top;
679
+ if (!clamp && (i < 0 || i >= shown.length))
680
+ return undefined;
681
+ return { row: start + Math.min(Math.max(i, 0), shown.length - 1), col: Math.max(0, mouse.x - 1) };
682
+ };
683
+ if (mouse.button === 64)
510
684
  store.scrollBy(WHEEL_LINES, max);
511
- else if (button === 65)
685
+ else if (mouse.button === 65)
512
686
  store.scrollBy(-WHEEL_LINES, max);
513
- else if (button === 0 && mouse[3] === "M") {
514
- // 点在对话区里已经完成的输出上:展开或收起那一项
515
- const i = Number(mouse[2]) - 1 - top;
516
- if (i >= 0 && i < shown.length && start + i < done.length)
517
- store.toggle(start + i, start, view);
687
+ else if (mouse.button === 0 && mouse.press) {
688
+ if (selected.current)
689
+ setSelection(undefined);
690
+ pressed.current = at(false);
691
+ }
692
+ else if (mouse.button === DRAG && pressed.current) {
693
+ setSelection({ anchor: pressed.current, focus: at(true) });
694
+ }
695
+ else if (mouse.button === 0 && !mouse.press && pressed.current) {
696
+ const p = pressed.current;
697
+ pressed.current = undefined;
698
+ const s = selected.current;
699
+ if (s && !same(s.anchor, s.focus))
700
+ copySelection(s);
701
+ else {
702
+ if (s)
703
+ setSelection(undefined);
704
+ // 点在对话区里已经完成的输出上:展开或收起那一项
705
+ if (p.row < done.length)
706
+ store.toggle(p.row, start, view);
707
+ }
518
708
  }
519
709
  return;
520
710
  }
711
+ // 按别的键取消选中;Ctrl+C 由输入框和对话框处理(见 SelectionContext)
712
+ if (selected.current && !(key.ctrl && input === "c"))
713
+ setSelection(undefined);
521
714
  // 选择框自己用 PgUp/PgDn 翻选项
522
715
  if (dialog?.kind === "select")
523
716
  return;
@@ -533,7 +726,10 @@ function App({ store, version, commands, handlers, history, }) {
533
726
  // 总高度要比终端少一行,否则 Ink 认为输出占满了屏幕,每帧清屏重画。
534
727
  // 重画那一帧上下各垫一行空白:终端把顶上那行滚出去后,看到的和平时逐行一样,所以不会闪。
535
728
  // 只做纵向裁剪:每行都已按宽度折好或截断,横向裁剪会让 Ink 每帧对每一行再切一遍 ANSI 字符串
536
- return (_jsx(Box, { flexDirection: "column", width: columns, height: repaint ? rows + 1 : Math.max(1, rows - 1), paddingY: repaint ? 1 : 0, overflowY: "hidden", children: _jsxs(Box, { flexDirection: "column", flexGrow: 1, overflowY: "hidden", children: [_jsx(Header, { status: state.status, version: version, compact: rows < COMPACT_ROWS }), _jsxs(Box, { ref: ref, flexDirection: "column", flexGrow: 1, flexShrink: 1, flexBasis: 0, overflowY: "hidden", paddingX: 1, children: [shown.map((l, i) => (_jsx(Text, { wrap: "truncate-end", children: l || " " }, i))), scrolled ? (_jsx(Text, { dimColor: true, wrap: "truncate-end", children: `── ↓ ${scroll} more lines · wheel / PgDn to scroll · ctrl+end to jump to the bottom ──` })) : null] }), _jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [state.busy && !dialog ? (_jsx(Spinner, { label: state.busy.label, since: state.busy.since })) : null, state.queued.map((q, i) => (_jsxs(Text, { dimColor: true, wrap: "truncate-end", children: [" ↳ queued: ", q.replace(/\s+/g, " ")] }, i))), dialog ? (dialog.kind === "select" ? (_jsx(SelectDialog, { dialog: dialog }, dialogKey(dialog))) : (_jsx(InputDialog, { dialog: dialog }, dialogKey(dialog)))) : null, _jsx(Prompt, { commands: commands, handlers: handlers, history: history, busy: Boolean(state.busy), active: !dialog, onSubmit: () => store.scrollBy(-max, max) }), _jsx(StatusBar, { status: state.status, width: Math.max(10, columns - 2) })] })] }) }));
729
+ return (_jsx(SelectionContext.Provider, { value: selectionApi, children: _jsx(Box, { flexDirection: "column", width: columns, height: repaint ? rows + 1 : Math.max(1, rows - 1), paddingY: repaint ? 1 : 0, overflowY: "hidden", children: _jsxs(Box, { flexDirection: "column", flexGrow: 1, overflowY: "hidden", children: [_jsx(Header, { status: state.status, version: version, compact: rows < COMPACT_ROWS }), _jsxs(Box, { ref: ref, flexDirection: "column", flexGrow: 1, flexShrink: 1, flexBasis: 0, overflowY: "hidden", paddingX: 1, children: [shown.map((l, i) => {
730
+ const cols = selection && selectedCols(selection, start + i);
731
+ return (_jsx(Text, { wrap: "truncate-end", children: cols ? highlight(l || " ", ...cols) : l || " " }, i));
732
+ }), scrolled ? (_jsx(Text, { dimColor: true, wrap: "truncate-end", children: `── ↓ ${scroll} more lines · wheel / PgDn to scroll · ctrl+end to jump to the bottom ──` })) : null] }), _jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [state.busy && !dialog ? (_jsx(Spinner, { label: state.busy.label, since: state.busy.since })) : null, state.queued.map((q, i) => (_jsxs(Text, { dimColor: true, wrap: "truncate-end", children: [" ↳ queued: ", q.replace(/\s+/g, " ")] }, i))), dialog ? (dialog.kind === "select" ? (_jsx(SelectDialog, { dialog: dialog }, dialogKey(dialog))) : (_jsx(InputDialog, { dialog: dialog }, dialogKey(dialog)))) : null, _jsx(Prompt, { commands: commands, handlers: handlers, history: history, bridge: draft, busy: Boolean(state.busy), active: !dialog, onSubmit: () => store.scrollBy(-max, max), flash: copied }), _jsx(StatusBar, { status: state.status, width: Math.max(10, columns - 2) })] })] }) }) }));
537
733
  }
538
734
  const JADE = "#00a86b";
539
735
  const SHINE = "#b6f2d4";
@@ -639,9 +835,11 @@ function StatusBar({ status, width }) {
639
835
  },
640
836
  ]
641
837
  : []),
838
+ // 插件的段落:比提示晚、比缓存早去掉
839
+ ...(status.plugins ?? []).map((p) => ({ text: p.text, dropAt: 7.5, dim: true })),
642
840
  {
643
- text: "PgUp/PgDn scroll · click ▸ to expand · shift+drag to select",
644
- short: "click ▸ to expand",
841
+ text: "PgUp/PgDn scroll · click ▸ or ctrl+o to expand · drag to select and copy",
842
+ short: "ctrl+o to expand",
645
843
  shortAt: 10,
646
844
  dropAt: 9,
647
845
  dim: true,
@@ -716,7 +914,7 @@ function editKey(s, input, key) {
716
914
  return text ? edit.insert(s, text) : undefined;
717
915
  }
718
916
  /** 渲染可编辑文本并把终端光标放到输入位置(输入法的候选框跟着它) */
719
- function EditableText({ state, width, prefix, mask, placeholder, active, maxRows = Infinity, }) {
917
+ function EditableText({ state, width, prefix, mask, placeholder, active, maxRows = Infinity, place, }) {
720
918
  const ref = useRef(null);
721
919
  // 只用来在布局变化后重画一次、重新计算光标位置;它给的是相对父元素的坐标,光标要的是相对整个输出
722
920
  const metrics = useBoxMetrics(ref);
@@ -740,6 +938,8 @@ function EditableText({ state, width, prefix, mask, placeholder, active, maxRows
740
938
  ? origin(ref.current)
741
939
  : undefined;
742
940
  const position = at && { x: at.x + prefix.length + col, y: at.y + row };
941
+ if (place)
942
+ place.current = at && { x: at.x + prefix.length, y: at.y, first, rows: rows.length };
743
943
  const [, recheck] = useReducer((n) => n + 1, 0);
744
944
  useEffect(() => {
745
945
  if (!at || !ref.current)
@@ -773,7 +973,8 @@ function origin(node) {
773
973
  }
774
974
  return { x, y };
775
975
  }
776
- function Prompt({ commands, handlers, history: initial, busy, active, onSubmit, }) {
976
+ function Prompt({ commands, handlers, history: initial, bridge, busy, active, onSubmit, flash, }) {
977
+ const selection = useContext(SelectionContext);
777
978
  const [current, setState] = useLive(empty);
778
979
  const [getSelected, setSelected] = useLive(0);
779
980
  const [getNotice, setNotice] = useLive(undefined);
@@ -782,7 +983,12 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
782
983
  const browsing = useRef(-1);
783
984
  const draft = useRef("");
784
985
  const lastCtrlC = useRef(0);
986
+ const lastEsc = useRef(0);
987
+ /** 输入框文字在屏幕上的位置,点击时换算光标位置用(见 EditableText 的 place) */
988
+ const place = useRef(undefined);
785
989
  const { columns, rows } = useScreenSize();
990
+ /** 输入框里文字的宽度:边框、内边距和前面的 "› " 之外 */
991
+ const textWidth = Math.max(10, columns - 5) - 2;
786
992
  /** 补全菜单、搜索结果最多显示几项;输入框最多几行 */
787
993
  const menuRows = roomFor(rows, MENTION_ROWS);
788
994
  const inputRows = roomFor(rows, 10);
@@ -865,19 +1071,30 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
865
1071
  setState(s);
866
1072
  setSelected(0);
867
1073
  setNotice(undefined);
1074
+ lastEsc.current = 0;
868
1075
  };
869
- const submit = (text) => {
870
- if (!text.trim())
871
- return;
1076
+ const remember = (text) => {
872
1077
  history.current = [
873
1078
  ...history.current.filter((h) => h !== text),
874
1079
  text,
875
1080
  ].slice(-100);
876
1081
  browsing.current = -1;
1082
+ };
1083
+ const submit = (text) => {
1084
+ if (!text.trim())
1085
+ return;
1086
+ remember(text);
877
1087
  set(empty);
878
1088
  onSubmit();
879
1089
  handlers.submit(text);
880
1090
  };
1091
+ /** 清空输入;清掉的内容放进(本次运行的)历史,按 ↑ 能找回来 */
1092
+ const discard = () => {
1093
+ const text = current().value;
1094
+ if (text.trim())
1095
+ remember(text);
1096
+ set(empty);
1097
+ };
881
1098
  /** 用选中的路径替换正在输入的 @ 引用;目录不加空格,接着补全里面的文件 */
882
1099
  const complete = (p) => {
883
1100
  const { state, mention } = derive();
@@ -889,6 +1106,7 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
889
1106
  cursor: mention.start + text.length,
890
1107
  });
891
1108
  };
1109
+ bridge.current = { get: () => current().value, apply: (f) => set(f(current())) };
892
1110
  const recall = (i) => {
893
1111
  browsing.current = i;
894
1112
  const value = i === -1
@@ -938,6 +1156,8 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
938
1156
  setSearch({ query: s.query + text, index: 0 });
939
1157
  };
940
1158
  useInput((input, key) => {
1159
+ if (key.ctrl && input === "c" && selection.active())
1160
+ return selection.clear();
941
1161
  const search = getSearch();
942
1162
  if (search)
943
1163
  return searchKey(search, input, key);
@@ -950,7 +1170,7 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
950
1170
  if (busy)
951
1171
  return handlers.interrupt();
952
1172
  if (state.value)
953
- return set(empty);
1173
+ return discard();
954
1174
  if (Date.now() - lastCtrlC.current < 2000)
955
1175
  return handlers.exit();
956
1176
  lastCtrlC.current = Date.now();
@@ -959,7 +1179,28 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
959
1179
  if (key.escape) {
960
1180
  if (busy)
961
1181
  return handlers.interrupt();
962
- return set(empty);
1182
+ if (!state.value)
1183
+ return;
1184
+ // 误按一下 Esc 不清掉写了半天的内容:连按两次才清空
1185
+ if (Date.now() - lastEsc.current < 1500)
1186
+ return discard();
1187
+ setNotice("Press Esc again to clear the input");
1188
+ lastEsc.current = Date.now();
1189
+ return;
1190
+ }
1191
+ // 点击输入框里的文字:光标移到点的位置
1192
+ const mouse = mouseEvent(input);
1193
+ if (mouse) {
1194
+ const at = place.current;
1195
+ if (!at || mouse.button !== 0 || !mouse.press)
1196
+ return;
1197
+ const row = mouse.y - at.y;
1198
+ if (row < 0 || row >= at.rows)
1199
+ return;
1200
+ const cursor = offsetAt(state.value, textWidth, at.first + row, mouse.x - at.x);
1201
+ if (cursor !== undefined)
1202
+ setState({ ...state, cursor });
1203
+ return;
963
1204
  }
964
1205
  // 文字和回车在同一块里到达(输入很快时终端可能合并):插入文字后发送
965
1206
  if (!key.ctrl &&
@@ -998,8 +1239,10 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
998
1239
  const { menu, selected } = derive();
999
1240
  if (menu)
1000
1241
  return setSelected((selected - 1 + menu) % menu);
1001
- if (!edit.onFirstLine(state))
1002
- return setState(edit.up(state));
1242
+ // 按折行后的屏幕行移动:一大段没有换行的文字也能上下走,到了第一行才翻历史
1243
+ const up = moveRow(state, textWidth, -1);
1244
+ if (up)
1245
+ return setState(up);
1003
1246
  if (browsing.current + 1 < history.current.length) {
1004
1247
  if (browsing.current === -1)
1005
1248
  draft.current = state.value;
@@ -1011,12 +1254,16 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
1011
1254
  const { menu, selected } = derive();
1012
1255
  if (menu)
1013
1256
  return setSelected((selected + 1) % menu);
1014
- if (!edit.onLastLine(state))
1015
- return setState(edit.down(state));
1257
+ const down = moveRow(state, textWidth, 1);
1258
+ if (down)
1259
+ return setState(down);
1016
1260
  if (browsing.current >= 0)
1017
1261
  recall(browsing.current - 1);
1018
1262
  return;
1019
1263
  }
1264
+ const spec = keySpec(input, key);
1265
+ if (spec && handlers.key?.(spec))
1266
+ return;
1020
1267
  const next = editKey(state, input, key);
1021
1268
  if (next)
1022
1269
  set(next);
@@ -1026,7 +1273,7 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
1026
1273
  ? "Type to queue a message · esc to interrupt"
1027
1274
  : columns >= 70
1028
1275
  ? "Message jade · / commands · @ files · ↑ or ctrl+r for history"
1029
- : "Message jade · / commands · @ files", active: active, maxRows: inputRows })) }), search ? (_jsxs(Box, { flexDirection: "column", paddingX: 2, children: [results.length ? (results.slice(first, first + menuRows).map((h, i) => {
1276
+ : "Message jade · / commands · @ files", active: active, maxRows: inputRows, place: place })) }), search ? (_jsxs(Box, { flexDirection: "column", paddingX: 2, children: [results.length ? (results.slice(first, first + menuRows).map((h, i) => {
1030
1277
  const on = first + i === hit;
1031
1278
  return (_jsxs(Text, { wrap: "truncate-end", color: on ? "cyan" : undefined, bold: on, children: [on ? "❯ " : " ", h.replace(/\s*\n\s*/g, " ⏎ ")] }, first + i));
1032
1279
  })) : (_jsx(Text, { dimColor: true, children: " no match" })), _jsx(Hint, { width: hintWidth, variants: [
@@ -1045,7 +1292,7 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
1045
1292
  " ↑↓ select · enter/tab insert the path · the file's content is sent with the message",
1046
1293
  " ↑↓ select · enter/tab insert the path",
1047
1294
  " ↑↓ · enter insert",
1048
- ] })] })) : notice ? (_jsxs(Text, { color: "yellow", children: [" ", notice] })) : null] }));
1295
+ ] })] })) : notice ? (_jsxs(Text, { color: "yellow", children: [" ", notice] })) : null, flash ? (_jsx(Box, { position: "absolute", top: 0, right: 2, children: _jsxs(Text, { color: "green", children: [" ", flash, " "] }) })) : null] }));
1049
1296
  }
1050
1297
  /** @ 补全最多显示几项 */
1051
1298
  const MENTION_ROWS = 8;
@@ -1058,6 +1305,7 @@ const VISIBLE = 10;
1058
1305
  /** 选项多于这么多时可以打字筛选(这时 j/k 和数字键不再是快捷键) */
1059
1306
  const FILTER_FROM = 10;
1060
1307
  function SelectDialog({ dialog, }) {
1308
+ const selection = useContext(SelectionContext);
1061
1309
  const [getSelected, setSelected] = useLive(0);
1062
1310
  const [getQuery, setQuery] = useLive("");
1063
1311
  const { rows, columns } = useScreenSize();
@@ -1075,16 +1323,16 @@ function SelectDialog({ dialog, }) {
1075
1323
  const selected = Math.min(getSelected(), Math.max(0, n - 1));
1076
1324
  // 终端矮时少显示几项,加上预览一起不超过终端的高度
1077
1325
  const visible = roomFor(rows, VISIBLE);
1078
- // 预览(例如要写入的文件)过长时截断:整个界面高过终端时 Ink 会每帧清屏重画
1079
- const lines = dialog.body?.split("\n") ?? [];
1326
+ // 预览(例如要写入的文件)过长时截断:整个界面高过终端时 Ink 会每帧清屏重画,底部的选项和提示也会被裁掉。
1327
+ // 按折行后的屏幕行数截断(一行长代码会占好几行),每一行单独显示、不再折行
1328
+ const lines = !dialog.body ? [] : wrap(dialog.body, Math.max(1, columns - 4));
1080
1329
  const room = Math.max(3, rows - Math.min(n, visible) - 16);
1081
1330
  const body = lines.length > room
1082
- ? [
1083
- ...lines.slice(0, room),
1084
- dim(`… ${lines.length - room} more lines`),
1085
- ].join("\n")
1086
- : dialog.body;
1331
+ ? [...lines.slice(0, room - 1), dim(`… ${lines.length - room + 1} more lines`)]
1332
+ : lines;
1087
1333
  useInput((input, key) => {
1334
+ if (key.ctrl && input === "c" && selection.active())
1335
+ return selection.clear();
1088
1336
  const items = filtered();
1089
1337
  const n = items.length;
1090
1338
  const selected = Math.min(getSelected(), Math.max(0, n - 1));
@@ -1127,7 +1375,7 @@ function SelectDialog({ dialog, }) {
1127
1375
  });
1128
1376
  // 选项多时只显示选中项附近的一段
1129
1377
  const start = around(selected, n, visible);
1130
- return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1, children: [_jsx(Text, { bold: true, wrap: "truncate-end", children: dialog.title }), body ? _jsx(Text, { children: body }) : null, filtering ? (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: "cyan", children: "filter\u203A " }), query ? (_jsx(Text, { children: query })) : (_jsxs(Text, { dimColor: true, children: ["type to filter ", dialog.choices.length, " items"] }))] })) : null, _jsxs(Box, { flexDirection: "column", marginTop: filtering ? 0 : 1, children: [start > 0 ? _jsxs(Text, { dimColor: true, children: [" \u2191 ", start, " more"] }) : null, n === 0 ? _jsx(Text, { dimColor: true, children: " no match" }) : null, items.slice(start, start + visible).map(({ c, i }, j) => {
1378
+ return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1, children: [_jsx(Text, { bold: true, wrap: "truncate-end", children: dialog.title }), body.map((l, i) => (_jsx(Text, { wrap: "truncate-end", children: l || " " }, i))), filtering ? (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: "cyan", children: "filter\u203A " }), query ? (_jsx(Text, { children: query })) : (_jsxs(Text, { dimColor: true, children: ["type to filter ", dialog.choices.length, " items"] }))] })) : null, _jsxs(Box, { flexDirection: "column", marginTop: filtering ? 0 : 1, children: [start > 0 ? _jsxs(Text, { dimColor: true, children: [" \u2191 ", start, " more"] }) : null, n === 0 ? _jsx(Text, { dimColor: true, children: " no match" }) : null, items.slice(start, start + visible).map(({ c, i }, j) => {
1131
1379
  const on = start + j === selected;
1132
1380
  return (_jsxs(Text, { wrap: "truncate-end", children: [_jsxs(Text, { color: on ? "cyan" : undefined, bold: on, children: [on ? "❯ " : " ", filtering ? "" : `${i + 1}. `, c.label] }), c.hint ? _jsxs(Text, { dimColor: true, children: [" ", c.hint] }) : null] }, i));
1133
1381
  }), start + visible < n ? (_jsxs(Text, { dimColor: true, children: [" \u2193 ", n - start - visible, " more"] })) : null] }), _jsx(Hint, { width: Math.max(10, columns - 4), variants: filtering
@@ -1135,6 +1383,7 @@ function SelectDialog({ dialog, }) {
1135
1383
  : ["↑↓ select · enter confirm · esc cancel", "↑↓ · enter · esc"] })] }));
1136
1384
  }
1137
1385
  function InputDialog({ dialog, }) {
1386
+ const selection = useContext(SelectionContext);
1138
1387
  const initial = dialog.initial ?? "";
1139
1388
  const [current, setState] = useLive({
1140
1389
  value: initial,
@@ -1144,6 +1393,8 @@ function InputDialog({ dialog, }) {
1144
1393
  const { columns } = useScreenSize();
1145
1394
  usePaste((text) => setState(edit.insert(current(), text.replace(/\r?\n/g, ""))));
1146
1395
  useInput((input, key) => {
1396
+ if (key.ctrl && input === "c" && selection.active())
1397
+ return selection.clear();
1147
1398
  const state = current();
1148
1399
  if (key.return)
1149
1400
  return dialog.resolve(state.value.trim());