@trim21/personal-pi-extensions 0.0.294 → 0.0.295
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/package.json +1 -1
- package/src/lib/ui.ts +23 -13
- package/src/opencode/question.ts +1 -1
package/package.json
CHANGED
package/src/lib/ui.ts
CHANGED
|
@@ -54,19 +54,20 @@ export async function selectWithOptionalInput(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/** 已选 / 未选 的符号标记:打勾方框 / 空方框 */
|
|
57
|
-
const CHECKED_PREFIX = "
|
|
58
|
-
const UNCHECKED_PREFIX = "
|
|
57
|
+
const CHECKED_PREFIX = "☑ ";
|
|
58
|
+
const UNCHECKED_PREFIX = "☐ ";
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* Toggle-style multi-select loop built on `ui.select`.
|
|
62
62
|
*
|
|
63
63
|
* Every round lists ALL `entries` — already-selected ones render with a
|
|
64
|
-
*
|
|
65
|
-
* Picking an entry with `inputPrompt` opens an input dialog
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
64
|
+
* `☑ ` marker, the rest with `☐ ` — so re-selecting an entry unchecks it.
|
|
65
|
+
* Picking an entry with `inputPrompt` opens an input dialog; the typed text
|
|
66
|
+
* joins the selection as a `☑ ` row in later rounds and can be unselected
|
|
67
|
+
* like any other entry. Picking `doneLabel` (or dismissing the dialog) ends
|
|
68
|
+
* the loop and returns the selected labels in selection order. Display text
|
|
69
|
+
* is mapped back to the original label via an explicit table so a `☐ ` /
|
|
70
|
+
* `☑ ` prefix inside a label is unambiguous.
|
|
70
71
|
*/
|
|
71
72
|
export async function selectMultiple(
|
|
72
73
|
title: string,
|
|
@@ -78,11 +79,19 @@ export async function selectMultiple(
|
|
|
78
79
|
while (true) {
|
|
79
80
|
const selectedSet = new Set(selected);
|
|
80
81
|
const displayToLabel = new Map<string, string>();
|
|
81
|
-
const round =
|
|
82
|
+
const round: SelectAction[] = [];
|
|
83
|
+
for (const entry of entries) {
|
|
82
84
|
const display = `${selectedSet.has(entry.label) ? CHECKED_PREFIX : UNCHECKED_PREFIX}${entry.label}`;
|
|
83
85
|
displayToLabel.set(display, entry.label);
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
+
round.push({ ...entry, label: display });
|
|
87
|
+
}
|
|
88
|
+
// 经 inputPrompt 输入的自定义答案不是固定条目:单独列出,同样可反选
|
|
89
|
+
for (const label of selected) {
|
|
90
|
+
if (entries.some((entry) => entry.label === label)) continue;
|
|
91
|
+
const display = `${CHECKED_PREFIX}${label}`;
|
|
92
|
+
displayToLabel.set(display, label);
|
|
93
|
+
round.push({ label: display });
|
|
94
|
+
}
|
|
86
95
|
const result = await selectWithOptionalInput(
|
|
87
96
|
title,
|
|
88
97
|
[...round, { label: opts.doneLabel }],
|
|
@@ -91,8 +100,9 @@ export async function selectMultiple(
|
|
|
91
100
|
);
|
|
92
101
|
if (result === undefined || result.label === opts.doneLabel) break;
|
|
93
102
|
if (result.prompted) {
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
// 自定义答案进入已选并继续循环:可反选或继续勾选,最终手动提交
|
|
104
|
+
if (result.input && !selectedSet.has(result.input)) selected.push(result.input);
|
|
105
|
+
continue;
|
|
96
106
|
}
|
|
97
107
|
const label = displayToLabel.get(result.label);
|
|
98
108
|
if (label === undefined) continue;
|
package/src/opencode/question.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* https://github.com/anomalyco/opencode/blob/999be62662/packages/opencode/src/tool/question.ts
|
|
6
6
|
* 与 opencode 的差异:opencode 输出 title "Asked N question(s)",这里未设置;
|
|
7
7
|
* 多选交互是平台差异(opencode 用 checkbox,这里循环 ctx.ui.select 勾选,
|
|
8
|
-
* 已选项显示
|
|
8
|
+
* 已选项显示 `☑ ` 前缀,再次选择即反选,最后选「✓ Done」提交)。
|
|
9
9
|
*
|
|
10
10
|
* 参数与语义和 opencode 的 `question` 工具一致:
|
|
11
11
|
* questions 数组,每项含 question / header / options / multiple:
|