summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit/tty_color_test.ts29
-rw-r--r--runtime/colors.rs7
2 files changed, 34 insertions, 2 deletions
diff --git a/cli/tests/unit/tty_color_test.ts b/cli/tests/unit/tty_color_test.ts
index 3adc16b23..b49ffa6bd 100644
--- a/cli/tests/unit/tty_color_test.ts
+++ b/cli/tests/unit/tty_color_test.ts
@@ -24,3 +24,32 @@ Deno.test(
assertEquals(output, "false\n");
},
);
+
+Deno.test(
+ { permissions: { run: true, read: true } },
+ async function denoNoColorTrueEmptyVar() {
+ const { stdout } = await new Deno.Command(Deno.execPath(), {
+ args: ["eval", "console.log(Deno.noColor)"],
+ env: {
+ // https://no-color.org/ -- should not be true when empty
+ NO_COLOR: "",
+ },
+ }).output();
+ const output = new TextDecoder().decode(stdout);
+ assertEquals(output, "false\n");
+ },
+);
+
+Deno.test(
+ { permissions: { run: true, read: true } },
+ async function denoNoColorTrueEmptyVar() {
+ const { stdout } = await new Deno.Command(Deno.execPath(), {
+ args: ["eval", "console.log(Deno.noColor)"],
+ env: {
+ NO_COLOR: "1",
+ },
+ }).output();
+ const output = new TextDecoder().decode(stdout);
+ assertEquals(output, "true\n");
+ },
+);
diff --git a/runtime/colors.rs b/runtime/colors.rs
index fe5a3dcbe..8d915b571 100644
--- a/runtime/colors.rs
+++ b/runtime/colors.rs
@@ -22,8 +22,11 @@ use termcolor::BufferWriter;
#[cfg(windows)]
use termcolor::ColorChoice;
-static NO_COLOR: Lazy<bool> =
- Lazy::new(|| std::env::var_os("NO_COLOR").is_some());
+static NO_COLOR: Lazy<bool> = Lazy::new(|| {
+ std::env::var_os("NO_COLOR")
+ .map(|v| !v.is_empty())
+ .unwrap_or(false)
+});
static IS_TTY: Lazy<bool> = Lazy::new(|| std::io::stdout().is_terminal());