Skip to content

Commit

Permalink
(bug) Remove ansi escape codes from UI Log Display (#600)
Browse files Browse the repository at this point in the history
Ansi escape codes are intended to manipulate a terminal and when they're
printed they make it more difficult to read the intended log content.
  • Loading branch information
zph committed Jul 5, 2024
1 parent 428f91b commit fdcc93a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ui/src/components/organizations/ExecutionLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ type Props = {
log?: LogFile;
};

// Credit: https://github.com/chalk/ansi-regex/commit/02fa893d619d3da85411acc8fd4e2eea0e95a9d9 under MIT license
const ANSI_CODES_REGEX = [
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
].join('|');

function ExecutionLog({ log }: Props) {
if (!log) {
return <LoadingIndicator />;
}
log.Content = log.Content.replace(new RegExp(ANSI_CODES_REGEX, 'g'), '');
return (
<Box>
<Stack spacing={1} direction="column" sx={{ width: '100%' }}>
Expand Down

0 comments on commit fdcc93a

Please sign in to comment.