Color function v20 patched

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Color function v20 patched

#1 Post by carlos » 03 Apr 2013 20:54

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

Last edited by carlos on 15 Dec 2013 15:28, edited 4 times in total.

DigitalSnow
Posts: 20
Joined: 21 Dec 2012 13:36
Location: United States

Re: Color function v20

#2 Post by DigitalSnow » 23 Aug 2013 16:17

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Color function v20

#3 Post by foxidrive » 23 Aug 2013 23:06

It doesn't display quite right in Windows 8 32 bit either.

Code: Select all

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

carlsomo
Posts: 91
Joined: 02 Oct 2012 17:21

Re: Color function v20

#4 Post by carlsomo » 23 Aug 2013 23:27

Win7 64 bit gives same display as foxdrive win8 32 with \\'s
##################
\=\Final Version 20\=\
##################

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Color function v20

#5 Post by carlos » 23 Aug 2013 23:55

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.

carlsomo
Posts: 91
Joined: 02 Oct 2012 17:21

Re: Color function v20

#6 Post by carlsomo » 24 Aug 2013 01:00

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

only had to hit a key to get back to prompt

DigitalSnow
Posts: 20
Joined: 21 Dec 2012 13:36
Location: United States

Re: Color function v20

#7 Post by DigitalSnow » 26 Aug 2013 08:11

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"
##################

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Color function v20

#8 Post by foxidrive » 26 Aug 2013 16:47

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.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Color function v20 patched

#9 Post by carlos » 26 Aug 2013 19:13

Thanks for all, I edited the first post for left the patched version.

xLightAcex
Posts: 1
Joined: 15 Dec 2013 09:28

Re: Color function v20 patched

#10 Post by xLightAcex » 15 Dec 2013 09:33

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)

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Color function v20 patched

#11 Post by Squashman » 15 Dec 2013 12:23

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.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Color function v20 patched

#12 Post by carlos » 15 Dec 2013 15:34

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.

JMan
Posts: 5
Joined: 18 May 2018 08:26

Re: Color function v20 patched

#13 Post by JMan » 18 May 2018 09:04

Nice works perfect on windows 10!
but i get the error:

Code: Select all

FINDSTR: Argument missing after /A

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Color function v20 patched

#14 Post by Squashman » 18 May 2018 16:44

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.

JMan
Posts: 5
Joined: 18 May 2018 08:26

Re: Color function v20 patched

#15 Post by JMan » 21 May 2018 04:36

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!

Post Reply