Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10 console colors not working (Virtual terminal control character sequences)

Tags:

windows

cmd

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

like image 470
Qwerty Avatar asked May 18 '17 12:05

Qwerty


People also ask

Do ANSI escape codes work on Windows?

The Win32 console does not natively support ANSI escape sequences at all. Software such as Ansicon can however act as a wrapper around the standard Win32 console and add support for ANSI escape sequences.

Can CMD display colors?

Color is an inbuilt command found inside the Windows Command Processor (cmd.exe), that is used for changing the colors for the console's foreground and background. By default, the console has white foreground color and black background color (07 color code).

How do I change the color of the Windows console?

To set the default Command Prompt window color, select the upper-left corner of the Command Prompt window, select Defaults, select the Colors tab, and then select the colors that you want to use for the Screen Text and Screen Background.

How do you exit a Windows command prompt?

In the Command Prompt, the caret character ( ^ ) will let you escape spaces—in theory. Just add it before each space in the file name. (You'll find this character in the number row on your keyboard. To type the caret character, press Shift+6.)


1 Answers

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.

like image 165
Qwerty Avatar answered Oct 08 '22 02:10

Qwerty