]>
git.proxmox.com Git - mirror_xterm.js.git/blob - dist/addons/fit/fit.js
2 * Fit terminal columns and rows to the dimensions of its DOM element.
5 * - Rows: Truncate the division of the terminal parent element height by the terminal row height.
7 * - Columns: Truncate the division of the terminal parent element width by the terminal character
8 * width (apply display: inline at the terminal row and truncate its width with the current
10 * @module xterm/addons/fit/fit
14 if (typeof exports
=== 'object' && typeof module
=== 'object') {
16 * CommonJS environment
18 module
.exports
= fit(require('../../xterm'));
20 else if (typeof define
== 'function') {
22 * Require.js is available
24 define(['../../xterm'], fit
);
28 * Plain browser environment
34 exports
.proposeGeometry = function (term
) {
35 var parentElementStyle
= window
.getComputedStyle(term
.element
.parentElement
), parentElementHeight
= parseInt(parentElementStyle
.getPropertyValue('height')), parentElementWidth
= parseInt(parentElementStyle
.getPropertyValue('width')), elementStyle
= window
.getComputedStyle(term
.element
), elementPaddingVer
= parseInt(elementStyle
.getPropertyValue('padding-top')) + parseInt(elementStyle
.getPropertyValue('padding-bottom')), elementPaddingHor
= parseInt(elementStyle
.getPropertyValue('padding-right')) + parseInt(elementStyle
.getPropertyValue('padding-left')), availableHeight
= parentElementHeight
- elementPaddingVer
, availableWidth
= parentElementWidth
- elementPaddingHor
, container
= term
.rowContainer
, subjectRow
= term
.rowContainer
.firstElementChild
, contentBuffer
= subjectRow
.innerHTML
, characterHeight
, rows
, characterWidth
, cols
, geometry
;
36 subjectRow
.style
.display
= 'inline';
37 subjectRow
.innerHTML
= 'W'; // Common character for measuring width, although on monospace
38 characterWidth
= subjectRow
.getBoundingClientRect().width
;
39 subjectRow
.style
.display
= ''; // Revert style before calculating height, since they differ.
40 characterHeight
= parseInt(subjectRow
.offsetHeight
);
41 subjectRow
.innerHTML
= contentBuffer
;
42 rows
= parseInt(availableHeight
/ characterHeight
);
43 cols
= parseInt(availableWidth
/ characterWidth
) - 1;
44 geometry
= { cols
: cols
, rows
: rows
};
47 exports
.fit = function (term
) {
48 var geometry
= exports
.proposeGeometry(term
);
49 term
.resize(geometry
.cols
, geometry
.rows
);
51 Xterm
.prototype.proposeGeometry = function () {
52 return exports
.proposeGeometry(this);
54 Xterm
.prototype.fit = function () {
55 return exports
.fit(this);
59 //# sourceMappingURL=fit.js.map