diff options
author | Speykious <speykious.the.king@gmail.com> | 2020-05-19 20:19:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-19 14:19:26 -0400 |
commit | 9752b853ddac3ba41378d0ae8a8604a28e285ffb (patch) | |
tree | 1082dc9786adf3dbbda04b39b67ff3f421a6736f /std/fmt/colors.ts | |
parent | cdc9323cccdee544562712018f722026bdfbbd6c (diff) |
Provide better ANSI colorized output when inspecting objects (#5404)
Diffstat (limited to 'std/fmt/colors.ts')
-rw-r--r-- | std/fmt/colors.ts | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/std/fmt/colors.ts b/std/fmt/colors.ts index 64b4458fc..832f3b164 100644 --- a/std/fmt/colors.ts +++ b/std/fmt/colors.ts @@ -205,3 +205,16 @@ export function bgRgb24(str: string, color: Rgb): string { ) ); } + +// https://github.com/chalk/ansi-regex/blob/2b56fb0c7a07108e5b54241e8faec160d393aedb/index.js +const ANSI_PATTERN = new RegExp( + [ + "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", + "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", + ].join("|"), + "g" +); + +export function stripColor(string: string): string { + return string.replace(ANSI_PATTERN, ""); +} |