nodejs / nodejs/node

Possible node interfering with console color?

未关闭
#37,132 12 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdio
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,在现代 Windows 10 控制台中使用 node -e console.logprocess.stdoutFORCE_COLOR 和提供的 ANSI 颜色循环重现该行为。将 Node 的输出与 printf 和 Python 进行比较,然后确定是 Node 修改了 ANSI 序列,还是外部控制台层进行了修改;确定了负责的组件和配置即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js
领域
cli
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。