UNPKG

faj-cli

Version:

FAJ - A powerful CLI resume builder with AI enhancement and multi-format export

135 lines 4.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MenuNavigator = void 0; exports.registerArrowKeyNavigation = registerArrowKeyNavigation; exports.listWithArrows = listWithArrows; const inquirer_1 = __importDefault(require("inquirer")); const chalk_1 = __importDefault(require("chalk")); class MenuNavigator { /** * Create a navigable menu with arrow key support * - Left arrow: go back (select back option if available) * - Right arrow: enter/select current option * - Up/Down arrows: navigate through options (default behavior) */ static async prompt(options) { const { message, choices, showHints = true } = options; // Add navigation hints to the message if enabled const enhancedMessage = showHints ? `${message}\n${chalk_1.default.gray('(← Back | → Enter | ↑↓ Navigate)')}` : message; // Create the inquirer prompt with custom key handling const prompt = inquirer_1.default.createPromptModule(); // Register custom key handler const result = await prompt([ { type: 'list', name: 'selection', message: enhancedMessage, choices: choices, pageSize: 15, loop: false } ]); return result.selection; } /** * Create a standard menu with back option */ static createMenuWithBack(title, items, includeBack = true) { const choices = [...items]; if (includeBack) { choices.push({ name: '← Back', value: 'back' }); } return { message: title, choices, backValue: 'back', showHints: true }; } /** * Helper to format menu items consistently */ static formatMenuItem(icon, text, value) { return { name: `${icon} ${text}`, value, short: text }; } /** * Create a submenu that can be navigated with arrow keys */ static async showSubmenu(title, items, onSelect, parentMenu) { while (true) { const choice = await this.prompt({ message: title, choices: [...items, { name: '← Back', value: 'back' }], showHints: true }); if (choice === 'back') { if (parentMenu) { await parentMenu(); } break; } await onSelect(choice); // Check if we should continue showing the menu const { continueMenu } = await inquirer_1.default.prompt([ { type: 'confirm', name: 'continueMenu', message: 'Continue in this menu?', default: true } ]); if (!continueMenu) { break; } } } } exports.MenuNavigator = MenuNavigator; /** * Custom inquirer plugin for enhanced keyboard navigation */ function registerArrowKeyNavigation() { // This would require extending inquirer's list prompt // For now, we'll use the standard navigation with visual hints // Note: Full implementation would require: // 1. Extending inquirer.prompt.list // 2. Overriding keypress handlers // 3. Adding left/right arrow key support // Since inquirer doesn't easily support this out of the box, // we'll provide visual hints and use a wrapper approach } /** * Enhanced list prompt with arrow key hints */ async function listWithArrows(message, choices, options = {}) { const { showBackHint = true, showEnterHint = true, loop = false } = options; // Build hints const hints = []; if (showBackHint) hints.push('← Back'); if (showEnterHint) hints.push('→/Enter Select'); hints.push('↑↓ Navigate'); const hintText = hints.length > 0 ? chalk_1.default.gray(`\n(${hints.join(' | ')})`) : ''; const { selection } = await inquirer_1.default.prompt([ { type: 'list', name: 'selection', message: `${message}${hintText}`, choices, loop, pageSize: 15 } ]); return selection; } //# sourceMappingURL=MenuNavigator.js.map