Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
597 views
in Technique[技术] by (71.8m points)

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

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
gitgit-cmd.exe, gitgit-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
image

new, old from new
image

/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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.oldWindowsSystem32cmd.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...