18

I'm using the Write-Host cmdlet to change the color of my prompt and I noticed that the DarkYellow color was not displaying as any sort of yellow, but as a gray! Here's a test of all the colors

PS> 0..15 | %{ Write-Host "Hello, world!" -ForegroundColor $_ }

I got a list of all the enum values by using a bad value

PS> Write-Host "Hello, World!" -ForegroundColor foo

Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, White

And I realized that this list of "console colors" somehow corresponds to the settings for this console window/shortcut, right? So, DarkYellow would be this 7th one in and it sure looks gray.

enter image description here

What's the connection between ForegroundColor, System.ConsoleColor, and these console shortcut settings? Why is dark yellow displaying as gray "out of the box"? Should I change it? Will this change every console on my system or just this shortcut?

Why are consoles so finnicky on Windows?!


I'm on Windows 7 Pro SP1 64-bit and I'm launching the "Windows PowerShell" shortcut from the Start Menu.

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
  • All works fine for me in a *standard* console. What Windows do you use and what console exactly? I am on Windows 7. In the PowerShell console provided by Microsoft two colors are really bad. – Roman Kuzmin Feb 21 '14 at 18:06
  • Just in case, you may find this script useful for playing with console colors: https://github.com/nightroman/PowerShelf/blob/master/Show-Color.ps1 – Roman Kuzmin Feb 21 '14 at 18:08
  • So I think that you use the PowerShell console from Microsoft with colors predefined by them. I would say this is a defect (bug), you may submit it [here](https://connect.microsoft.com/PowerShell/Feedback) :) – Roman Kuzmin Feb 21 '14 at 18:15
  • I should probably write about the new colortool https://devblogs.microsoft.com/commandline/introducing-the-windows-console-colortool/ – Anthony Mastrean Nov 11 '19 at 17:14

2 Answers2

12

Lee Holmes' blog post, PowerShell's Noble Blue, talks about this a bit, but doesn't actually explain why DarkYellow was changed. Most likely the default DarkYellow was unreadable with the blue background.

As you've probably figured out - the System.ConsoleColor is slightly misnamed as it doesn't actually specify a color, it specifies an index into a color table which can be modified by shortcuts. This is unfortunately a limitation of the console subsystem.

If you change the shortcut PowerShell.lnk, you'll be changing the colors only for yourself and only when you start PowerShell from that link. If you use Start | Run, or say run cmd, then run PowerShell from cmd, you'll get different settings.

Lee's blog post should give you enough hints to get the behavior you prefer.

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
Jason Shirk
  • 7,734
  • 2
  • 24
  • 29
  • If I change the settings using the top left-corner menu (what's that called?) and pick "Defaults" it says I'm editing "Console Windows Properties" and then affects my PowerShell, Mingw, and Command Prompt windows (all are "ConsoleWindowClass" type windows)! – Anthony Mastrean Feb 21 '14 at 22:55
  • In the MSDN page for [ConsoleColor](http://msdn.microsoft.com/en-us/library/system.consolecolor(v=vs.110).aspx), `DarkYellow` is described as "ochre". I found [this RGB value](http://colors.findthedata.org/q/621/10857/What-are-the-RGB-values-of-Ochre) for Ochre and it looks great against the "noble blue"! I think red on blue (used in a lot of output) is unreadable. – Anthony Mastrean Feb 21 '14 at 22:56
  • I see Red:128 Green:128 Blue:0 for that color on my Win8.1 box. It wouldn't call it DarkYellow though. At any rate, it doesn't seem that bad to me, so maybe none of the other colors looked great as the default text color, so they changed two colors. I'm just guessing here. – Jason Shirk Feb 21 '14 at 23:24
  • Yes, I think if you change the Defaults, you affect all console windows that don't have their own settings. – Jason Shirk Feb 21 '14 at 23:25
7

I don't have the exact answers, but I have something that kind of works! I did some research (thanks, Jason Shirk) and found that System.ConsoleColor is just an index into the color table, which must be represented by this

enter image description here

The documentation does mention that DarkYellow is supposed to be "ochre" (RGB: 204, 119, 34).

| DarkYellow  | The color dark yellow (ochre). |

Choose "Defaults" from the application's top-left window menu and you'll see the generic "Console Windows Properties" (like above), which will modify any ConsoleWindowClass type window.

Pick the "Screen Text" option and you'll notice it's set to use the value in DarkYellow's spot. I don't know why they didn't use Gray or DarkGray right next to it! Click on the 7th box (the index for DarkYellow) and change it to ochre's RGB value. Then, set the "Screen Text" to the Gray or DarkGray (unless you really want ochre foreground text by default).

All of your Command Prompt, PowerShell, and Git Bash (mingw) consoles will be changed (mine were).


I did have a little trouble with the PowerShell prompt from the "run" dialog. It took the colors, but not some of my other settings (physical and buffer size, etc). I ended up using scoop to install concfg

PS> scoop install concfg
PS> scoop install sudo

and exported my good console settings

PS> concfg export > ~\.consolerc

and imported them into my misbehaving prompt with prejudice (you can use sudo, also from scoop, or just launch an admin prompt)

PS> sudo concfg import ~\.consolerc

And, actually, concfg seemed to export everything, the color table values and the selections! Here's a partial dump of my configuration (the color parts)

{
    "popup_colors":  "cyan,white",
    "dark_gray":  "#808080",
    "screen_colors":  "gray,dark_magenta",
    "dark_green":  "#008000",
    "blue":  "#0000ff",
    "dark_yellow":  "#cc7722",
    "red":  "#ff0000",
    "magenta":  "#ff00ff",
    "dark_red":  "#800000",
    "yellow":  "#ffff00",
    "dark_magenta":  "#012456",
    "cyan":  "#00ffff",
    "green":  "#00ff00",
    "dark_blue":  "#000080",
    "gray":  "#c0c0c0",
    "white":  "#ffffff",
    "black":  "#000000",
    "dark_cyan":  "#008080"
}
AlpacaFur
  • 194
  • 2
  • 12
Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
  • RGB:204,119,34 did not match the 'DarkYellow' in PowerShell ISE for me. A screen grab and the eye dropper tool in Paint suggests RGB:136,136,0. – Jason Boyd Jun 02 '17 at 19:17
  • Just ran into this issue myself. PS has the same issue for me (even on fresh installs of Creator's 1703. I've tried [console]::ResetColor() but still had the issue. – SOSidb Oct 14 '17 at 11:15