summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-02-10 01:13:44 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-02-09 19:13:44 -0500
commit52e047138a32e8366369737dc54198f1a5baa1cb (patch)
tree5504af906095fe21d318cec0c1bc3b214fd84e78
parentfa3f8cf67b2e97087f044c2ee430a0b32e338d0b (diff)
support NO_COLOR in colors module (denoland/deno_std#182)
Original: https://github.com/denoland/deno_std/commit/a81d2ae1f962c3e0c845e63bf06da01e4b7cfcc2
-rw-r--r--colors/README.md2
-rw-r--r--colors/mod.ts7
2 files changed, 8 insertions, 1 deletions
diff --git a/colors/README.md b/colors/README.md
index 3c371197f..e6e0890ff 100644
--- a/colors/README.md
+++ b/colors/README.md
@@ -16,6 +16,8 @@ import { bgBlue, red, bold } from "https://deno.land/x/std/colors/mod.ts";
console.log(bgBlue(red(bold("Hello world!"))));
```
+This module supports `NO_COLOR` environmental variable disabling any coloring if `NO_COLOR` is set.
+
## TODO
- Currently, it just assumes it is running in an environment that supports ANSI
diff --git a/colors/mod.ts b/colors/mod.ts
index e271c54cf..c8bb5b539 100644
--- a/colors/mod.ts
+++ b/colors/mod.ts
@@ -1,4 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+import { noColor } from "deno";
interface Code {
open: string;
@@ -6,9 +7,13 @@ interface Code {
regexp: RegExp;
}
-let enabled = true;
+let enabled = !noColor;
export function setEnabled(value: boolean) {
+ if (noColor) {
+ return;
+ }
+
enabled = value;
}