color single lines of ASCII characters with batch CMD

大城市里の小女人 提交于 2020-01-01 20:49:26

问题


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



来源:https://stackoverflow.com/questions/41207496/color-single-lines-of-ascii-characters-with-batch-cmd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!