Initial versions of new bansi codes

This commit is contained in:
Nathan Byrd 2023-09-18 23:35:44 +00:00
parent 5e120d1749
commit 08841528e2
1 changed files with 68 additions and 18 deletions

View File

@ -77,6 +77,7 @@ function ANSIEscapeParser(options) {
self.clearScreen = function () { self.clearScreen = function () {
self.column = 1; self.column = 1;
self.row = 1; self.row = 1;
self.positionUpdated();
self.emit('clear screen'); self.emit('clear screen');
}; };
@ -281,8 +282,8 @@ function ANSIEscapeParser(options) {
if (pos < buffer.length) { if (pos < buffer.length) {
var lastBit = buffer.slice(pos); var lastBit = buffer.slice(pos);
// :TODO: check for various ending LF's, not just DOS \r\n // handles either \r\n or \n
if ('\r\n' === lastBit.slice(-2).toString()) { if ('\n' === lastBit.slice(-1).toString()) {
switch (self.trailingLF) { switch (self.trailingLF) {
case 'default': case 'default':
// //
@ -290,14 +291,14 @@ function ANSIEscapeParser(options) {
// if we're going to end on termHeight // if we're going to end on termHeight
// //
if (this.termHeight === self.row) { if (this.termHeight === self.row) {
lastBit = lastBit.slice(0, -2); lastBit = lastBit.slice(0, -1);
} }
break; break;
case 'omit': case 'omit':
case 'no': case 'no':
case false: case false:
lastBit = lastBit.slice(0, -2); lastBit = lastBit.slice(0, -1);
break; break;
} }
} }
@ -382,6 +383,18 @@ function ANSIEscapeParser(options) {
self.moveCursor(-arg, 0); self.moveCursor(-arg, 0);
break; break;
// line feed
case 'E':
arg = isNaN(args[0]) ? 1 : args[0];
if(this.row + arg > this.termHeight) {
this.emit('scroll', arg - (this.termHeight - this.row));
self.moveCursor(0, this.termHeight);
}
else {
self.moveCursor(0, arg);
}
break;
case 'f': // horiz & vertical case 'f': // horiz & vertical
case 'H': // cursor position case 'H': // cursor position
//self.row = args[0] || 1; //self.row = args[0] || 1;
@ -392,14 +405,19 @@ function ANSIEscapeParser(options) {
self.positionUpdated(); self.positionUpdated();
break; break;
// save position
case 's': // erase display/screen
self.saveCursorPosition(); case 'J':
// :TODO: Handle other 'J' types!
if (2 === args[0]) {
self.clearScreen();
}
break; break;
// restore position // insert line
case 'u': case 'L':
self.restoreCursorPosition(); arg = isNaN(args[0]) ? 1 : args[0];
self.emit('insert line', self.row, arg);
break; break;
// set graphic rendition // set graphic rendition
@ -471,15 +489,47 @@ function ANSIEscapeParser(options) {
self.emit('sgr update', self.graphicRendition); self.emit('sgr update', self.graphicRendition);
break; // m break; // m
// :TODO: s, u, K // save position
case 's':
// erase display/screen self.saveCursorPosition();
case 'J':
// :TODO: Handle other 'J' types!
if (2 === args[0]) {
self.clearScreen();
}
break; break;
// Scroll up
case 'S':
arg = isNaN(args[0]) ? 1 : args[0];
self.emit('scroll', arg);
break;
// Scroll down
case 'T':
arg = isNaN(args[0]) ? 1 : args[0];
self.emit('scroll', -arg);
break;
// restore position
case 'u':
self.restoreCursorPosition();
break;
// clear
case 'U':
self.clearScreen();
break;
// delete line
// TODO: how should we handle 'M'?
case 'Y':
arg = isNaN(args[0]) ? 1 : args[0];
self.emit('delete line', self.row, arg);
break;
// back tab
case 'Z':
// calculate previous tabstop
self.column = Math.max( 1, self.column - (self.column % 8 || 8) );
self.positionUpdated();
break;
} }
} }
} }