Coloured console output support for windows.

Coloured console output support for windows.

am 21.09.2009 12:59:22 von Richard Quadling

Hi.

As previously mentioned, there is a tool for Windows XP+ called
ANSICON [1] which can be loaded via the registry or manually and
provides support for ANSI coloured output at the console.

Whilst editing the registry is not something many people actually like
doing, it can be done quite easily using the REG command from the
Windows Resource Toolkit.

REG ADD "HKLM\Software\Microsoft\Command Processor" /v AutoRun /t
REG_SZ /d "C:\Utils\ANSICon.exe -p"



Another useful feature is that ANSICON maintains an environment
variable which holds the current screensize ...

ANSICON=200x9999 (200x100)

200x9999 is the window size
200x100 is the current visible portion.

So, for text-tabled output, you can tailor the size to fit. Useful for
interactive console apps.

Regards,

Richard.


[1] http://adoxa.110mb.com/ansicon/index.html
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Coloured console output support for windows.

am 21.09.2009 19:16:13 von Hannes Magnusson

On Mon, Sep 21, 2009 at 12:59, Richard Quadling
wrote:
> doing, it can be done quite easily using the REG command from the
> Windows Resource Toolkit.
>
> REG ADD "HKLM\Software\Microsoft\Command Processor" /v AutoRun /t
> REG_SZ /d "C:\Utils\ANSICon.exe -p"

Right, but that has to be done when installing the application, not
every time phd.bat is executed.
And we would also have to detect if the system supports it rather then
blindly polluting the registry.

Plus, afaik, the PEAR installer doesn't support doing such things.

-Hannes

Re: Coloured console output support for windows.

am 22.09.2009 11:38:04 von Richard Quadling

2009/9/21 Hannes Magnusson :
> On Mon, Sep 21, 2009 at 12:59, Richard Quadling
> wrote:
>> doing, it can be done quite easily using the REG command from the
>> Windows Resource Toolkit.
>>
>> REG ADD "HKLM\Software\Microsoft\Command Processor" /v AutoRun /t
>> REG_SZ /d "C:\Utils\ANSICon.exe -p"
>
> Right, but that has to be done when installing the application, not
> every time phd.bat is executed.

Agreed. And the ANSICON instructions could easily be amended to show this.


> And we would also have to detect if the system supports it rather then
> blindly polluting the registry.

"blindly polluting the registry" ?

From cmd /? ...

"If /D was NOT specified on the command line, then when CMD.EXE starts, it
looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if
either or both are present, they are executed first.

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun

and/or

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun"


This is "blindly polluting", but a completely standard and supported
facility, albeit an obscure one.

As for detection, once ANSICON is loaded, the ANSICON environment variable.

But maybe ANSICon needs a small installer which has the option of
doing this (Jason - possible?) automatically for those too nervous of
editing registry.

>
> Plus, afaik, the PEAR installer doesn't support doing such things.
>

!is_null(getenv('ANSICON')) ?

> -Hannes
>

I think that whilst windows no longer has coloured console output as
standard, a free alternative is a viable option.

The other option is to disable coloured output when on windows, but if
that was the case, I would like the option of having a mechanism to
enable this without having to add it to the command line every time -
yet another env_var?

The source is available. Jason has been very receptive to the issues
that I've raised.

Richard

--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

Re: Coloured console output support for windows.

am 22.09.2009 22:55:16 von Hannes Magnusson

On Tue, Sep 22, 2009 at 11:38, Richard Quadling
wrote:
> As for detection, once ANSICON is loaded, =A0the ANSICON environment vari=
able.
>
> But maybe ANSICon needs a small installer which has the option of
> doing this (Jason - possible?) automatically for those too nervous of
> editing registry.
>
>>
>> Plus, afaik, the PEAR installer doesn't support doing such things.
>>
>
> !is_null(getenv('ANSICON')) ?

We cannot do any such check at install time.

We can do it when running the application, but then we'd have to check
the registry if we already have added the setting before trying to
adding it yet again.

In any case, I don't think its the job of PhD to do registry magic.
Check if the environment variable exists, and then print out color
codes however is something we should probably be doing.

-Hannes

Re: Coloured console output support for windows.

am 23.09.2009 00:05:20 von Brett Bieber

Greetings

On Tue, Sep 22, 2009 at 3:55 PM, Hannes Magnusson
wrote:
>> As for detection, once ANSICON is loaded, =A0the ANSICON environment var=
iable.
>>
>> But maybe ANSICon needs a small installer which has the option of
>> doing this (Jason - possible?) automatically for those too nervous of
>> editing registry.
>>
>>>
>>> Plus, afaik, the PEAR installer doesn't support doing such things.

