]>
git.proxmox.com Git - mirror_xterm.js.git/blob - addons/fit/fit.js
2 * Fit terminal columns and rows to the dimensions of its
6 * - Rows: Truncate the division of the terminal parent element height
7 * by the terminal row height
9 * - Columns: Truncate the division of the terminal parent element width by
10 * the terminal character width (apply display: inline at the
11 * terminal row and truncate its width with the current number
15 if (typeof exports
=== 'object' && typeof module
=== 'object') {
17 * CommonJS environment
19 module
.exports
= fit
.call(this);
20 } else if (typeof define
== 'function') {
22 * Require.js is available
24 define(['../../src/xterm'], fit
);
27 * Plain browser environment
32 Xterm
.prototype.proposeGeometry = function () {
33 var parentElementStyle
= window
.getComputedStyle(this.element
.parentElement
),
34 parentElementHeight
= parseInt(parentElementStyle
.getPropertyValue('height')),
35 parentElementWidth
= parseInt(parentElementStyle
.getPropertyValue('width')),
36 elementStyle
= window
.getComputedStyle(this.element
),
37 elementPaddingVer
= parseInt(elementStyle
.getPropertyValue('padding-top')) + parseInt(elementStyle
.getPropertyValue('padding-bottom')),
38 elementPaddingHor
= parseInt(elementStyle
.getPropertyValue('padding-right')) + parseInt(elementStyle
.getPropertyValue('padding-left')),
39 availableHeight
= parentElementHeight
- elementPaddingVer
,
40 availableWidth
= parentElementWidth
- elementPaddingHor
,
41 container
= this.rowContainer
,
42 subjectRow
= this.rowContainer
.firstElementChild
,
43 contentBuffer
= subjectRow
.innerHTML
,
50 subjectRow
.style
.display
= 'inline';
51 subjectRow
.innerHTML
= 'W'; // Common character for measuring width, although on monospace
52 characterWidth
= subjectRow
.getBoundingClientRect().width
;
53 subjectRow
.style
.display
= ''; // Revert style before calculating height, since they differ.
54 characterHeight
= parseInt(subjectRow
.offsetHeight
);
55 subjectRow
.innerHTML
= contentBuffer
;
57 rows
= parseInt(availableHeight
/ characterHeight
);
58 cols
= parseInt(availableWidth
/ characterWidth
) - 1;
60 geometry
= {cols
: cols
, rows
: rows
};
64 Xterm
.prototype.fit = function () {
65 var geometry
= this.proposeGeometry();
67 this.resize(geometry
.cols
, geometry
.rows
);