remove background colors from combination setters as well (#245734)

This commit is contained in:
Aaron Munger
2025-04-04 15:05:22 -07:00
committed by GitHub
parent 30ea977d8e
commit dac6e8999f
2 changed files with 10 additions and 0 deletions
@@ -11,6 +11,7 @@ export function formatStackTrace(stack: string): { formattedStack: string; error
// Remove background colors. The ones from IPython don't work well with
// themes 40-49 sets background color
cleaned = stack.replace(/\u001b\[4\dm/g, '');
cleaned = cleaned.replace(/(?<=\u001b\[[\d;]*?);4\d(?=m)/g, '');
// Also remove specific foreground colors (38 is the ascii code for picking one) (they don't translate either)
// Turn them into default foreground
@@ -105,4 +105,13 @@ suite('StackTraceHelper', () => {
formattedLines.slice(1).forEach(line => assert.ok(!/<a href=.*>/.test(line), 'line should not contain a link: ' + line));
});
test('background (40-49) ANSI colors are removed', () => {
const stack =
'open\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43m\'\u001b[39;49m\u001b[33;43minput.txt\u001b[39;49m\u001b[33;43m\'\u001b[39;49m\u001b[43m)\u001b[49m;';
const formattedLines = formatStackTrace(stack).formattedStack.split('\n');
assert.ok(!/4\d/.test(formattedLines[0]), 'should not contain background colors ' + formattedLines[0]);
formattedLines.slice(1).forEach(line => assert.ok(!/<a href=.*>/.test(line), 'line should not contain a link: ' + line));
});
});