malwoden
Version:
   
72 lines • 3.3 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LabelWidget = void 0;
var terminal_1 = require("../terminal");
var color_1 = require("../terminal/color");
var widget_1 = require("./widget");
/**
* Represents a label drawn on the screen, often for help text.
* The direction can be controlled to make sure the label doesn't
* get cut off on the edge of the screen.
*/
var LabelWidget = /** @class */ (function (_super) {
__extends(LabelWidget, _super);
function LabelWidget(config) {
var _this = _super.call(this, config) || this;
_this.state = __assign({ foreColor: color_1.Color.White, backColor: color_1.Color.Black }, config.initialState);
return _this;
}
LabelWidget.prototype.renderLeftLabel = function (terminal) {
var origin = this.getAbsoluteOrigin();
var _a = this.state, text = _a.text, foreColor = _a.foreColor, backColor = _a.backColor;
var start = { x: origin.x - text.length - 2, y: origin.y };
terminal.writeAt(start, text, foreColor, backColor);
terminal.drawCharCode({ x: start.x + text.length, y: origin.y }, terminal_1.CharCode.fullBlock, backColor);
terminal.drawCharCode({ x: start.x + text.length + 1, y: origin.y }, terminal_1.CharCode.rightwardsArrow, backColor, foreColor);
};
LabelWidget.prototype.renderRightLabel = function (terminal) {
var origin = this.getAbsoluteOrigin();
var _a = this.state, text = _a.text, foreColor = _a.foreColor, backColor = _a.backColor;
var start = { x: origin.x + 1, y: origin.y };
terminal.drawCharCode(start, terminal_1.CharCode.leftwardsArrow, backColor, foreColor);
terminal.drawCharCode({ x: start.x + 1, y: start.y }, terminal_1.CharCode.fullBlock, backColor, foreColor);
terminal.writeAt({ x: start.x + 2, y: start.y }, text, foreColor, backColor);
};
LabelWidget.prototype.onDraw = function () {
if (!this.terminal)
return;
if (this.state.direction === "left") {
this.renderLeftLabel(this.terminal);
}
else {
this.renderRightLabel(this.terminal);
}
};
return LabelWidget;
}(widget_1.Widget));
exports.LabelWidget = LabelWidget;
//# sourceMappingURL=label-widget.js.map