Color problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Color problem

#1 Post by abc0502 » 23 Apr 2012 09:50

I use that code

Code: Select all

SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a" )
:: Put caode here
:c
echo off
<nul set /p ".="%DEL% " " >> "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

to color a start screen to my batch file but keep getting strange files with no extention on my work folder and i can't delete them any idea why and how to stop getting these files.
here is my code:

Code: Select all

@echo off
cls
mode 80,30
:: Color Function Part1
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a" )

:: Start Screen Picture
call :c 0c "           ii                                                " &echo:
call :c 0c "            vMb                                                   ii" &echo:
call :c 0c "             CMMMC                                              MMi" &echo:
call :c 0c "              iBMMMBC                                         MHMM " &echo:
call :c 0c "                 idMMMBY                                     MHM " &echo:
call :c 0c "                 i  ioMMMBv                                PMMHM " &echo:
call :c 0c "                 ZMBXiiYbBMMWi                          iWMMMHM " &echo:
call :c 0c "                  IMMMMBbEFBMMMOi                    ibiiMBMMHH " &echo:
call :c 0c "                    AWMMMMMBQOBMMMQi              ii BMBjEBMMH " &echo:
call :c 0c "                       vvjtZbdBBQBMMp            BMMFjBMEWMMi" &echo:
call :c 0f "                       iWMBbQFQBWQBBMBi        vi QMMBEBMMBn " &echo:
call :c 0f "                         XMMMMBBBBWQWMMb      iMMzidMMMMWi   " &echo:
call :c 0f "                           tWOQdEdEWBWBMMi    BMMMMOWMMF     " &echo:
call :c 0f "                             iQBBWOBWBBBMME  EMOQBBMMMn      " &echo:
call :c 0f "                               oBMMBBBBBBBMMpBBWbPBMMS       " &echo:
call :c 0f "                                  CBBBBBBBBMMMWQbEEMv        " &echo:
call :c 0f "                            iiYjtXZBMBBBBBBBMMMBBBMME        " &echo:
call :c 0f "                     WMMMMMMMMMMMMMMMBBBBBBBBBBBBMMMMMM      " &echo:
call :c 0f "                     izXcYoQBBBBBBMMMMMBBBMBMBBBMMMMMMMMi    " &echo:
call :c 08 "                       MMMWAobWMBMMMMBMMMMMBOWBdvi  iMMMM    " &echo:
call :c 08 "                        ivoQBBEOMMBY  MMMBMBBWMB       MM    " &echo:
call :c 08 "                         BMYipMMZi    vMMMMMMMMMB       i    " &echo:
call :c 08 "                           MMMc        BMMMMMMMBMB           " &echo:
call :c 08 "                           F             ioMMMMMMMW    M     " &echo:
call :c 08 "                                             iMMMMMMMMMMi    " &echo:
call :c 08 "                                                EMMMJAMM     " &echo:
call :c 08 "                                                 Bi    E     " &echo:
pause >nul
goto Main

:Main
:: Here I write My Code For The batch

:: Color Function Part2
:c
echo off
<nul set /p ".="%DEL% " " >> "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
:: Main Menu

and same problem happen here:

Code: Select all

