BP


Win32::Console::ANSI


La perfection est atteinte non quand il n'y a plus rien ajouter,
mais quand il n'y a plus rien retrancher.
[Perfection is achieved, not when there is nothing left to add,
but when there is nothing left to take away.]

Antoine de Saint-Exupry

Introduction

Windows NT/2000/XP does not support ANSI escape sequences in Win32 Console applications. One can use the ansi.sys driver but only in the MS-DOS subsystem with the old COMMAND.COM, not with CMD.EXE (See the Microsoft Knowledge Base).

The module Win32::Console::ANSI (former Win32::ANSIConsole) emulate an ANSI console for the script which uses it. See the doc for the supported escape sequences: Console::ANSI doc

Back to Top

Colors rendition

colors

Back to Top

Characters conversion

By default, this module convert the characters from the Windows code page to the DOS code page (the so-called ANSI to OEM conversion). The conversion permits the display of the accented characters in the console like in a Windows-based editor. For example, on my machine, Windows use the codepage cp1252 and DOS use the codepage the cp850. Here, the conversion is made by the Encode module :

characters

For comparison and additional information, see : Microsoft GlobalDev site.

Back to Top

Extra escape sequence

The previous conversion is necessary because the code page of Windows and the code page of the DOS are different. Another solution would be to change the code page of the console: it is possible, but only if the console uses an Unicode police (See the Microsoft Knowledge Base).
In this case, you can change the code page with the escape sequence \e(#X where # is the code page needed. (It's not a standard escape sequence!) It is then possible to change the code page when one wants :
(Lucida Console 14 pt)

codepages

Note: you can change the console code page with the DOS command chcp. (Don't forget: this command is efficient only if the police in use is an Unicode police.) Type help chcp in the console for more info.
The available code pages are under the Register key :
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage

Back to Top

Download

Current version is 1.08

The module was rewritten in C.
By hooking the WriteFile API function in all the modules loaded by the script, it is possible to interpret the escape sequences just before they are written in the console. There is no perturbance with Perl or your script.
This suppresses several previous versions limitations:

Successfully tested on Win98, Win98SE, Win2000, WinXP, Windows Server 2003, Vista (32 and 64 bits), Windows 7, Windows 8 (32 and 64 bits).

The module is in my ppm repository for 32 bit Perl and in my ppm repository for 64 bit Perl.
If you are using ActiveState's Perl distribution (Perl 5.6, Perl 5.8, Perl 5.10, Perl 5.12, Perl 5.14, Perl 5.16, Perl 5.18), the easiest way to install this module is to use ppm. Enter (or cut & paste) this command in a DOS console:

for 32 bit perl:

    ppm install http://www.bribes.org/perl/ppm/Win32-Console-ANSI.ppd

for 64 bit perl:

    ppm install http://www.bribes.org/perl/ppm64/Win32-Console-ANSI.ppd

The documentation, in html format, is at its usual location.

If you want, you can download the source file here: Win32-Console-ANSI-1.08.tar.gz
or from the CPAN
To install the module, read the README file.

Back to Top

Links

Using part of code in this module, Jason Hood wrote a program ANSICON that provides ANSI escape sequence recognition for Windows console programs.

From the PerlMonks site, some JAPH using Win32::Console::ANSI:

Back to Top
CMD


BP 2003-2014 J-L Morel - Contact : jl_morel@bribes.org [Validation HTML 4.0!]