diff options
Diffstat (limited to 'cli/rt')
-rw-r--r-- | cli/rt/01_colors.js | 9 | ||||
-rw-r--r-- | cli/rt/02_console.js | 19 | ||||
-rw-r--r-- | cli/rt/40_testing.js | 7 |
3 files changed, 12 insertions, 23 deletions
diff --git a/cli/rt/01_colors.js b/cli/rt/01_colors.js index 39e4a7a18..2dc559186 100644 --- a/cli/rt/01_colors.js +++ b/cli/rt/01_colors.js @@ -10,7 +10,9 @@ } function run(str, code) { - return `${code.open}${str.replace(code.regexp, code.open)}${code.close}`; + return !globalThis || !globalThis.Deno || globalThis.Deno.noColor + ? str + : `${code.open}${str.replace(code.regexp, code.open)}${code.close}`; } function bold(str) { @@ -70,10 +72,6 @@ return string.replace(ANSI_PATTERN, ""); } - function maybeColor(fn) { - return !(globalThis.Deno?.noColor ?? false) ? fn : (s) => s; - } - window.__bootstrap.colors = { bold, italic, @@ -87,6 +85,5 @@ magenta, dim, stripColor, - maybeColor, }; })(this); diff --git a/cli/rt/02_console.js b/cli/rt/02_console.js index bb2b6ea41..0eb7f0aac 100644 --- a/cli/rt/02_console.js +++ b/cli/rt/02_console.js @@ -1425,12 +1425,10 @@ const timerMap = new Map(); const isConsoleInstance = Symbol("isConsoleInstance"); - function getConsoleInspectOptions() { - return { - ...DEFAULT_INSPECT_OPTIONS, - colors: !(globalThis.Deno?.noColor ?? false), - }; - } + const CONSOLE_INSPECT_OPTIONS = { + ...DEFAULT_INSPECT_OPTIONS, + colors: true, + }; class Console { #printFunc = null; @@ -1453,7 +1451,7 @@ log = (...args) => { this.#printFunc( inspectArgs(args, { - ...getConsoleInspectOptions(), + ...CONSOLE_INSPECT_OPTIONS, indentLevel: this.indentLevel, }) + "\n", false, @@ -1465,8 +1463,7 @@ dir = (obj, options = {}) => { this.#printFunc( - inspectArgs([obj], { ...getConsoleInspectOptions(), ...options }) + - "\n", + inspectArgs([obj], { ...CONSOLE_INSPECT_OPTIONS, ...options }) + "\n", false, ); }; @@ -1476,7 +1473,7 @@ warn = (...args) => { this.#printFunc( inspectArgs(args, { - ...getConsoleInspectOptions(), + ...CONSOLE_INSPECT_OPTIONS, indentLevel: this.indentLevel, }) + "\n", true, @@ -1682,7 +1679,7 @@ trace = (...args) => { const message = inspectArgs( args, - { ...getConsoleInspectOptions(), indentLevel: 0 }, + { ...CONSOLE_INSPECT_OPTIONS, indentLevel: 0 }, ); const err = { name: "Trace", diff --git a/cli/rt/40_testing.js b/cli/rt/40_testing.js index 082d17fe0..c374e0ca6 100644 --- a/cli/rt/40_testing.js +++ b/cli/rt/40_testing.js @@ -2,7 +2,7 @@ ((window) => { const core = window.Deno.core; - const colors = window.__bootstrap.colors; + const { gray, green, italic, red, yellow } = window.__bootstrap.colors; const { exit } = window.__bootstrap.os; const { Console, inspectArgs } = window.__bootstrap.console; const { stdout } = window.__bootstrap.files; @@ -19,8 +19,6 @@ } function formatDuration(time = 0) { - const gray = colors.maybeColor(colors.gray); - const italic = colors.maybeColor(colors.italic); const timeStr = `(${time}ms)`; return gray(italic(timeStr)); } @@ -141,9 +139,6 @@ finishing test case.`; } function reportToConsole(message) { - const green = colors.maybeColor(colors.green); - const red = colors.maybeColor(colors.red); - const yellow = colors.maybeColor(colors.yellow); const redFailed = red("FAILED"); const greenOk = green("ok"); const yellowIgnored = yellow("ignored"); |