node
node copied to clipboard
Add API to worker thread to check whether main thread is TTY
What is the problem this feature will solve?
In worker threads, process.stdout.isTTY
and process.stderr.isTTY
are undefined
. However, they do forward stdout/stderr to the main thread, and the main thread could potentially be isTTY === true
. This makes sense as some things don't work, like raw mode. However, things that produce colors would want to be able to detect that the main thread is TTY, so colors can be shown when logged from a worker thread.
What is the feature you are proposing to solve the problem?
Add an API to worker threads to check whether stdout/stderr in the main thread is TTY.
This is needed for color packages like chalk
to be able to support showing colors when running in worker threads.
Relevant issue: https://github.com/nodejs/node/issues/26946
What alternatives have you considered?
No response
would a solution like explicity setting in the worker options new Worker(__filename, { isTTY: true })
work?
And on the other side workerData.isTTY
.
It doesnt seem high effort
That doesn't work for my use-case, where a package needs this. The package has no control over the worker creation.
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the https://github.com/nodejs/node/labels/never-stale label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document.
Please keep this open.