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

Output contains ANSI escape code if redirecting output to file #116

Closed
fangbinwei opened this issue Dec 1, 2020 · 3 comments
Closed

Output contains ANSI escape code if redirecting output to file #116

fangbinwei opened this issue Dec 1, 2020 · 3 comments
Labels

Comments

@fangbinwei
Copy link

index.js

const highlight = require('cli-highlight').highlight
console.log(highlight('module.exports = {a: 1}', { language: 'js' }))

node index.js > t.js

output is

�[36mmodule�[39m.exports = {�[36ma�[39m: �[32m1�[39m}

It's caused by 7384705 according to vuejs/vue-cli#6084 (comment)

@felixfbecker
Copy link
Owner

Hmm I see, but this is somewhat intentional. 7384705 aligned the code to the behavior that was always intended, which is the thought that if you use cli-highlight but don't want colored output, why would you use cli-highlight? This way it still works even when you redirect the output e.g. to a pager, to a log file being viewed with a viewer that supports colors, etc. You could for example use cat t.js to view the file with colors.

I see though that there is a use case for non-highlighted direction, so it's probably better to let the user force colors as needed with --color/--no-color and the FORCE_COLOR env var.

@github-actions
Copy link

github-actions bot commented Dec 1, 2020

🎉 This issue has been resolved in version 2.1.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

@fangbinwei
Copy link
Author

Thanks a lot !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants