UNPKG

claude-arcade

Version:

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

101 lines (100 loc) 3.57 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.log('Starting Claude Code... (Press Ctrl+G for game)'); // Start Claude with piped stdin so we can control input claudeProcess = (0, child_process_1.spawn)('claude', process.argv.slice(2), { stdio: ['pipe', 'inherit', 'inherit'] }); claudeProcess.on('error', (err) => { console.error('Failed to start Claude:', err.message); console.error('Make sure the "claude" command is installed and in your PATH'); process.exit(1); }); // Set up keyboard monitoring if (process.stdin.isTTY) { process.stdin.setRawMode(true); readline.emitKeypressEvents(process.stdin); process.stdin.on('keypress', (str, key) => { // Ctrl+G = Launch game if (key?.ctrl && key.name === 'g' && !gameProcess) { launchGame(); return; } // Everything else = Forward to Claude immediately if (claudeProcess?.stdin?.writable) { const data = key?.sequence || str; if (data) claudeProcess.stdin.write(data); } }); } // Clean exit claudeProcess.on('exit', (code) => { if (process.stdin.isTTY) process.stdin.setRawMode(false); process.exit(code || 0); }); function launchGame() { if (process.stdin.isTTY) process.stdin.setRawMode(false); process.stdin.removeAllListeners('keypress'); gameProcess = (0, child_process_1.spawn)('npm', ['run', 'play'], { stdio: 'inherit', cwd: __dirname + '/..' }); gameProcess.on('close', () => { gameProcess = null; // Resume keyboard monitoring if (process.stdin.isTTY) { process.stdin.setRawMode(true); // Keypress listener is already set up above } }); } process.on('SIGINT', () => { if (claudeProcess) claudeProcess.kill('SIGINT'); if (gameProcess) gameProcess.kill('SIGINT'); if (process.stdin.isTTY) process.stdin.setRawMode(false); process.exit(0); });