nodejs / nodejs/node

Possible node interfering with console color?

Aperta
#37,132 12 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdio
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il comportamento con node -e console.log, process.stdout, FORCE_COLOR e il ciclo di colori ANSI fornito nella console moderna di Windows 10. Confronta l'output di Node con printf e Python, quindi determina se Node modifica le sequenze ANSI o se lo fa un livello esterno della console; il lavoro è completato quando sono stati identificati il componente e la configurazione responsabili.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js
Ambito
cli
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.