Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::: Batch same line multi color print function. Uses ansi color codes, color variables and a macro for a call to a subroutine that
- ::: inserts the desired color value into the escape code, then uses a syntax of set /p to print the text without changing line.
- ::: use of any 3rd parameter will echo. a new line after printing the string
- ::: Much faster than findstring color print scripts, however only windows 10 systems support Ansi color Codes.
- @Echo off
- Set /A Red=31,Green=32,Yellow=33,dark.blue=34,Purple=35,light.Blue=36,White=0,Grey=90,Pink=91,Beige=93,Aqua=94,Magenta=95,Teal=96 & Rem on Black Background
- Set "Color=Call :Colorprint"
- For %%A in (red,green,yellow,dark.blue,purple,light.blue,white,grey,pink,beige,aqua,magenta,teal) do %Color% %%A %%A
- Echo.
- %Color% grey "Hello World." nl
- %Color% red "This is"
- %Color% green "a Multicolor"
- %Color% beige "text Printer"
- %Color% aqua "for windows 10." nl
- %Color% pink "I hope you"
- %Color% light.blue "enjoy!"
- pause>nul
- Exit /B
- :Colorprint
- ::: allows strings containing problem characters to be output.
- Setlocal DisableDelayedExpansion
- Set "text_out=%~2"
- (
- Endlocal & Set "text_out=%text_out%"
- )
- Setlocal EnableDelayedExpansion
- REM use ansi color code in conjunction with nul syntax of set /p to print text on same line in chosen color
- <nul set /P "=[!%~1!m!text_out! [0m"
- REM force new line with any 3rd parameter
- If not "%~3"=="" Echo.
- Endlocal
- Exit /B
- ::: End Version 1
- ::: Version 2 - Shorthand with concatenated commands. Exceptionaly fast operation.
- @Echo off & Cls & title %~n0
- Set "LF=Echo."
- REM Ansi Color Code reference
- REM Red = 31 , Green = 32 , Yellow = 33 , dark.blue = 34 , Purple = 35 , light.Blue = 36
- REM White = 0 , Grey = 90 , Pink = 91 , Beige = 93 , Aqua = 94 , Magenta = 95 , Teal = 96
- Set "A#=Call :Colorprint "
- Echo.
- %A#%90 "Hello World." & %A#%31 "This is" & %A#%32 "a Multicolor" & %A#%93 "text Printer" & %A#%94 "for windows 10." & %LF%
- %A#%91 "I hope you" & %A#%36 "enjoy!"
- pause>nul
- Exit /B
- :Colorprint
- Setlocal DisableDelayedExpansion
- Set "text_out=%~2"
- ( Endlocal & Set "text_out=%text_out%" )
- Setlocal EnableDelayedExpansion
- (
- REM use ansi color code in conjunction with nul syntax of set /p to print text on same line in chosen color
- <nul set /P "=[%~1m!text_out! [0m"
- REM force new line with any 3rd parameter
- If not "%~3"=="" Echo.
- Endlocal
- Exit /B
- )
- ::: End Version 2
Advertisement
Add Comment
Please, Sign In to add comment