Skip to content

Commit

Permalink
handle vt100 reverse video escape code (#3598)
Browse files Browse the repository at this point in the history
  • Loading branch information
partouf committed Apr 29, 2022
1 parent fa9a274 commit 5969633
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions static/ansi-to-html.ts
Expand Up @@ -167,6 +167,8 @@ function handleDisplay(stack: string[], _code: string | number, options: AnsiToH
return codeMap[code]();
} else if (4 < code && code < 7) {
return pushTag(stack, 'blink');
} else if (code === 7) {
return '';
} else if (29 < code && code < 38) {
// @ts-ignore
return pushForegroundColor(stack, options.colors[code - 30]);
Expand Down
30 changes: 18 additions & 12 deletions test/ansi-to-html-tests.js
Expand Up @@ -34,32 +34,38 @@ describe('ansi-to-html', () => {
};
it('Should leave non-ansi colours alone', () => {
const filter = new Filter(filterOpts);
filter.toHtml('I am a boring old string')
.should.equal('I am a boring old string');
filter.toHtml('I am a boring old string').should.equal('I am a boring old string');
});
it('Should handle simple cases', () => {
const filter = new Filter(filterOpts);
filter.toHtml('\x1B[38;5;99mTest')
.should.equal('<span style="color:#875fff">Test</span>');
filter.toHtml('\x1B[38;5;99mTest').should.equal('<span style="color:#875fff">Test</span>');
});
it('Should handle nasty edge cases', () => {
const filter = new Filter(filterOpts);
// See #1666, this used to cause catastrophic backtracking.
filter.toHtml('\x1B[38;5;9999999999999999999999999999999999999999999999999999999999999999999999999999999' +
'99999999999999999999"mTest').should.equal(
'5;9999999999999999999999999999999999999999999999999999999999999' +
'99999999999999999999999999999999999999"mTest');
filter
.toHtml(
'\x1B[38;5;9999999999999999999999999999999999999999999999999999999999999999999999999999999' +
'99999999999999999999"mTest',
)
.should.equal(
'5;9999999999999999999999999999999999999999999999999999999999999' +
'99999999999999999999999999999999999999"mTest',
);
});

// With thanks to https://github.com/rburns/ansi-to-html/pull/84/files
it('renders xterm foreground 256 sequences', () => {
const filter = new Filter(filterOpts);
filter.toHtml('\x1B[38;5;196mhello')
.should.equal('<span style="color:#ff0000">hello</span>');
filter.toHtml('\x1B[38;5;196mhello').should.equal('<span style="color:#ff0000">hello</span>');
});
it('renders xterm background 256 sequences', () => {
const filter = new Filter(filterOpts);
filter.toHtml('\x1B[48;5;196mhello')
.should.equal('<span style="background-color:#ff0000">hello</span>');
filter.toHtml('\x1B[48;5;196mhello').should.equal('<span style="background-color:#ff0000">hello</span>');
});

it('should ignore reverse video', () => {
const filter = new Filter(filterOpts);
filter.toHtml('\x1B[7mhello').should.equal('hello');
});
});

0 comments on commit 5969633

Please sign in to comment.