color single lines of ASCII characters with batch

2020-08-04 10:52发布

问题:

I was recently overwhelmed with quick responses for a question I had the other day! hopefully this will be a quick one for those in the know, I've searched and played for hours and just not getting it.

I have found code to modify color per character in batch CMD although cant make it work for ASCII characters.

This shows hows output window with errors:

Here's the code I've tried to modify to suit, it explains exactly whats happening and what im attempting:

@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"
)

call :colorEcho 0a "This works!!"
echo.
call :colorEcho 0C "But ASCII characters don't"
echo.
echo expect this in set color 
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º                             º
echo º                             º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.    
echo but get this instead?
echo.
call :colorEcho 0a "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
echo.
call :colorEcho 0a "º                             º"
echo.
call :colorEcho 0a "º                             º"
echo.
call :colorEcho 0a "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
pause
exit

:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i

回答1:

Seems my solution was more simple than i ever expected, once i stopped and thought about it.

so because i want all extended ascii characters to be the same color its simple.

change the whole page to match what color i want menu border (extended ascii characters) using simple color function

and then color all the text separately using the call :colorEcho from my original script.

thanks