@inst/vscode-bin-darwin
Version:
BINARY ONLY - VSCode binary deployment for macOS
154 lines (152 loc) • 7.38 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var TextRenderLayer_1 = require("./TextRenderLayer");
var SelectionRenderLayer_1 = require("./SelectionRenderLayer");
var CursorRenderLayer_1 = require("./CursorRenderLayer");
var ColorManager_1 = require("./ColorManager");
var LinkRenderLayer_1 = require("./LinkRenderLayer");
var EventEmitter_1 = require("../EventEmitter");
var Renderer = (function (_super) {
__extends(Renderer, _super);
function Renderer(_terminal, theme) {
var _this = _super.call(this) || this;
_this._terminal = _terminal;
_this._refreshRowsQueue = [];
_this._refreshAnimationFrame = null;
_this.colorManager = new ColorManager_1.ColorManager();
if (theme) {
_this.colorManager.setTheme(theme);
}
_this._renderLayers = [
new TextRenderLayer_1.TextRenderLayer(_this._terminal.element, 0, _this.colorManager.colors),
new SelectionRenderLayer_1.SelectionRenderLayer(_this._terminal.element, 1, _this.colorManager.colors),
new LinkRenderLayer_1.LinkRenderLayer(_this._terminal.element, 2, _this.colorManager.colors, _this._terminal),
new CursorRenderLayer_1.CursorRenderLayer(_this._terminal.element, 3, _this.colorManager.colors)
];
_this.dimensions = {
scaledCharWidth: null,
scaledCharHeight: null,
scaledLineHeight: null,
scaledLineDrawY: null,
scaledCanvasWidth: null,
scaledCanvasHeight: null,
canvasWidth: null,
canvasHeight: null,
actualCellWidth: null,
actualCellHeight: null
};
_this._devicePixelRatio = window.devicePixelRatio;
return _this;
}
Renderer.prototype.onWindowResize = function (devicePixelRatio) {
if (this._devicePixelRatio !== devicePixelRatio) {
this._devicePixelRatio = devicePixelRatio;
this.onResize(this._terminal.cols, this._terminal.rows, true);
}
};
Renderer.prototype.setTheme = function (theme) {
var _this = this;
this.colorManager.setTheme(theme);
this._renderLayers.forEach(function (l) {
l.onThemeChanged(_this._terminal, _this.colorManager.colors);
l.reset(_this._terminal);
});
this._terminal.refresh(0, this._terminal.rows - 1);
return this.colorManager.colors;
};
Renderer.prototype.onResize = function (cols, rows, didCharSizeChange) {
var _this = this;
if (!this._terminal.charMeasure.width || !this._terminal.charMeasure.height) {
return;
}
this.dimensions.scaledCharWidth = Math.floor(this._terminal.charMeasure.width * window.devicePixelRatio);
this.dimensions.scaledCharHeight = Math.ceil(this._terminal.charMeasure.height * window.devicePixelRatio);
this.dimensions.scaledLineHeight = Math.floor(this.dimensions.scaledCharHeight * this._terminal.options.lineHeight);
this.dimensions.scaledLineDrawY = this._terminal.options.lineHeight === 1 ? 0 : Math.round((this.dimensions.scaledLineHeight - this.dimensions.scaledCharHeight) / 2);
this.dimensions.scaledCanvasHeight = this._terminal.rows * this.dimensions.scaledLineHeight;
this.dimensions.scaledCanvasWidth = Math.round(this._terminal.cols * this.dimensions.scaledCharWidth);
this.dimensions.canvasHeight = Math.round(this.dimensions.scaledCanvasHeight / window.devicePixelRatio);
this.dimensions.canvasWidth = Math.round(this.dimensions.scaledCanvasWidth / window.devicePixelRatio);
this.dimensions.actualCellHeight = this.dimensions.canvasHeight / this._terminal.rows;
this.dimensions.actualCellWidth = this.dimensions.canvasWidth / this._terminal.cols;
this._renderLayers.forEach(function (l) { return l.resize(_this._terminal, _this.dimensions, didCharSizeChange); });
this._terminal.refresh(0, this._terminal.rows - 1);
this.emit('resize', {
width: this.dimensions.canvasWidth,
height: this.dimensions.canvasHeight
});
};
Renderer.prototype.onCharSizeChanged = function () {
this.onResize(this._terminal.cols, this._terminal.rows, true);
};
Renderer.prototype.onBlur = function () {
var _this = this;
this._renderLayers.forEach(function (l) { return l.onBlur(_this._terminal); });
};
Renderer.prototype.onFocus = function () {
var _this = this;
this._renderLayers.forEach(function (l) { return l.onFocus(_this._terminal); });
};
Renderer.prototype.onSelectionChanged = function (start, end) {
var _this = this;
this._renderLayers.forEach(function (l) { return l.onSelectionChanged(_this._terminal, start, end); });
};
Renderer.prototype.onCursorMove = function () {
var _this = this;
this._renderLayers.forEach(function (l) { return l.onCursorMove(_this._terminal); });
};
Renderer.prototype.onOptionsChanged = function () {
var _this = this;
this._renderLayers.forEach(function (l) { return l.onOptionsChanged(_this._terminal); });
};
Renderer.prototype.clear = function () {
var _this = this;
this._renderLayers.forEach(function (l) { return l.reset(_this._terminal); });
};
Renderer.prototype.queueRefresh = function (start, end) {
this._refreshRowsQueue.push({ start: start, end: end });
if (!this._refreshAnimationFrame) {
this._refreshAnimationFrame = window.requestAnimationFrame(this._refreshLoop.bind(this));
}
};
Renderer.prototype._refreshLoop = function () {
var _this = this;
var start;
var end;
if (this._refreshRowsQueue.length > 4) {
start = 0;
end = this._terminal.rows - 1;
}
else {
start = this._refreshRowsQueue[0].start;
end = this._refreshRowsQueue[0].end;
for (var i = 1; i < this._refreshRowsQueue.length; i++) {
if (this._refreshRowsQueue[i].start < start) {
start = this._refreshRowsQueue[i].start;
}
if (this._refreshRowsQueue[i].end > end) {
end = this._refreshRowsQueue[i].end;
}
}
}
this._refreshRowsQueue = [];
this._refreshAnimationFrame = null;
start = Math.max(start, 0);
end = Math.min(end, this._terminal.rows - 1);
this._renderLayers.forEach(function (l) { return l.onGridChanged(_this._terminal, start, end); });
this._terminal.emit('refresh', { start: start, end: end });
};
return Renderer;
}(EventEmitter_1.EventEmitter));
exports.Renderer = Renderer;
//# sourceMappingURL=Renderer.js.map