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

worker_threads in node.js report supportsColor false #97

Open
mdouglass opened this issue Mar 26, 2019 · 1 comment
Open

worker_threads in node.js report supportsColor false #97

mdouglass opened this issue Mar 26, 2019 · 1 comment

Comments

@mdouglass
Copy link

In worker threads, supports-color is unable to automatically detect color support.

const { Worker, isMainThread } = require('worker_threads')
const supportsColor = require('supports-color')

if (isMainThread) {
  console.log('mainThread, supportsColor.stdout', supportsColor.stdout)
  console.log('mainThread, supportsColor.stderr', supportsColor.stderr)
  new Worker(__filename)
} else {
  console.log('workerThread, supportsColor.stdout', supportsColor.stdout)
  console.log('workerThread, supportsColor.stderr', supportsColor.stderr)
}
$ node ./main.js 
mainThread, supportsColor.stdout { level: 2, hasBasic: true, has256: true, has16m: false }
mainThread, supportsColor.stderr { level: 2, hasBasic: true, has256: true, has16m: false }
workerThread, supportsColor.stdout false
workerThread, supportsColor.stderr false

It looks like the stream type in worker threads is WritableWorkerStdio which returns isTTY false so the check at:

if (stream && !stream.isTTY && forceColor === undefined) {
fails. If I skip that check (with stream.constructor.name === 'WritableWorkerStdio') then supportsColor returns correct information and color output does work. I'm not sure if that's the best fix or whether it even should be fixed.

@Qix-
Copy link
Member

Qix- commented Mar 27, 2019

Ehhh depends. I've not yet used worker threads, so I'm not 100% sure, but if their stdio handles map to TTY handles they should probably report isatty==1.

Might be worth seeing if node has an issue open for it.

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

2 participants