UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

54 lines 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils"); class GameService { command; ui; statusMessage; killed = false; constructor(command, ui) { this.command = command; this.ui = ui; this.command.setCwd(spruce_skill_utils_1.diskUtil.resolvePath(__dirname, '../../')); } setStatusMessage(message) { this.statusMessage = message; } async play(introductionSentences = []) { const sentencesToPlay = [...introductionSentences]; await this.ui.stopLoading(); this.killed = false; while (sentencesToPlay.length > 0) { const next = sentencesToPlay.shift(); this.ui.renderLine(next); await new Promise((r) => setTimeout(r, 2000)); if (this.killed) { return; } } await this.command.execute('node ./node_modules/.bin/js-tetris-cli', { spawnOptions: { stdio: [process.stdin, 'pipe', 'pipe'], }, onData: (data) => { if (!this.killed) { process.stdout?.write(data); if (this.statusMessage) { this.ui.saveCursor(); this.ui.moveCursorTo(0, 25); this.ui.clearBelowCursor(); process.stdout?.write(this.statusMessage); this.ui.restoreCursor(); } } }, }); } kill() { this.killed = true; this.command.kill(); this.ui.clear(); } } exports.default = GameService; //# sourceMappingURL=GameService.js.map