]>
git.proxmox.com Git - mirror_xterm.js.git/blob - addons/fit/fit.js
0700502f74e2d40005253dd1a8c27dbd08bb5f07
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 define
== 'function') {
17 * Require.js is available
19 define(['../../src/xterm'], fit
);
22 * Plain browser environment
27 Xterm
.prototype.proposeGeometry = function () {
28 var container
= this.rowContainer
,
29 subjectRow
= this.rowContainer
.firstElementChild
,
35 subjectRow
.style
.display
= 'inline';
37 contentBuffer
= subjectRow
.textContent
;
39 subjectRow
.innerHTML
= ' '; /* Arbitrary character to calculate its dimensions */
40 characterWidth
= parseInt(subjectRow
.offsetWidth
);
41 characterHeight
= parseInt(subjectRow
.offsetHeight
);
43 subjectRow
.style
.display
= '';
45 cols
= container
.offsetWidth
/ characterWidth
;
46 cols
= parseInt(cols
);
48 var parentElementStyle
= window
.getComputedStyle(this.element
.parentElement
),
49 parentElementHeight
= parseInt(parentElementStyle
.getPropertyValue('height')),
50 elementStyle
= window
.getComputedStyle(this.element
),
51 elementPadding
= parseInt(elementStyle
.getPropertyValue('padding-top')) + parseInt(elementStyle
.getPropertyValue('padding-bottom')),
52 availableHeight
= parentElementHeight
- elementPadding
,
53 rowHeight
= this.rowContainer
.firstElementChild
.offsetHeight
;
55 rows
= parseInt(availableHeight
/ rowHeight
);
65 Xterm
.prototype.fit = function () {
66 var geometry
= this.proposeGeometry();
68 this.resize(geometry
.cols
, geometry
.rows
);