cli-menu-kit 0.1.18 → 0.1.20
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.
|
@@ -12,15 +12,39 @@ const renderer_js_1 = require("../../core/renderer.js");
|
|
|
12
12
|
const colors_js_1 = require("../../core/colors.js");
|
|
13
13
|
const registry_js_1 = require("../../i18n/registry.js");
|
|
14
14
|
/**
|
|
15
|
-
* Generate hints based on menu configuration
|
|
15
|
+
* Generate hints based on menu configuration and actual options
|
|
16
16
|
*/
|
|
17
|
-
function generateHints(allowNumberKeys, allowLetterKeys) {
|
|
18
|
-
const hints = [
|
|
17
|
+
function generateHints(options, allowNumberKeys, allowLetterKeys) {
|
|
18
|
+
const hints = [];
|
|
19
|
+
// Count selectable options
|
|
20
|
+
const selectableCount = options.filter(opt => !(typeof opt === 'object' && 'type' in opt && opt.type === 'separator')).length;
|
|
21
|
+
// Only show arrow hints if there are multiple options
|
|
22
|
+
if (selectableCount > 1) {
|
|
23
|
+
hints.push((0, registry_js_1.t)('hints.arrows'));
|
|
24
|
+
}
|
|
25
|
+
// Check if there are actually number-prefixed options
|
|
19
26
|
if (allowNumberKeys) {
|
|
20
|
-
|
|
27
|
+
const hasNumberOptions = options.some(opt => {
|
|
28
|
+
if (typeof opt === 'string') {
|
|
29
|
+
return /^\d+\./.test(opt);
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
});
|
|
33
|
+
if (hasNumberOptions) {
|
|
34
|
+
hints.push((0, registry_js_1.t)('hints.numbers'));
|
|
35
|
+
}
|
|
21
36
|
}
|
|
37
|
+
// Check if there are actually letter-prefixed options
|
|
22
38
|
if (allowLetterKeys) {
|
|
23
|
-
|
|
39
|
+
const hasLetterOptions = options.some(opt => {
|
|
40
|
+
if (typeof opt === 'string') {
|
|
41
|
+
return /^[a-zA-Z]\./.test(opt);
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
});
|
|
45
|
+
if (hasLetterOptions) {
|
|
46
|
+
hints.push((0, registry_js_1.t)('hints.letters'));
|
|
47
|
+
}
|
|
24
48
|
}
|
|
25
49
|
hints.push((0, registry_js_1.t)('hints.enter'));
|
|
26
50
|
return hints;
|
|
@@ -35,7 +59,7 @@ async function showRadioMenu(config) {
|
|
|
35
59
|
// Use i18n for default prompt if not provided
|
|
36
60
|
const displayPrompt = prompt || (0, registry_js_1.t)('menus.selectPrompt');
|
|
37
61
|
// Generate hints dynamically if not provided
|
|
38
|
-
const displayHints = hints || generateHints(allowNumberKeys, allowLetterKeys);
|
|
62
|
+
const displayHints = hints || generateHints(options, allowNumberKeys, allowLetterKeys);
|
|
39
63
|
// Validate options
|
|
40
64
|
if (!options || options.length === 0) {
|
|
41
65
|
throw new Error('RadioMenu requires at least one option');
|
|
@@ -65,6 +89,8 @@ async function showRadioMenu(config) {
|
|
|
65
89
|
selectableIndices.push(index);
|
|
66
90
|
}
|
|
67
91
|
});
|
|
92
|
+
// Use MINIMAL layout for single-option menus
|
|
93
|
+
const effectiveLayout = selectableIndices.length === 1 ? layout_types_js_1.LAYOUT_PRESETS.MINIMAL : layout;
|
|
68
94
|
// Ensure selectedIndex points to a selectable option
|
|
69
95
|
if (!selectableIndices.includes(selectedIndex)) {
|
|
70
96
|
selectedIndex = selectableIndices[0] || 0;
|
|
@@ -90,16 +116,16 @@ async function showRadioMenu(config) {
|
|
|
90
116
|
(0, terminal_js_1.clearMenu)(state);
|
|
91
117
|
let lineCount = 0;
|
|
92
118
|
// Render based on layout order
|
|
93
|
-
|
|
119
|
+
effectiveLayout.order.forEach(element => {
|
|
94
120
|
// Add spacing before element
|
|
95
121
|
const spacingKey = `before${element.charAt(0).toUpperCase() + element.slice(1)}`;
|
|
96
|
-
if (
|
|
97
|
-
(0, renderer_js_1.renderBlankLines)(
|
|
98
|
-
lineCount +=
|
|
122
|
+
if (effectiveLayout.spacing?.[spacingKey]) {
|
|
123
|
+
(0, renderer_js_1.renderBlankLines)(effectiveLayout.spacing[spacingKey]);
|
|
124
|
+
lineCount += effectiveLayout.spacing[spacingKey];
|
|
99
125
|
}
|
|
100
126
|
switch (element) {
|
|
101
127
|
case 'header':
|
|
102
|
-
if (
|
|
128
|
+
if (effectiveLayout.visible.header && title) {
|
|
103
129
|
(0, renderer_js_1.renderHeader)(` ${title}`, colors_js_1.colors.cyan);
|
|
104
130
|
lineCount++;
|
|
105
131
|
}
|
|
@@ -132,7 +158,7 @@ async function showRadioMenu(config) {
|
|
|
132
158
|
});
|
|
133
159
|
break;
|
|
134
160
|
case 'input':
|
|
135
|
-
if (
|
|
161
|
+
if (effectiveLayout.visible.input) {
|
|
136
162
|
// Calculate display value (current selection number)
|
|
137
163
|
let displayValue = '';
|
|
138
164
|
const currentItem = optionData[selectedIndex];
|
|
@@ -150,7 +176,7 @@ async function showRadioMenu(config) {
|
|
|
150
176
|
}
|
|
151
177
|
break;
|
|
152
178
|
case 'hints':
|
|
153
|
-
if (
|
|
179
|
+
if (effectiveLayout.visible.hints && displayHints.length > 0) {
|
|
154
180
|
(0, renderer_js_1.renderHints)(displayHints);
|
|
155
181
|
lineCount++;
|
|
156
182
|
}
|
|
@@ -158,9 +184,9 @@ async function showRadioMenu(config) {
|
|
|
158
184
|
}
|
|
159
185
|
// Add spacing after element
|
|
160
186
|
const afterSpacingKey = `after${element.charAt(0).toUpperCase() + element.slice(1)}`;
|
|
161
|
-
if (
|
|
162
|
-
(0, renderer_js_1.renderBlankLines)(
|
|
163
|
-
lineCount +=
|
|
187
|
+
if (effectiveLayout.spacing?.[afterSpacingKey]) {
|
|
188
|
+
(0, renderer_js_1.renderBlankLines)(effectiveLayout.spacing[afterSpacingKey]);
|
|
189
|
+
lineCount += effectiveLayout.spacing[afterSpacingKey];
|
|
164
190
|
}
|
|
165
191
|
});
|
|
166
192
|
state.renderedLines = lineCount;
|
package/package.json
CHANGED