0

I am coding a batch image viewer, set out of pixels which are shown on the screen with a actual way of colored words, lines or even just letters in the same line with different colors. Said that I am making a pixel type of a image viewer. The problem is that the code for coloring the lines that I found on stack overflow does not accept me to enter a variable instead of the color code(P.S. The variable contains the color code) while calling the command in code. This is the code for the actually command that let's me do color coding:

:Echo.Color %1=Color %2=Str [%3=/n]
setlocal enableDelayedExpansion
set "str=%~2"
:Echo.Color.2
set "str=a%ECHO.DEL%!str:\=a%ECHO.DEL%\..\%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%!"
set "str=!str:/=a%ECHO.DEL%/..\%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%!"
set "str=!str:"=\"!"
pushd "%ECHO.DIR%"
findstr /p /r /a:%~1 "^^-" "!str!\..\!ECHO.FILE!" nul
popd
for /l %%n in (1,1,12) do if not "!ECHO.FILE:~%%n!"=="" <nul set /p "=%ECHO.DEL%"
<nul set /p "=%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%"
if not "%~3"=="" echo.
endlocal & goto :eof
:Echo.Color.Var %1=Color %2=StrVar [%3=/n]
if not defined %~2 goto :eof
setlocal enableDelayedExpansion
set "str=!%~2!"
goto :Echo.Color.2

:Echo.Color.Init
set "ECHO.COLOR=call :Echo.Color"
set "ECHO.DIR=%~dp0"
set "ECHO.FILE=%~nx0"
set "ECHO.FULL=%ECHO.DIR%%ECHO.FILE%"
for /F "tokens=1 delims=#" %%a in ('"prompt #$H# & echo on & for %%b in (1) do rem"') do set "ECHO.DEL=%%a"
goto :eof

The command to display something is:

call :Echo.Color E0 "a"

That will display the "a" letter in a yellow background and black font color.

The actual thing I want to do is:

call :Echo.Color %c1% "a"

The %c1%is actually set from a c1.txt file and it's contents are E0 which should produce the same result, just with the .txt file I get to make my own picture format kind of and then anyone could edit the file and make his own colored pixel which would make a picture.

The solution to this answer is that someone gives me a different color code which I would not prefer, the smarter thing is to actually edit this code and somehow help me making the thing so it can use the variables. Or I have another solution of mine but I don't know will it work and how to get it to work. I could again echo out all of the commands with the variable and then save that into a text file(each one of them) and then load them back but I don't know how to use a variable as a actual command.

Frosty Tosty
  • 63
  • 1
  • 8
  • 1
    Color script you found isn't working? [There's a truckload of others](http://stackoverflow.com/questions/4339649/) you can try. ([This one](http://stackoverflow.com/a/27322578/1683264) is my favorite.) – rojo Apr 09 '15 at 12:15
  • The truckload link you have actually put there is a link to the one I use. If I actually write something the color works perfectly, it just does not want to accept when I am using a variable instead of the color code, gonna test your favorite tho. – Frosty Tosty Apr 09 '15 at 12:19
  • Thank you dude really much, I used the original jeb's method that was used in your favorite code. You could mind posting a normal answer if you want to so I could check it as solution. – Frosty Tosty Apr 09 '15 at 12:33
  • 1
    I appreciate it, but the answer is so trivial S.O. just converts it to a comment anyway. – rojo Apr 09 '15 at 12:45
  • If you're talking about the script above, you never actually `set "ECHO.FILE=something"`. The variable is empty. If you intend to use `findstr` on a variable rather than a file, you need to pipe it. `echo(!str! | findstr etc.` – rojo Apr 09 '15 at 12:52
  • Thank you dude for the help turns out I am dumb enough to forget to do cd.. out of the directory i was in and also turns out I forgot to use Load which is a command in my picture viewer to actually load all the variables anyways got it working now and at least the color coding script is simple and smaller now :D – Frosty Tosty Apr 09 '15 at 12:55
  • If you are interested in a Batch image viewer that show pixels in color, I suggest you to see [this post](http://stackoverflow.com/questions/4339649/how-to-have-multiple-colors-in-a-batch-file/23956113#23956113). – Aacini Apr 09 '15 at 17:23
  • Thank you, but I have my own system and it is done now so yea.... – Frosty Tosty Apr 11 '15 at 09:10

0 Answers0