nodejs / nodejs/node

Possible node interfering with console color?

Open
#37,132 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdio
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

There's a whole lot of things I don't understand here, so please let me apologize in advance for this ticket as a shambles.

Initially I was trying to work with a high quality console color library, and I was confounded because I had just switched to the modern Win10 console, with its 24 bit color support, and it wasn't 24 bit coloring. It's a big library by a big programmer, so I was surprised.

So I thought "it's just ansi codes, I'll do it myself," and tried to do it myself. Worked them out in console printf, looked good, node -e, and ... and ... wha?

image

The same string in the same console was working with printf and not with node -e console.log. The latter was getting downgraded to a different color range.

Okay, node must just not know it's 2-- wha?

image

So I tried using the FORCE_COLOR flag as a leader. No.

image

So I tried using it as an envvar. No.

image

So I switched to process.stdout. No.

image

And then I looked up my TERM setting. xterm-color-256. Initially I thought "aha!", except then I realized that's not the color you'd get from my testcase in a 6-cube.

Oh, dear. Am I in ... am I in 4-bit color in node, despite having a 24-bit terminal?

Wrote this to find out

const seq = n => new Array(n).fill(false).map( (_, i) => i );
const col = (r,g,b) => 16 + b + (g*6) + (r*36);

seq(6).map(b => {
  seq(6).map(g => {
    seq(6).map(r => process.stdout.write(`\x1b[38;5;${col(r,g,b)}m*`) );
  process.stdout.write(' '); });
process.stdout.write('\n'); });

Yep.

image

Gulp.

Am I missing something? It seems like my terminal is set up for 24 bit, and node is manually downsampling my terminal output for me despite FORCE_COLOR. It couldn't be doing that, could it? That wouldn't make any sense.

What exists between node and the console which could be doing this?

So I thought I'd be tricky and see if some other language on the machine would get it right, yeah?

Tried python. ... lol

image

So then, yes, there is something between the language and the console, which is capable of screwing ansi codes up.

How do I find what that something is for node, so that I can find what's misconfigured in it, please?

Thanks

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 reproducing the behavior with node -e console.log, process.stdout, FORCE_COLOR, and the provided ANSI color loop in the modern Windows 10 console. Compare Node's output with printf and Python, then determine whether Node changes the ANSI sequences or an external console layer does; done means the responsible component and configuration are identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.