From 450ba655651db21a8ab5b15a989dbe0c3b3edad6 Mon Sep 17 00:00:00 2001 From: Nathan Byrd Date: Sun, 24 Sep 2023 20:39:57 +0000 Subject: [PATCH] Fixed missing ansi codes causing formatting misses --- core/ansi_escape_parser.js | 18 +++++++----------- core/art.js | 11 +++++++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/core/ansi_escape_parser.js b/core/ansi_escape_parser.js index 7b6914ea..6fdbc667 100644 --- a/core/ansi_escape_parser.js +++ b/core/ansi_escape_parser.js @@ -12,7 +12,6 @@ const _ = require('lodash'); exports.ANSIEscapeParser = ANSIEscapeParser; -const TAB = 0x09; const CR = 0x0d; const LF = 0x0a; @@ -25,7 +24,7 @@ function ANSIEscapeParser(options) { this.graphicRendition = {}; this.parseState = { - re: /(?:\x1b)(?:(?:\x5b([?=;0-9]*?)([ABCDEFGfHJKLmMsSTuUYZ]))|([78DEHM]))/g, // eslint-disable-line no-control-regex + re: /(?:\x1b)(?:(?:\x5b([?=;0-9]*?)([ABCDEFGfHJKLmMsSTuUYZt@PX]))|([78DEHM]))/g, // eslint-disable-line no-control-regex }; options = miscUtil.valueWithDefault(options, { @@ -111,14 +110,6 @@ function ANSIEscapeParser(options) { charCode = text.charCodeAt(pos) & 0xff; // 8bit clean switch (charCode) { - case TAB: - self.emit('literal', text.slice(start, pos + 1)); - start = pos + 1; - - self.column += 8 - ((self.column - 1) % 8); - - self.positionUpdated(); - break; case CR: self.emit('literal', text.slice(start, pos + 1)); start = pos + 1; @@ -255,7 +246,7 @@ function ANSIEscapeParser(options) { self.parseState = { // ignore anything past EOF marker, if any buffer: input.split(String.fromCharCode(0x1a), 1)[0], - re: /(?:\x1b)(?:(?:\x5b([?=;0-9]*?)([ABCDEFGfHJKLmMsSTuUYZ]))|([78DEHM]))/g, // eslint-disable-line no-control-regex + re: /(?:\x1b)(?:(?:\x5b([?=;0-9]*?)([ABCDEFGfHJKLmMsSTuUYZt@PX]))|([78DEHM]))/g, // eslint-disable-line no-control-regex stop: false, }; }; @@ -585,6 +576,11 @@ function ANSIEscapeParser(options) { self.column = Math.max( 1, self.column - (self.column % 8 || 8) ); self.positionUpdated(); break; + case '@': + // insert column(s) + arg = isNaN(args[0]) ? 1 : args[0]; + self.emit('insert columns', self.row, self.column, arg); + break; } } diff --git a/core/art.js b/core/art.js index 61471a47..baf02c70 100644 --- a/core/art.js +++ b/core/art.js @@ -338,6 +338,17 @@ function display(client, art, options, cb) { }); }); + ansiParser.on('insert columns', (row, startCol, numCols) => { + _.forEach(mciMap, (mciInfo, mapKey) => { + if (mciInfo.position[0] === row && mciInfo.position[1] >= startCol) { + mciInfo.position[1] += numCols; + if(mciInfo.position[1] > client.term.termWidth) { + delete mciMap[mapKey]; + } + } + }); + }); + // Clear the screen, removing any MCI's ansiParser.on('clear screen', () => { _.forEach(mciMap, (mciInfo, mapKey) => {