2013-12-14 12 views
1

我想知道是否有一種方法可以在文本的一行上使用多種顏色(例如:「Hello world」,當「Hello」是藍色,「world」是綠色時(BATCH)在一條線上的多種顏色

我很抱歉在第一時間提出這個愚蠢的問題......我正在做大量的研究,其中一些沒有正常工作,我希望有更簡單的方法來獲得我想要的東西。 (

回答

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

+0

驚人!!! +1卡洛斯 – SachaDee