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 /cli/js/colors.ts | |
| parent | cdc9323cccdee544562712018f722026bdfbbd6c (diff) | |
Provide better ANSI colorized output when inspecting objects (#5404)
Diffstat (limited to 'cli/js/colors.ts')
| -rw-r--r-- | cli/js/colors.ts | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/cli/js/colors.ts b/cli/js/colors.ts index 9b5e7be4e..eccb3567a 100644 --- a/cli/js/colors.ts +++ b/cli/js/colors.ts @@ -1,18 +1,11 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -// TODO(kitsonk) Replace with `deno_std/colors/mod.ts` when we can load modules -// which end in `.ts`. - -import { noColor } from "./deno.ts"; - interface Code { open: string; close: string; regexp: RegExp; } -const enabled = !noColor; - function code(open: number, close: number): Code { return { open: `\x1b[${open}m`, @@ -22,9 +15,9 @@ function code(open: number, close: number): Code { } function run(str: string, code: Code): string { - return enabled - ? `${code.open}${str.replace(code.regexp, code.open)}${code.close}` - : str; + return !globalThis || !globalThis.Deno || globalThis.Deno.noColor + ? str + : `${code.open}${str.replace(code.regexp, code.open)}${code.close}`; } export function bold(str: string): string { @@ -63,6 +56,14 @@ export function gray(str: string): string { return run(str, code(90, 39)); } +export function magenta(str: string): string { + return run(str, code(35, 39)); +} + +export function dim(str: string): string { + return run(str, code(2, 22)); +} + // https://github.com/chalk/ansi-regex/blob/2b56fb0c7a07108e5b54241e8faec160d393aedb/index.js const ANSI_PATTERN = new RegExp( [ |
