Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::: Batch Color Print macro with additional Subroutines
- ::: This macro is much faster than other Colorprint functions I've encountered elsewhere, and outputs to specific screen Co-ordinates.
- ::: Example of output can be found here: https://stackoverflow.com/questions/4339649/how-to-have-multiple-colors-in-a-windows-batch-file/61119122#61119122
- @Echo off & CLS
- %= Establish Environment for macro Definition =%
- Setlocal DisableDelayedExpansion
- (Set LF=^
- %= NewLine =%)
- Set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
- %= cursor Positiong bookends used to prevent ansi escape code disrupting macro during definition =%
- Set "[=["
- Set "]=H"
- %= define color code values=%
- Set Red=[31m
- Set Green=[32m
- Set Yellow=[33m
- Set dark.blue=[34m
- Set Purple=[35m
- Set light.Blue=[36m
- Set White=[37m
- Set Grey=[90m
- Set Pink=[91m
- Set Beige=[93m
- Set Aqua=[94m
- Set Magenta=[95m
- Set Teal=[96m
- Set Off=[0m
- %= Defines a Fancy pause =%
- Set "@holdPos=Echo. & Call :ColorLetters [Example Completed.] & Echo.%off% & pause>nul"
- %= Color Print Macro =%
- Set @CP=for /L %%n in (1 1 2) do if %%n==2 (%\n%
- For /F "tokens=1,2,3,4 delims=, " %%G in ("!argv!") do (%\n%
- Echo(![!%%G!]!!%%I!!%%H!!Off!^&^&Endlocal%\n%
- ) %\n%
- ) ELSE setlocal enableDelayedExpansion ^& set argv=,
- Goto :main
- :ColorPrint
- For %%C in (%~1) do (
- <nul set /p=[!#A!m%%~C
- Set /A #A+=1
- IF "!#A!"=="37" (Set #A=31)
- )
- Exit /B
- %= Calls ColorPrint with each parameters as strings to be printed in the next color sequence =%
- :Colorwords
- Setlocal EnableDelayedExpansion
- Set #A=31
- For %%A in (%*) do (
- Set "Word=%%~A"
- Call :ColorPrint "!Word!"
- <nul set /p=[30m.[0m
- )
- Endlocal
- Exit /B
- %= builds a new string for the call by inserting a space between each letter in a word, colorPrint then prints each letter of a word in the next color in the sequence =%
- :ColorLetters
- Setlocal EnableDelayedExpansion
- Set #A=31
- For %%A in (%*) do (
- Set "Word=%%~A"
- For %%B In (a b c d e f g h i j k l m n o p q r s t u v w x y z . [ ] ) do Set "Word=!Word:%%~B=%%~B !
- Call :ColorPrint "!Word!"
- <nul set /p=[30m.[0m
- )
- Endlocal
- Exit /B
- :main
- Setlocal EnableDelayedExpansion
- For %%A in (red aqua beige magenta green pink light.blue grey purple teal) do (
- Set /A XP+=1
- Set /A YP+=1
- Set "output=%%A !XP!;!YP!"
- %@CP% !XP!;!YP! output %%A
- )
- %@holdPos%
- Exit /B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement