Skip to content

Ignore %c format specifier in the console and support #9021

@sebmarkbage

Description

@sebmarkbage

What is the problem this feature would solve?

I'm trying to call console.log with color formatting and have it behave the same in the terminal and in WebKit inspector.

As far as I can tell both ANSI escape characters and the %c format specifier with CSS styles are used in the community. Chrome supports both.

https://developer.chrome.com/docs/devtools/console/format-style

Node ignores the %c format specifier and skips its corresponding arguments, but prints any ANSI. Deno seems to go further and sometimes tries to convert the %c format specifier and CSS to ANSI in terminal.

Bun doesn't ignore the %c so it prints it and its argument.

Safari doesn't support ANSI color sequences. It prints them as visible characters. Therefore when inspecting Bun with WebKit inspector it prints the color sequences but this console supports CSS.

In Node, I can emit both ANSI and CSS format specifiers and have the CSS one override ANSI in the browser and get ignored in the terminal.

In Bun if I emit ANSI it works in the terminal but not inspector, if I emit CSS it works in the inspector but not the terminal.

What is the feature you are proposing to solve the problem?

Bun should ignore/hide %c format specifiers and their arguments in the terminal output.

Bun should ideally also strip out ANSI color sequences before passing them to WebKit inspector protocol so that the Inspector doesn't print them visibly.

That way I can mix ANSI and %c to target each environment in a single call.

What alternatives have you considered?

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions