1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 08:09:08 -05:00

Revert "fix(console): support NO_COLOR and colors option in all scena… (#22507)

…rios (#21910)"

This reverts commit bd1358efab.

This change caused https://github.com/denoland/deno/issues/22496 and
https://github.com/denoland/deno/issues/22445
This commit is contained in:
Bartek Iwańczuk 2024-02-21 00:17:50 +00:00 committed by GitHub
parent ca8bc7ece8
commit 77b90f408c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 55 deletions

View file

@ -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",

View file

@ -5164,17 +5164,3 @@ console.log(add(3, 4));
let output = test_context.new_command().args("run main.ts").run();
output.assert_matches_text("[WILDCARD]5\n7\n");
}
#[test]
fn inspect_color_overwrite() {
let test_context = TestContextBuilder::new().build();
let output = test_context
.new_command()
.skip_strip_ansi()
.split_output()
.env("NO_COLOR", "1")
.args("run run/inspect_color_overwrite.ts")
.run();
assert_eq!(output.stdout(), "foo\u{1b}[31mbar\u{1b}[0m\n");
}

View file

@ -1,5 +0,0 @@
console.log(
Deno[Deno.internal].inspectArgs(["%cfoo%cbar", "", "color: red"], {
colors: true,
}),
);

View file

@ -357,7 +357,6 @@ pub struct TestCommandBuilder {
args_text: String,
args_vec: Vec<String>,
split_output: bool,
skip_strip_ansi: bool,
}
impl TestCommandBuilder {
@ -369,7 +368,6 @@ impl TestCommandBuilder {
stderr: None,
stdin_text: None,
split_output: false,
skip_strip_ansi: false,
cwd: None,
envs: Default::default(),
envs_remove: Default::default(),
@ -453,11 +451,6 @@ impl TestCommandBuilder {
self
}
pub fn skip_strip_ansi(mut self) -> Self {
self.skip_strip_ansi = true;
self
}
pub fn stdin<T: Into<Stdio>>(mut self, cfg: T) -> Self {
self.stdin = Some(StdioContainer::new(cfg.into()));
self
@ -581,14 +574,8 @@ impl TestCommandBuilder {
output
}
fn sanitize_output(
mut text: String,
args: &[OsString],
skip_strip_ansi: bool,
) -> String {
if !skip_strip_ansi {
text = strip_ansi_codes(&text).to_string();
}
fn sanitize_output(text: String, args: &[OsString]) -> String {
let mut text = strip_ansi_codes(&text).to_string();
// deno test's output capturing flushes with a zero-width space in order to
// synchronize the output pipes. Occasionally this zero width space
// might end up in the output so strip it from the output comparison here.
@ -635,15 +622,14 @@ impl TestCommandBuilder {
// and dropping it closes them.
drop(command);
let combined = combined_reader.map(|pipe| {
sanitize_output(read_pipe_to_string(pipe), &args, self.skip_strip_ansi)
});
let combined = combined_reader
.map(|pipe| sanitize_output(read_pipe_to_string(pipe), &args));
let status = process.wait().unwrap();
let std_out_err = std_out_err_handle.map(|(stdout, stderr)| {
(
sanitize_output(stdout.join().unwrap(), &args, self.skip_strip_ansi),
sanitize_output(stderr.join().unwrap(), &args, self.skip_strip_ansi),
sanitize_output(stdout.join().unwrap(), &args),
sanitize_output(stderr.join().unwrap(), &args),
)
});
let exit_code = status.code();

View file

@ -511,7 +511,6 @@ pub struct CheckOutputIntegrationTest<'a> {
pub http_server: bool,
pub envs: Vec<(String, String)>,
pub env_clear: bool,
pub skip_strip_ansi: bool,
pub temp_cwd: bool,
/// Copies the files at the specified directory in the "testdata" directory
/// to the temp folder and runs the test from there. This is useful when
@ -553,9 +552,6 @@ impl<'a> CheckOutputIntegrationTest<'a> {
if self.env_clear {
command_builder = command_builder.env_clear();
}
if self.skip_strip_ansi {
command_builder = command_builder.skip_strip_ansi();
}
if let Some(cwd) = &self.cwd {
command_builder = command_builder.current_dir(cwd);
}