Just so everyone is aware, PEAR supports post-install-scripts which
can do anything PHP can do.

This does require an additional step by the end-user when the package
is installed, pear run-scripts mychannel/Package, but it is possible
to do this.

--=20
Brett Bieber

Re: Coloured console output support for windows.

am 23.09.2009 12:32:27 von Richard Quadling

2009/9/22 Brett Bieber :
> Greetings
>
> On Tue, Sep 22, 2009 at 3:55 PM, Hannes Magnusson
> wrote:
>>> As for detection, once ANSICON is loaded,  the ANSICON environment=
variable.
>>>
>>> But maybe ANSICon needs a small installer which has the option of
>>> doing this (Jason - possible?) automatically for those too nervous of
>>> editing registry.
>>>
>>>>
>>>> Plus, afaik, the PEAR installer doesn't support doing such things.
>
> Just so everyone is aware, PEAR supports post-install-scripts which
> can do anything PHP can do.
>
> This does require an additional step by the end-user when the package
> is installed, pear run-scripts mychannel/Package, but it is possible
> to do this.
>
> --
> Brett Bieber
>

Jason has suggested adding the ability to install/uninstall ANSICON so
that would take care of the registry setting.

I only look at the envvar to determine if I should provide coloured output.


One issue though, running php.exe via Windows run dialog (i.e. NOT at
a command prompt), will not load ANSICon as php.exe provides it's own
console window which isn't the same as loading the shell to run PHP.


MAYBE ... combining PHP with ANSICon COULD be a solution? Maybe an
php_ansicon.dll extension.

--=20
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
ZOPA : http://uk.zopa.com/member/RQuadling

Re: Coloured console output support for windows.

am 24.09.2009 04:13:14 von Jason Hood

Richard Quadling wrote:
> MAYBE ... combining PHP with ANSICon COULD be a solution? Maybe an
> php_ansicon.dll extension.

