summaryrefslogtreecommitdiff
path: root/cli/js/colors.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/colors.ts')
-rw-r--r--cli/js/colors.ts21
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(
[