node icon indicating copy to clipboard operation
node copied to clipboard

Add API to worker thread to check whether main thread is TTY

Open sindresorhus opened this issue 1 year ago • 2 comments

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

sindresorhus avatar Feb 13 '24 20:02 sindresorhus

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

marco-ippolito avatar Feb 14 '24 11:02 marco-ippolito

That doesn't work for my use-case, where a package needs this. The package has no control over the worker creation.

sindresorhus avatar Feb 14 '24 12:02 sindresorhus

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.

github-actions[bot] avatar Aug 13 '24 01:08 github-actions[bot]

Please keep this open.

sindresorhus avatar Aug 13 '24 08:08 sindresorhus