Skip to content

Commit

Permalink
fix: Adding Better regex for ansi codes stripping from the string (#435)
Browse files Browse the repository at this point in the history
* Measure ansi escape codes correctly

Modified regex to allow for more variations of ansi codes like '\x1b[38;5m', bolding, etc.

* Update console-utils.ts

---------

Co-authored-by: Nahiyan Kamal <noyanayihan@gmail.com>
  • Loading branch information
wmalkin and ayonious committed Feb 15, 2023
1 parent b8b76b0 commit a90525f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/console-utils.ts
Expand Up @@ -2,7 +2,7 @@ import { wcswidth } from 'simple-wcswidth';
import { CharLengthDict } from '../models/common';

/* eslint-disable no-control-regex */
const colorRegex = /\x1b\[\d{1,3}m/g; // \x1b[30m \x1b[305m
const colorRegex = /\x1b\[\d{1,3}(;\d{1,3})*m/g; // \x1b[30m \x1b[305m \x1b[38;5m

const stripAnsi = (str: string): string => str.replace(colorRegex, '');

Expand Down

0 comments on commit a90525f

Please sign in to comment.