Changed ansi parser to use SAUCE width when available

This commit is contained in:
Nathan Byrd 2023-08-24 18:00:02 -05:00
parent b11ddfc382
commit 0b157ddd1b
1 changed files with 19 additions and 1 deletions

View File

@ -46,6 +46,16 @@ function getFontNameFromSAUCE(sauce) {
} }
} }
function getWidthFromSAUCE(sauce) {
if (sauce.Character) {
let sauceWidth = _.toNumber(sauce.Character.characterWidth);
if(!(_.isNaN(sauceWidth) && sauceWidth > 0)) {
return sauceWidth;
}
}
return null;
}
function sliceAtEOF(data, eofMarker) { function sliceAtEOF(data, eofMarker) {
let eof = data.length; let eof = data.length;
const stopPos = Math.max(data.length - 256, 0); // 256 = 2 * sizeof(SAUCE) const stopPos = Math.max(data.length - 256, 0); // 256 = 2 * sizeof(SAUCE)
@ -270,10 +280,18 @@ function display(client, art, options, cb) {
} }
} }
// Use width from SAUCE if available - if the width is less than the term width,
// we need to set that as the width for the parser so that wide terminals
// display correctly
let parseWidth = getWidthFromSAUCE(options.sauce);
if(_.isNil(parseWidth) || parseWidth > client.term.termWidth) {
parseWidth = client.term.termWidth;
}
const ansiParser = new aep.ANSIEscapeParser({ const ansiParser = new aep.ANSIEscapeParser({
mciReplaceChar: options.mciReplaceChar, mciReplaceChar: options.mciReplaceChar,
termHeight: client.term.termHeight, termHeight: client.term.termHeight,
termWidth: client.term.termWidth, termWidth: parseWidth,
trailingLF: options.trailingLF, trailingLF: options.trailingLF,
startRow: options.startRow, startRow: options.startRow,
}); });