summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Docs.md11
-rw-r--r--js/deno.ts2
-rw-r--r--js/main.ts2
-rw-r--r--js/os.ts6
-rw-r--r--src/msg.fbs1
-rw-r--r--src/ops.rs14
-rw-r--r--tests/no_color.js2
-rwxr-xr-xtools/test.py16
8 files changed, 45 insertions, 9 deletions
diff --git a/Docs.md b/Docs.md
index e1a4ba44a..b029874d8 100644
--- a/Docs.md
+++ b/Docs.md
@@ -305,6 +305,17 @@ import { test, assertEqual } from "./package.ts";
This design circumvents a plethora of complexity spawned by package management
software, centralized code repositories, and superfluous file formats.
+## Environmental Variables
+
+There are several env vars that control how Deno behaves:
+
+`DENO_DIR` defaults to `$HOME/.deno` but can be set to any path to control where
+generated and cached source code is written and read to.
+
+`NO_COLOR` will turn off color output if set. See https://no-color.org/. User
+code can test if `NO_COLOR` was set without having `--allow-env` by using the
+boolean constant `deno.noColor`.
+
## Browser compatibility
The subset of Deno programs which are written completely in JavaScript and do
diff --git a/js/deno.ts b/js/deno.ts
index 42bd38013..5f3998116 100644
--- a/js/deno.ts
+++ b/js/deno.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// Public deno module.
-export { pid, env, exit, isTTY } from "./os";
+export { noColor, pid, env, exit, isTTY } from "./os";
export { chdir, cwd } from "./dir";
export {
File,
diff --git a/js/main.ts b/js/main.ts
index b26cefcbf..4151abe75 100644
--- a/js/main.ts
+++ b/js/main.ts
@@ -39,7 +39,7 @@ export default function denoMain() {
os.exit(0);
}
- os.setPid(startResMsg.pid());
+ os.setGlobals(startResMsg.pid(), startResMsg.noColor());
const cwd = startResMsg.cwd();
log("cwd", cwd);
diff --git a/js/os.ts b/js/os.ts
index 3122830cf..d8c3288d5 100644
--- a/js/os.ts
+++ b/js/os.ts
@@ -9,9 +9,13 @@ import * as util from "./util";
/** process id */
export let pid: number;
-export function setPid(pid_: number): void {
+/** Reflects the NO_COLOR enviromental variable: https://no-color.org/ */
+export let noColor: boolean;
+
+export function setGlobals(pid_: number, noColor_: boolean): void {
assert(!pid);
pid = pid_;
+ noColor = noColor_;
}
interface CodeInfo {
diff --git a/src/msg.fbs b/src/msg.fbs
index d7e71ab14..de69c31ad 100644
--- a/src/msg.fbs
+++ b/src/msg.fbs
@@ -160,6 +160,7 @@ table StartRes {
version_flag: bool;
deno_version: string;
v8_version: string;
+ no_color: bool;
}
table WorkerGetMessage {
diff --git a/src/ops.rs b/src/ops.rs
index 86bc6efad..2b4136208 100644
--- a/src/ops.rs
+++ b/src/ops.rs
@@ -1,5 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+use atty;
+use crate::ansi;
use crate::errors;
use crate::errors::{DenoError, DenoResult, ErrorKind};
use crate::fs as deno_fs;
@@ -18,8 +20,6 @@ use crate::resources::table_entries;
use crate::resources::Resource;
use crate::tokio_util;
use crate::version;
-
-use atty;
use flatbuffers::FlatBufferBuilder;
use futures;
use futures::Async;
@@ -33,10 +33,6 @@ use std;
use std::convert::From;
use std::fs;
use std::net::Shutdown;
-#[cfg(unix)]
-use std::os::unix::fs::PermissionsExt;
-#[cfg(unix)]
-use std::os::unix::process::ExitStatusExt;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
@@ -48,6 +44,11 @@ use tokio::net::TcpStream;
use tokio_process::CommandExt;
use tokio_threadpool;
+#[cfg(unix)]
+use std::os::unix::fs::PermissionsExt;
+#[cfg(unix)]
+use std::os::unix::process::ExitStatusExt;
+
type OpResult = DenoResult<Buf>;
// TODO Ideally we wouldn't have to box the Op being returned.
@@ -266,6 +267,7 @@ fn op_start(
version_flag: state.flags.version,
v8_version: Some(v8_version_off),
deno_version: Some(deno_version_off),
+ no_color: !ansi::use_color(),
..Default::default()
},
);
diff --git a/tests/no_color.js b/tests/no_color.js
new file mode 100644
index 000000000..0963c94c4
--- /dev/null
+++ b/tests/no_color.js
@@ -0,0 +1,2 @@
+import { noColor } from "deno";
+console.log("noColor", noColor);
diff --git a/tools/test.py b/tools/test.py
index 246b094b7..0fe1d6a23 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -8,6 +8,7 @@ from integration_tests import integration_tests
from deno_dir_test import deno_dir_test
from setup_test import setup_test
from util import build_path, enable_ansi_colors, executable_suffix, run, rmtree
+from util import run_output, tests_path, green_ok
from unit_tests import unit_tests
from util_test import util_test
from benchmark_test import benchmark_test
@@ -25,6 +26,19 @@ def check_exists(filename):
sys.exit(1)
+def test_no_color(deno_exe):
+ sys.stdout.write("no_color test...")
+ sys.stdout.flush()
+ t = os.path.join(tests_path, "no_color.js")
+ output = run_output([deno_exe, t], merge_env={"NO_COLOR": "1"})
+ assert output.strip() == "noColor true"
+ t = os.path.join(tests_path, "no_color.js")
+ output = run_output([deno_exe, t])
+ assert output.strip() == "noColor false"
+ print green_ok()
+
+
+
def main(argv):
if len(argv) == 2:
build_dir = sys.argv[1]
@@ -81,6 +95,8 @@ def main(argv):
deno_dir_test(deno_exe, deno_dir)
+ test_no_color(deno_exe)
+
if __name__ == '__main__':
sys.exit(main(sys.argv))