[size=85]@echo off
cls
mode 80,55
Rem These are in use " %%a, %DEL%, %~2, %1, :C,
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
color 0D
::==============================================================================================================
echo                                                                     
call :C 0f "                              jvvi vbi" & echo:
call :C 0f "                             MMBEEMMMMMMMMo" & echo:
call :C 0f "                              vOMMMicZi   Mj" & echo:
call :C 0f "                                 MMC      vM" & echo:
call :C 0f "                                 iM       iM" & echo:
call :C 0f "                                  Mi      iM" & echo:
call :C 0f "                                  M        M" & echo:
call :C 0f "                                 jM        M" & echo:
call :C 0f "                                 M ZQMiMFB Mv" & echo:
call :C 0f "            iQQWBBBWCi          MB MiM MiM CM          ipBBBBWQP" & echo:
call :C 0f "           AO      iSQWzi      MM bXiM M AC Mc      cbBdv      iM" & echo:
call :C 0f "           MoM pv      iIBBQIjMB iM MY bM M  MCjdBBBti      bizBBM" & echo:
call :C 0e "          iMMM MM" & call :C 0f "M         iMMoMMWBPBIBFMMMBBMMi         Z" & call :C 0E "MMcoMMM" & echo:
call :C 0e "          iMMM MMMi" & call :C 0f "C             Ji  iM   in            v" & call :C 0E "MMMciMMM" & echo:
call :C 0E "          YMMM MMM MM" & call :C 0f "z             vI" & call :C 0E "CY" & call :C 0f "tti            i" & call :C 0E "MMioMMCN" & echo:
call :C 0E "          JMMB MMM MMMi" & call :C 0f "dBIcviiivivjz" & call :C 0E "FbdP" & call :C 0f "zFYciviiicjEMi" & call :C 0E "MMMiiMMdM" & echo:
call :C 0E "          bMMO MMM MMM MM iviivvzBbXiibivXBPtviiic EMipMMYiMMO MMMi" & echo:
call :C 0E "          BMMZ MMM MMM MN" & call :C 0c "WMMMMMMMi" & call :C 0F "00000" & call :C 08 "MMMMMMMMi" & call :C 0E "iMi MMo MMB MMM" & echo:     
call :C 0E "          MMMX MMB MMM MM" & call :C 0c "CMMMMMMMi" & call :C 0F "00000" & call :C 08 "MMMMMMMM" & call :C 0E "IMi MMZ MMM MMMi" & echo:
call :C 0E "          MMMv iMM MMM MM" & call :C 0c "iMMMMMMMi" & call :C 0F "00000" & call :C 08 "MMMMMMMM" & call :C 0E "MMt MMB MMM MMMi" & echo:   
call :C 0E "          MMMi vMM MMM MMB" & call :C 0c "MMMMMMMi" & call :C 0F "00000" & call :C 08 "MMMMMMMv" & call :C 0E "MMI MMB MMM MMMC" & echo:   
call :C 0E "          MMM CMMC MMB MMM" & call :C 0c "iMMMMMMi" & call :C 0F "00000" & call :C 08 "MMMMMMM" & call :C 0E "IMMQ MMM MMM BMMI" & echo:   
call :C 0E "          MMM bMMi MMZ MMMM" & call :C 0c "MMMMMMi" & call :C 0F "00000" & call :C 08 "MMMMMMc" & call :C 0E "MMMB MMM MMM bMMW" & echo:   
call :C 0E "          MMM WMM YMMo MMMWi" & call :C 0c "MMMMMi" & call :C 0F "00000" &call :C 08 "MMMMMM" & call :C 0E "BIMMM MMM MMM zMMP" & echo:   
call :C 0E "          MMM MMM IMMv MME M" & call :C 0c "iMMMMI" & call :C 0F "00000" & call :C 08 "MMMMM" & call :C 0E "WM MMM MMM QMM vMMM" & echo:   
call :C 0E "         iMMM MMM bMMi iMMZ MM" & call :C 0c "MMMi" & call :C 0F "00000" & call :C 08 "MMMM" & call :C 0E "pMM MMM MMM PMMi MMMi" & echo:
call :C 0E "         iMMM MMM BMM tMMC iMvM" & call :C 0c "MMi" & call :C 0F "00000" & call :C 08 "MMZ" & call :C 0E "WEBM MMM BMM CMMC MMMo" & echo:
call :C 0E "         CMMB MMM MMM IMMvjM CMn" & call :C 0c "Bb" & call :C 0F "00000" & call :C 08 "Mi" & call :C 0E "MM  M MMM QMMivMMF MMMi" & echo:
call :C 0E "         IMMB MMM MMM QMMiZ MMibi" & call :C 0c "v" & call :C 0F "00000" & call :C 08 "i" & call :C 0E "AJivbiMi B BMM oMMv MMQI" & echo:
call :C 0E "         QMMp MMM MMM BMMCMtWjB  MoviApniCQM iEbtMbWMMiXMMt MMB MMMM" & echo:   
call :C 0E "         BMMo MMB MMM MMMMiB" & call :C 0f "  QEME" & call :C 0e "UoMiiIM" & call :C 0f "iMEM" & call :C 0e "  dMMMiiMMd MMM MMM" & echo:   
call :C 0E "         MMMv MME MMM MMMB" & call :C 0f " iM M SM" & call :C 0e "Y  McME" & call :C 0f "iiM MM  " & call :C 0e "KKiMMW MMM MMMMoM" & echo:   
call :C 0E "         MMMi MMp MMM MpEi" & call :C 0f " BM MGH" & call :C 0e "MMOM MMb" & call :C 0f "uUM YMnB" & call :C 0e "B MMM MMM MMMYY" & echo:   
call :C 0E "         MMM tMMC MMM i" & call :C 0f " MB nMQMio" & call :C 0e "MMvvM MM" & call :C 0f "oMQMMHHM " & call :C 0e "iiMMM MMM BMMoM" & echo:   
call :C 0E "         MMM UMMv MMt" & call :C 0f "  iM fgb iBj" & call :C 0e "BM IM BMo" & call :C 0f "vM iY  iM" & call :C 0e "iMMM MMM OMMo" & echo:   
call :C 0E "         MMM BMMv M" & call :C 0f "   iMMfdovffMc" & call :C 0e "MM BM IMv" & call :C 0f "oMFggWftZM " & call :C 0e "ivM MMM zMMP" & echo:   
call :C 0E "         MMM MMMv" & call :C 0f "   BBBviEJMM YM" & call :C 0e "MMM Mii MM" & call :C 0f "QM CMMiM M" & call :C 0e "  yiMMMijMMM" & echo:
call :C 0E "         MMM MMi" & call :C 0f "  hghMiuMp iMii" & call :C 0e "pQMM MMF MMv" & call :C 0f "BM  Mb jBBk" & call :C 0e "  iOMIiMMM" & echo:
call :C 0E "         MMM z" & call :C 0f "   icddBtfbMghjuh" & call :C 0e "MMMB" & call :C 0e "MMM" & call :C 0e "MMMv" & call :C 0f "ihhiMgfMihiv    " & call :C 0e "  v CMMM" & echo:
call :C 0E "         MMB" & call :C 0f "   vMBSiotCFcQYvMZ"  & call :C 0e "MBMM"  & call :C 0e " MME" & call :C 0e "QMBIM"  & call :C 0f "iMMiBvbCnJYiIM " & call :C 0e "uuMMM" & echo:
call :C 0E "         Mi" & call :C 0f "    MBMMMBtQDD" & call :C 0e "n WAMjvvW  " & call :C 0e "     CiMQMiioPJ" & call :C 0f "iEYMMMMBZ" & call :C 0e "    M" & echo:
call :C 0E "         i    MMMB vZdBMMCMMbMQBQBJMMMZMMBnQBBMBBMWBMMMMn iMMMj" & echo:
call :C 0E "            BMb                                               MMi" & echo:
call :C 0E "            BM              Arab Republic Of Egypt            ZM" & echo:
call :C 0E "             BMC                                             BMi" & echo:
call :C 0E "              JME                                           MM" & echo:
call :C 0E "               nBMMMMQZci                           ivPBMMMMEi" & echo:
call :C 0E "                    ijFQBMMMMMMMMMMMBQQMMMMMMMMMMMMMBdti" & echo:
::==============================================================================================================
:C
echo off
<nul set /p ".="%DEL% " " >> "%~2"
findstr /v /a:%~1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof[/size]

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

