Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds deno.noColor #1716

Merged
merged 3 commits into from
Feb 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add deno.noColor
  • Loading branch information
ry committed Feb 8, 2019
commit 1014734b12d70a9f5cbdf480f5736e00fb81d599
9 changes: 9 additions & 0 deletions Docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ 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/

## Browser compatibility

The subset of Deno programs which are written completely in JavaScript and do
Expand Down
2 changes: 1 addition & 1 deletion js/deno.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion js/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/msg.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ table StartRes {
version_flag: bool;
deno_version: string;
v8_version: string;
no_color: bool;
}

table WorkerGetMessage {
Expand Down
14 changes: 8 additions & 6 deletions src/ops.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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()
},
);
Expand Down
2 changes: 2 additions & 0 deletions tests/no_color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { noColor } from "deno";
console.log("noColor", noColor);
16 changes: 16 additions & 0 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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
Expand All @@ -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 == "noColor true\n"
t = os.path.join(tests_path, "no_color.js")
output = run_output([deno_exe, t])
assert output == "noColor false\n"
print green_ok()



def main(argv):
if len(argv) == 2:
build_dir = sys.argv[1]
Expand Down Expand Up @@ -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))