]>
Commit | Line | Data |
---|---|---|
189a5564 PK |
1 | /* |
2 | * Fit terminal columns and rows to the dimensions of its | |
3 | * DOM element. | |
4 | * | |
5 | * Approach: | |
6 | * - Rows: Truncate the division of the terminal parent element height | |
7 | * by the terminal row height | |
8 | * | |
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 | |
12 | * of columns) | |
13 | */ | |
14 | Terminal.prototype.fit = function () { | |
d12406be | 15 | var container = this.rowContainer, |
189a5564 PK |
16 | subjectRow = this.rowContainer.firstElementChild, |
17 | rows = parseInt(container.offsetHeight / subjectRow.offsetHeight), | |
18 | characterWidth, | |
19 | cols; | |
20 | ||
21 | subjectRow.style.display = 'inline'; | |
22 | characterWidth = parseInt(subjectRow.offsetWidth / this.cols); | |
23 | subjectRow.style.display = ''; | |
24 | ||
d12406be PK |
25 | cols = container.offsetWidth / characterWidth; |
26 | cols = parseInt(cols); | |
189a5564 PK |
27 | |
28 | this.resize(cols, rows); | |
d12406be | 29 | }; |