Advertisement
T3RRYT3RR0R

Batch fast ColorPrint Macro

Apr 10th, 2020
984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.44 KB | None | 0 0
  1. ::: Batch Color Print macro with additional Subroutines
  2.  
  3. ::: This macro is much faster than other Colorprint functions I've encountered elsewhere, and outputs to specific screen Co-ordinates.
  4.  
  5. ::: Example of output can be found here: https://stackoverflow.com/questions/4339649/how-to-have-multiple-colors-in-a-windows-batch-file/61119122#61119122
  6.  
  7. @Echo off & CLS
  8. %= Establish Environment for macro Definition =%
  9.     Setlocal DisableDelayedExpansion
  10.  
  11.     (Set LF=^
  12.  
  13.  
  14.     %= NewLine =%)
  15.  
  16.     Set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
  17.  
  18. %= cursor Positiong bookends used to prevent ansi escape code disrupting macro during definition =%
  19.     Set "[=["
  20.     Set "]=H"
  21. %= define color code values=%
  22.     Set Red=
  23.     Set Green=
  24.     Set Yellow=
  25.     Set dark.blue=
  26.     Set Purple=
  27.     Set light.Blue=
  28.     Set White=
  29.     Set Grey=
  30.     Set Pink=
  31.     Set Beige=
  32.     Set Aqua=
  33.     Set Magenta=
  34.     Set Teal=
  35.     Set Off=
  36.    
  37. %= Defines a Fancy pause =%
  38.     Set "@holdPos=Echo. & Call :ColorLetters [Example Completed.] & Echo.%off% & pause>nul"
  39.  
  40. %= Color Print Macro =%
  41.     Set @CP=for /L %%n in (1 1 2) do if %%n==2 (%\n%
  42.         For /F "tokens=1,2,3,4 delims=, " %%G in ("!argv!") do (%\n%
  43.             Echo(![!%%G!]!!%%I!!%%H!!Off!^&^&Endlocal%\n%
  44.         ) %\n%
  45.     ) ELSE setlocal enableDelayedExpansion ^& set argv=,
  46.  
  47.     Goto :main
  48.  
  49. :ColorPrint
  50.     For %%C in (%~1) do (
  51.         <nul set /p=[!#A!m%%~C
  52.         Set /A #A+=1
  53.         IF "!#A!"=="37" (Set #A=31)
  54.     )
  55. Exit /B
  56.  
  57. %= Calls ColorPrint with each parameters as strings to be printed in the next color sequence =%
  58. :Colorwords
  59.     Setlocal EnableDelayedExpansion
  60.     Set #A=31
  61.     For %%A in (%*) do (
  62.         Set "Word=%%~A"
  63.         Call :ColorPrint "!Word!"
  64.         <nul set /p=.
  65.     )
  66.     Endlocal
  67. Exit /B
  68.  
  69. %= 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 =%
  70. :ColorLetters
  71.     Setlocal EnableDelayedExpansion
  72.     Set #A=31
  73.     For %%A in (%*) do (
  74.         Set "Word=%%~A"
  75.         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 !
  76.         Call :ColorPrint "!Word!"
  77.         <nul set /p=.
  78.     )
  79.     Endlocal
  80. Exit /B
  81.  
  82. :main
  83.     Setlocal EnableDelayedExpansion
  84.     For %%A in (red aqua beige magenta green pink light.blue grey purple teal) do (
  85.         Set /A XP+=1
  86.         Set /A YP+=1
  87.         Set "output=%%A !XP!;!YP!"
  88.         %@CP% !XP!;!YP! output %%A
  89.     )
  90.     %@holdPos%
  91. Exit /B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement