T3RRYT3RR0R

Color Selection and Printing.

Jan 3rd, 2020
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.25 KB | None | 0 0
  1. @ECHO OFF
  2. MODE CON: cols=110 lines=40
  3.  
  4. REM - Required
  5. SETLOCAL EnableDelayedExpansion
  6.  
  7. REM - Used in Function to Remove the Prompt.
  8. for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  9.   set "DEL=%%a"
  10. )
  11.  
  12. REM - Use output of choice to assign Variables for Color Codes and Display info with TESTCC function
  13. :ColorSelect
  14. cls
  15. CHOICE /N /C:abcdef0123456789 /M "Select Background Color: A B C D E F 0 1 2 3 4 5 6 7 8 9"
  16. FOR %%a in ("!ERRORLEVEL!") do (
  17. CALL :TESTCC %%a bgcode bgcolor
  18. )
  19.  
  20. CHOICE /N /C:abcdef0123456789 /M "Select Foreground Color: A B C D E F 0 1 2 3 4 5 6 7 8 9"
  21. FOR %%a in ("!ERRORLEVEL!") do (
  22. CALL :TESTCC %%a fgcode fgcolor
  23. )
  24.  
  25. IF "!fgcode!"=="!bgcode!" (
  26.     ECHO Colors Cannot Match.
  27.     Timeout 2 > nul
  28.     GOTO ColorSelect
  29. )
  30.  
  31. cls
  32.  
  33. REM - Display color code information, in plain colors and in selected colors.
  34. ECHO Color !bgcode!!fgcode! Foreground Code [!fgcode!] Color [!fgcolor!] Background Code [!bgcode!] Color [!bgcolor!]
  35. CALL :colorize "!bgcode!!fgcode!" "Color !bgcode!!fgcode! Foreground Code [!fgcode!] Color [!fgcolor!] Background Code [!bgcode!] Color [!bgcolor!]"
  36. ECHO.
  37. pause
  38. GOTO ColorSelect
  39.  
  40. :TESTCC
  41. IF %~1==1 Set "%~2=a" && Set "%~3=Light Green"
  42. IF %~1==2 Set "%~2=b" && Set "%~3=Light Aqua"
  43. IF %~1==3 Set "%~2=c" && Set "%~3=Light Red"
  44. IF %~1==4 Set "%~2=d" && Set "%~3=Light Purple"
  45. IF %~1==5 Set "%~2=e" && Set "%~3=Light Yellow"
  46. IF %~1==6 Set "%~2=f" && Set "%~3=Light White"
  47. IF %~1==7 Set "%~2=0" && Set "%~3=Black"
  48. IF %~1==8 Set "%~2=1" && Set "%~3=Blue"
  49. IF %~1==9 Set "%~2=2" && Set "%~3=Green"
  50. IF %~1==10 Set "%~2=3" && Set "%~3=Aqua"
  51. IF %~1==11 Set "%~2=4" && Set "%~3=Red"
  52. IF %~1==12 Set "%~2=5" && Set "%~3=Purple"
  53. IF %~1==13 Set "%~2=6" && Set "%~3=Yellow"
  54. IF %~1==14 Set "%~2=7" && Set "%~3=White"
  55. IF %~1==15 Set "%~2=8" && Set "%~3=Grey"
  56. IF %~1==16 Set "%~2=9" && Set "%~3=light Blue"
  57. exit /b
  58.  
  59. REM - Colorize function. To use: CALL colorcode "String in quotes"
  60. REM - Function works by creating a temporary file named using the string and Printing it Colored with FINDSTR
  61. :Colorize
  62. IF NOT EXIST "%TEMP%\colorize" md "%TEMP%\colorize"
  63. PUSHD %TEMP%\colorize
  64. <nul set /p ".=%DEL%" > "%~2"
  65. findstr /v /a:%1 /R "^$" "%~2" nul
  66. del "%~2" > nul 2>&1
  67. POPD
  68. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment