From 826db2d718e1ed515eaa40c2d731f827fa8b67db Mon Sep 17 00:00:00 2001 From: Nathan Byrd Date: Wed, 20 Sep 2023 23:00:32 +0000 Subject: [PATCH] Added scrolling. --- core/ansi_escape_parser.js | 14 ++++++++++++++ core/art.js | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/core/ansi_escape_parser.js b/core/ansi_escape_parser.js index 55dc9a82..974399c8 100644 --- a/core/ansi_escape_parser.js +++ b/core/ansi_escape_parser.js @@ -86,6 +86,20 @@ function ANSIEscapeParser(options) { }; self.positionUpdated = function () { + if(self.row > self.termHeight) { + if(this.savedPosition) { + this.savedPosition.row -= self.row - self.termHeight; + } + self.emit('scroll', self.row - self.termHeight); + self.row = self.termHeight; + } + else if(self.row < 1) { + if(this.savedPosition) { + this.savedPosition.row -= self.row - 1; + } + self.emit('scroll', -(self.row - 1)); + self.row = 1; + } self.emit('position update', self.row, self.column); }; diff --git a/core/art.js b/core/art.js index 2145f5ad..f6c0c4d9 100644 --- a/core/art.js +++ b/core/art.js @@ -316,6 +316,12 @@ function display(client, art, options, cb) { } }); + ansiParser.on('scroll', (scrollY) => { + _.forEach(mciMap, (mciInfo) => { + mciInfo.position[0] -= scrollY; + }); + }); + ansiParser.on('literal', literal => client.term.write(literal, false)); ansiParser.on('control', control => client.term.rawWrite(control));