diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-05-14 17:32:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-14 17:32:09 -0400 |
commit | e39b94f3aa09bc77280b98caebb9ae472f8f6c5a (patch) | |
tree | 8bfaec53de64cd6dcfccf2045f4231265b091fdd /runtime/js | |
parent | 1e2b0a22196ab2a17ceae855293fdcd5a2596161 (diff) |
fix(runtime): output to stderr with colors if a tty and stdout is piped (#23813)
This also fixes a bug where Deno would output to stderr with colours
when piped and stdout was not piped.
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/99_main.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 2ea122e34..fcec6b91a 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -8,7 +8,8 @@ import { core, internals, primordials } from "ext:core/mod.js"; const ops = core.ops; import { op_bootstrap_args, - op_bootstrap_is_tty, + op_bootstrap_is_stderr_tty, + op_bootstrap_is_stdout_tty, op_bootstrap_no_color, op_bootstrap_pid, op_main_module, @@ -62,10 +63,10 @@ import * as timers from "ext:deno_web/02_timers.js"; import { customInspect, getDefaultInspectOptions, - getNoColor, + getStderrNoColor, inspectArgs, quoteString, - setNoColorFn, + setNoColorFns, } from "ext:deno_console/01_console.js"; import * as performance from "ext:deno_web/15_performance.js"; import * as url from "ext:deno_url/00_url.js"; @@ -379,7 +380,10 @@ function importScripts(...urls) { const opArgs = memoizeLazy(() => op_bootstrap_args()); const opPid = memoizeLazy(() => op_bootstrap_pid()); -setNoColorFn(() => op_bootstrap_no_color() || !op_bootstrap_is_tty()); +setNoColorFns( + () => op_bootstrap_no_color() || !op_bootstrap_is_stdout_tty(), + () => op_bootstrap_no_color() || !op_bootstrap_is_stderr_tty(), +); function formatException(error) { if ( @@ -390,11 +394,11 @@ function formatException(error) { } else if (typeof error == "string") { return `Uncaught ${ inspectArgs([quoteString(error, getDefaultInspectOptions())], { - colors: !getNoColor(), + colors: !getStderrNoColor(), }) }`; } else { - return `Uncaught ${inspectArgs([error], { colors: !getNoColor() })}`; + return `Uncaught ${inspectArgs([error], { colors: !getStderrNoColor() })}`; } } |