Вы могли бы попробовать что-то вроде этого:
@echo off
setlocal EnableDelayedExpansion
set "timeout=2"
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
:loop
FOR %%G IN (9,a,b,c,d,e) DO (
::[HELLO
::[WORLD
::]RED
cls
for /f "delims=:[ tokens=*" %%A in ('findstr /b "::[" "%~f0"') do @call :ColorText 0%%G "%%A"
for /f "delims=:] tokens=*" %%A in ('findstr /b "::]" "%~f0"') do @call :ColorText 0c "%%A"
ping -n !timeout! 127.0.0.1 > nul
)
goto loop
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
echo.
goto :eof
Кредиты на NiklasJ для this post о окраски в каждой строке в пакетном режиме. Обратите внимание, что вы не можете, однако, использовать следующие специальные символы:
. | ! %; : [])/\ <>%^*? "
в тексте, чтобы отобразить.
Это перекликается все строки после :: [с изменением цвета, и после ::] в красном цвете.
EDIT
Так Я снова выстрелил в него, на этот раз используя the code used by Jeb in this post, и вот обновленная версия. Он по-прежнему не может обрабатывать все символы, но, похоже, это ограничивается тем, что он не может обрабатывать
:/\
@echo off
set "timeout=2"
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 Prepare a file "X" with only one dot
:loop
FOR %%G IN (9,a,b,c,d,e) DO (
cls
for /f "delims=:[ tokens=*" %%A in ('findstr /b "::[" "%~f0"') do @call :color 0%%G "%%A"
for /f "delims=:] tokens=*" %%A in ('findstr /b "::]" "%~f0"') do @call :color 0c "%%A"
ping -n !timeout! 127.0.0.1 > nul
)
goto loop
exit /b
:color
<nul > X set /p ".=."
set "param=^%~2" !
set "param=!param:"=\"!"
findstr /p /A:%1 "." "!param!\..\X" nul
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
echo.
del /f /q X >nul 2>nul
exit /b
::[ _ _ _ _
::[ | | | | | | |
::[ | |__| |____| | | ___
::[ | __ | _ | | || _ |
::[ | | | | __| | | (_) |
::[ |_| |_|____|_|_||___|
::[
::] _____ _
::] | __ | | |
::] | |__) |___ __| |
::] | _ || _ || _` |
::] | | | | __| (_| |
::] |_| |_|___||__,_|
EDIT # 2 Наконец, после экспериментов с другим кодом по dbenham в this answer, то кажется, что это единственная версия, которая действительно поддерживает весь ваш характер, хотя он не похож на пустые строки и намного медленнее:
@echo off
setlocal EnableDelayedExpansion
set "timeout=2"
set q=^"
:loop
FOR %%G IN (9,a,b,c,d,e) DO (
cls
for /f "delims=:[ tokens=*" %%A in ('findstr /b "::[" "%~f0"') do @call :c 0%%G "%%A" /n
for /f "delims=:] tokens=*" %%A in ('findstr /b "::]" "%~f0"') do @call :c 0c "%%A" /n
ping -n !timeout! 127.0.0.1 > nul
)
goto loop
exit /b
:c
setlocal enableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:colorPrint Color Str [/n]
setlocal
set "s=%~2"
call :colorPrintVar %1 s %3
exit /b
:colorPrintVar Color StrVar [/n]
if not defined DEL call :initColorPrint
setlocal enableDelayedExpansion
pushd .
':
cd \
set "s=!%~2!"
:: The single blank line within the following IN() clause is critical - DO NOT REMOVE
for %%n in (^"^
^") do (
set "s=!s:\=%%~n\%%~n!"
set "s=!s:/=%%~n/%%~n!"
set "s=!s::=%%~n:%%~n!"
)
for /f delims^=^ eol^= %%s in ("!s!") do (
if "!" equ "" setlocal disableDelayedExpansion
if %%s==\ (
findstr /a:%~1 "." "\'" nul
<nul set /p "=%DEL%%DEL%%DEL%"
) else if %%s==/ (
findstr /a:%~1 "." "/.\'" nul
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%"
) else (
>colorPrint.txt (echo %%s\..\')
findstr /a:%~1 /f:colorPrint.txt "."
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
)
)
if /i "%~3"=="/n" echo(
popd
exit /b
:initColorPrint
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A"
<nul >"%temp%\'" set /p "=."
subst ': "%temp%" >nul
exit /b
:cleanupColorPrint
2>nul del "%temp%\'"
2>nul del "%temp%\colorPrint.txt"
>nul subst ': /d
exit /b
::[ _ _ _ _
::[ | | | | | | |
::[ | |__| | ___| | | ___
::[ | __ |/ _ \ | |/ _ \
::[ | | | | __/ | | (_) |
::[ |_| |_|\___|_|_|\___/
::] _____ _
::] | __ \ | |
::] | |__) |___ __| |
::] | _ // _ \/ _` |
::] | | \ \ __/ (_| |
::] |_| \_\___|\__,_|
Возможно, вас заинтересует [этот вопрос] (http://stackoverflow.com/q/4339649/1683264). – rojo