如何在Windows批处理文件中有多种颜色?我想知道是否有可能在Windows批处理文件中的同一行中有不同颜色的文本,例如,如果它说echo hi world我希望“嗨”是一种颜色,“世界”是另一种颜色。也许我可以将color命令设置为变量:set color1= color 2
set color9= color A然后将它们部署在同一条线上,同时echo hi world但我不知道我该怎么做。
3 回答
LEATH
TA贡献1936条经验 获得超7个赞
@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"
)
echo say the name of the colors, don't read
call :ColorText 0a "blue"
call :ColorText 0C "green"
call :ColorText 0b "red"
echo(
call :ColorText 19 "yellow"
call :ColorText 2F "black"
call :ColorText 4e "white"
goto :eof
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof<backspace><backspace>.
所有字符都是有效的。
@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"
)
rem Prepare a file "X" with only one dot
<nul > X set /p ".=."
call :color 1a "a"
call :color 1b "b"
call :color 1c "^!<>&| %%%%"*?"
exit /b
:color
set "param=^%~2" !
set "param=!param:"=\"!"
findstr /p /A:%1 "." "!param!\..\X" nul
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
exit /b\..\
收到一只叮咚
TA贡献1821条经验 获得超5个赞
call :PrintBright Something Something (do actual batch stuff here) call :PrintBright Done! goto :eof :PrintBright powershell -Command Write-Host "%*" -foreground "White"
- 3 回答
- 0 关注
- 1980 浏览
添加回答
举报
0/150
提交
取消
