cli-menu-kit 0.1.0

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 (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +716 -0
  3. package/dist/api.d.ts +158 -0
  4. package/dist/api.js +128 -0
  5. package/dist/components/display/headers.d.ts +32 -0
  6. package/dist/components/display/headers.js +84 -0
  7. package/dist/components/display/index.d.ts +8 -0
  8. package/dist/components/display/index.js +31 -0
  9. package/dist/components/display/messages.d.ts +41 -0
  10. package/dist/components/display/messages.js +90 -0
  11. package/dist/components/display/progress.d.ts +41 -0
  12. package/dist/components/display/progress.js +82 -0
  13. package/dist/components/display/summary.d.ts +33 -0
  14. package/dist/components/display/summary.js +82 -0
  15. package/dist/components/inputs/index.d.ts +8 -0
  16. package/dist/components/inputs/index.js +15 -0
  17. package/dist/components/inputs/language-input.d.ts +11 -0
  18. package/dist/components/inputs/language-input.js +104 -0
  19. package/dist/components/inputs/modify-field.d.ts +11 -0
  20. package/dist/components/inputs/modify-field.js +42 -0
  21. package/dist/components/inputs/number-input.d.ts +11 -0
  22. package/dist/components/inputs/number-input.js +143 -0
  23. package/dist/components/inputs/text-input.d.ts +11 -0
  24. package/dist/components/inputs/text-input.js +114 -0
  25. package/dist/components/menus/boolean-menu.d.ts +11 -0
  26. package/dist/components/menus/boolean-menu.js +169 -0
  27. package/dist/components/menus/checkbox-menu.d.ts +11 -0
  28. package/dist/components/menus/checkbox-menu.js +161 -0
  29. package/dist/components/menus/index.d.ts +7 -0
  30. package/dist/components/menus/index.js +13 -0
  31. package/dist/components/menus/radio-menu.d.ts +11 -0
  32. package/dist/components/menus/radio-menu.js +158 -0
  33. package/dist/components.d.ts +55 -0
  34. package/dist/components.js +166 -0
  35. package/dist/core/colors.d.ts +64 -0
  36. package/dist/core/colors.js +139 -0
  37. package/dist/core/keyboard.d.ts +124 -0
  38. package/dist/core/keyboard.js +185 -0
  39. package/dist/core/renderer.d.ts +74 -0
  40. package/dist/core/renderer.js +217 -0
  41. package/dist/core/terminal.d.ts +89 -0
  42. package/dist/core/terminal.js +170 -0
  43. package/dist/features/commands.d.ts +57 -0
  44. package/dist/features/commands.js +161 -0
  45. package/dist/features/wizard.d.ts +62 -0
  46. package/dist/features/wizard.js +112 -0
  47. package/dist/i18n/languages/en.d.ts +5 -0
  48. package/dist/i18n/languages/en.js +54 -0
  49. package/dist/i18n/languages/zh.d.ts +5 -0
  50. package/dist/i18n/languages/zh.js +54 -0
  51. package/dist/i18n/registry.d.ts +36 -0
  52. package/dist/i18n/registry.js +82 -0
  53. package/dist/i18n/types.d.ts +65 -0
  54. package/dist/i18n/types.js +5 -0
  55. package/dist/index.d.ts +27 -0
  56. package/dist/index.js +104 -0
  57. package/dist/input.d.ts +40 -0
  58. package/dist/input.js +211 -0
  59. package/dist/menu-core.d.ts +52 -0
  60. package/dist/menu-core.js +201 -0
  61. package/dist/menu-multi.d.ts +21 -0
  62. package/dist/menu-multi.js +119 -0
  63. package/dist/menu-single.d.ts +18 -0
  64. package/dist/menu-single.js +138 -0
  65. package/dist/menu.d.ts +66 -0
  66. package/dist/menu.js +78 -0
  67. package/dist/types/display.types.d.ts +57 -0
  68. package/dist/types/display.types.js +5 -0
  69. package/dist/types/input.types.d.ts +88 -0
  70. package/dist/types/input.types.js +5 -0
  71. package/dist/types/layout.types.d.ts +56 -0
  72. package/dist/types/layout.types.js +36 -0
  73. package/dist/types/menu.types.d.ts +85 -0
  74. package/dist/types/menu.types.js +5 -0
  75. package/dist/types.d.ts +49 -0
  76. package/dist/types.js +5 -0
  77. package/package.json +35 -0
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ /**
3
+ * Commands - Command handling system
4
+ * Handles special commands like /quit, /help, /clear, /back
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.registerCommand = registerCommand;
8
+ exports.unregisterCommand = unregisterCommand;
9
+ exports.clearCustomCommands = clearCustomCommands;
10
+ exports.isCommand = isCommand;
11
+ exports.parseCommand = parseCommand;
12
+ exports.handleCommand = handleCommand;
13
+ exports.getAvailableCommands = getAvailableCommands;
14
+ exports.showCommandHelp = showCommandHelp;
15
+ const terminal_js_1 = require("../core/terminal.js");
16
+ const colors_js_1 = require("../core/colors.js");
17
+ /**
18
+ * Default command registry
19
+ */
20
+ const defaultCommands = {
21
+ quit: {
22
+ handler: () => {
23
+ (0, terminal_js_1.writeLine)('\n👋 再见!');
24
+ process.exit(0);
25
+ },
26
+ description: '退出应用程序'
27
+ },
28
+ help: {
29
+ handler: () => {
30
+ (0, terminal_js_1.writeLine)('\n可用命令:');
31
+ Object.entries(defaultCommands).forEach(([cmd, { description }]) => {
32
+ (0, terminal_js_1.writeLine)(` ${colors_js_1.colors.cyan}/${cmd}${colors_js_1.colors.reset} - ${description}`);
33
+ });
34
+ (0, terminal_js_1.writeLine)('');
35
+ return false; // Don't exit, continue
36
+ },
37
+ description: '显示帮助信息'
38
+ },
39
+ clear: {
40
+ handler: () => {
41
+ (0, terminal_js_1.clearScreen)();
42
+ return false; // Don't exit, continue
43
+ },
44
+ description: '清除屏幕'
45
+ },
46
+ back: {
47
+ handler: () => {
48
+ return true; // Signal to go back
49
+ },
50
+ description: '返回上一级菜单'
51
+ }
52
+ };
53
+ /**
54
+ * Custom command registry (can be extended by users)
55
+ */
56
+ let customCommands = {};
57
+ /**
58
+ * Register a custom command
59
+ * @param command - Command name (without /)
60
+ * @param handler - Command handler function
61
+ * @param description - Command description
62
+ */
63
+ function registerCommand(command, handler, description) {
64
+ customCommands[command.toLowerCase()] = { handler, description };
65
+ }
66
+ /**
67
+ * Unregister a custom command
68
+ * @param command - Command name (without /)
69
+ */
70
+ function unregisterCommand(command) {
71
+ delete customCommands[command.toLowerCase()];
72
+ }
73
+ /**
74
+ * Clear all custom commands
75
+ */
76
+ function clearCustomCommands() {
77
+ customCommands = {};
78
+ }
79
+ /**
80
+ * Check if input is a command
81
+ * @param input - Input string
82
+ * @returns True if input is a command
83
+ */
84
+ function isCommand(input) {
85
+ return input.startsWith('/');
86
+ }
87
+ /**
88
+ * Parse command from input
89
+ * @param input - Input string
90
+ * @returns Command name and args, or null if not a command
91
+ */
92
+ function parseCommand(input) {
93
+ if (!isCommand(input)) {
94
+ return null;
95
+ }
96
+ const parts = input.slice(1).split(/\s+/);
97
+ const command = parts[0].toLowerCase();
98
+ const args = parts.slice(1);
99
+ return { command, args };
100
+ }
101
+ /**
102
+ * Handle a command
103
+ * @param input - Input string
104
+ * @returns Command result (true = handled and should exit/go back, false = continue, undefined = not a command)
105
+ */
106
+ function handleCommand(input) {
107
+ const parsed = parseCommand(input);
108
+ if (!parsed) {
109
+ return undefined; // Not a command
110
+ }
111
+ const { command, args } = parsed;
112
+ // Check custom commands first
113
+ if (customCommands[command]) {
114
+ const result = customCommands[command].handler(args);
115
+ return result === undefined ? false : result;
116
+ }
117
+ // Check default commands
118
+ if (defaultCommands[command]) {
119
+ const result = defaultCommands[command].handler(args);
120
+ return result === undefined ? false : result;
121
+ }
122
+ // Unknown command
123
+ (0, terminal_js_1.writeLine)(`${colors_js_1.colors.red}✗ 未知命令: /${command}${colors_js_1.colors.reset}`);
124
+ (0, terminal_js_1.writeLine)(`${colors_js_1.colors.dim}输入 /help 查看可用命令${colors_js_1.colors.reset}\n`);
125
+ return false;
126
+ }
127
+ /**
128
+ * Get all available commands
129
+ * @returns Array of command names with descriptions
130
+ */
131
+ function getAvailableCommands() {
132
+ const commands = [];
133
+ // Add default commands
134
+ Object.entries(defaultCommands).forEach(([cmd, { description }]) => {
135
+ commands.push({ command: cmd, description });
136
+ });
137
+ // Add custom commands
138
+ Object.entries(customCommands).forEach(([cmd, { description }]) => {
139
+ commands.push({ command: cmd, description });
140
+ });
141
+ return commands;
142
+ }
143
+ /**
144
+ * Show help for all commands
145
+ */
146
+ function showCommandHelp() {
147
+ (0, terminal_js_1.writeLine)('\n可用命令:');
148
+ // Show default commands
149
+ (0, terminal_js_1.writeLine)(`\n${colors_js_1.colors.cyan}默认命令:${colors_js_1.colors.reset}`);
150
+ Object.entries(defaultCommands).forEach(([cmd, { description }]) => {
151
+ (0, terminal_js_1.writeLine)(` ${colors_js_1.colors.cyan}/${cmd}${colors_js_1.colors.reset} - ${description}`);
152
+ });
153
+ // Show custom commands if any
154
+ if (Object.keys(customCommands).length > 0) {
155
+ (0, terminal_js_1.writeLine)(`\n${colors_js_1.colors.cyan}自定义命令:${colors_js_1.colors.reset}`);
156
+ Object.entries(customCommands).forEach(([cmd, { description }]) => {
157
+ (0, terminal_js_1.writeLine)(` ${colors_js_1.colors.cyan}/${cmd}${colors_js_1.colors.reset} - ${description}`);
158
+ });
159
+ }
160
+ (0, terminal_js_1.writeLine)('');
161
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Wizard - Initialization wizard system
3
+ * Multi-step configuration flow with progress tracking
4
+ */
5
+ /**
6
+ * Wizard step component type
7
+ */
8
+ export type WizardComponentType = 'radio-menu' | 'checkbox-menu' | 'boolean-menu' | 'text-input' | 'number-input' | 'language-selector';
9
+ /**
10
+ * Wizard step configuration
11
+ */
12
+ export interface WizardStep {
13
+ /** Step name/identifier */
14
+ name: string;
15
+ /** Step title for display */
16
+ title: string;
17
+ /** Component type to use */
18
+ component: WizardComponentType;
19
+ /** Component-specific configuration */
20
+ config: any;
21
+ /** Whether this step is required */
22
+ required?: boolean;
23
+ /** Validation function */
24
+ validate?: (value: any) => boolean | string;
25
+ /** Skip condition (if returns true, skip this step) */
26
+ skip?: (results: Record<string, any>) => boolean;
27
+ }
28
+ /**
29
+ * Wizard configuration
30
+ */
31
+ export interface WizardConfig {
32
+ /** Wizard title */
33
+ title?: string;
34
+ /** Array of wizard steps */
35
+ steps: WizardStep[];
36
+ /** Show progress indicator */
37
+ showProgress?: boolean;
38
+ /** Callback when wizard completes */
39
+ onComplete?: (results: Record<string, any>) => void;
40
+ /** Callback when wizard is cancelled */
41
+ onCancel?: () => void;
42
+ }
43
+ /**
44
+ * Wizard result
45
+ */
46
+ export interface WizardResult {
47
+ completed: boolean;
48
+ results: Record<string, any>;
49
+ }
50
+ /**
51
+ * Run a wizard
52
+ * @param config - Wizard configuration
53
+ * @returns Promise resolving to wizard results
54
+ */
55
+ export declare function runWizard(config: WizardConfig): Promise<WizardResult>;
56
+ /**
57
+ * Create a simple wizard
58
+ * @param steps - Array of wizard steps
59
+ * @param onComplete - Completion callback
60
+ * @returns Promise resolving to wizard results
61
+ */
62
+ export declare function createWizard(steps: WizardStep[], onComplete?: (results: Record<string, any>) => void): Promise<WizardResult>;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ /**
3
+ * Wizard - Initialization wizard system
4
+ * Multi-step configuration flow with progress tracking
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.runWizard = runWizard;
8
+ exports.createWizard = createWizard;
9
+ const radio_menu_js_1 = require("../components/menus/radio-menu.js");
10
+ const checkbox_menu_js_1 = require("../components/menus/checkbox-menu.js");
11
+ const boolean_menu_js_1 = require("../components/menus/boolean-menu.js");
12
+ const text_input_js_1 = require("../components/inputs/text-input.js");
13
+ const number_input_js_1 = require("../components/inputs/number-input.js");
14
+ const language_input_js_1 = require("../components/inputs/language-input.js");
15
+ const progress_js_1 = require("../components/display/progress.js");
16
+ const messages_js_1 = require("../components/display/messages.js");
17
+ /**
18
+ * Run a wizard
19
+ * @param config - Wizard configuration
20
+ * @returns Promise resolving to wizard results
21
+ */
22
+ async function runWizard(config) {
23
+ const { title, steps, showProgress = true, onComplete, onCancel } = config;
24
+ const results = {};
25
+ const stepNames = steps.map(s => s.title);
26
+ for (let i = 0; i < steps.length; i++) {
27
+ const step = steps[i];
28
+ // Check skip condition
29
+ if (step.skip && step.skip(results)) {
30
+ continue;
31
+ }
32
+ // Show progress
33
+ if (showProgress) {
34
+ console.log('');
35
+ (0, progress_js_1.createProgressIndicator)(stepNames, i);
36
+ console.log('');
37
+ }
38
+ // Show stage header
39
+ (0, progress_js_1.createStageHeader)(step.title, i + 1);
40
+ console.log('');
41
+ // Execute step component
42
+ let value;
43
+ try {
44
+ switch (step.component) {
45
+ case 'radio-menu':
46
+ value = await (0, radio_menu_js_1.showRadioMenu)(step.config);
47
+ break;
48
+ case 'checkbox-menu':
49
+ value = await (0, checkbox_menu_js_1.showCheckboxMenu)(step.config);
50
+ break;
51
+ case 'boolean-menu':
52
+ value = await (0, boolean_menu_js_1.showBooleanMenu)(step.config);
53
+ break;
54
+ case 'text-input':
55
+ value = await (0, text_input_js_1.showTextInput)(step.config);
56
+ break;
57
+ case 'number-input':
58
+ value = await (0, number_input_js_1.showNumberInput)(step.config);
59
+ break;
60
+ case 'language-selector':
61
+ value = await (0, language_input_js_1.showLanguageSelector)(step.config);
62
+ break;
63
+ default:
64
+ throw new Error(`Unknown component type: ${step.component}`);
65
+ }
66
+ }
67
+ catch (error) {
68
+ // User cancelled (Ctrl+C)
69
+ if (onCancel) {
70
+ onCancel();
71
+ }
72
+ return { completed: false, results };
73
+ }
74
+ // Validate result
75
+ if (step.validate) {
76
+ const validationResult = step.validate(value);
77
+ if (validationResult !== true) {
78
+ const errorMsg = typeof validationResult === 'string'
79
+ ? validationResult
80
+ : 'Validation failed';
81
+ console.log(`\n❌ ${errorMsg}\n`);
82
+ i--; // Retry this step
83
+ continue;
84
+ }
85
+ }
86
+ // Store result
87
+ results[step.name] = value;
88
+ // Show stage separator (except after last step)
89
+ if (i < steps.length - 1) {
90
+ console.log('');
91
+ (0, progress_js_1.createStageSeparator)();
92
+ console.log('');
93
+ }
94
+ }
95
+ // Wizard completed
96
+ console.log('');
97
+ (0, messages_js_1.showSuccess)('配置完成!');
98
+ console.log('');
99
+ if (onComplete) {
100
+ onComplete(results);
101
+ }
102
+ return { completed: true, results };
103
+ }
104
+ /**
105
+ * Create a simple wizard
106
+ * @param steps - Array of wizard steps
107
+ * @param onComplete - Completion callback
108
+ * @returns Promise resolving to wizard results
109
+ */
110
+ async function createWizard(steps, onComplete) {
111
+ return runWizard({ steps, onComplete });
112
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * English translations
3
+ */
4
+ import { LanguageMap } from '../types.js';
5
+ export declare const en: LanguageMap;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /**
3
+ * English translations
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.en = void 0;
7
+ exports.en = {
8
+ menus: {
9
+ selectPrompt: 'Enter option or use ↑↓ to select, press Enter to confirm',
10
+ multiSelectPrompt: 'Space to toggle, Enter to confirm',
11
+ confirmPrompt: 'Press Enter to confirm',
12
+ selectedCount: 'selected'
13
+ },
14
+ hints: {
15
+ arrows: '↑↓ Arrow keys',
16
+ space: 'Space Toggle',
17
+ enter: '⏎ Confirm',
18
+ numbers: '0-9 Number keys',
19
+ letters: 'A-Z Letter keys',
20
+ selectAll: 'A Select all',
21
+ invert: 'I Invert',
22
+ yesNo: 'Y/N Quick keys'
23
+ },
24
+ messages: {
25
+ success: 'Success',
26
+ error: 'Error',
27
+ warning: 'Warning',
28
+ info: 'Info',
29
+ question: 'Question',
30
+ goodbye: '👋 Goodbye!',
31
+ unknownCommand: 'Unknown command',
32
+ helpPrompt: 'Type /help to see available commands'
33
+ },
34
+ inputs: {
35
+ defaultValue: 'default',
36
+ enterText: 'Enter text',
37
+ enterNumber: 'Enter number',
38
+ minLength: 'Min length',
39
+ maxLength: 'Max length',
40
+ minValue: 'Min value',
41
+ maxValue: 'Max value',
42
+ invalidInput: 'Invalid input',
43
+ cannotBeEmpty: 'Cannot be empty'
44
+ },
45
+ commands: {
46
+ quit: 'Exit application',
47
+ help: 'Show help information',
48
+ clear: 'Clear screen',
49
+ back: 'Go back to previous menu',
50
+ availableCommands: 'Available commands',
51
+ defaultCommands: 'Default commands',
52
+ customCommands: 'Custom commands'
53
+ }
54
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Chinese (Simplified) translations
3
+ */
4
+ import { LanguageMap } from '../types.js';
5
+ export declare const zh: LanguageMap;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /**
3
+ * Chinese (Simplified) translations
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.zh = void 0;
7
+ exports.zh = {
8
+ menus: {
9
+ selectPrompt: '输入选项或用↑↓选择,回车确认',
10
+ multiSelectPrompt: '空格选中/取消,回车确认',
11
+ confirmPrompt: '回车确认',
12
+ selectedCount: '项已选'
13
+ },
14
+ hints: {
15
+ arrows: '↑↓ 方向键',
16
+ space: '空格 选中/取消',
17
+ enter: '⏎ 确认',
18
+ numbers: '0-9 输入序号',
19
+ letters: 'A-Z 字母选择',
20
+ selectAll: 'A 全选',
21
+ invert: 'I 反选',
22
+ yesNo: 'Y/N 快捷键'
23
+ },
24
+ messages: {
25
+ success: '成功',
26
+ error: '错误',
27
+ warning: '警告',
28
+ info: '提示',
29
+ question: '问题',
30
+ goodbye: '👋 再见!',
31
+ unknownCommand: '未知命令',
32
+ helpPrompt: '输入 /help 查看可用命令'
33
+ },
34
+ inputs: {
35
+ defaultValue: '默认',
36
+ enterText: '请输入文本',
37
+ enterNumber: '请输入数字',
38
+ minLength: '最小长度',
39
+ maxLength: '最大长度',
40
+ minValue: '最小值',
41
+ maxValue: '最大值',
42
+ invalidInput: '输入无效',
43
+ cannotBeEmpty: '输入不能为空'
44
+ },
45
+ commands: {
46
+ quit: '退出应用程序',
47
+ help: '显示帮助信息',
48
+ clear: '清除屏幕',
49
+ back: '返回上一级菜单',
50
+ availableCommands: '可用命令',
51
+ defaultCommands: '默认命令',
52
+ customCommands: '自定义命令'
53
+ }
54
+ };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * i18n registry - Language management system
3
+ */
4
+ import { LanguageCode, LanguageMap } from './types.js';
5
+ /**
6
+ * Get current language code
7
+ * @returns Current language code
8
+ */
9
+ export declare function getCurrentLanguage(): LanguageCode;
10
+ /**
11
+ * Set current language
12
+ * @param lang - Language code to set
13
+ */
14
+ export declare function setLanguage(lang: LanguageCode): void;
15
+ /**
16
+ * Get translation for a key path
17
+ * @param keyPath - Dot-separated key path (e.g., 'menus.selectPrompt')
18
+ * @returns Translated string
19
+ */
20
+ export declare function t(keyPath: string): string;
21
+ /**
22
+ * Register a new language
23
+ * @param code - Language code
24
+ * @param translations - Language translations
25
+ */
26
+ export declare function registerLanguage(code: string, translations: LanguageMap): void;
27
+ /**
28
+ * Get all registered languages
29
+ * @returns Array of language codes
30
+ */
31
+ export declare function getAvailableLanguages(): LanguageCode[];
32
+ /**
33
+ * Get current language map
34
+ * @returns Current language translations
35
+ */
36
+ export declare function getCurrentLanguageMap(): LanguageMap;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ /**
3
+ * i18n registry - Language management system
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getCurrentLanguage = getCurrentLanguage;
7
+ exports.setLanguage = setLanguage;
8
+ exports.t = t;
9
+ exports.registerLanguage = registerLanguage;
10
+ exports.getAvailableLanguages = getAvailableLanguages;
11
+ exports.getCurrentLanguageMap = getCurrentLanguageMap;
12
+ const zh_js_1 = require("./languages/zh.js");
13
+ const en_js_1 = require("./languages/en.js");
14
+ /**
15
+ * Global i18n registry
16
+ */
17
+ const registry = {
18
+ languages: {
19
+ zh: zh_js_1.zh,
20
+ en: en_js_1.en
21
+ },
22
+ current: 'zh' // Default language
23
+ };
24
+ /**
25
+ * Get current language code
26
+ * @returns Current language code
27
+ */
28
+ function getCurrentLanguage() {
29
+ return registry.current;
30
+ }
31
+ /**
32
+ * Set current language
33
+ * @param lang - Language code to set
34
+ */
35
+ function setLanguage(lang) {
36
+ if (!registry.languages[lang]) {
37
+ throw new Error(`Language '${lang}' is not registered`);
38
+ }
39
+ registry.current = lang;
40
+ }
41
+ /**
42
+ * Get translation for a key path
43
+ * @param keyPath - Dot-separated key path (e.g., 'menus.selectPrompt')
44
+ * @returns Translated string
45
+ */
46
+ function t(keyPath) {
47
+ const keys = keyPath.split('.');
48
+ const langMap = registry.languages[registry.current];
49
+ let value = langMap;
50
+ for (const key of keys) {
51
+ if (value && typeof value === 'object' && key in value) {
52
+ value = value[key];
53
+ }
54
+ else {
55
+ console.warn(`Translation key not found: ${keyPath}`);
56
+ return keyPath; // Return key path as fallback
57
+ }
58
+ }
59
+ return typeof value === 'string' ? value : keyPath;
60
+ }
61
+ /**
62
+ * Register a new language
63
+ * @param code - Language code
64
+ * @param translations - Language translations
65
+ */
66
+ function registerLanguage(code, translations) {
67
+ registry.languages[code] = translations;
68
+ }
69
+ /**
70
+ * Get all registered languages
71
+ * @returns Array of language codes
72
+ */
73
+ function getAvailableLanguages() {
74
+ return Object.keys(registry.languages);
75
+ }
76
+ /**
77
+ * Get current language map
78
+ * @returns Current language translations
79
+ */
80
+ function getCurrentLanguageMap() {
81
+ return registry.languages[registry.current];
82
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * i18n types - Internationalization type definitions
3
+ */
4
+ /**
5
+ * Language code type
6
+ */
7
+ export type LanguageCode = 'zh' | 'en';
8
+ /**
9
+ * Translation map structure
10
+ */
11
+ export interface LanguageMap {
12
+ menus: {
13
+ selectPrompt: string;
14
+ multiSelectPrompt: string;
15
+ confirmPrompt: string;
16
+ selectedCount: string;
17
+ };
18
+ hints: {
19
+ arrows: string;
20
+ space: string;
21
+ enter: string;
22
+ numbers: string;
23
+ letters: string;
24
+ selectAll: string;
25
+ invert: string;
26
+ yesNo: string;
27
+ };
28
+ messages: {
29
+ success: string;
30
+ error: string;
31
+ warning: string;
32
+ info: string;
33
+ question: string;
34
+ goodbye: string;
35
+ unknownCommand: string;
36
+ helpPrompt: string;
37
+ };
38
+ inputs: {
39
+ defaultValue: string;
40
+ enterText: string;
41
+ enterNumber: string;
42
+ minLength: string;
43
+ maxLength: string;
44
+ minValue: string;
45
+ maxValue: string;
46
+ invalidInput: string;
47
+ cannotBeEmpty: string;
48
+ };
49
+ commands: {
50
+ quit: string;
51
+ help: string;
52
+ clear: string;
53
+ back: string;
54
+ availableCommands: string;
55
+ defaultCommands: string;
56
+ customCommands: string;
57
+ };
58
+ }
59
+ /**
60
+ * i18n registry interface
61
+ */
62
+ export interface I18nRegistry {
63
+ languages: Record<LanguageCode, LanguageMap>;
64
+ current: LanguageCode;
65
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /**
3
+ * i18n types - Internationalization type definitions
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * CLI Menu Kit - Main Entry Point
3
+ * A comprehensive, modular menu system for Node.js CLI applications
4
+ */
5
+ export { menuAPI as menu, inputAPI as input, wizardAPI as wizard } from './api.js';
6
+ export { default } from './api.js';
7
+ export { showRadioMenu, showCheckboxMenu, showBooleanMenu } from './components/menus/index.js';
8
+ export { showTextInput, showNumberInput, showLanguageSelector, showModifyField } from './components/inputs/index.js';
9
+ export { renderSimpleHeader, renderAsciiHeader, createSimpleHeader, createAsciiHeader, renderProgressIndicator, renderStageHeader, renderStageSeparator, createProgressIndicator, createStageHeader, createStageSeparator, renderMessage, showSuccess, showError, showWarning, showInfo, showQuestion, createMessage, renderSummaryTable, createSummaryTable, createSimpleSummary } from './components/display/index.js';
10
+ export { runWizard, createWizard, WizardConfig, WizardStep, WizardResult } from './features/wizard.js';
11
+ export { registerCommand, unregisterCommand, clearCustomCommands, isCommand, parseCommand, handleCommand, getAvailableCommands, showCommandHelp } from './features/commands.js';
12
+ export { getCurrentLanguage, setLanguage, t, registerLanguage, getAvailableLanguages, getCurrentLanguageMap } from './i18n/registry.js';
13
+ export type { MenuLayout, LayoutElement, LayoutVisibility, LayoutSpacing } from './types/layout.types.js';
14
+ export type { MenuOption, BaseMenuConfig, RadioMenuConfig, CheckboxMenuConfig, BooleanMenuConfig, RadioMenuResult, CheckboxMenuResult, BooleanMenuResult } from './types/menu.types.js';
15
+ export type { BaseInputConfig, TextInputConfig, NumberInputConfig, LanguageSelectorConfig, ModifyFieldConfig, TextInputResult, NumberInputResult, LanguageSelectorResult, ModifyFieldResult } from './types/input.types.js';
16
+ export type { HeaderType, SimpleHeaderConfig, AsciiHeaderConfig, ProgressConfig, MessageType, MessageConfig, SummaryTableConfig } from './types/display.types.js';
17
+ export type { LanguageCode, LanguageMap, I18nRegistry } from './i18n/types.js';
18
+ export { colors, createGradient, applyGradient, colorize } from './core/colors.js';
19
+ export { KEY_CODES } from './core/keyboard.js';
20
+ export { LAYOUT_PRESETS } from './types/layout.types.js';
21
+ export * from './types';
22
+ export * from './components';
23
+ export * from './menu-core';
24
+ export * from './menu-single';
25
+ export * from './menu-multi';
26
+ export * from './input';
27
+ export * from './menu';