http-server icon indicating copy to clipboard operation
http-server copied to clipboard

don't print color on non-tty stdout

Open joezimjs opened this issue 8 years ago • 5 comments

I often start up my server as a build script in Sublime because it doesn't require me to open up another console window. The problem is that Sublime's output doesn't support color so it looks ridiculous:

[33mStarting up http-server, serving [39m[36mdist[39m[33m Available on:[39m [32m http://192.168.1.115:8080[39m [32m http://25.89.186.247:8080[39m [32m http://127.0.0.1:8080[39m

Can you add an option via the command line that turns off color? Or you can find a way to output color without causing Sublime to look like that. RunJS has color output in my console but doesn't cause any escaped character nonsense to show up

joezimjs avatar Feb 01 '17 02:02 joezimjs

Something like strip-ansi-cli might help you.

However, in general, it's a good idea to have command line tools detect if stdout is a TTY. For non-TTY stdouts, they shouldn't necessarily output color. See also https://github.com/chalk/chalk/issues/38 .

derhuerst avatar Feb 01 '17 12:02 derhuerst

Thanks. strip-ansi-cli works for me. I was looking for something similar as an alternative to putting this issue up but couldn't find it.

joezimjs avatar Feb 01 '17 18:02 joezimjs

As your original question is answered but the point about TTY detection is still valid, would you mind renaming your issue to sth like "don't print color on non-tty stdout"? It will make it easier for the maintainers.

derhuerst avatar Feb 01 '17 18:02 derhuerst

There you go

joezimjs avatar Feb 01 '17 19:02 joezimjs

This issue has been inactive for 180 days

github-actions[bot] avatar Oct 12 '21 12:10 github-actions[bot]