Re: Color problem

#2 Post by foxidrive » 23 Apr 2012 10:03

Try this line - does it work?

Code: Select all

<nul set /p "=%DEL%" >> "%~2"

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

Re: Color problem

#3 Post by foxidrive » 23 Apr 2012 10:28

This works here:

Code: Select all

@echo off
cls
mode 80,30
:: Color Function Part1
SETLOCAL EnableDelayedExpansion

:: Start Screen Picture
call :c 0c "           ii                                                "
call :c 0c "            vMb                                                   ii"
call :c 0c "             CMMMC                                              MMi"
call :c 0c "              iBMMMBC                                         MHMM "
call :c 0c "                 idMMMBY                                     MHM "
call :c 0c "                 i  ioMMMBv                                PMMHM "
call :c 0c "                 ZMBXiiYbBMMWi                          iWMMMHM "
call :c 0c "                  IMMMMBbEFBMMMOi                    ibiiMBMMHH "
call :c 0c "                    AWMMMMMBQOBMMMQi              ii BMBjEBMMH "
call :c 0c "                       vvjtZbdBBQBMMp            BMMFjBMEWMMi"
call :c 0f "                       iWMBbQFQBWQBBMBi        vi QMMBEBMMBn "
call :c 0f "                         XMMMMBBBBWQWMMb      iMMzidMMMMWi   "
call :c 0f "                           tWOQdEdEWBWBMMi    BMMMMOWMMF     "
call :c 0f "                             iQBBWOBWBBBMME  EMOQBBMMMn      "
call :c 0f "                               oBMMBBBBBBBMMpBBWbPBMMS       "
call :c 0f "                                  CBBBBBBBBMMMWQbEEMv        "
call :c 0f "                            iiYjtXZBMBBBBBBBMMMBBBMME        "
call :c 0f "                     WMMMMMMMMMMMMMMMBBBBBBBBBBBBMMMMMM      "
call :c 0f "                     izXcYoQBBBBBBMMMMMBBBMBMBBBMMMMMMMMi    "
call :c 08 "                       MMMWAobWMBMMMMBMMMMMBOWBdvi  iMMMM    "
call :c 08 "                        ivoQBBEOMMBY  MMMBMBBWMB       MM    "
call :c 08 "                         BMYipMMZi    vMMMMMMMMMB       i    "
call :c 08 "                           MMMc        BMMMMMMMBMB           "
call :c 08 "                           F             ioMMMMMMMW    M     "
call :c 08 "                                             iMMMMMMMMMMi    "
call :c 08 "                                                EMMMJAMM     "
call :c 08 "                                                 Bi    E     "
pause >nul
goto :Main

