Page 1 of 1

Color function v20 patched

Posted: 03 Apr 2013 20:54
by carlos
Hello. Recently I updated my code of color function. Now is more speedy. I release this version 20 as the ultimate version.
Note: 26 august 2013 this code was patched fixing a problem, anyways it have other problem with the ! for example if you try print "!windir!" it prints "C:\WINDOWS". Please, consider the version 20 as deprecated and please use version 21.

Link to version 21: http://www.dostips.com/forum/viewtopic.php?f=3&t=4881

Image

Code: Select all

@Echo Off
Call :Color 9 "##################" \n
Call :Color F ""
Call :Color A "Final"
Call :Color B " Version"
Call :Color C " 20"
Call :Color F "" \n
Call :Color 9 "##################" \n
Pause >Nul
Exit /B

:Color
:: v20 deprecated.
:: Arguments: hexColor text [\n]
:: Supported in windows XP, 7, 8.
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Set "Text=%~2"
If Not Defined Text (Set Text=^")
Subst `: "!Temp!" >Nul &`: &Cd \
If Not Exist `.7 (
Echo(|(Pause >Nul &Findstr "^" >`)
Set /P "=." >>` <Nul
For /F "delims=;" %%# In (
'"Prompt $H;&For %%_ In (_) Do Rem"') Do (
Set /P "=%%#%%#%%#" <Nul >`.3
Set /P "=%%#%%#%%#%%#%%#" <Nul >`.5
Set /P "=%%#%%#%%#%%#%%#%%#%%#" <Nul >`.7))
Set /P "LF=" <` &Set "LF=!LF:~0,1!"
For %%# in ("!LF!") Do For %%_ In (
\ / :) Do Set "Text=!Text:%%_=%%~#%%_%%~#!"
For /F delims^=^ eol^= %%# in ("!Text!") Do (
If #==#! SetLocal DisableDelayedExpansion
If \==%%# (Findstr /A:%~1 . \` Nul
Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
Type `.5) Else (Echo %%#\..\`>`.dat
Findstr /F:`.dat /A:%~1 .
Type `.7))
If "\n"=="%~3" (Echo()
Goto :Eof


Re: Color function v20

Posted: 23 Aug 2013 16:17
by DigitalSnow
Thanks for the fun script, but version 20 is not working as well as 19.

I have not looked into why yet, but version 20 does not work correctly for me. This is how it outputs.
Windows 7 Enterprise x64

Image

Also Note that neither version 19 or 20 work when cmd is in unicode /u mode. In version 19, this could be fixed by changing the .dat echo line to

Code: Select all

) else (cmd /a /c echo %%#\..\`>`.dat

and version 20 by

Code: Select all

Type `.5) Else (cmd /a /c Echo %%#\..\`>`.dat

Re: Color function v20

Posted: 23 Aug 2013 23:06
by foxidrive
It doesn't display quite right in Windows 8 32 bit either.

Code: Select all

##################
\=\Final Version 20\=\
##################

Re: Color function v20

Posted: 23 Aug 2013 23:27
by carlsomo
Win7 64 bit gives same display as foxdrive win8 32 with \\'s
##################
\=\Final Version 20\=\
##################

Re: Color function v20

Posted: 23 Aug 2013 23:55
by carlos
Very thanks DigitalSnow, carlsomo and foxidrive for report the problem.
I remember be fix the problem, but I forgive post the solution, please sorry.

For fix it, please replace:

Code: Select all

(Set "Text=%~2"
) || (Set Text=^")


by

Code: Select all

Set "Text=%~2"
If ""=="!Text!" (Set Text=^")


If you test it and works i will post that fixed as the version 20 se.

DigitalSnow, also you mentions add support for when we are using cmd /u, you post a partial solution, using /u all output are unicode, then if we remove all the temp files and run this function it will create the files in unicode, that will not work.

I thinking produce a version with unicode support coming soon.


DigitalSnow:
please you can remove all your temp files and run the script. Your screenshoot looks as other problem.

Re: Color function v20

Posted: 24 Aug 2013 01:00
by carlsomo
##################
"Final Version 20"
##################

only had to hit a key to get back to prompt

Re: Color function v20

Posted: 26 Aug 2013 08:11
by DigitalSnow
The change fixed the issue for me too. I used defined instead.

Code: Select all

Set "Text=%~2"
If Not Defined Text (Set Text=^")


Code: Select all

##################
"Final Version 20"
##################

Re: Color function v20

Posted: 26 Aug 2013 16:47
by foxidrive
DigitalSnow wrote:The change fixed the issue for me too. I used defined instead.

Code: Select all

Set "Text=%~2"
If Not Defined Text (Set Text=^")


Code: Select all

##################
"Final Version 20"
##################


That worked here too in Win 8.

Re: Color function v20 patched

Posted: 26 Aug 2013 19:13
by carlos
Thanks for all, I edited the first post for left the patched version.

Re: Color function v20 patched

Posted: 15 Dec 2013 09:33
by xLightAcex
Hey, I've been wondering if theres a way of making it into a .exe that you put into C:\WINDOWS so you can call it that way (unless it's impossible to do it that way)

Re: Color function v20 patched

Posted: 15 Dec 2013 12:23
by Squashman
xLightAcex wrote:Hey, I've been wondering if theres a way of making it into a .exe that you put into C:\WINDOWS so you can call it that way (unless it's impossible to do it that way)

Save the code of the function as a bat file and call it.

Re: Color function v20 patched

Posted: 15 Dec 2013 15:34
by carlos
xLightAcex wrote:Hey, I've been wondering if theres a way of making it into a .exe that you put into C:\WINDOWS so you can call it that way (unless it's impossible to do it that way)


Hello. The function 20 is deprecated. The version 21: http://www.dostips.com/forum/viewtopic.php?f=3&t=4881 is the last version.

If you like a executable version I can post a executable utility that do the same. off course with the source.

Re: Color function v20 patched

Posted: 18 May 2018 09:04
by JMan
Nice works perfect on windows 10!
but i get the error:

Code: Select all

FINDSTR: Argument missing after /A

Re: Color function v20 patched

Posted: 18 May 2018 16:44
by Squashman
JMan wrote:
18 May 2018 09:04
Nice works perfect on windows 10!
but i get the error:

Code: Select all

FINDSTR: Argument missing after /A
Read the post above yours.

Re: Color function v20 patched

Posted: 21 May 2018 04:36
by JMan
I created a command for it.
download: http://www.filedropper.com/colorecho

Its just a bat file!
all credits to Carlos! :lol:

You can drop the bat file into your project folder.

or you drop it to: "C:\WINDOWS\system32" to set it as a real command!