UNPKG

@jharrilim/game-of-life

Version:
31 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const CellMap_1 = require("./CellMap"); const os_1 = require("os"); const readline_1 = require("readline"); class ConsoleMap extends CellMap_1.CellMap { constructor(width = process.stdout.columns || 80, height = process.stdout.rows || 24) { super(width, height); this.width = width; this.height = height; process.stdout.on('resize', () => { this.resize(process.stdout.columns || 80, process.stdout.rows || 24); }); } render() { readline_1.cursorTo(process.stdout, 0, 0); readline_1.clearScreenDown(process.stdout); let map = ''; for (let i = 0; i < this.cells[0].length /* this should be safe since it is rectangular */; i++) { for (let j = 0; j < this.cells.length; j++) { const line = this.cells[j][i].isAlive ? '■' : ' '; map += line; } map += os_1.EOL; } process.stdout.write(map); readline_1.cursorTo(process.stdout, 0, 0); } } exports.ConsoleMap = ConsoleMap; //# sourceMappingURL=ConsoleMap.js.map