Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recognize ansi color escape codes in Windows7 64 bit command terminal

Tags:

I have tried Ansicon and I still cannot get ansi escape sequences to become recognized and interpreted in my CMD.EXE command prompt on Windows 7 64 bit. Has anyone been able to work this correctly and get a colorized console with this OS?

like image 895
VanRaizen Avatar asked Feb 19 '10 05:02

VanRaizen


People also ask

What is ANSI color in terminal?

The ANSI ASCII standard represents the escape ESC character by the decimal number 27 (33 in octal, 1B in hexadecimal). This is one of the control characters (0-31 and 127), not one of the printable characters (32-126).

Does Windows CMD support ANSI?

To use ANSI colours in the Windows terminal requires setting VirtualTerminalLevel. VirtualTerminalLevel = 1 is now set by default for the terminal and in ConPTY. Alternatively it can be enabled by calling the SetConsoleMode API with the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag.

Do ANSI escape sequences work on Windows?

The advantage of using ANSI escape codes is that, today, these are available on most operating systems, including Windows, and you don't need to install third party libraries. These are well suited for simple command line applications. If you need to do complex text graphics check the ncurses library.


2 Answers

I ran into the same problem today, and found a workaround.

The commandline utility Windows ANSI Color detects ANSI color codes and sets the corresponding console color.

Example:

myapp.bat | wac

where wac is the Windows ANSI color utility

like image 108
Marco Tolk Avatar answered Oct 11 '22 11:10

Marco Tolk


Ansicon use dll injection in order to enable ansi color in cmd.exe, which is disabled with the standard user privileges.

Try launching ansicon with "run as administrator" (right click)

like image 39
Steve Gury Avatar answered Oct 11 '22 11:10

Steve Gury