UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

249 lines 9.37 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HelpPanel = void 0; const blessed_1 = __importDefault(require("blessed")); class HelpPanel { constructor(screen, eventBus, config = {}) { this.shortcuts = []; this.isVisible = false; this.screen = screen; this.eventBus = eventBus; this.config = { title: 'PolyV Monitoring Dashboard - Help', showShortcuts: true, showNavigation: true, showUsageTips: true, ...config, }; } setShortcuts(shortcuts) { this.shortcuts = shortcuts; } show() { if (this.isVisible) return; this.createHelpBox(); this.isVisible = true; this.eventBus.emit('help:shown', { timestamp: new Date(), }); } hide() { if (!this.isVisible || !this.helpBox) return; try { this.screen.remove(this.helpBox); this.helpBox = null; this.isVisible = false; this.screen.render(); this.eventBus.emit('help:hidden', { timestamp: new Date(), }); } catch (error) { console.error('Failed to hide help panel:', error); this.helpBox = null; this.isVisible = false; } } toggle() { if (this.isVisible) { this.hide(); } else { this.show(); } } createHelpBox() { try { const content = this.generateHelpContent(); this.helpBox = blessed_1.default.box({ top: 'center', left: 'center', width: '90%', height: '90%', content, tags: true, border: { type: 'line', }, style: { fg: 'white', bg: 'black', border: { fg: 'cyan', }, scrollbar: { bg: 'cyan', fg: 'white', }, }, label: ` ${this.config.title} `, scrollable: true, alwaysScroll: true, mouse: true, keys: true, vi: true, }); this.setupHelpBoxEvents(); this.screen.append(this.helpBox); this.helpBox.focus(); this.screen.render(); } catch (error) { console.error('Failed to create help panel:', error); this.isVisible = false; this.helpBox = null; } } setupHelpBoxEvents() { if (!this.helpBox) return; this.helpBox.key(['escape', 'enter', 'q', 'C-c'], () => { this.hide(); }); this.helpBox.key(['up', 'down', 'pageup', 'pagedown'], (_ch, key) => { switch (key.name) { case 'up': this.helpBox.scroll(-1); break; case 'down': this.helpBox.scroll(1); break; case 'pageup': this.helpBox.scroll(-10); break; case 'pagedown': this.helpBox.scroll(10); break; } this.screen.render(); }); this.helpBox.on('wheelup', () => { this.helpBox.scroll(-3); this.screen.render(); }); this.helpBox.on('wheeldown', () => { this.helpBox.scroll(3); this.screen.render(); }); } generateHelpContent() { const sections = []; sections.push('{center}{bold}PolyV Live Monitoring Dashboard - Help{/bold}{/center}'); sections.push(''); sections.push('Welcome to the PolyV Live Streaming Monitoring Dashboard!'); sections.push('This interactive terminal interface provides real-time monitoring of your live streaming services.'); sections.push(''); if (this.config.showNavigation) { sections.push('{cyan-fg}{bold}Navigation:{/bold}{/cyan-fg}'); sections.push(' {bold}Tab{/bold} - Move focus to next component'); sections.push(' {bold}Shift+Tab{/bold} - Move focus to previous component'); sections.push(' {bold}Arrow Keys{/bold} - Navigate within lists and tables'); sections.push(' {bold}Home/End{/bold} - Move to first/last component'); sections.push(' {bold}Enter{/bold} - Activate selected item'); sections.push(' {bold}Escape{/bold} - Cancel operation or close dialogs'); sections.push(''); } if (this.config.showShortcuts && this.shortcuts.length > 0) { sections.push('{cyan-fg}{bold}Keyboard Shortcuts:{/bold}{/cyan-fg}'); const categories = this.groupShortcutsByCategory(); for (const [category, shortcuts] of Object.entries(categories)) { if (shortcuts.length > 0) { sections.push(` {yellow-fg}{bold}${category}:{/bold}{/yellow-fg}`); shortcuts.forEach(shortcut => { const keyDisplay = this.formatKeyForDisplay(shortcut.key); const spacing = ' '.repeat(Math.max(1, 15 - keyDisplay.length)); sections.push(` {bold}${keyDisplay}{/bold}${spacing}- ${shortcut.description}`); }); sections.push(''); } } } if (this.config.showUsageTips) { sections.push('{cyan-fg}{bold}Usage Tips:{/bold}{/cyan-fg}'); sections.push(' • Use Tab to navigate between different monitoring panels'); sections.push(' • Press F5 to refresh all data or Ctrl+R for current panel'); sections.push(' • Right-click on components for context menus'); sections.push(' • Use number keys (1-9) to quickly switch layouts'); sections.push(' • Press "/" or Ctrl+F to search in channel lists'); sections.push(' • Press F11 to toggle fullscreen for focused panel'); sections.push(' • Use arrow keys and Page Up/Down to scroll in this help'); sections.push(''); } if (this.config.customSections) { this.config.customSections.forEach(section => { sections.push(`{cyan-fg}{bold}${section.title}:{/bold}{/cyan-fg}`); section.content.forEach(line => { sections.push(` ${line}`); }); sections.push(''); }); } sections.push('{center}{yellow-fg}Press Escape, Enter, or Q to close this help{/yellow-fg}{/center}'); sections.push('{center}{gray-fg}Use arrow keys or mouse wheel to scroll{/gray-fg}{/center}'); return sections.join('\n'); } groupShortcutsByCategory() { const categories = { 'Data & Refresh': [], 'Navigation': [], 'Panels & Layout': [], 'Search & Filter': [], 'Application': [], 'Other': [], }; this.shortcuts.forEach(shortcut => { const action = shortcut.action.toLowerCase(); if (action.includes('refresh') || action.includes('update')) { categories['Data & Refresh']?.push(shortcut); } else if (action.includes('layout') || action.includes('panel') || action.includes('fullscreen')) { categories['Panels & Layout']?.push(shortcut); } else if (action.includes('search') || action.includes('filter')) { categories['Search & Filter']?.push(shortcut); } else if (action.includes('exit') || action.includes('help') || action.includes('cancel')) { categories['Application']?.push(shortcut); } else { categories['Other']?.push(shortcut); } }); Object.keys(categories).forEach(key => { if (categories[key]?.length === 0) { delete categories[key]; } }); return categories; } formatKeyForDisplay(key) { return key .replace(/ctrl\+/gi, 'Ctrl+') .replace(/alt\+/gi, 'Alt+') .replace(/shift\+/gi, 'Shift+') .replace(/meta\+/gi, 'Meta+') .replace(/f(\d+)/gi, 'F$1') .replace(/^(.)$/, (match) => match.toUpperCase()); } isHelpVisible() { return this.isVisible; } updateConfig(config) { this.config = { ...this.config, ...config }; if (this.isVisible) { this.hide(); this.show(); } } destroy() { this.hide(); this.shortcuts = []; } } exports.HelpPanel = HelpPanel; //# sourceMappingURL=help-panel.js.map