有没有办法在Windows命令提示符中更改一个字符的颜色?我找了这个,但只发现了如何改变整个背景和前景。有没有办法只为一个字符实现Color
命令?
由于
答案 0 :(得分:1)
没有一个简单的命令,但Carlos创建了这个函数来帮助改变字符颜色。运行批处理文件,它会显示一些颜色变化。
@Echo Off
Call :Color A "######" \n E "" C " 21 " E "!" \n B "######" \n
Pause >Nul
Exit /B
:Color
:: v21
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
If Not Exist `.7 (
Echo(|(Pause >Nul &Findstr "^" >`)
Set /P "=." >>` <Nul
For /F "delims=;" %%# In (
'"Prompt $H;&For %%_ In (_) Do Rem"') Do (
Set /P "=%%#%%#%%#" <Nul >`.3
Set /P "=%%#%%#%%#%%#%%#" <Nul >`.5
Set /P "=%%#%%#%%#%%#%%#%%#%%#" <Nul >`.7))
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
Set /P "LF=" <` &Set "LF=!LF:~0,1!"
For %%# in ("!LF!") Do For %%_ In (
\ / :) Do Set "Text=!Text:%%_=%%~#%%_%%~#!"
For /F delims^=^ eol^= %%# in ("!Text!") Do (
If #==#! EndLocal
If \==%%# (Findstr /A:%~1 . \` Nul
Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
Type `.5) Else (Echo %%#\..\`>`.dat
Findstr /F:`.dat /A:%~1 .
Type `.7))
If "\n"=="%~3" (Shift
Echo()
Shift
Shift
If ""=="%~1" Goto :Eof
Goto :__Color
答案 1 :(得分:0)
如果使用Windows 10,则可以选择使用VT100序列来实现此目的: 通过设置ESC字符开始文件
for /f "delims=" %%E in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x1B"') do (
set "ESC=%%E"
)
现在您可以使用它来内联更改颜色:
echo This is %ESC%[36ma%ESC%[0m single character
给予
This is a single character
而a是蓝色。您可以像这样制作便利宏:
set "BLUE=%ESC%[36m"
set "ENDC=%ESC%[0m"
然后像这样使用它们:
echo This is also %BLUE%a%ENDC% single character
看看here了解有关VT100的更多信息