UNPKG

intent-cli

Version:

A fully functional CLI built with TypeScript and modern tools

382 lines • 16.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleFileOperations = exports.handleSystemInfo = exports.showSystemStats = exports.runTodoList = exports.runStopwatch = exports.runPomodoro = exports.runNotesManager = exports.runCalculator = exports.runTimer = exports.handleFileSearch = exports.listDirectory = exports.deleteFileInteractive = exports.createNewFile = exports.showCPUInfo = exports.showMemoryInfo = exports.showSystemOverview = exports.interactiveCommand = void 0; exports.handleConfiguration = handleConfiguration; exports.showHelpAndShortcuts = showHelpAndShortcuts; exports.handleProductivityTools = handleProductivityTools; exports.handleError = handleError; exports.formatBytes = formatBytes; exports.createProgressBar = createProgressBar; exports.parseDuration = parseDuration; exports.evaluateCalculation = evaluateCalculation; exports.playCompletionSound = playCompletionSound; exports.parseDiskUsage = parseDiskUsage; exports.searchInDirectory = searchInDirectory; exports.handleSystemInfoIntent = handleSystemInfoIntent; exports.handleFileOperationIntent = handleFileOperationIntent; exports.handleProductivityIntent = handleProductivityIntent; exports.handleNetworkIntent = handleNetworkIntent; exports.handleCalculatorIntent = handleCalculatorIntent; exports.handleTimerIntent = handleTimerIntent; exports.handleNotesIntent = handleNotesIntent; exports.routeIntentToAction = routeIntentToAction; exports.showDetailedFileInfo = showDetailedFileInfo; exports.displayFileContent = displayFileContent; exports.editFile = editFile; exports.copyPathToClipboard = copyPathToClipboard; exports.copyFileInteractive = copyFileInteractive; exports.moveFileInteractive = moveFileInteractive; exports.showQuickNote = showQuickNote; exports.handleDashboard = handleDashboard; const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const inquirer_1 = __importDefault(require("inquirer")); const promises_1 = require("fs/promises"); const path_1 = require("path"); const intent_commands_service_1 = require("../services/intent-commands.service"); const intentjs_parser_1 = require("../utils/intentjs-parser"); exports.interactiveCommand = new commander_1.Command('interactive') .description('Launch interactive terminal interface') .action(async () => { await startInteractiveInterface(); }); async function startInteractiveInterface() { // Initialize IntentJS services const intentParser = new intentjs_parser_1.IntentJSParser(); const intentService = new intent_commands_service_1.IntentCommandsService(); // Clear screen and show welcome console.clear(); showWelcomeScreen(); showQuickShortcuts(); // Main interactive loop while (true) { try { const { action } = await inquirer_1.default.prompt([ { type: 'list', name: 'action', message: chalk_1.default.cyan('šŸš€ What would you like to do?'), choices: [ { name: 'šŸ  Dashboard', value: 'dashboard' }, { name: 'šŸ“ File Manager', value: 'file' }, { name: 'šŸ’» System Monitor', value: 'system' }, { name: 'šŸ› ļø Productivity Suite', value: 'productivity' }, { name: 'šŸ” Command Palette', value: 'palette' }, { name: 'šŸ¤– AI Intent Mode (IntentJS)', value: 'ai' }, { name: 'āš™ļø Settings', value: 'config' }, { name: 'ā“ Help & Shortcuts', value: 'help' }, { name: '─────────────────────', value: 'separator' }, { name: '🧮 Quick Calculator', value: 'calculator' }, { name: 'šŸ“ Quick Note', value: 'note' }, { name: 'āŒ Exit', value: 'exit' }, ], pageSize: 14, }, ]); if (action === 'exit') { console.log(chalk_1.default.yellow.bold('\nšŸ‘‹ Goodbye! Thanks for using Intent CLI!')); break; } if (action === 'separator') { continue; } await handleAction(action, intentService, intentParser); // Ask if user wants to continue const { continue: shouldContinue } = await inquirer_1.default.prompt([ { type: 'confirm', name: 'continue', message: 'Would you like to perform another action?', default: true, }, ]); if (!shouldContinue) { console.log(chalk_1.default.yellow.bold('\nšŸ‘‹ Thanks for using Intent CLI!')); break; } // Clear screen for next action console.clear(); showWelcomeScreen(); showQuickShortcuts(); } catch (error) { const shouldContinue = await handleError(error, 'main interface'); if (!shouldContinue) { break; } } } } function showQuickShortcuts() { console.log(chalk_1.default.magenta.bold('\n⚔ Quick Shortcuts:')); console.log(chalk_1.default.dim(` • Type ${chalk_1.default.cyan('help')} anytime to see all commands`)); console.log(chalk_1.default.dim(` • Press ${chalk_1.default.cyan('Ctrl+C')} to cancel any operation`)); console.log(chalk_1.default.dim(` • Use ${chalk_1.default.cyan('↑/↓')} arrows to navigate menus`)); console.log(chalk_1.default.gray('─'.repeat(70))); } function showWelcomeScreen() { console.log(chalk_1.default.cyan.bold(` ╔════════════════════════════════════════════════════╗ ā•‘ ā•‘ ā•‘ šŸŒ€ IntentJS CLI - Interactive Terminal Interface ā•‘ ā•‘ ā•‘ ā•‘ - This is made with ā¤ļø by Unmesh100 ā•‘ ā•‘ ā•‘ ā•‘ Your powerful command-line companion for productivity, ā•‘ ā•‘ system management, and development tasks! ā•‘ ā•‘ ā•‘ ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā• `)); // Show quick stats const currentTime = new Date().toLocaleTimeString(); console.log(chalk_1.default.dim(`šŸ• Current time: ${currentTime}`)); console.log(chalk_1.default.gray('─'.repeat(70))); } async function handleAction(action, intentService, intentParser) { switch (action) { case 'dashboard': await intentService.handleSystemCommand(); break; case 'file': await intentService.handleCreateFileCommand(); break; case 'system': await intentService.handleSystemCommand(); break; case 'productivity': await intentService.handleCalculatorCommand(); break; case 'palette': await showCommandPalette(intentService, intentParser); break; case 'ai': await intentService.handleAICommand(); break; case 'config': await handleConfiguration(); break; case 'help': await intentService.handleHelpCommand(); break; case 'calculator': await intentService.handleCalculatorCommand(); break; case 'note': await intentService.handleNotesCommand(); break; case 'search': await intentService.handleSearchFilesCommand(); break; case 'stats': await handleSystemStats(); break; } } // Command Palette function async function showCommandPalette(intentService, intentParser) { console.log(chalk_1.default.green.bold('\nšŸ” Command Palette - Quick Access\n')); while (true) { const { command } = await inquirer_1.default.prompt([ { type: 'list', name: 'command', message: 'Select a command or action:', choices: [ { name: 'šŸ“Š System Monitor', value: 'system' }, { name: 'šŸ“ File Manager', value: 'file' }, { name: 'šŸ” Search Files', value: 'search' }, { name: 'šŸ“ˆ Live System Stats', value: 'stats' }, { name: 'šŸ› ļø Productivity Tools', value: 'productivity' }, { name: 'ā° Timer', value: 'timer' }, { name: 'ā±ļø Stopwatch', value: 'stopwatch' }, { name: 'šŸ… Pomodoro Timer', value: 'pomodoro' }, { name: '🧮 Calculator', value: 'calculator' }, { name: 'šŸ“ Notes Manager', value: 'notes' }, { name: 'āœ… Todo List', value: 'todo' }, { name: 'āš™ļø Settings', value: 'config' }, { name: 'ā“ Help', value: 'help' }, { name: 'šŸ  Dashboard', value: 'dashboard' }, { name: 'šŸ¤– AI Intent Mode (IntentJS)', value: 'ai' }, { name: '─────────────────────', value: 'separator' }, { name: 'šŸ”™ Back to Main Menu', value: 'back' }, ], pageSize: 16, }, ]); if (command === 'back' || command === 'separator') { break; } // Handle specific command palette actions if (command === 'ai') { await intentService.handleAICommand(); } else if (['timer', 'stopwatch', 'pomodoro', 'notes', 'todo'].includes(command)) { if (command === 'timer') { await intentService.handleTimerCommand(); } else if (command === 'notes') { await intentService.handleNotesCommand(); } else { // Handle other commands with existing functions await handleAction(command, intentService, intentParser); } } else { await handleAction(command, intentService, intentParser); } const { continue: shouldContinue } = await inquirer_1.default.prompt([ { type: 'confirm', name: 'continue', message: 'Continue using command palette?', default: true, }, ]); if (!shouldContinue) { break; } console.clear(); console.log(chalk_1.default.green.bold('\nšŸ” Command Palette - Quick Access\n')); } } // Need to import these functions from somewhere or define them here // For now, let's create minimal placeholder implementations async function handleSystemStats() { console.log(chalk_1.default.cyan('šŸ“ˆ System Stats - Basic implementation')); } async function handleConfiguration() { console.log(chalk_1.default.cyan('āš™ļø Settings - Basic implementation')); } async function showHelpAndShortcuts() { console.log(chalk_1.default.cyan('ā“ Help - Basic implementation')); } async function handleProductivityTools() { console.log(chalk_1.default.cyan('šŸ› ļø Productivity Tools - Basic implementation')); } // Include all the required helper functions function formatBytes(bytes) { const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; if (bytes === 0) return '0 Bytes'; const i = Math.floor(Math.log(bytes) / Math.log(1024)); return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i]; } function createProgressBar(percentage, width) { const percent = parseFloat(percentage); const filled = Math.round((percent / 100) * width); const empty = width - filled; const color = percent > 80 ? chalk_1.default.red : percent > 60 ? chalk_1.default.yellow : chalk_1.default.green; return color('ā–ˆ'.repeat(filled)) + chalk_1.default.gray('ā–‘'.repeat(empty)); } function parseDuration(duration) { const match = duration.match(/^(\d+)([smh]?)$/i); if (!match) return 0; const value = parseInt(match[1]); const unit = match[2]?.toLowerCase() || 's'; switch (unit) { case 'h': return value * 3600; case 'm': return value * 60; default: return value; } } function evaluateCalculation(expression) { try { return new Function('return ' + expression)(); } catch { throw new Error('Invalid calculation'); } } function playCompletionSound() { process.stdout.write('\x07'); } function parseDiskUsage(output) { const lines = output.split('\n').slice(1); return lines .filter(line => line.trim()) .map(line => { const parts = line.trim().split(/\s+/); return { filesystem: parts[0], size: parts[1], used: parts[2], available: parts[3], usage: parts[4], }; }); } async function searchInDirectory(dir, pattern, recursive) { const results = []; const items = await (0, promises_1.readdir)(dir, { withFileTypes: true }); const regexPattern = new RegExp(pattern.replace(/\*/g, '.*').replace(/\?/g, '.'), 'i'); for (const item of items) { const itemPath = (0, path_1.join)(dir, item.name); if (regexPattern.test(item.name)) { results.push(itemPath); } if (recursive && item.isDirectory() && item.name !== '.' && item.name !== '..') { const subResults = await searchInDirectory(itemPath, pattern, recursive); results.push(...subResults); } } return results; } // Placeholder implementations for all the exported functions async function handleError(error, context) { console.error(chalk_1.default.red(`Error in ${context}:`, error)); return true; } async function handleSystemInfoIntent(entities, originalText) { await intentService.handleSystemCommand(); } async function handleFileOperationIntent(entities) { await intentService.handleCreateFileCommand(); } async function handleProductivityIntent(entities, originalText) { await intentService.handleCalculatorCommand(); } async function handleNetworkIntent(entities) { await intentService.handleNetworkCommand(); } async function handleCalculatorIntent(entities) { await intentService.handleCalculatorCommand(); } async function handleTimerIntent(entities) { await intentService.handleTimerCommand(); } async function handleNotesIntent(entities) { await intentService.handleNotesCommand(); } async function routeIntentToAction(intent) { await intentService.processIntent(intent); } async function showDetailedFileInfo(path, stats) { console.log(chalk_1.default.cyan(`šŸ“‹ File Info: ${path}`)); } async function displayFileContent(path, content, stats) { console.log(chalk_1.default.cyan(`šŸ“„ Content: ${content.substring(0, 100)}...`)); } async function editFile(path, content) { console.log(chalk_1.default.cyan(`āœļø Editing: ${path}`)); } async function copyPathToClipboard(path) { console.log(chalk_1.default.cyan(`šŸ“‹ Path: ${path}`)); } async function copyFileInteractive() { console.log(chalk_1.default.cyan('šŸ“‹ Copy file - Basic implementation')); } async function moveFileInteractive() { console.log(chalk_1.default.cyan('šŸ“‹ Move file - Basic implementation')); } async function showQuickNote() { console.log(chalk_1.default.cyan('šŸ“‹ Quick note - Basic implementation')); } async function handleDashboard() { console.log(chalk_1.default.cyan('šŸ  Dashboard - Basic implementation')); } //# sourceMappingURL=interactive-optimized.js.map