From fe0d878b23ffaac5faa857ffc811bf83e4b04765 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 9 Oct 2016 12:51:58 -0700 Subject: [PATCH 1/6] Implement scrollPages --- src/xterm.js | 8 ++++++++ test/test.js | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/xterm.js b/src/xterm.js index 83592bb7..957c3b6b 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -1307,6 +1307,14 @@ Terminal.prototype.scrollDisp = function(disp, suppressScrollEvent) { this.refresh(0, this.rows - 1); }; +/** + * Scroll the display of the terminal by a number of pages. + * @param {number} pageCount The number of pages to scroll. + */ +Terminal.prototype.scrollPages = function(pageCount) { + this.scrollDisp(pageCount * (this.rows - 1)); +} + /** * 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 b5dc20ec..fc44b319 100644 --- a/test/test.js +++ b/test/test.js @@ -88,6 +88,12 @@ describe('xterm.js', function() { }); }); + describe('scrollDisp', function() { + it('should scroll a single line', function() { + assert.equal(xterm.ydisp, -1); + }); + }); + describe('evaluateKeyEscapeSequence', function() { it('should return the correct escape sequence for unmodified keys', function() { // Backspace From c02eea6ad34b17b93bd2e222b71805a9723d3918 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 9 Oct 2016 13:00:51 -0700 Subject: [PATCH 2/6] Add tests for scrollDisp --- test/test.js | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/test/test.js b/test/test.js index fc44b319..c24122df 100644 --- a/test/test.js +++ b/test/test.js @@ -88,9 +88,40 @@ describe('xterm.js', function() { }); }); - describe('scrollDisp', function() { - it('should scroll a single line', function() { - assert.equal(xterm.ydisp, -1); + describe('scroll', function() { + describe('scrollDisp', function() { + var startYDisp; + beforeEach(function() { + for (var i = 0; i < xterm.rows * 2; i++) { + xterm.writeln('test'); + } + startYDisp = xterm.rows + 1; + }); + it('should scroll a single line', function() { + assert.equal(xterm.ydisp, startYDisp); + xterm.scrollDisp(-1); + assert.equal(xterm.ydisp, startYDisp - 1); + xterm.scrollDisp(1); + assert.equal(xterm.ydisp, startYDisp); + }); + it('should scroll multiple lines', function() { + assert.equal(xterm.ydisp, startYDisp); + xterm.scrollDisp(-5); + assert.equal(xterm.ydisp, startYDisp - 5); + xterm.scrollDisp(5); + assert.equal(xterm.ydisp, startYDisp); + }); + it('should not scroll beyond the bounds of the buffer', function() { + assert.equal(xterm.ydisp, startYDisp); + xterm.scrollDisp(1); + assert.equal(xterm.ydisp, startYDisp); + for (var i = 0; i < startYDisp; i++) { + xterm.scrollDisp(-1); + } + assert.equal(xterm.ydisp, 0); + xterm.scrollDisp(-1); + assert.equal(xterm.ydisp, 0); + }); }); }); From 941e57a218be73fcce8c41bc9d922b514da4187b Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 9 Oct 2016 13:10:18 -0700 Subject: [PATCH 3/6] Add tests for scrollPages --- test/test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test.js b/test/test.js index c24122df..3c24401e 100644 --- a/test/test.js +++ b/test/test.js @@ -123,6 +123,30 @@ describe('xterm.js', function() { assert.equal(xterm.ydisp, 0); }); }); + + describe('scrollPages', 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 a single page', function() { + assert.equal(xterm.ydisp, startYDisp); + xterm.scrollPages(-1); + assert.equal(xterm.ydisp, startYDisp - (xterm.rows - 1)); + xterm.scrollPages(1); + assert.equal(xterm.ydisp, startYDisp); + }); + it('should scroll a multiple pages', function() { + assert.equal(xterm.ydisp, startYDisp); + xterm.scrollPages(-2); + assert.equal(xterm.ydisp, startYDisp - (xterm.rows - 1) * 2); + xterm.scrollPages(2); + assert.equal(xterm.ydisp, startYDisp); + }); + }); }); describe('evaluateKeyEscapeSequence', function() { From e5d130b6989a3236658dfbc0a79f73c0449071dc Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 9 Oct 2016 13:19:08 -0700 Subject: [PATCH 4/6] Add scrollToBottom --- src/xterm.js | 8 ++++++++ test/test.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/xterm.js b/src/xterm.js index 957c3b6b..ecfe466c 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 3c24401e..eb34a44e 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() { From 0bf7bf56a533e72325513e451ffe7f357a58af40 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 9 Oct 2016 13:20:33 -0700 Subject: [PATCH 5/6] Add jsdoc to scrollTo functions --- src/xterm.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/xterm.js b/src/xterm.js index ecfe466c..e9b3f17d 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -1315,10 +1315,16 @@ Terminal.prototype.scrollPages = function(pageCount) { this.scrollDisp(pageCount * (this.rows - 1)); } +/** + * Scrolls the display of the terminal to the top. + */ Terminal.prototype.scrollToTop = function() { this.scrollDisp(-this.ydisp); } +/** + * Scrolls the display of the terminal to the bottom. + */ Terminal.prototype.scrollToBottom = function() { this.scrollDisp(this.ybase - this.ydisp); } From 0ad02a4afa1dec5bd67da55f6334ad1b9d4c7bbf Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 10 Oct 2016 08:25:01 -0700 Subject: [PATCH 6/6] Add note that negative scrolls up on scrollPages --- src/xterm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xterm.js b/src/xterm.js index e9b3f17d..fabde179 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -1309,7 +1309,7 @@ Terminal.prototype.scrollDisp = function(disp, suppressScrollEvent) { /** * Scroll the display of the terminal by a number of pages. - * @param {number} pageCount The number of pages to scroll. + * @param {number} pageCount The number of pages to scroll (negative scrolls up). */ Terminal.prototype.scrollPages = function(pageCount) { this.scrollDisp(pageCount * (this.rows - 1));