Handle deleting rows / columns

This commit is contained in:
Nathan Byrd 2023-09-20 23:52:34 +00:00
parent c0c262c971
commit 79a3f4e1ce
2 changed files with 51 additions and 4 deletions

View File

@ -28,7 +28,7 @@ function ANSIEscapeParser(options) {
this.graphicRendition = {}; this.graphicRendition = {};
this.parseState = { this.parseState = {
re: /(?:\x1b)(?:(?:\x5b([?=;0-9]*?)([ABCDEFGfHJLmMsSTuUYZ]))|([78DEHM]))/g, // eslint-disable-line no-control-regex re: /(?:\x1b)(?:(?:\x5b([?=;0-9]*?)([ABCDEFGfHJKLmMsSTuUYZ]))|([78DEHM]))/g, // eslint-disable-line no-control-regex
}; };
options = miscUtil.valueWithDefault(options, { options = miscUtil.valueWithDefault(options, {
@ -280,7 +280,7 @@ function ANSIEscapeParser(options) {
self.parseState = { self.parseState = {
// ignore anything past EOF marker, if any // ignore anything past EOF marker, if any
buffer: input.split(String.fromCharCode(0x1a), 1)[0], buffer: input.split(String.fromCharCode(0x1a), 1)[0],
re: /(?:\x1b)(?:(?:\x5b([?=;0-9]*?)([ABCDEFGfHJLmMsSTuUYZ]))|([78DEHM]))/g, // eslint-disable-line no-control-regex re: /(?:\x1b)(?:(?:\x5b([?=;0-9]*?)([ABCDEFGfHJKLmMsSTuUYZ]))|([78DEHM]))/g, // eslint-disable-line no-control-regex
stop: false, stop: false,
}; };
}; };
@ -471,12 +471,30 @@ function ANSIEscapeParser(options) {
// erase display/screen // erase display/screen
case 'J': case 'J':
// :TODO: Handle other 'J' types! if(isNaN(args[0]) || 0 === args[0]) {
if (2 === args[0]) { self.emit('erase rows', self.row, self.termHeight);
}
else if (1 === args[0]) {
self.emit('erase rows', 1, self.row);
}
else if (2 === args[0]) {
self.clearScreen(); self.clearScreen();
} }
break; break;
// erase text in line
case 'K':
if(isNaN(args[0]) || 0 === args[0]) {
self.emit('erase columns', self.row, self.column, self.termWidth);
}
else if (1 === args[0]) {
self.emit('erase columns', self.row, 1, self.column);
}
else if (2 === args[0]) {
self.emit('erase columns', self.row, 1, self.termWidth);
}
break;
// insert line // insert line
case 'L': case 'L':
arg = isNaN(args[0]) ? 1 : args[0]; arg = isNaN(args[0]) ? 1 : args[0];

View File

@ -316,6 +316,35 @@ function display(client, art, options, cb) {
} }
}); });
// Remove any MCI's that are in erased rows
ansiParser.on('erase row', (startRow, endRow) => {
_.forEach(mciMap, (mciInfo, mapKey) => {
if (mciInfo.position[0] >= startRow && mciInfo.position[0] <= endRow) {
delete mciMap[mapKey];
}
});
});
// Remove any MCI's that are in erased columns
ansiParser.on('erase columns', (row, startCol, endCol) => {
_.forEach(mciMap, (mciInfo, mapKey) => {
if (
mciInfo.position[0] === row &&
mciInfo.position[1] >= startCol &&
mciInfo.position[1] <= endCol
) {
delete mciMap[mapKey];
}
});
});
// Clear the screen, removing any MCI's
ansiParser.on('clear screen', () => {
_.forEach(mciMap, (mciInfo, mapKey) => {
delete mciMap[mapKey];
});
});
ansiParser.on('scroll', (scrollY) => { ansiParser.on('scroll', (scrollY) => {
_.forEach(mciMap, (mciInfo) => { _.forEach(mciMap, (mciInfo) => {
mciInfo.position[0] -= scrollY; mciInfo.position[0] -= scrollY;