malwoden
Version:
   
50 lines • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseTerminal = void 0;
var color_1 = require("./color");
var glyph_1 = require("./glyph");
var BaseTerminal = /** @class */ (function () {
function BaseTerminal(config) {
var _a, _b;
this.width = config.width;
this.height = config.height;
this.foreColor = (_a = config.foreColor) !== null && _a !== void 0 ? _a : color_1.Color.White;
this.backColor = (_b = config.backColor) !== null && _b !== void 0 ? _b : color_1.Color.Black;
}
BaseTerminal.prototype.size = function () {
return {
x: this.width,
y: this.height,
};
};
BaseTerminal.prototype.clear = function () {
this.fill({ x: 0, y: 0 }, { x: this.width - 1, y: this.height - 1 }, new glyph_1.Glyph(" "));
};
BaseTerminal.prototype.fill = function (v1, v2, glyph) {
for (var x = v1.x; x <= v2.x; x++) {
for (var y = v1.y; y <= v2.y; y++) {
this.drawGlyph({ x: x, y: y }, glyph);
}
}
};
BaseTerminal.prototype.writeAt = function (pos, text, fore, back) {
if (fore === void 0) { fore = this.foreColor; }
if (back === void 0) { back = this.backColor; }
for (var i = 0; i < text.length; i++) {
if (pos.x + i >= this.width)
break;
this.drawGlyph({
x: pos.x + i,
y: pos.y,
}, glyph_1.Glyph.fromCharCode(text.charCodeAt(i), fore, back));
}
};
BaseTerminal.prototype.drawCharCode = function (pos, charCode, foreColor, backColor) {
if (foreColor === void 0) { foreColor = this.foreColor; }
if (backColor === void 0) { backColor = this.backColor; }
this.drawGlyph(pos, glyph_1.Glyph.fromCharCode(charCode, foreColor, backColor));
};
return BaseTerminal;
}());
exports.BaseTerminal = BaseTerminal;
//# sourceMappingURL=terminal.js.map