mirror of
https://github.com/denoland/deno.git
synced 2025-10-02 23:24:37 +00:00
Adds deno.noColor (#1716)
This commit is contained in:
parent
4c869dc885
commit
526497bc29
8 changed files with 45 additions and 9 deletions
11
Docs.md
11
Docs.md
|
@ -305,6 +305,17 @@ import { test, assertEqual } from "./package.ts";
|
||||||
This design circumvents a plethora of complexity spawned by package management
|
This design circumvents a plethora of complexity spawned by package management
|
||||||
software, centralized code repositories, and superfluous file formats.
|
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
|
## Browser compatibility
|
||||||
|
|
||||||
The subset of Deno programs which are written completely in JavaScript and do
|
The subset of Deno programs which are written completely in JavaScript and do
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
// Public deno module.
|
// Public deno module.
|
||||||
export { pid, env, exit, isTTY } from "./os";
|
export { noColor, pid, env, exit, isTTY } from "./os";
|
||||||
export { chdir, cwd } from "./dir";
|
export { chdir, cwd } from "./dir";
|
||||||
export {
|
export {
|
||||||
File,
|
File,
|
||||||
|
|
|
@ -39,7 +39,7 @@ export default function denoMain() {
|
||||||
os.exit(0);
|
os.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
os.setPid(startResMsg.pid());
|
os.setGlobals(startResMsg.pid(), startResMsg.noColor());
|
||||||
|
|
||||||
const cwd = startResMsg.cwd();
|
const cwd = startResMsg.cwd();
|
||||||
log("cwd", cwd);
|
log("cwd", cwd);
|
||||||
|
|
6
js/os.ts
6
js/os.ts
|
@ -9,9 +9,13 @@ import * as util from "./util";
|
||||||
/** process id */
|
/** process id */
|
||||||
export let pid: number;
|
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);
|
assert(!pid);
|
||||||
pid = pid_;
|
pid = pid_;
|
||||||
|
noColor = noColor_;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CodeInfo {
|
interface CodeInfo {
|
||||||
|
|
|
@ -160,6 +160,7 @@ table StartRes {
|
||||||
version_flag: bool;
|
version_flag: bool;
|
||||||
deno_version: string;
|
deno_version: string;
|
||||||
v8_version: string;
|
v8_version: string;
|
||||||
|
no_color: bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
table WorkerGetMessage {
|
table WorkerGetMessage {
|
||||||
|
|
14
src/ops.rs
14
src/ops.rs
|
@ -1,5 +1,7 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
use atty;
|
||||||
|
use crate::ansi;
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
use crate::errors::{DenoError, DenoResult, ErrorKind};
|
use crate::errors::{DenoError, DenoResult, ErrorKind};
|
||||||
use crate::fs as deno_fs;
|
use crate::fs as deno_fs;
|
||||||
|
@ -18,8 +20,6 @@ use crate::resources::table_entries;
|
||||||
use crate::resources::Resource;
|
use crate::resources::Resource;
|
||||||
use crate::tokio_util;
|
use crate::tokio_util;
|
||||||
use crate::version;
|
use crate::version;
|
||||||
|
|
||||||
use atty;
|
|
||||||
use flatbuffers::FlatBufferBuilder;
|
use flatbuffers::FlatBufferBuilder;
|
||||||
use futures;
|
use futures;
|
||||||
use futures::Async;
|
use futures::Async;
|
||||||
|
@ -33,10 +33,6 @@ use std;
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::net::Shutdown;
|
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::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
@ -48,6 +44,11 @@ use tokio::net::TcpStream;
|
||||||
use tokio_process::CommandExt;
|
use tokio_process::CommandExt;
|
||||||
use tokio_threadpool;
|
use tokio_threadpool;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::process::ExitStatusExt;
|
||||||
|
|
||||||
type OpResult = DenoResult<Buf>;
|
type OpResult = DenoResult<Buf>;
|
||||||
|
|
||||||
// TODO Ideally we wouldn't have to box the Op being returned.
|
// TODO Ideally we wouldn't have to box the Op being returned.
|
||||||
|
@ -266,6 +267,7 @@ fn op_start(
|
||||||
version_flag: state.flags.version,
|
version_flag: state.flags.version,
|
||||||
v8_version: Some(v8_version_off),
|
v8_version: Some(v8_version_off),
|
||||||
deno_version: Some(deno_version_off),
|
deno_version: Some(deno_version_off),
|
||||||
|
no_color: !ansi::use_color(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
2
tests/no_color.js
Normal file
2
tests/no_color.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import { noColor } from "deno";
|
||||||
|
console.log("noColor", noColor);
|
|
@ -8,6 +8,7 @@ from integration_tests import integration_tests
|
||||||
from deno_dir_test import deno_dir_test
|
from deno_dir_test import deno_dir_test
|
||||||
from setup_test import setup_test
|
from setup_test import setup_test
|
||||||
from util import build_path, enable_ansi_colors, executable_suffix, run, rmtree
|
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 unit_tests import unit_tests
|
||||||
from util_test import util_test
|
from util_test import util_test
|
||||||
from benchmark_test import benchmark_test
|
from benchmark_test import benchmark_test
|
||||||
|
@ -25,6 +26,19 @@ def check_exists(filename):
|
||||||
sys.exit(1)
|
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):
|
def main(argv):
|
||||||
if len(argv) == 2:
|
if len(argv) == 2:
|
||||||
build_dir = sys.argv[1]
|
build_dir = sys.argv[1]
|
||||||
|
@ -81,6 +95,8 @@ def main(argv):
|
||||||
|
|
||||||
deno_dir_test(deno_exe, deno_dir)
|
deno_dir_test(deno_exe, deno_dir)
|
||||||
|
|
||||||
|
test_no_color(deno_exe)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main(sys.argv))
|
sys.exit(main(sys.argv))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue