nodejs / nodejs/node

Possible node interfering with console color?

Ouverte
#37,132 12 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

stdio
Langage dominant
JavaScript
Étoiles
122k
Forks
37.4k
Merge moyen
4 j 3 h
PR mergées (30 j)
272

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par reproduire le comportement avec node -e console.log, process.stdout, FORCE_COLOR et la boucle de couleurs ANSI fournie dans la console moderne de Windows 10. Comparez la sortie de Node avec printf et Python, puis déterminez si Node modifie les séquences ANSI ou si c’est une couche externe de la console qui le fait ; le travail est terminé lorsque le composant et la configuration responsables sont identifiés.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, node.js
Domaine
cli
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
À clarifier
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.