cli-menu-kit 0.1.17 → 0.1.18

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.
@@ -14,18 +14,18 @@ const colors_js_1 = require("../../core/colors.js");
14
14
  * @returns Promise resolving to boolean result
15
15
  */
16
16
  async function showBooleanMenu(config) {
17
- const { question, defaultValue = true, yesText = '是', noText = '否', orientation = 'horizontal', onExit } = config;
17
+ const { question, defaultValue = true, yesText = '是', noText = '否', orientation = 'horizontal', onExit, preserveOnSelect = false } = config;
18
18
  if (orientation === 'horizontal') {
19
- return showBooleanMenuHorizontal(question, defaultValue, yesText, noText, onExit);
19
+ return showBooleanMenuHorizontal(question, defaultValue, yesText, noText, onExit, preserveOnSelect);
20
20
  }
21
21
  else {
22
- return showBooleanMenuVertical(question, defaultValue, yesText, noText, onExit);
22
+ return showBooleanMenuVertical(question, defaultValue, yesText, noText, onExit, preserveOnSelect);
23
23
  }
24
24
  }
25
25
  /**
26
26
  * Show horizontal boolean menu (side by side)
27
27
  */
28
- async function showBooleanMenuHorizontal(question, defaultValue, yesText, noText, onExit) {
28
+ async function showBooleanMenuHorizontal(question, defaultValue, yesText, noText, onExit, preserveOnSelect = false) {
29
29
  const state = (0, terminal_js_1.initTerminal)();
30
30
  let selected = defaultValue;
31
31
  const render = () => {
@@ -61,7 +61,9 @@ async function showBooleanMenuHorizontal(question, defaultValue, yesText, noText
61
61
  // Handle Enter
62
62
  if ((0, keyboard_js_1.isEnter)(key)) {
63
63
  state.stdin.removeListener('data', onData);
64
- (0, terminal_js_1.clearMenu)(state);
64
+ if (!preserveOnSelect) {
65
+ (0, terminal_js_1.clearMenu)(state);
66
+ }
65
67
  (0, terminal_js_1.restoreTerminal)(state);
66
68
  resolve(selected);
67
69
  return;
@@ -96,7 +98,7 @@ async function showBooleanMenuHorizontal(question, defaultValue, yesText, noText
96
98
  /**
97
99
  * Show vertical boolean menu (stacked)
98
100
  */
99
- async function showBooleanMenuVertical(question, defaultValue, yesText, noText, onExit) {
101
+ async function showBooleanMenuVertical(question, defaultValue, yesText, noText, onExit, preserveOnSelect = false) {
100
102
  const state = (0, terminal_js_1.initTerminal)();
101
103
  let selected = defaultValue;
102
104
  const render = () => {
@@ -135,7 +137,9 @@ async function showBooleanMenuVertical(question, defaultValue, yesText, noText,
135
137
  // Handle Enter
136
138
  if ((0, keyboard_js_1.isEnter)(key)) {
137
139
  state.stdin.removeListener('data', onData);
138
- (0, terminal_js_1.clearMenu)(state);
140
+ if (!preserveOnSelect) {
141
+ (0, terminal_js_1.clearMenu)(state);
142
+ }
139
143
  (0, terminal_js_1.restoreTerminal)(state);
140
144
  resolve(selected);
141
145
  return;
@@ -30,7 +30,7 @@ function generateHints(allowSelectAll, allowInvert) {
30
30
  * @returns Promise resolving to selected options
31
31
  */
32
32
  async function showCheckboxMenu(config) {
33
- const { options, title, prompt, hints, layout = { ...layout_types_js_1.LAYOUT_PRESETS.SUB_MENU, order: ['input', 'options', 'hints'] }, defaultSelected = [], minSelections = 0, maxSelections, allowSelectAll = true, allowInvert = true, separatorWidth = 30, onExit } = config;
33
+ const { options, title, prompt, hints, layout = { ...layout_types_js_1.LAYOUT_PRESETS.SUB_MENU, order: ['input', 'options', 'hints'] }, defaultSelected = [], minSelections = 0, maxSelections, allowSelectAll = true, allowInvert = true, separatorWidth = 30, onExit, preserveOnSelect = false } = config;
34
34
  // Use i18n for default prompt if not provided
35
35
  const displayPrompt = prompt || (0, registry_js_1.t)('menus.multiSelectPrompt');
36
36
  // Generate hints dynamically if not provided
@@ -160,7 +160,9 @@ async function showCheckboxMenu(config) {
160
160
  return;
161
161
  }
162
162
  state.stdin.removeListener('data', onData);
163
- (0, terminal_js_1.clearMenu)(state);
163
+ if (!preserveOnSelect) {
164
+ (0, terminal_js_1.clearMenu)(state);
165
+ }
164
166
  (0, terminal_js_1.restoreTerminal)(state);
165
167
  const indices = Array.from(selected).sort((a, b) => a - b);
166
168
  const values = indices.map(i => {
@@ -31,7 +31,7 @@ function generateHints(allowNumberKeys, allowLetterKeys) {
31
31
  * @returns Promise resolving to selected option
32
32
  */
33
33
  async function showRadioMenu(config) {
34
- const { options, title, prompt, hints, layout = layout_types_js_1.LAYOUT_PRESETS.MAIN_MENU, defaultIndex = 0, allowNumberKeys = true, allowLetterKeys = false, separatorWidth = 30, onExit } = config;
34
+ const { options, title, prompt, hints, layout = layout_types_js_1.LAYOUT_PRESETS.MAIN_MENU, defaultIndex = 0, allowNumberKeys = true, allowLetterKeys = false, separatorWidth = 30, onExit, preserveOnSelect = false } = config;
35
35
  // Use i18n for default prompt if not provided
36
36
  const displayPrompt = prompt || (0, registry_js_1.t)('menus.selectPrompt');
37
37
  // Generate hints dynamically if not provided
@@ -186,7 +186,12 @@ async function showRadioMenu(config) {
186
186
  // Handle Enter
187
187
  if ((0, keyboard_js_1.isEnter)(key)) {
188
188
  state.stdin.removeListener('data', onData);
189
- (0, terminal_js_1.clearMenu)(state);
189
+ if (!preserveOnSelect) {
190
+ (0, terminal_js_1.clearMenu)(state);
191
+ }
192
+ else {
193
+ (0, terminal_js_1.writeLine)('');
194
+ }
190
195
  (0, terminal_js_1.restoreTerminal)(state);
191
196
  const selectedOption = options[selectedIndex];
192
197
  let value;
@@ -30,6 +30,8 @@ export interface BaseMenuConfig {
30
30
  onExit?: () => void;
31
31
  /** Separator width for section labels (default: 30) */
32
32
  separatorWidth?: number;
33
+ /** Keep menu rendered after selection instead of clearing (default: false) */
34
+ preserveOnSelect?: boolean;
33
35
  }
34
36
  /**
35
37
  * Radio menu (single-select) configuration
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cli-menu-kit",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "A lightweight, customizable CLI menu system with keyboard shortcuts and real-time rendering",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",