:Main
:: Here I write My Code For The batch
goto :EOF

:: Color Function Part2
:c
echo off
<nul set /p "= " >"%~2"
findstr /v /a:%1 "^$" "%~2" nul
del "%~2" >nul 2>&1
echo.
goto :eof
:: Main Menu

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Color problem

#4 Post by abc0502 » 23 Apr 2012 10:40

Thanks foxi it worked with the first batch and generated the files but it disappear by it self,
i tested on small text like this:

Code: Select all

@echo off
cls
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a" )


call :c 0a "   #    # #    # #       ####   ####  #    # ###### #####  "&echo:
call :c 0b "   #    # ##   # #      #    # #    # #   #  #      #    # "&echo:
call :c 0c "   #    # # #  # #      #    # #      ####   #####  #    # "&echo:
call :c 0d "   #    # #  # # #      #    # #      #  #   #      #    # "&echo:
call :c 0e "   #    # #   ## #      #    # #    # #   #  #      #    # "&echo:
call :c 0f "    ####  #    # ######  ####   ####  #    # ###### ##### "&echo:
pause >nul
:C
echo off
<nul set /p "=%DEL%" >> "%~2"
findstr /v /a:%~1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

it work great without the files be generated on the work folder it seams that this file is generated becasue of the big amount of text being displayed in dos, i think i will use simple start screen like the above :)

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Color problem

#5 Post by abc0502 » 29 Apr 2012 03:03

I found a temporary solution for the un deleted files that appear in the big images
add that command to change the default directory of the cmd window to temp directory
Like that "note the red line"

:C
echo off
CD %temp%
<nul set /p "=%DEL%" >> "%~2"
findstr /v /a:%~1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

That won't solve it bu it will keep this files in temp directory till i find a fix for it :)

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Color problem

#6 Post by aGerman » 29 Apr 2012 09:11

Code: Select all

@echo off &setlocal
 
