(BATCH)一行上有多种颜色

时间:2013-12-14 20:01:26

标签: batch-file

我想知道是否有办法在一行文字中使用多种颜色(例如:“Hello world”,当“Hello”为蓝色且“world”为绿色时。

我很抱歉首先要问这个愚蠢的问题......我正在进行大量的研究,其中一些没有正常工作,我希望有更简单的方法来获得我想要的东西。对不起伙计=(

1 个答案:

答案 0 :(得分:1)

@Echo Off
Call :Color 9 "hello" 

Call :Color A " world"

Pause >Nul
Exit /B


:Color
:: v20  by carlos.
:: http://www.dostips.com/forum/viewtopic.php?f=3&t=4453
:: Arguments: hexColor text [\n]
:: Supported in windows XP, 7, 8.
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Set "Text=%~2"
If Not Defined Text (Set Text=^")
Subst `: "!Temp!" >Nul &`: &Cd \
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))
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 #==#! SetLocal DisableDelayedExpansion
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" (Echo()
Goto :Eof

Here's the color function by carlos