UNPKG

claude-arcade

Version:

Add classic arcade games to your Claude Code workflow with Ctrl+G

112 lines (111 loc) 4.14 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const child_process_1 = require("child_process"); const readline = __importStar(require("readline")); let gameRunning = false; console.clear(); console.log('\x1b[36m╔════════════════════════════════════════════════╗\x1b[0m'); console.log('\x1b[36m║ Claude Code with Game Hotkey (Ctrl+G) ║\x1b[0m'); console.log('\x1b[36m╚════════════════════════════════════════════════╝\x1b[0m'); console.log(''); console.log('\x1b[32mStarting Claude Code...\x1b[0m'); console.log('\x1b[35m→ Press Ctrl+G at any time to launch the game!\x1b[0m'); console.log(''); // Set raw mode to capture Ctrl+G if (process.stdin.isTTY) { process.stdin.setRawMode(true); } readline.emitKeypressEvents(process.stdin); // Start Claude const claude = (0, child_process_1.spawn)('claude', process.argv.slice(2), { stdio: 'inherit', shell: true }); claude.on('error', (err) => { console.log(''); console.log('\x1b[31m✗ Error launching Claude Code:\x1b[0m', err.message); console.log('\x1b[33m Make sure "claude" is installed and in your PATH\x1b[0m'); process.exit(1); }); claude.on('close', () => { if (process.stdin.isTTY) { process.stdin.setRawMode(false); } console.log(''); console.log('\x1b[32m✓ Claude Code exited.\x1b[0m'); process.exit(0); }); // Listen for Ctrl+G process.stdin.on('keypress', (str, key) => { if (key && key.ctrl && key.name === 'g' && !gameRunning) { gameRunning = true; launchGame(); } }); function launchGame() { // Don't pause stdin - Claude keeps running console.log(''); console.log('\x1b[32m→ Launching game in alternate screen...\x1b[0m'); console.log(''); const game = (0, child_process_1.spawn)('npm', ['run', 'game'], { stdio: 'inherit', shell: true, cwd: __dirname + '/..' }); game.on('close', () => { gameRunning = false; console.log(''); console.log('\x1b[32m✓ Game exited! Claude Code still running...\x1b[0m'); console.log('\x1b[35m→ Press Ctrl+G again to play more!\x1b[0m'); console.log(''); }); game.on('error', (err) => { gameRunning = false; console.log(''); console.log('\x1b[31m✗ Error launching game:\x1b[0m', err.message); }); } // Handle exit process.on('SIGINT', () => { if (claude) { claude.kill('SIGINT'); } if (process.stdin.isTTY) { process.stdin.setRawMode(false); } process.exit(0); });