If PHP supports loading DLLs, you should be able to do that
now, since it should be enough to just load ANSI.dll. Anyway,
the new version of ANSICON with the install option is on my
site (http://adoxa.110mb.com/ansicon/ansi121.zip).

Jason.

Re: Coloured console output support for windows.

am 24.09.2009 10:23:34 von Richard Quadling

2009/9/24 Jason Hood :
> Richard Quadling wrote:
>>
>> MAYBE ... combining PHP with ANSICon COULD be a solution? Maybe an
>> php_ansicon.dll extension.
>
> If PHP supports loading DLLs, you should be able to do that
> now, since it should be enough to just load ANSI.dll.  Anyway,
> the new version of ANSICON with the install option is on my
> site (http://adoxa.110mb.com/ansicon/ansi121.zip).
>
> Jason.
>

With ansicon loaded

php -r "while(1) { echo getenv('ANSICON'), ""\r""; }"

provides the realtime size of the console window as you stretch it or
change the layout.
--=20
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
ZOPA : http://uk.zopa.com/member/RQuadling

Re: Coloured console output support for windows.

am 24.09.2009 14:36:21 von Nathan Adams

On Tue, Sep 22, 2009 at 4:38 AM, Richard Quadling
wrote:
> 2009/9/21 Hannes Magnusson :
>> On Mon, Sep 21, 2009 at 12:59, Richard Quadling
>> wrote:
>>> doing, it can be done quite easily using the REG command from the
>>> Windows Resource Toolkit.
>>>
>>> REG ADD "HKLM\Software\Microsoft\Command Processor" /v AutoRun /t
>>> REG_SZ /d "C:\Utils\ANSICon.exe -p"
>>
>> Right, but that has to be done when installing the application, not
>> every time phd.bat is executed.
>
> Agreed. And the ANSICON instructions could easily be amended to show this=
..
>
>
>> And we would also have to detect if the system supports it rather then
>> blindly polluting the registry.
>
> "blindly polluting the registry" ?
>
> From cmd /? ...
>
> "If /D was NOT specified on the command line, then when CMD.EXE starts, i=
t
> looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if
> either or both are present, they are executed first.
>
> =A0 =A0HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
>
> =A0 =A0 =A0 =A0and/or
>
> =A0 =A0HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun"
>
>
> This is "blindly polluting", but a completely standard and supported
> facility, albeit an obscure one.
>
> As for detection, once ANSICON is loaded, =A0the ANSICON environment vari=
able.
>
> But maybe ANSICon needs a small installer which has the option of
> doing this (Jason - possible?) automatically for those too nervous of
> editing registry.
>
>>
>> Plus, afaik, the PEAR installer doesn't support doing such things.
>>
>
> !is_null(getenv('ANSICON')) ?
>
>> -Hannes
>>
>
> I think that whilst windows no longer has coloured console output as
> standard, a free alternative is a viable option.

Windows does indeed support colored console output. You have a few
options to accomplish this without installing 3rd party programs:use
the DOS subsystem, you can program in 16bit assembly using interrupts
(which will just get launched in the DOS subsystem), or use Windows
API to output text in colored format. Microsoft has dropped support
for DOS interrupts in the 32bit console unfortunately and replaced it
with goofy API that you have to call : (. Now, I could just be talking
through my teeth but I am 99% sure of what I said (at least for
Windows OS based on the NT kernel such as 2K/XP, I have very little
experience with Vista so I can't comment).

See the following KB article for more info
http://support.microsoft.com/kb/101875

>
> The other option is to disable coloured output when on windows, but if
> that was the case, I would like the option of having a mechanism to
> enable this without having to add it to the command line every time -
> yet another env_var?
>
> The source is available. Jason has been very receptive to the issues
> that I've raised.
>
> Richard
>
> --
> -----
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D2134=
74731
> ZOPA : http://uk.zopa.com/member/RQuadling
>

My 2 cents anyways.

Re: [PHP-DOC] Coloured console output support for windows.

am 24.09.2009 15:04:54 von Richard Quadling

2009/9/24 Nathan Adams :
> On Tue, Sep 22, 2009 at 4:38 AM, Richard Quadling
> wrote:
>> 2009/9/21 Hannes Magnusson :
>>> On Mon, Sep 21, 2009 at 12:59, Richard Quadling
>>> wrote:
>>>> doing, it can be done quite easily using the REG command from the
>>>> Windows Resource Toolkit.
>>>>
>>>> REG ADD "HKLM\Software\Microsoft\Command Processor" /v AutoRun /t
>>>> REG_SZ /d "C:\Utils\ANSICon.exe -p"
>>>
>>> Right, but that has to be done when installing the application, not
>>> every time phd.bat is executed.
>>
>> Agreed. And the ANSICON instructions could easily be amended to show thi=
s.
>>
>>
>>> And we would also have to detect if the system supports it rather then
>>> blindly polluting the registry.
>>
>> "blindly polluting the registry" ?
>>
>> From cmd /? ...
>>
>> "If /D was NOT specified on the command line, then when CMD.EXE starts, =
it
>> looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if
>> either or both are present, they are executed first.
>>
>>    HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\Aut=
oRun
>>
>>        and/or
>>
>>    HKEY_CURRENT_USER\Software\Microsoft\Command Processor\Auto=
Run"
>>
>>
>> This is "blindly polluting", but a completely standard and supported
>> facility, albeit an obscure one.
>>
>> As for detection, once ANSICON is loaded,  the ANSICON environment =
variable.
>>
>> But maybe ANSICon needs a small installer which has the option of
>> doing this (Jason - possible?) automatically for those too nervous of
>> editing registry.
>>
>>>
>>> Plus, afaik, the PEAR installer doesn't support doing such things.
>>>
>>
>> !is_null(getenv('ANSICON')) ?
>>
>>> -Hannes
>>>
>>
>> I think that whilst windows no longer has coloured console output as
>> standard, a free alternative is a viable option.
>
> Windows does indeed support colored console output. You have a few
> options to accomplish this without installing 3rd party programs:use
> the DOS subsystem, you can program in 16bit assembly using interrupts
> (which will just get launched in the DOS subsystem), or use Windows
> API to output text in colored format. Microsoft has dropped support
> for DOS interrupts in the 32bit console unfortunately and replaced it
> with goofy API that you have to call : (. Now, I could just be talking
> through my teeth but I am 99% sure of what I said (at least for
> Windows OS based on the NT kernel such as 2K/XP, I have very little
> experience with Vista so I can't comment).
>
> See the following KB article for more info
> http://support.microsoft.com/kb/101875
>
>>
>> The other option is to disable coloured output when on windows, but if
>> that was the case, I would like the option of having a mechanism to
>> enable this without having to add it to the command line every time -
>> yet another env_var?
>>
>> The source is available. Jason has been very receptive to the issues
>> that I've raised.
>>
>> Richard
>>
>> --
>> -----
>> Richard Quadling
>> "Standing on the shoulders of some very clever giants!"
>> EE : http://www.experts-exchange.com/M_248814.html
>> Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213=
474731
>> ZOPA : http://uk.zopa.com/member/RQuadling
>>
>
> My 2 cents anyways.
>

Natan, sorry.

I should have said, windows no longer has a native support for ANSI
escape sequences which worked admirably on previous incarnations of
MSDos and Windows (via ANSI.SYS) and many other operating systems.

So, technically, yes you CAN DIY if you like making wheels or you can
use a freely available alternative.

Sorry for the confusion.

--=20
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php