Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
carlos
- Expert
- Posts: 503
- Joined: 20 Aug 2010 13:57
- Location: Chile
-
Contact:
#1
Post
by carlos » 26 Aug 2013 23:03
Note: the latest version 23c is found here: http://www.dostips.com/forum/viewtopic.php?p=41155#p41155Also I write a utility called out.exe that bypass some limitations of the function color here: http://www.dostips.com/forum/viewtopic.php?p=41335#p41335Hello, recently I patched the version 20 of the function color. But I found another problem related with the ! symbol. Because this I write the version 21 that have solved the problem and also I add a nice feature: overload parameters for speedy and save lines.
color21.cmd
Code: Select all
@Echo Off
Call :Color A "######" \n E "" C " 21 " E "!" \n B "######" \n
Pause >Nul
Exit /B
:Color
:: v21
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
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))
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
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 #==#! EndLocal
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" (Shift
Echo()
Shift
Shift
If ""=="%~1" Goto :Eof
Goto :__Color
Last edited by
carlos on 19 May 2015 14:57, edited 7 times in total.
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#3
Post
by penpen » 27 Aug 2013 02:10
It's running with no problems under Windows XP home & prof versions, too.
penpen
-
miskox
- Posts: 630
- Joined: 28 Jun 2010 03:46
#6
Post
by miskox » 20 Feb 2014 12:25
I see that it leaves temporary files.
Can you update the code (to v22) so it deletes temporary files, please (so you add it in the right place)?
Code: Select all
@Echo Off
Call :Color A "######" \n E "" C " 21 " E "!" \n B "######" \n
Pause >Nul
Exit /B
:Color
:: v21
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
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))
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
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 #==#! EndLocal
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" (Shift
Echo()
Shift
Shift
If ""=="%~1" del ` `.3 `.5 `.7 `.dat&Goto :Eof
Goto :__Color
Did I make correct modifications?
Saso
-
carlos
- Expert
- Posts: 503
- Joined: 20 Aug 2010 13:57
- Location: Chile
-
Contact:
#7
Post
by carlos » 20 Feb 2014 17:56
@miskox: you are right.
But for post a new version I also fix a problem in all previous versions (all previous versions not works with you use cmd /u).
I fixed in the new version 22 that as you request delete the temp files.
color22.cmd
Code: Select all
@Echo Off
Call :Color A "######" \n E "" C " 22 " E "!" \n B "######" \n
Pause >Nul
Exit /B
:Color
:: v22
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: This version works using Cmd /U
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
Echo(|(Pause >Nul &Findstr "^" >`)
Cmd /A /D /C Set /P "=." >>` <Nul
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do (
Cmd /A /D /C Set /P "=%%# %%#" <Nul >`.1
Copy /Y `.1 /B + `.1 /B + `.1 /B `.3 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.3 /B `.5 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.5 /B `.7 /B >Nul
)
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
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 #==#! EndLocal
If \==%%# (Findstr /A:%~1 . \` Nul
Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
Type `.5) Else (Cmd /A /D /C Echo %%#\..\`>`.dat
Findstr /F:`.dat /A:%~1 .
Type `.7))
If "\n"=="%~3" (Shift
Echo()
Shift
Shift
If ""=="%~1" Del ` `.1 `.3 `.5 `.7 `.dat &Goto :Eof
Goto :__Color
-
ebloch
- Posts: 3
- Joined: 20 Apr 2015 14:09
#8
Post
by ebloch » 20 Apr 2015 14:50
Win 7 Home Premium SP-1 64 bit
I may have found an error/bug:
- - After the following two commands:
SET xc=%Time: =0% Start Test
CALL :COLOR C "%xc%" \n
- - The following command works:
ECHO %Linex% %Time: =0% & ECHO(
- - The following does NOT work:
(ECHO %Linex% %Time: =0%) & ECHO(
Because I frequently use (...) for clarity with & this is a problem that turned up.
Any solution?
-
carlos
- Expert
- Posts: 503
- Joined: 20 Aug 2010 13:57
- Location: Chile
-
Contact:
#9
Post
by carlos » 08 May 2015 08:34
Hello.
I found a little bug con the version 22, when you use special characters like & it fails.
This is the version 23c that have the fix:
Code: Select all
@Echo Off
Call :Color A "######" \n E "" C " 23 " E "!" \n B "#&calc" \n
Pause >Nul
Exit /B
:Color
:: v23c
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: This version works using Cmd /U
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
Echo(|(Pause >Nul &Findstr "^" >`)
Cmd /A /D /C Set /P "=." >>` <Nul
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do (
Cmd /A /D /C Set /P "=%%# %%#" <Nul >`.1
Copy /Y `.1 /B + `.1 /B + `.1 /B `.3 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.3 /B `.5 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.5 /B `.7 /B >Nul
)
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
For %%_ In ("&" "|" ">" "<"
) Do Set "Text=!Text:%%~_=^%%~_!"
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 #==#! EndLocal
If \==%%# (Findstr /A:%~1 . \` Nul
Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
Type `.5) Else (Cmd /A /D /C Echo %%#\..\`>`.dat
Findstr /F:`.dat /A:%~1 .
Type `.7))
If "\n"=="%~3" (Shift
Echo()
Shift
Shift
If ""=="%~1" Del ` `.1 `.3 `.5 `.7 `.dat &Goto :Eof
Goto :__Color
Last edited by
carlos on 09 May 2015 08:09, edited 1 time in total.
-
Ben Mar
- Posts: 22
- Joined: 03 May 2015 10:51
#10
Post
by Ben Mar » 08 May 2015 13:14
I think I found a bug for version 23:
For the character "^" it prints out double "^^"
Unless I don't use any quotes and put double ^^ then it prints out one ^
@Echo Off
rem this prints out 2 ^^
Call color23.cmd A "######" \n E "^" C " 21 " E "!" \n B "######" \n
rem this prints out 4 ^^^^
Call color23.cmd A "######" \n E "^^" C " 21 " E "!" \n B "######" \n
rem this prints out 1 ^
Call color23.cmd A "######" \n E ^^ C " 21 " E "!" \n B "######" \n
Exit /B
-
carlos
- Expert
- Posts: 503
- Joined: 20 Aug 2010 13:57
- Location: Chile
-
Contact:
#11
Post
by carlos » 08 May 2015 15:14
@Ben Mar, thanks.
Seems that is fixed replacing this line:
by:
-
Ben Mar
- Posts: 22
- Joined: 03 May 2015 10:51
#12
Post
by Ben Mar » 08 May 2015 15:44
Yes, with the new fixed, that bug is taken care of.
Thanks Carlos.
-
carlos
- Expert
- Posts: 503
- Joined: 20 Aug 2010 13:57
- Location: Chile
-
Contact:
#14
Post
by carlos » 09 May 2015 08:11
Thanks, also I forgotten support the special characters > and <
I updated the code to version 23c that have all the fixes supporting the special characters:& | > < ^
-
miskox
- Posts: 630
- Joined: 28 Jun 2010 03:46
#15
Post
by miskox » 10 May 2015 07:59
Please see this:
Code: Select all
@echo off
call :color 0E " SOME TEXT TO DISPLAY HERE IN COLOR"
echo.
echo.
echo.
call :color 0E " SOME TEXT TO DISPLAY HERE IN COLOR"
echo.
echo.
echo.
call :color 0E " SOME TEXT TO DISPLAY HERE IN COLOR"
goto :EOF
:Color
:: v23c
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: This version works using Cmd /U
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
Echo(|(Pause >Nul &Findstr "^" >`)
Cmd /A /D /C Set /P "=." >>` <Nul
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do (
Cmd /A /D /C Set /P "=%%# %%#" <Nul >`.1
Copy /Y `.1 /B + `.1 /B + `.1 /B `.3 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.3 /B `.5 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.5 /B `.7 /B >Nul
)
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
For %%_ In ("&" "|" ">" "<"
) Do Set "Text=!Text:%%~_=^%%~_!"
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 #==#! EndLocal
If \==%%# (Findstr /A:%~1 . \` Nul
Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
Type `.5) Else (Cmd /A /D /C Echo %%#\..\`>`.dat
Findstr /F:`.dat /A:%~1 .
Type `.7))
If "\n"=="%~3" (Shift
Echo()
Shift
Shift
If ""=="%~1" Del ` `.1 `.3 `.5 `.7 `.dat &Goto :Eof
Goto :__Color
Output:
Code: Select all
C:\color_test.cmd
SOME TEXT TO DISPLAY HERE IN COLOR\.
SOME TEXT TO DISPLAY HERE IN COLOR
SOME TEXT TO DISPLAY HERE IN COLOR\..\`:.
C:\>
Also notice different number of empy lines.
This error occurs in previuos versions, too.
Any ideas?
Thanks.
Saso