Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console.log CSS should support initial (or unset/revert) #13638

Open
0az opened this issue Feb 10, 2022 · 0 comments
Open

Console.log CSS should support initial (or unset/revert) #13638

0az opened this issue Feb 10, 2022 · 0 comments
Labels
ext/console Related to the ext/console crate suggestion suggestions for new features (yet to be agreed) web related to Web APIs

Comments

@0az
Copy link

0az commented Feb 10, 2022

When pretty-printing output, it's common to apply a style for a span, before reverting back to the terminal's default style. This is used in terminal prompts and in log output, for example.

Screenshot of ANSI-colored terminal prompt

As a specific motivating example, consider this output (this program does not output color to non-tty stdouts).

; deno run --allow-env --allow-net --allow-hrtime src/index.ts | cat
Check file:///[snipped]/src/index.ts
Listening on port 8000
status=200 route="POST /" duration=1.3ms
status=200 route="GET /" duration=0.3ms
status=200 route="PUT /" duration=0.2ms
status=200 route="DELETE /" duration=0.2ms
status=200 route="HEAD /" duration=0.1ms

With color, it looks like this:

image

But what if we want to use background-color instead?

image

In this case, I simply forgot to change the color: white used as resets to background-color: black. That's an easy fix, but it shows the limitations of the current level of support. Furthermore, this color reset is fragile. What if the user uses a green terminal background?

image

This breaks in an ugly way.

A quick test reveals that support exists in Firefox:

console.log('%cRED%cUNSET', 'color: red', 'color: unset')

image

Thus, implementing at least one of initial/unset/revert is needed to make it easier to write good programs with well-formatted console output, in addition to improving parity with web platforms.

@lucacasonato lucacasonato added ext/console Related to the ext/console crate suggestion suggestions for new features (yet to be agreed) web related to Web APIs labels Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext/console Related to the ext/console crate suggestion suggestions for new features (yet to be agreed) web related to Web APIs
Projects
None yet
Development

No branches or pull requests

2 participants