ANSI color codes

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

ANSI color codes

Post by Chris Corbyn »

Does anyone know if the windows cmd.exe can display ANSI color escape sequences using the same code as under UNIX-like systems?

Could someone with a windows machine give this a little test for me? :)

Run on command line:

Code: Select all

<?php
 
echo "First : \033[31m Fail \033[0m" . PHP_EOL;
echo "Second : \033[32m OK \033[0m" . PHP_EOL;
echo "Third : \033[31m\033[1m Exception \033[0m" . PHP_EOL;
echo "Fourth : \033[34m\033[1m Skip \033[0m" . PHP_EOL;
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: ANSI color codes

Post by Christopher »

Windows wrote:First : ←[31m Fail ←[0m
Second : ←[32m OK ←[0m
Third : ←[31m←[1m Exception ←[0m
Fourth : ←[34m←[1m Skip ←[0m
(#10850)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: ANSI color codes

Post by Chris Corbyn »

*sigh* :dubious:

Thanks man :)
xpt
Forum Newbie
Posts: 23
Joined: Tue Feb 20, 2007 1:00 pm

Re: ANSI color codes

Post by xpt »

Chris Corbyn wrote:Does anyone know if the windows cmd.exe can display ANSI color escape sequences using the same code as under UNIX-like systems?
Back to the old DOS days, one can display ANSI color escape sequences, and cursor reallocation too, provided that the

Code: Select all

device=\path\ansi.sys
is included in the config.sys

Haven't been playing with DOS/Windows for nearly 10 years, and I don't know what's the status now...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: ANSI color codes

Post by Chris Corbyn »

Ah, I was just coming back here to ask about ansi.sys. Thanks for the reply :) It seems that windows does require this device driver to be loaded before it will display ansi color (wtf???). My windows knowledge is completely zilch when it comes to this type of thing, but does anyone know some kind of COM check I can run to determine if I can display ansi colors? I can get by with just displaying plain black/white if it's not loaded, but since it displays those silly backspace chars without it I'll need to do a check.

If push comes to shove I'll just check if PHP_OS looks like windows and disable color if so.

It's not for anything important... just the CLI interface to a test runner:
Attachments
test-runner.png
test-runner.png (44.96 KiB) Viewed 5160 times
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: ANSI color codes

Post by Ambush Commander »

In theory, it should be possible to use COM to get the effect we want. Researching right now...
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: ANSI color codes

Post by Ambush Commander »

Gave up, but here's what I found:

1. COM is one possibility, but I couldn't figure out how to directly interface with the COM to manipulate the Console

2. Next, I turned to scripting with COM, but Console didn't seem to be defined in Jscript

3. Finally, I tried instantiating the System.Console dot-net class, but PHP fatally errored on me.

Whee...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: ANSI color codes

Post by Chris Corbyn »

Hey thanks for trying man! I guess windows users will just have to live with black and white.
Post Reply