我知道color bf
命令设置了整个命令行窗口的颜色,但我想用不同的颜色打印一行。
发布于 2014-04-15 08:09:45
您可以使用要打印的单词的名称创建文件,使用可以彩色打印的findstr,然后擦除该文件。试一下这个例子:
@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 :ColorText 0a "green"
call :ColorText 0C "red"
call :ColorText 0b "cyan"
echo(
call :ColorText 19 "blue"
call :ColorText 2F "white"
call :ColorText 4e "yellow"
goto :eof
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
运行color /?
以获取颜色列表。
发布于 2012-01-19 11:49:27
您可以使用ANSICON在旧版本的Windows中启用ANSI终端代码。我在Windows XP和Windows 7中使用过32位和64位版本。
发布于 2015-02-09 13:00:46
我之所以考虑这个问题,是因为我想向Win7批处理文件引入一些简单的文本颜色。这就是我想出来的。谢谢你的帮助。
@echo off
cls && color 08
rem .... the following line creates a [DEL] [ASCII 8] [Backspace] character to use later
rem .... All this to remove [:]
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "DEL=%%a")
echo.
<nul set /p="("
call :PainText 09 "BLUE is cold" && <nul set /p=") ("
call :PainText 02 "GREEN is earth" && <nul set /p=") ("
call :PainText F0 "BLACK is night" && <nul set /p=")"
echo.
<nul set /p="("
call :PainText 04 "RED is blood" && <nul set /p=") ("
call :PainText 0e "YELLOW is pee" && <nul set /p=") ("
call :PainText 0F "WHITE all colors"&& <nul set /p=")"
goto :end
:PainText
<nul set /p "=%DEL%" > "%~2"
findstr /v /a:%1 /R "+" "%~2" nul
del "%~2" > nul
goto :eof
:end
echo.
pause
https://stackoverflow.com/questions/2048509
复制相似问题