18

Console's text colors are not working in Windows 10 build 15063.296.
I have dug into it a bit and found myself lost. Here's everything I've found...

From several discussions, it seems that the support for 'Virtual terminal sequences' or 'control character sequences' was removed in recent versions of Windows 10 (#1, #2). Some also adviced to downgrade a git version (that didn't work for me).

I tried to copy a cmd.exe from my other machine, the version was 10.0.10586.0 and the coloring worked, however, upon further reading and experimenting, I am no longer sure where the problem lies.

See compared the outputs of ls --color=auto
git\git-cmd.exe, git\git-bash.exe, windows' original cmd.exe and older cmd.exe

ls --color=auto outputs in several consoles

According to this site, the support for coloring does not lie in a command window, but in a conhost.exe, which brings up the question --Why does it work in some consoles and in some not?

If you start powershell.exe from cmd.exe, it will inherit the conhost settings since it’s attaching to a previously created console, not allocating a new one; this also enables escape sequences in powershell.exe.

Given this quote, I tried the following that only deepened my confusion. I run a ls --color=auto command in each cmd version, then tried running older cmd from newer and vice versa and got the following results. (red underline is cmd v15063, green underline is cmd v10586)

old, new from old

new, old from new

/EDIT I've made few more experiments...

What is interesting/confusing is the different result of type and cat and a compared result of ls --color=auto with the same content typed from a file.

Old console old console

New console new console

Console Virtual Terminal Sequences msdn
ANSI.SYS historical documentation

Community
  • 1
  • 1
Qwerty
  • 29,062
  • 22
  • 108
  • 136
  • 1
    That cmd.exe enabled this in build 15063 was actually a bug. Corrected in the next build. Amazing how quickly a bug can turn into a feature :) – Hans Passant May 18 '17 at 14:13
  • 2
    "support for coloring does not lie in a command window, but in a conhost.exe". This is a confused statement. The console window is always hosted by conhost.exe, and cmd.exe is a console client program, i.e. it can *use* a console. Whether or not VT support is enabled depends on the mode flags of the console's screen buffer. It happens that cmd.exe in build 10586 had a bug that left the console's VT mode enabled for console applications that inherited the current console (e.g. cat.exe). This was fixed in build 14393, and your attempts to unfix it are misguided. – Eryk Sun May 19 '17 at 00:32
  • 4
    If you want VT mode enabled, you'll have to do it yourself. cmd.exe will honor the startup value, so just write a little console program that opens `CONOUT$` (don't assume the `StandardOutput` handle is a console handle); calls `GetConsoleMode` to get the current mode; sets the `ENABLE_VIRTUAL_TERMINAL_PROCESSING` flag; calls `SetConsoleMode` to set the new mode; and finally `CreateProcess` and `WaitForSingleObject` to spawn and wait on a new cmd shell. Or modify git-cmd.exe to do this. – Eryk Sun May 19 '17 at 00:39
  • 1
    If the 15063's way of displaying those escape sequences is correct, what are the authors of console applications doing wrong that their output is not colored correctly? Why did the `ls` command not work, but the same output `type`d from a file did work? If I understand correctly, cmd.exe does have support for VT sequences enabled, but does not pass it to console applications - why? – Qwerty May 19 '17 at 09:56
  • 1
    @eryksun You make it sound awfully simple! How would you practically do all that you mentioned. Let's say, in powershell? If it's so simple can you point to a more viable solution? Perhaps even code example. – not2qubit Dec 02 '18 at 16:15

1 Answers1

2

As for now, I have "fixed" it by replacing the newer cmd_10.0.15063.0 with the older cmd_10.0.10586.0 that I copied from my old system. If you have run a windows upgrade, you may find an older cmd version in C:\Windows.old\Windows\System32\cmd.exe. (the folder is hidden)

To replace the system's cmd.exe you will need to take ownership of the file Properties -> Security -> Advanced, there at the top Owner: TrustedInstaller (Change), set to Administrators, then give Administrators full permissions in Permissions -> Change permissions -> Administrators -> Edit -> Full control.

Qwerty
  • 29,062
  • 22
  • 108
  • 136