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

feat(fmt): enable setColorEnabled in browsers #3485

Merged
merged 4 commits into from
Jul 13, 2023
Merged

Conversation

halvardssm
Copy link
Contributor

Allowed for programmatic override of enable color.

When Deno is not available in global this, and we want to use the colors library in e.g. browsers without shiming (dnt), it is not possible to view colors in the console, or set it to enabled. This pr changes this behavior so that it is possible to programmatically override the enable variable.

Allowed for programmatic override of enable color
@halvardssm halvardssm requested a review from kt3k as a code owner July 10, 2023 09:20
@CLAassistant
Copy link

CLAassistant commented Jul 10, 2023

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the fmt label Jul 10, 2023
@kt3k
Copy link
Member

kt3k commented Jul 10, 2023

This makes sense to me. Deno.noColor is still respected (as the default value), but it can be overridable by setColorEnabled(true) call.

Does anyone have any concerns?

@kt3k kt3k changed the title Update colors.ts feat(fmt): enable setColorEnabled in browsers Jul 11, 2023
@kt3k
Copy link
Member

kt3k commented Jul 11, 2023

Changes for browsers make sense, but if the runtime is Deno, maybe we still want to keep that if block (to prevent accidentally enable the color in that case)

How about using Deno?.noColor as the condition?

@halvardssm
Copy link
Contributor Author

That sounds like a good alternative. I will change the code accordingly.

@halvardssm
Copy link
Contributor Author

@kt3k Also, for this condition

const noColor = typeof Deno?.noColor === "boolean"
  ? Deno.noColor as boolean
  : true;

Wouldn't it be better to change it to

const noColor = typeof Deno?.noColor === "boolean"
  ? Deno.noColor as boolean
  : false;

To have this as opt out rather than opt in?

@kt3k
Copy link
Member

kt3k commented Jul 11, 2023

I think that would make sense, but I'm not sure about the exact reasoning.

@nayeemrmn Do you remember why noColor = true by default in browsers? denoland/deno#5847

@nayeemrmn
Copy link
Contributor

Do you remember why noColor = true by default in browsers? denoland/deno#5847

It was because browser consoles don't support ANSI sequences. Though I just checked and apparently Chromium does (now?)! But Firefox doesn't. I'm in favour of enabling it by default

@halvardssm
Copy link
Contributor Author

Updated according to our discussion, but let me know if there is anything else

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@kt3k kt3k merged commit 2e647b0 into denoland:main Jul 13, 2023
@halvardssm halvardssm deleted the patch-1 branch July 13, 2023 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants