-
-
Notifications
You must be signed in to change notification settings - Fork 88
Open
Description
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:
Line 57 in 14a0e6f
if (stream && !stream.isTTY && forceColor === undefined) { |
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.Metadata
Metadata
Assignees
Labels
No labels