call :ColorText 0a "Hello World! "&call :ColorText f6 "This is a "&call :ColorText f1 "test."&echo(
<nul set /p "=One "&call :ColorText 0c "red "&echo word.
call :ColorText 0e "some special characters ;,{[]}-+^&%%%%()"&echo(
echo(
echo NOTE \/:*?^"^<^>^| are forbidden characters!
pause>nul
goto :eof

:ColorText
setlocal
set "file=%~2"
set "file=%file:^^=^%"
for /f "delims=#" %%a in ('"prompt #$H# &echo on &for %%b in (1) do rem"') do set "BSB=%%a"
pushd "%temp%"
>"%file%X" set /p "=%BSB%%BSB%"<nul
findstr /a:%1 . "%file%X" nul
del "%file%X" >nul 2>&1
popd
endlocal
goto :eof

:wink: This should also solve some minor problems like trailing dots...

Regards
aGerman

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Color problem

#7 Post by abc0502 » 29 Apr 2012 15:54

thanks aGerman for the code but what is the use of this:<nul set /p "=One "
why don't use call :ColorText 0e instead ?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Color problem

#8 Post by aGerman » 29 Apr 2012 16:02

It's faster in case you don't need to change the current color :wink:
Of course you could call the sub routine as well.

Regards
aGerman

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Color problem

#9 Post by abc0502 » 29 Apr 2012 16:17

aGerman wrote:It's faster in case you don't need to change the current color :wink:
Of course you could call the sub routine as well.

Regards
aGerman

I didn't know about that, it's a very nice trick.
thanks :)

jeb
Expert
Posts: 1042
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Color problem

#10 Post by jeb » 30 Apr 2012 03:42

I was a bit annoyed about the limitation of the :color function. Until now you can only color valid filename characters. :(

BUT NOW: You can use any character, even "& |<>!%<space><quote>/" :D

Code: Select all

@echo off
setlocal EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
  rem set "del=!del:~0,1!"
)

rem Prepare a file "X" with only one dot
<nul > X set /p ".=."

call :color 1a "a"
call :color 1b "b"
call :color 1c "^!"
call :color 1d "<"
call :color 1e ">"
call :color 1f "&"
call :color 2a "|"
call :color 2b " "
call :color 2c "%%%%"
call :color 2d """
call :color 2e "*"
call :color 2f "?"
exit /b

:color
set "param=^%~2" !
set "param=!param:"=\"!"
findstr /p /A:%1 "." "!param!\..\X" nul
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
exit /b


It uses a simple trick, a filename is also valid if the first part will be removed by a \..\
then the first part is completly ignored :!:

jeb

Cat
Posts: 32
Joined: 11 Nov 2011 12:04

Re: Color problem

#11 Post by Cat » 30 Apr 2012 13:18

Anyone try using this (http://bit.ly/IKyEmM) for colors? It's faster and doesn't require filenames

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

Re: Color problem

#12 Post by foxidrive » 30 Apr 2012 13:32

Cat wrote:Anyone try using this (http://bit.ly/IKyEmM) for colors? It's faster and doesn't require filenames


It has a dependency. See this image:

http://www22.zippyshare.com/v/22214760/file.html


Can you compile it with the library?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Color problem

#13 Post by aGerman » 30 Apr 2012 14:43

I developed similar applications in C++ but I rarely shared them and I like pure batch solutions in this forum much more. It's because they run on each Windows computer without 3rd party tools.

However, the reason why Cats app doesn't run is that the tool is developed using VC2010. The newest runtime files don't come with Windows yet. You could install them though.
Microsoft Visual C++ 2010 Redistributable Package

Regards
aGerman

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

Re: Color problem

#14 Post by foxidrive » 30 Apr 2012 14:53

Thanks aGerman.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Color problem

#15 Post by dbenham » 01 May 2012 06:48

Great improvement to the pure batch solution jeb. :D

\ and / are still irritating.

"a\", "a\\\", "a/" and "a///" all work without changes. But "a\b\" will require extra code to determine how many "..\" and %DEL% to use. Perhaps the easiest solution is to stipulate that strings with multiple "\" and/or "/" with intervening chars be broken into multiple strings.

Of course, neither "\" nor "/" work as leading characters. But I was very pleasantly surprised that "a%DEL%\" and "a%DEL%/" do work. :D


Dave Benham

Post Reply