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

Disable color output in pipes #33

Merged
merged 11 commits into from
Jun 24, 2020
Merged

Disable color output in pipes #33

merged 11 commits into from
Jun 24, 2020

Conversation

ai
Copy link
Contributor

@ai ai commented Jun 23, 2020

Most of color output libraries like chalk, supports-color, or colorette do not enable color output in pipes.

it is useful for cases like:

$ npx app > log.txt
# you send the log via email
$ vscode log.txt
# now you can’t read the log in a text editor because of color marks

Also, color marks could force grep to have unexpected results.

@lukeed What do you think if we will add the same process.stdout.isTTY check to kleur as well?

@lukeed
Copy link
Owner

lukeed commented Jun 23, 2020

Hey, it should be fine, but let me investigate some dependents to make sure it's not depended on.

I'll add some extra process-based tests after this PR

@lukeed
Copy link
Owner

lukeed commented Jun 23, 2020

Ok, the conditions have to be tweaked a little bit, but I'll take care of it. You're right that we should match the default chalk behavior – but still give a way to get colors back on if you want it.

@codecov-commenter
Copy link

codecov-commenter commented Jun 23, 2020

Codecov Report

Merging #33 into master will decrease coverage by 1.29%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##            master      #33      +/-   ##
===========================================
- Coverage   100.00%   98.70%   -1.30%     
===========================================
  Files            2        2              
  Lines          151      155       +4     
  Branches        28       30       +2     
===========================================
+ Hits           151      153       +2     
- Misses           0        2       +2     
Impacted Files Coverage Δ
colors.mjs 97.95% <100.00%> (-2.05%) ⬇️
index.mjs 99.05% <100.00%> (-0.95%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f2e8aa...109cfb3. Read the comment docs.

@lukeed
Copy link
Owner

lukeed commented Jun 23, 2020

I wanted to keep my pretty formatting inside GitHub Actions 😇

Taking your original example, along with these changes:

$ node app.js > log.txt 
#=> NO COLORS

$ node app.js
#=> COLORS

$ FORCE_COLOR=1 node app.js > log.txt
#=> COLORS

$ FORCE_COLOR=0 node app.js > log.txt
#=> NO COLORS

@ai If you can confirm that it also looks correct to you, then this is ready to go.

@ai
Copy link
Contributor Author

ai commented Jun 23, 2020

Do we enable or disable color output on GitHub Action?

GitHub Action user can call tool with a pipe as well.

@lukeed
Copy link
Owner

lukeed commented Jun 23, 2020

Right now it's enabled on GH because I thought supports-color did this by default, but it doesn't actually.
Will revert~

@ai
Copy link
Contributor Author

ai commented Jun 23, 2020

LGTM. Thanks for fixing the tests 👍

@lukeed
Copy link
Owner

lukeed commented Jun 24, 2020

Now have bash tests in place for detections with & without TTY sessions.

Sorry for notification noise; wanted it all in together.
Thanks for report/PR 👍

@lukeed lukeed merged commit 5c7353f into lukeed:master Jun 24, 2020
lukeed added a commit to lukeed/uvu that referenced this pull request Jun 24, 2020
Maintains CI colorization; users can disable with:
* `uvu --no-color`
* `NODE_DISABLE_COLORS=1 uvu`

Related:
- lukeed/kleur#33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants