nodejs / nodejs/node

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

Open
#51,750 13 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request never-stale worker
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the worker_threads API and the related issue #26946, then trace how process.stdout.isTTY and process.stderr.isTTY behave when output is forwarded from a worker. Done means the proposed worker-thread API can detect the main thread's stdout and stderr TTY state and covers the color-package use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.