nodejs / nodejs/node

util.styleText: support background colors with hex codes

Aperta
#64,685 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

What is the problem this feature will solve?

util.styleText() supports arbitrary foreground colors via hex codes (styleText('#ff5733', text), added in #61556), but there's no equivalent for background colors. Predefined colors already have both a foreground (red) and background (bgRed) variant, but hex colors only cover the foreground case (SGR 38;2;r;g;b).

What is the feature you are proposing to solve the problem?

Extend hex color detection in styleText to also accept a background variant, mirroring the existing bgRed/red naming convention by prefixing the hex code with bg:

styleText('bg#ff5733', 'Warning!');

This would emit the background TrueColor SGR sequence (48;2;r;g;b) instead of the foreground one (38;2;r;g;b), and composes with the existing array syntax to combine foreground + background:

styleText(['#ffffff', 'bg#ff5733'], 'Warning!');

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 dal punto di ingresso util.styleText e leggi la gestione esistente dei colori esadecimali per le sequenze SGR di primo piano. Estendi il comportamento alla forma con prefisso bg e verifica che gli stili di primo piano e di sfondo si compongano tramite la sintassi dell’array. È completato quando bg#ff5733 produce la sequenza 48;2;r;g;b, mentre #ffffff più bg#ff5733 produce entrambi gli stili.

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

Valutazione

Stack tecnologico
javascript
Ambito
cli
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
65/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.