0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

Revert "feat(cli/console): inspect with colors regardless of Deno.noColor (#7778)" (#7973)

This reverts commit f75bd89aff.
This commit is contained in:
Bartek Iwańczuk 2020-10-14 18:54:29 +02:00 committed by GitHub
parent 5bed06fb94
commit 81635c59e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 23 deletions

View file

@ -10,7 +10,9 @@
} }
function run(str, code) { 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) { function bold(str) {
@ -70,10 +72,6 @@
return string.replace(ANSI_PATTERN, ""); return string.replace(ANSI_PATTERN, "");
} }
function maybeColor(fn) {
return !(globalThis.Deno?.noColor ?? false) ? fn : (s) => s;
}
window.__bootstrap.colors = { window.__bootstrap.colors = {
bold, bold,
italic, italic,
@ -87,6 +85,5 @@
magenta, magenta,
dim, dim,
stripColor, stripColor,
maybeColor,
}; };
})(this); })(this);

View file

@ -1425,12 +1425,10 @@
const timerMap = new Map(); const timerMap = new Map();
const isConsoleInstance = Symbol("isConsoleInstance"); const isConsoleInstance = Symbol("isConsoleInstance");
function getConsoleInspectOptions() { const CONSOLE_INSPECT_OPTIONS = {
return { ...DEFAULT_INSPECT_OPTIONS,
...DEFAULT_INSPECT_OPTIONS, colors: true,
colors: !(globalThis.Deno?.noColor ?? false), };
};
}
class Console { class Console {
#printFunc = null; #printFunc = null;
@ -1453,7 +1451,7 @@
log = (...args) => { log = (...args) => {
this.#printFunc( this.#printFunc(
inspectArgs(args, { inspectArgs(args, {
...getConsoleInspectOptions(), ...CONSOLE_INSPECT_OPTIONS,
indentLevel: this.indentLevel, indentLevel: this.indentLevel,
}) + "\n", }) + "\n",
false, false,
@ -1465,8 +1463,7 @@
dir = (obj, options = {}) => { dir = (obj, options = {}) => {
this.#printFunc( this.#printFunc(
inspectArgs([obj], { ...getConsoleInspectOptions(), ...options }) + inspectArgs([obj], { ...CONSOLE_INSPECT_OPTIONS, ...options }) + "\n",
"\n",
false, false,
); );
}; };
@ -1476,7 +1473,7 @@
warn = (...args) => { warn = (...args) => {
this.#printFunc( this.#printFunc(
inspectArgs(args, { inspectArgs(args, {
...getConsoleInspectOptions(), ...CONSOLE_INSPECT_OPTIONS,
indentLevel: this.indentLevel, indentLevel: this.indentLevel,
}) + "\n", }) + "\n",
true, true,
@ -1682,7 +1679,7 @@
trace = (...args) => { trace = (...args) => {
const message = inspectArgs( const message = inspectArgs(
args, args,
{ ...getConsoleInspectOptions(), indentLevel: 0 }, { ...CONSOLE_INSPECT_OPTIONS, indentLevel: 0 },
); );
const err = { const err = {
name: "Trace", name: "Trace",

View file

@ -2,7 +2,7 @@
((window) => { ((window) => {
const core = window.Deno.core; 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 { exit } = window.__bootstrap.os;
const { Console, inspectArgs } = window.__bootstrap.console; const { Console, inspectArgs } = window.__bootstrap.console;
const { stdout } = window.__bootstrap.files; const { stdout } = window.__bootstrap.files;
@ -19,8 +19,6 @@
} }
function formatDuration(time = 0) { function formatDuration(time = 0) {
const gray = colors.maybeColor(colors.gray);
const italic = colors.maybeColor(colors.italic);
const timeStr = `(${time}ms)`; const timeStr = `(${time}ms)`;
return gray(italic(timeStr)); return gray(italic(timeStr));
} }
@ -141,9 +139,6 @@ finishing test case.`;
} }
function reportToConsole(message) { 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 redFailed = red("FAILED");
const greenOk = green("ok"); const greenOk = green("ok");
const yellowIgnored = yellow("ignored"); const yellowIgnored = yellow("ignored");