claude360 0.3.0 → 0.3.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/package.json +1 -1
- package/src/menu.js +9 -4
- package/src/prompts.js +3 -2
package/package.json
CHANGED
package/src/menu.js
CHANGED
|
@@ -89,12 +89,15 @@ export function buildDailyMenu() {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
// 分区标题渲染为
|
|
92
|
+
// 分区标题渲染为 `──── 标题 ────` 形式的居中分隔线,让各组功能在视觉上彼此分开
|
|
93
93
|
function renderSectionRule(title, color) {
|
|
94
94
|
const level = toLevel(color);
|
|
95
|
-
const lead = "───";
|
|
96
95
|
const label = ` ${title} `;
|
|
97
|
-
|
|
96
|
+
// 标题居中:左右横杠尽量均分(余数补到右侧),整体保持 MENU_RULE_WIDTH 宽
|
|
97
|
+
const remaining = Math.max(8, MENU_RULE_WIDTH - displayWidth(label));
|
|
98
|
+
const leadLen = Math.floor(remaining / 2);
|
|
99
|
+
const lead = "─".repeat(leadLen);
|
|
100
|
+
const tail = "─".repeat(remaining - leadLen);
|
|
98
101
|
if (!level) {
|
|
99
102
|
return `${lead}${label}${tail}`;
|
|
100
103
|
}
|
|
@@ -153,7 +156,9 @@ export function resolveMenuSelection(menu, input) {
|
|
|
153
156
|
export async function promptMenu({ menu, promptInput, select, writeLine = console.log } = {}) {
|
|
154
157
|
// 注入 select 时走方向键交互(优化需求一.2):分组转为分隔行
|
|
155
158
|
if (typeof select === "function") {
|
|
156
|
-
const choices = menu.sections.flatMap((section) => [
|
|
159
|
+
const choices = menu.sections.flatMap((section, sectionIndex) => [
|
|
160
|
+
// 非首个分组的标题前插入空行,与上一组功能拉开一行距离
|
|
161
|
+
...(sectionIndex > 0 && section.title ? [{ separator: "" }] : []),
|
|
157
162
|
...(section.title ? [{ separator: renderSectionRule(section.title, false) }] : []),
|
|
158
163
|
...section.items.map((item) => ({ label: item.label, value: item.value, hint: item.desc || "" })),
|
|
159
164
|
]);
|
package/src/prompts.js
CHANGED
|
@@ -75,8 +75,9 @@ const PAGE_SIZE = 14;
|
|
|
75
75
|
// 防御:调用方传入空列表或全部为分隔行时,方向键取模运算会得到 NaN 或
|
|
76
76
|
// 进入同步死循环,回车会访问 undefined.value。统一在渲染前抛出可读错误。
|
|
77
77
|
function getSelectableIndexes(choices = []) {
|
|
78
|
+
// separator 字段存在即视为分隔行(含空字符串空行),其余才是可选项
|
|
78
79
|
return choices
|
|
79
|
-
.map((choice, index) => (choice &&
|
|
80
|
+
.map((choice, index) => (choice && choice.separator === undefined ? index : -1))
|
|
80
81
|
.filter((index) => index >= 0);
|
|
81
82
|
}
|
|
82
83
|
|
|
@@ -128,7 +129,7 @@ export const interactiveSelect = createPrompt((config, done) => {
|
|
|
128
129
|
pageSize: PAGE_SIZE,
|
|
129
130
|
loop: false,
|
|
130
131
|
renderItem({ item, isActive }) {
|
|
131
|
-
if (item.separator) {
|
|
132
|
+
if (item.separator !== undefined) {
|
|
132
133
|
return paint(level,c.gray, item.separator);
|
|
133
134
|
}
|
|
134
135
|
const hint = item.hint ? ` ${paint(level,c.gray, item.hint)}` : "";
|