T3RRYT3RR0R

Batch Multicolor same line text print

Apr 9th, 2020
1,672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.45 KB | None | 0 0
  1. ::: Batch same line multi color print function. Uses ansi color codes, color variables and a macro for a call to a subroutine that
  2. ::: inserts the desired color value into the escape code, then uses a syntax of set /p to print the text without changing line.
  3. ::: use of any 3rd parameter will echo. a new line after printing the string
  4. ::: Much faster than findstring color print scripts, however only windows 10 systems support Ansi color Codes.
  5.  
  6.     @Echo off
  7.  
  8.     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
  9.         Set "Color=Call :Colorprint"
  10.  
  11.     For %%A in (red,green,yellow,dark.blue,purple,light.blue,white,grey,pink,beige,aqua,magenta,teal) do %Color% %%A %%A
  12.  
  13.     Echo.
  14.     %Color% grey "Hello World." nl
  15.     %Color% red "This is"
  16.     %Color% green "a Multicolor"
  17.     %Color% beige "text Printer"
  18.     %Color% aqua "for windows 10." nl
  19.     %Color% pink "I hope you"
  20.     %Color% light.blue "enjoy!"
  21.  
  22.     pause>nul
  23.     Exit /B
  24.  
  25. :Colorprint
  26. ::: allows strings containing problem characters to be output.
  27.     Setlocal DisableDelayedExpansion
  28.     Set "text_out=%~2"
  29.  
  30.     (
  31.     Endlocal & Set "text_out=%text_out%"
  32.     )
  33.  
  34.     Setlocal EnableDelayedExpansion
  35. REM use ansi color code in conjunction with nul syntax of set /p to print text on same line in chosen color
  36.     <nul set /P "=[!%~1!m!text_out! "
  37. REM force new line with any 3rd parameter
  38.     If not "%~3"=="" Echo.
  39.     Endlocal
  40. Exit /B
  41.  
  42. ::: End Version 1
  43.  
  44. ::: Version 2 - Shorthand with concatenated commands. Exceptionaly fast operation.
  45.     @Echo off & Cls & title %~n0
  46.  
  47.     Set "LF=Echo."
  48.    
  49.     REM Ansi Color Code reference
  50.     REM Red = 31 , Green = 32 , Yellow = 33 , dark.blue = 34 , Purple = 35 , light.Blue = 36
  51.     REM White = 0 , Grey = 90 , Pink = 91 , Beige = 93 , Aqua = 94 , Magenta = 95 , Teal = 96
  52.  
  53.     Set "A#=Call :Colorprint "
  54.     Echo.
  55.     %A#%90 "Hello World." & %A#%31 "This is" & %A#%32 "a Multicolor" & %A#%93 "text Printer" & %A#%94 "for windows 10." & %LF%
  56.     %A#%91 "I hope you" & %A#%36 "enjoy!"
  57.  
  58.     pause>nul
  59.     Exit /B
  60.  
  61. :Colorprint
  62.    
  63.     Setlocal DisableDelayedExpansion
  64.     Set "text_out=%~2"
  65.    
  66.     ( Endlocal & Set "text_out=%text_out%" )
  67.        
  68.     Setlocal EnableDelayedExpansion
  69.     (
  70. REM use ansi color code in conjunction with nul syntax of set /p to print text on same line in chosen color
  71.     <nul set /P "=[%~1m!text_out! "
  72. REM force new line with any 3rd parameter
  73.     If not "%~3"=="" Echo.
  74.     Endlocal
  75.     Exit /B
  76.     )
  77. ::: End Version 2
Advertisement
Add Comment
Please, Sign In to add comment