某些 git 颜色在 powershell 中不起作用。为什么?

rec*_*ive 4 powershell git cmd.exe

我将已更改文件的 git 控制台颜色设置为黄色。这在 中有效cmd.exe,但在 powershell 中无效。然而,有些颜色有效,而另一些颜色似乎映射到完全其他颜色。洋红色在 powershell 中呈现为蓝色。这种疯狂的状态是如何形成的,我怎样才能让它按预期工作?

外壳颜色对比

Lot*_*ngs 5

cmd控制台的颜色是通过颜色表条目定义的
(24位、8位颜色RGB反转0xBBGGRR),
可以在注册表中查看:

> reg query "hkcu\console"

HKEY_CURRENT_USER\console
    ColorTable00    REG_DWORD    0x0
    ColorTable01    REG_DWORD    0x800000
    ColorTable02    REG_DWORD    0x8000
    ColorTable03    REG_DWORD    0x808000
    ColorTable04    REG_DWORD    0x80
    ColorTable05    REG_DWORD    0x800080
    ColorTable06    REG_DWORD    0x8080
    ColorTable07    REG_DWORD    0xc0c0c0
    ColorTable08    REG_DWORD    0x808080
    ColorTable09    REG_DWORD    0xff0000
    ColorTable10    REG_DWORD    0xff00
    ColorTable11    REG_DWORD    0xffff00
    ColorTable12    REG_DWORD    0xff
    ColorTable13    REG_DWORD    0xff00ff
    ColorTable14    REG_DWORD    0xffff
    ColorTable15    REG_DWORD    0xffffff
Run Code Online (Sandbox Code Playgroud)

cmd命名与PowerShellcolor /?不同

Color /?         Dec Hex PowerShell 
0 = Black          0  0  Black  
1 = Blue           1  1  DarkBlue  
2 = Green          2  2  DarkGreen  
3 = Aqua           3  3  DarkCyan  
4 = Red            4  4  DarkRed  
5 = Purple         5  5  DarkMagenta  
6 = Yellow         6  6  DarkYellow  
7 = White          7  7  Gray  
8 = Gray           8  8  DarkGray  
9 = Light Blue     9  9  Blue  
A = Light Green   10  a  Green  
B = Light Aqua    11  b  Cyan  
C = Light Red     12  c  Red  
D = Light Purple  13  d  Magenta  
E = Light Yellow  14  e  Yellow  
F = Bright White  15  f  White
Run Code Online (Sandbox Code Playgroud)

PowerShell 还有两个不同的 ColorTable 条目:

ColorTable05    REG_DWORD    0x562401
ColorTable06    REG_DWORD    0xf0edee
Run Code Online (Sandbox Code Playgroud)

后一个是 PowerShellDarkYellow与 CMD 的比较,Yellow = 0x8080这解释了您的图片的差异。