如何在此批处理文件中使用多种字符串颜色?

时间:2017-10-15 13:17:54

标签: string batch-file colors

我有这个脚本,我无法获得多种字符串颜色。 这是剧本:

:Sentence 1
@echo off
setlocal enableextensions enabledelayedexpansion

set lines=1
set "line1=This Line in Blue, please" && set LineCount=26

for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
for /L %%a in (1,1,%lines%) do set num=0&set "line=!line%%a!"&call :type1

pause>nul
goto :EOF

:type1
set /a LineCount-=1
if %LineCount% == 0 ping localhost /n 2 >nul && goto Sentence2
set "letter=!line:~%num%,1!"
set "delay=%random%%random%%random%%random%%random%%random%%random%"
set "delay=%delay:~-6%"
if not "%letter%"=="" set /p "=a%bs%%letter%" <nul

for /L %%b in (1,40,%delay%) do rem
if "%letter%"=="" echo.&goto :EOF
set /a num+=1
goto type1

:Sentence2
@echo off
setlocal enableextensions enabledelayedexpansion
echo.
set lines=1
set "line1=This Line in Red, please" && set LineCount=25

for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
for /L %%a in (1,1,%lines%) do set num=0&set "line=!line%%a!"&call :type2

pause>nul
goto :EOF

:type2
set /a LineCount-=1
if %LineCount% == 0 ping localhost /n 2 >nul && goto end
set "letter=!line:~%num%,1!"
set "delay=%random%%random%%random%%random%%random%%random%%random%"
set "delay=%delay:~-6%"
if not "%letter%"=="" set /p "=a%bs%%letter%" <nul

for /L %%b in (1,40,%delay%) do rem
if "%letter%"=="" echo.&goto :EOF
set /a num+=1
goto type2

end
echo.
pause
exit

现在我想以不同的颜色获取这两个字符串: 请给我这条蓝线 - 这条红线,请

我尝试了FINDSTR /LCOLOR /n但是我无法正确使用它.....我知道批处理在单个命令窗口中并不真正支持多种颜色,但它是可以使用外部文件。

有人可以帮帮我吗?

〜Czgb

1 个答案:

答案 0 :(得分:0)

可能msr.exe的辅助功能可以帮助您为脚本的运行添加前景色和背景色,请参阅以下屏幕截图。更多用法和示例可以看到git文档,例如:msr on Windowsvivid demo

事实上,msr.exe / msr.gcc*my open project中用于文件/文本处理的跨平台exe大约1.6MB。

Enhance script