Skip to content

Commit

Permalink
correctly handle implicit font reset ansi code
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonbloom committed Jan 24, 2022
1 parent 562917c commit ece7542
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion gui/src/components/logs/parseSpans.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test('parseSpans', () => {
},
]);

check('\u001b[31mRed\u001b[32mGreen\u001b[34mBlue', [
check('\u001b[31mRed\u001b[32mGreen\u001b[34mBlue\u001b[mReset', [
{
foreground: 'rgb(170, 0, 0)',
text: 'Red',
Expand All @@ -57,5 +57,8 @@ test('parseSpans', () => {
foreground: 'rgb(0, 0, 170)',
text: 'Blue',
},
{
text: 'Reset',
},
]);
});
7 changes: 5 additions & 2 deletions gui/src/components/logs/parseSpans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,13 @@ export const parseSpans = (input: string): Span[] => {
}

// Handle control sequences.
const control = rest.match(/^\u001b\[([\d;]+)m/);
const control = rest.match(/^\u001b\[([\d;]*)m/);
if (control) {
emitSpan();
let codes = control[1].split(';').map((n) => parseInt(n, 10));
let codes = control[1]
.split(';')
.filter((n) => n !== '')
.map((n) => parseInt(n, 10));
if (codes.length === 0) {
codes = [0];
}
Expand Down

0 comments on commit ece7542

Please sign in to comment.