diff --git a/src/xterm.js b/src/xterm.js index 957c3b6..ecfe466 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -1315,6 +1315,14 @@ Terminal.prototype.scrollPages = function(pageCount) { this.scrollDisp(pageCount * (this.rows - 1)); } +Terminal.prototype.scrollToTop = function() { + this.scrollDisp(-this.ydisp); +} + +Terminal.prototype.scrollToBottom = function() { + this.scrollDisp(this.ybase - this.ydisp); +} + /** * Writes text to the terminal. * @param {string} text The text to write to the terminal. diff --git a/test/test.js b/test/test.js index 3c24401..eb34a44 100644 --- a/test/test.js +++ b/test/test.js @@ -147,6 +147,40 @@ describe('xterm.js', function() { assert.equal(xterm.ydisp, startYDisp); }); }); + + describe('scrollToTop', function() { + beforeEach(function() { + for (var i = 0; i < xterm.rows * 3; i++) { + xterm.writeln('test'); + } + }); + it('should scroll to the top', function() { + assert.notEqual(xterm.ydisp, 0); + xterm.scrollToTop(); + assert.equal(xterm.ydisp, 0); + }); + }); + + describe('scrollToBottom', function() { + var startYDisp; + beforeEach(function() { + for (var i = 0; i < xterm.rows * 3; i++) { + xterm.writeln('test'); + } + startYDisp = (xterm.rows * 2) + 1; + }); + it('should scroll to the bottom', function() { + xterm.scrollDisp(-1); + xterm.scrollToBottom(); + assert.equal(xterm.ydisp, startYDisp); + xterm.scrollPages(-1); + xterm.scrollToBottom(); + assert.equal(xterm.ydisp, startYDisp); + xterm.scrollToTop(); + xterm.scrollToBottom(); + assert.equal(xterm.ydisp, startYDisp); + }); + }); }); describe('evaluateKeyEscapeSequence', function() {