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 colors if the standard output is not a TTY #695

Open
dahlia opened this issue Apr 11, 2024 · 0 comments
Open

Disable colors if the standard output is not a TTY #695

dahlia opened this issue Apr 11, 2024 · 0 comments

Comments

@dahlia
Copy link

dahlia commented Apr 11, 2024

For the rationale, please read this article: Color and TTYs.

The reality is that assuming that a terminal supports ANSI color codes is a bad idea for a bunch of reasons.

The most important reason is that the file descriptor you're printing to might not be a TTY. This commonly happens when stdout is redirected to another program or a file. If you emit ANSI escape codes then the output is no longer "plain text" and it makes a bunch of common operations more difficult. It can break programs like grep if the search term spans escape codes. It also causes weird things to happen when you use programs like less (which will escape the escape codes by default).

In Deno, we can detect if it's a TTY or not using Deno.stdout.isTerminal() method.

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

No branches or pull requests

1 participant