UNPKG

claude-arcade

Version:

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

126 lines (125 loc) 4.58 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 claudeProcess = null; let gameProcess = null; console.clear(); console.log('\x1b[36m╔════════════════════════════════════════════════╗\x1b[0m'); console.log('\x1b[36m║ Claude + Game Manager (Ctrl+G) ║\x1b[0m'); console.log('\x1b[36m╚════════════════════════════════════════════════╝\x1b[0m'); console.log(''); console.log('\x1b[32m→ Starting Claude Code with full terminal control\x1b[0m'); console.log('\x1b[35m→ Press Ctrl+G to launch the game overlay\x1b[0m'); console.log(''); // Start Claude with FULL terminal control (no piping!) claudeProcess = (0, child_process_1.spawn)('claude', process.argv.slice(2), { stdio: 'inherit', // Claude gets direct terminal access! shell: true }); claudeProcess.on('error', (err) => { console.log(''); console.log('\x1b[31m✗ Error launching Claude:\x1b[0m', err.message); process.exit(1); }); claudeProcess.on('exit', (code) => { disableHotkey(); console.log(''); console.log('\x1b[32m✓ Claude exited.\x1b[0m'); process.exit(code || 0); }); // Set up hotkey listener in raw mode function enableHotkey() { if (process.stdin.isTTY) { process.stdin.setRawMode(true); } readline.emitKeypressEvents(process.stdin); process.stdin.on('keypress', onKeypress); } function disableHotkey() { if (process.stdin.isTTY) { process.stdin.setRawMode(false); } process.stdin.removeListener('keypress', onKeypress); } function onKeypress(str, key) { // Check for Ctrl+G if (key && key.ctrl && key.name === 'g' && !gameProcess && claudeProcess) { launchGame(); } } function launchGame() { if (!claudeProcess || gameProcess) return; // NO suspension needed! Alternate screen handles everything. // NO messages printed - keeps Claude terminal clean. // Disable hotkey while game is running disableHotkey(); // Launch game silently - alternate screen will overlay gameProcess = (0, child_process_1.spawn)('npm', ['run', 'game'], { stdio: 'inherit', shell: true, cwd: __dirname + '/..' }); gameProcess.on('close', () => { gameProcess = null; // Game exited, we're back in Claude - silently! // Claude is exactly where it was, input ready. // Re-enable hotkey enableHotkey(); }); gameProcess.on('error', () => { gameProcess = null; // Silently handle error and re-enable hotkey enableHotkey(); }); } // Handle exit signals function cleanup() { disableHotkey(); if (gameProcess) { gameProcess.kill('SIGTERM'); } if (claudeProcess) { claudeProcess.kill('SIGTERM'); } } process.on('SIGINT', cleanup); process.on('SIGTERM', cleanup); process.on('exit', cleanup); // Start hotkey listener enableHotkey();