summaryrefslogtreecommitdiff
path: root/ext/console/01_console.js
diff options
context:
space:
mode:
authorBartek Iwańczuk <biwanczuk@gmail.com>2024-02-21 00:17:50 +0000
committerGitHub <noreply@github.com>2024-02-21 00:17:50 +0000
commit77b90f408c4244e8ee2e4b3bd26c441d4a250671 (patch)
tree595945ffb83a3c17313222fe62da3f50000f09cc /ext/console/01_console.js
parentca8bc7ece8a37bc49aa3668cb64eada3027305d5 (diff)
Revert "fix(console): support NO_COLOR and colors option in all scena… (#22507)
…rios (#21910)" This reverts commit bd1358efab8ba7339a8e70034315fa7da840292e. This change caused https://github.com/denoland/deno/issues/22496 and https://github.com/denoland/deno/issues/22445
Diffstat (limited to 'ext/console/01_console.js')
-rw-r--r--ext/console/01_console.js30
1 files changed, 18 insertions, 12 deletions
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",