UNPKG

malwoden

Version:

![alt text](./coverage/badge-lines.svg) ![alt text](./coverage/badge-statements.svg) ![alt text](./coverage/badge-functions.svg) ![alt text](./coverage/badge-branches.svg)

72 lines 2.99 kB
"use strict"; 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.BarWidget = exports.getRoundedPercent = void 0; var terminal_1 = require("../terminal"); var widget_1 = require("./widget"); function getRoundedPercent(percent, divisor, round) { var roundFunc = Math.round; if (round === "up") { roundFunc = Math.ceil; } else if (round === "down") { roundFunc = Math.floor; } return roundFunc(percent * divisor) / divisor; } exports.getRoundedPercent = getRoundedPercent; /** * Represents a bar, like in a loading/progress indicator * or hp bar. */ var BarWidget = /** @class */ (function (_super) { __extends(BarWidget, _super); function BarWidget(config) { var _this = _super.call(this, config) || this; _this.state = __assign({ roundMode: "default", minValue: 0, currentValue: 0, foreGlyph: terminal_1.Glyph.fromCharCode(terminal_1.CharCode.fullBlock, terminal_1.Color.White), backGlyph: terminal_1.Glyph.fromCharCode(terminal_1.CharCode.fullBlock, terminal_1.Color.Gray) }, config.initialState); return _this; } BarWidget.prototype.onDraw = function () { if (!this.terminal) return; var origin = this.getAbsoluteOrigin(); var percent = (this.state.currentValue - this.state.minValue) / (this.state.maxValue - this.state.minValue); var roundedPercent = getRoundedPercent(percent, this.state.width + 1, this.state.roundMode); for (var x = origin.x; x <= origin.x + this.state.width; x++) { var p = (x - origin.x) / this.state.width; if (p <= roundedPercent) { this.terminal.drawGlyph({ x: x, y: origin.y }, this.state.foreGlyph); } else { this.terminal.drawGlyph({ x: x, y: origin.y }, this.state.backGlyph); } } }; return BarWidget; }(widget_1.Widget)); exports.BarWidget = BarWidget; //# sourceMappingURL=bar-widget.js.map