Make the terminal go to new line if the width of the term is greater than the art width
This commit is contained in:
parent
0b157ddd1b
commit
ccaaa71e23
|
@ -37,6 +37,10 @@ function ANSIEscapeParser(options) {
|
|||
this.mciReplaceChar = miscUtil.valueWithDefault(options.mciReplaceChar, '');
|
||||
this.termHeight = miscUtil.valueWithDefault(options.termHeight, 25);
|
||||
this.termWidth = miscUtil.valueWithDefault(options.termWidth, 80);
|
||||
this.breakWidth = this.termWidth;
|
||||
if(!(_.isNil(options.artWidth)) && options.artWidth > 0 && options.artWidth < this.breakWidth) {
|
||||
this.breakWidth = options.artWidth;
|
||||
}
|
||||
this.trailingLF = miscUtil.valueWithDefault(options.trailingLF, 'default');
|
||||
|
||||
this.row = Math.min(options?.startRow ?? 1, this.termHeight);
|
||||
|
@ -90,8 +94,8 @@ function ANSIEscapeParser(options) {
|
|||
|
||||
switch (charCode) {
|
||||
case CR:
|
||||
self.emit('literal', text.slice(start, pos));
|
||||
start = pos;
|
||||
self.emit('literal', text.slice(start, pos + 1));
|
||||
start = pos + 1;
|
||||
|
||||
self.column = 1;
|
||||
|
||||
|
@ -105,8 +109,8 @@ function ANSIEscapeParser(options) {
|
|||
self.column = 1;
|
||||
}
|
||||
|
||||
self.emit('literal', text.slice(start, pos));
|
||||
start = pos;
|
||||
self.emit('literal', text.slice(start, pos + 1));
|
||||
start = pos + 1;
|
||||
|
||||
self.row += 1;
|
||||
|
||||
|
@ -114,13 +118,16 @@ function ANSIEscapeParser(options) {
|
|||
break;
|
||||
|
||||
default:
|
||||
if (self.column === self.termWidth) {
|
||||
if (self.column === self.breakWidth) {
|
||||
self.emit('literal', text.slice(start, pos + 1));
|
||||
start = pos + 1;
|
||||
|
||||
// If the art is terminal, then we need to force the terminal to go to the next line.
|
||||
if(self.column < self.termWidth) {
|
||||
self.emit('literal', '\r\n');
|
||||
}
|
||||
self.column = 1;
|
||||
self.row += 1;
|
||||
|
||||
self.positionUpdated();
|
||||
} else {
|
||||
self.column += 1;
|
||||
|
@ -135,7 +142,7 @@ function ANSIEscapeParser(options) {
|
|||
//
|
||||
// Finalize this chunk
|
||||
//
|
||||
if (self.column > self.termWidth) {
|
||||
if (self.column > self.breakWidth) {
|
||||
self.column = 1;
|
||||
self.row += 1;
|
||||
|
||||
|
|
11
core/art.js
11
core/art.js
|
@ -280,18 +280,11 @@ 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({
|
||||
mciReplaceChar: options.mciReplaceChar,
|
||||
termHeight: client.term.termHeight,
|
||||
termWidth: parseWidth,
|
||||
termWidth: client.term.termWidth,
|
||||
artWidth: getWidthFromSAUCE(options.sauce),
|
||||
trailingLF: options.trailingLF,
|
||||
startRow: options.startRow,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue