From 615f633f256799680e5188a642fe3378d11bf81a Mon Sep 17 00:00:00 2001 From: paris Date: Mon, 17 Nov 2014 12:21:05 +0200 Subject: [PATCH] [fit addon] Introduce proposeGeometry method - Introduce new method to propose optimal geometry for the current terminal - Bump version to 0.23 --- addons/fit/fit.js | 69 +++++++++++++++++++++++++++-------------------- bower.json | 2 +- docs/conf.py | 4 +-- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/addons/fit/fit.js b/addons/fit/fit.js index 69909c41..3b1df002 100644 --- a/addons/fit/fit.js +++ b/addons/fit/fit.js @@ -24,36 +24,47 @@ fit(this.Xterm); } })(function (Xterm) { + Xterm.prototype.proposeGeometry = function () { + var container = this.rowContainer, + subjectRow = this.rowContainer.firstElementChild, + rows, + contentBuffer, + characterWidth, + cols; + + subjectRow.style.display = 'inline'; + + contentBuffer = subjectRow.textContent; + + subjectRow.innerHTML = ' '; /* Arbitrary character to calculate its dimensions */ + characterWidth = parseInt(subjectRow.offsetWidth); + characterHeight = parseInt(subjectRow.offsetHeight); + + subjectRow.style.display = ''; + + cols = container.offsetWidth / characterWidth; + cols = parseInt(cols); + + var parentElementStyle = window.getComputedStyle(this.element.parentElement), + parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')), + elementStyle = window.getComputedStyle(this.element), + elementPadding = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')), + availableHeight = parentElementHeight - elementPadding, + rowHeight = this.rowContainer.firstElementChild.offsetHeight; + + rows = parseInt(availableHeight / rowHeight); + + var geometry = { + 'cols': cols, + 'rows': rowss + }; + + return geometry; + }; + Xterm.prototype.fit = function () { - var container = this.rowContainer, - subjectRow = this.rowContainer.firstElementChild, - rows, - contentBuffer, - characterWidth, - cols; + var geometry = this.proposeGeometry(); - subjectRow.style.display = 'inline'; - - contentBuffer = subjectRow.textContent; - - subjectRow.innerHTML = ' '; /* Arbitrary character to calculate its dimensions */ - characterWidth = parseInt(subjectRow.offsetWidth); - characterHeight = parseInt(subjectRow.offsetHeight); - - subjectRow.style.display = ''; - - cols = container.offsetWidth / characterWidth; - cols = parseInt(cols); - - var parentElementStyle = window.getComputedStyle(this.element.parentElement), - parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')), - elementStyle = window.getComputedStyle(this.element), - elementPadding = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')), - availableHeight = parentElementHeight - elementPadding, - rowHeight = this.rowContainer.firstElementChild.offsetHeight; - - rows = parseInt(availableHeight / rowHeight); - - this.resize(cols, rows); + this.resize(geometry.cols, geometry.rows); }; }); \ No newline at end of file diff --git a/bower.json b/bower.json index 8648a77e..45b93416 100644 --- a/bower.json +++ b/bower.json @@ -1,5 +1,5 @@ { "name": "xterm.js", - "version": "0.22", + "version": "0.23", "ignore": ["demo", "docs", "test", ".gitignore"] } diff --git a/docs/conf.py b/docs/conf.py index 53ce9720..c14bb7c2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -51,9 +51,9 @@ copyright = u'2014, SourceLair Limited' # built documents. # # The short X.Y version. -version = '0.22' +version = '0.23' # The full version, including alpha/beta/rc tags. -release = '0.22 Alpha' +release = '0.23 Alpha' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages.