From 77b90f408c4244e8ee2e4b3bd26c441d4a250671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 21 Feb 2024 00:17:50 +0000 Subject: =?UTF-8?q?Revert=20"fix(console):=20support=20NO=5FCOLOR=20and=20?= =?UTF-8?q?colors=20option=20in=20all=20scena=E2=80=A6=20(#22507)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …rios (#21910)" This reverts commit bd1358efab8ba7339a8e70034315fa7da840292e. This change caused https://github.com/denoland/deno/issues/22496 and https://github.com/denoland/deno/issues/22445 --- ext/console/01_console.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'ext') diff --git a/ext/console/01_console.js b/ext/console/01_console.js index 02c962cd1..b851b4035 100644 --- a/ext/console/01_console.js +++ b/ext/console/01_console.js @@ -2335,14 +2335,10 @@ const denoInspectDefaultOptions = { }; function getDefaultInspectOptions() { - const color = !getNoColor(); - return { budget: {}, seen: [], ...denoInspectDefaultOptions, - colors: color, - stylize: color ? createStylizeWithColor(styles, colors) : stylizeNoColor, }; } @@ -2943,6 +2939,7 @@ function inspectArgs(args, inspectOptions = {}) { if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity; if (ctx.maxStringLength === null) ctx.maxStringLength = Infinity; + const noColor = getNoColor(); const first = args[0]; let a = 0; let string = ""; @@ -2985,7 +2982,7 @@ function inspectArgs(args, inspectOptions = {}) { formattedArg = formatValue(ctx, args[a++], 0); } else if (char == "c") { const value = args[a++]; - if (ctx.colors) { + if (!noColor) { const css = parseCss(value); formattedArg = cssToAnsi(css, prevCss); if (formattedArg != "") { @@ -3056,6 +3053,15 @@ const countMap = new SafeMap(); const timerMap = new SafeMap(); const isConsoleInstance = Symbol("isConsoleInstance"); +function getConsoleInspectOptions() { + const color = !getNoColor(); + return { + ...getDefaultInspectOptions(), + colors: color, + stylize: color ? createStylizeWithColor(styles, colors) : stylizeNoColor, + }; +} + class Console { #printFunc = null; [isConsoleInstance] = false; @@ -3084,7 +3090,7 @@ class Console { log = (...args) => { this.#printFunc( inspectArgs(args, { - ...getDefaultInspectOptions(), + ...getConsoleInspectOptions(), indentLevel: this.indentLevel, }) + "\n", 1, @@ -3094,7 +3100,7 @@ class Console { debug = (...args) => { this.#printFunc( inspectArgs(args, { - ...getDefaultInspectOptions(), + ...getConsoleInspectOptions(), indentLevel: this.indentLevel, }) + "\n", 0, @@ -3104,7 +3110,7 @@ class Console { info = (...args) => { this.#printFunc( inspectArgs(args, { - ...getDefaultInspectOptions(), + ...getConsoleInspectOptions(), indentLevel: this.indentLevel, }) + "\n", 1, @@ -3113,7 +3119,7 @@ class Console { dir = (obj = undefined, options = {}) => { this.#printFunc( - inspectArgs([obj], { ...getDefaultInspectOptions(), ...options }) + + inspectArgs([obj], { ...getConsoleInspectOptions(), ...options }) + "\n", 1, ); @@ -3124,7 +3130,7 @@ class Console { warn = (...args) => { this.#printFunc( inspectArgs(args, { - ...getDefaultInspectOptions(), + ...getConsoleInspectOptions(), indentLevel: this.indentLevel, }) + "\n", 2, @@ -3134,7 +3140,7 @@ class Console { error = (...args) => { this.#printFunc( inspectArgs(args, { - ...getDefaultInspectOptions(), + ...getConsoleInspectOptions(), indentLevel: this.indentLevel, }) + "\n", 3, @@ -3347,7 +3353,7 @@ class Console { trace = (...args) => { const message = inspectArgs( args, - { ...getDefaultInspectOptions(), indentLevel: 0 }, + { ...getConsoleInspectOptions(), indentLevel: 0 }, ); const err = { name: "Trace", -- cgit v1.2.3