nodejs / nodejs/node

util.styleText: support background colors with hex codes

オープン
#64,685 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

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!');

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

エントリーポイントの util.styleText から始め、前景 SGR シーケンスに対する既存の 16 進カラー処理を読みます。bg プレフィックス形式にも動作を拡張し、配列構文によって前景スタイルと背景スタイルが合成されることを確認します。bg#ff5733 が 48;2;r;g;b シーケンスを生成し、#ffffff と bg#ff5733 の組み合わせが両方のスタイルを生成すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript
領域
cli
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
65/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。