Skip to content

Commit

Permalink
Fix history trimming and screen size and offset computation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Soehnel committed Apr 24, 2012
1 parent a0af705 commit 6c4806d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
4 changes: 4 additions & 0 deletions schirm/resources/term.css
Expand Up @@ -41,6 +41,10 @@ body {
margin:0px;
border:0px;
padding:0px;
top:0px;
bottom:2px;
left:0px;
right:2px;
}

iframe {
Expand Down
39 changes: 26 additions & 13 deletions schirm/resources/term.js
Expand Up @@ -13,7 +13,13 @@ function getCharSize(preElement) {
function getTermSize(preElement) {
var blockSize = getCharSize(preElement);
var cols = Math.floor(document.body.clientWidth/blockSize.width);
var lines = Math.floor(document.body.clientHeight/blockSize.height);
// No idea why but the size reported by using offsetHeight in
// getCharSize needs to be decremented by one to get the *real* size
// of a char block in a pre element. Without this, the line
// calculation will be inaccurate for large windows and will lead to
// a few lines of trailing whitespace.
var lines = Math.floor(document.body.clientHeight/(blockSize.height - 1));

return { lines: lines, cols: cols };
}

Expand Down Expand Up @@ -81,6 +87,7 @@ var Lines = (function(linesElement, term) {

// pointer to the first terminal line
screen0: 0,
pendingRemoveHistory: false,

init: function() { },

Expand All @@ -93,25 +100,30 @@ var Lines = (function(linesElement, term) {
},

checkHistorySize: function() {
// generate an remove history event if necessary

var maxHistoryHeight = 10000; // in pixels
var start = this.screen0;
var historyHeight = linesElement.childNodes[start].offsetTop;

if (historyHeight > maxHistoryHeight) {
for (var i=0; i<start; i++) {
if ((historyHeight - linesElement.childNodes[i].offsetTop) < maxHistoryHeight) {
console.log('removehistory' + i);
return
// generate an remove_history event if necessary

// only check and generate the remove_history event if there is
// no event waiting to be processed
if (!this.pendingRemoveHistory) {
var maxHistoryHeight = 10000; // in pixels
var start = this.screen0;
var historyHeight = linesElement.childNodes[start].offsetTop;

if (historyHeight > maxHistoryHeight) {
for (var i=0; i<start; i++) {
if ((historyHeight - linesElement.childNodes[i].offsetTop) < maxHistoryHeight) {
console.log('removehistory' + i);
this.pendingRemoveHistory = true; // change state: wait for the removeHistory response
return
}
}
}
}
},

adjustTrailingSpace: function() {
// adjust layout to 'render' empty lines at the bottom
if (linesElement.childNodes.length && ((linesElement.childNodes.length - this.screen0) < term.size.lines)) {
if (linesElement.childNodes.length && ((linesElement.childNodes.length - this.screen0) <= term.size.lines)) {
var historyHeight = linesElement.childNodes[this.screen0].offsetTop;
// position the <pre> so that anything above the screen0 line is outside the termscreen client area
linesElement.style.setProperty("top", -historyHeight);
Expand Down Expand Up @@ -162,6 +174,7 @@ var Lines = (function(linesElement, term) {
for (var i=0; i<n; i++) {
linesElement.removeChild(linesElement.firstChild);
}
this.pendingRemoveHistory = false;
},

getSize: function() {
Expand Down

0 comments on commit 6c4806d

Please sign in to comment.