@ECHO OFF
MODE CON: cols=110 lines=40
REM - Required
SETLOCAL EnableDelayedExpansion
REM - Used in Colorize Function to Remove the Prompt.
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
REM - Code selection Function. Choice is used to select Colorcodes Independantly for FG/BG
:ColorSelect
cls
CHOICE /N /C:abcdef0123456789 /M "Select Background Color: A B C D E F 0 1 2 3 4 5 6 7 8 9"
CALL :TESTCC !ERRORLEVEL! bgcode bgcolor
REM - Three parameters get sent to :TESTCC with Call. <errorlevel> <codeposition> <positioncolor>
REM - The first paramater has a value that gets tested, the other 2 parameters are Variables to be Defined
REM c- in :TESTCC using the result of If checks on Parameter 1.
CHOICE /N /C:abcdef0123456789 /M "Select Foreground Color: A B C D E F 0 1 2 3 4 5 6 7 8 9"
CALL :TESTCC !ERRORLEVEL! fgcode fgcolor
REM - Test that matching color codes have not been selected
IF "!bgcode!"=="!fgcode!" (
ECHO Colors Cannot Match.
Timeout 2 > nul
GOTO ColorSelect
)
cls
- When you echo something to the console standard output - stdout, you choose what to say. As long as any variables you expand are defined, you can display their information
- It's really up to you to imagine what information you wish to
display, and figuring out what input or variables you need to get or set to achieve the desired result.
REM - Display in standard Colors, for those times Colors are hard to distinguish
REM - Calls the Function to Print the message in the Selected colors.
ECHO Color !bgcode!!fgcode! Background Code [!bgcode!] Color [!bgcolor!] Foreground Code [!fgcode!] Color [!fgcolor!]
CALL :colorize "!bgcode!!fgcode!" "Color !bgcode!!fgcode! Background Code [!bgcode!] Color [!bgcolor!] Foreground Code [!fgcode!] Color [!fgcolor!]"
ECHO.
pause
GOTO ColorSelect
REM - Uses Parameters Sent by Call to Define Variables for Use and Display
:TESTCC
IF %~1==1 Set "%~2=a" && Set "%~3=Light Green"
IF %~1==2 Set "%~2=b" && Set "%~3=Light Aqua"
IF %~1==3 Set "%~2=c" && Set "%~3=Light Red"
IF %~1==4 Set "%~2=d" && Set "%~3=Light Purple"
IF %~1==5 Set "%~2=e" && Set "%~3=Light Yellow"
IF %~1==6 Set "%~2=f" && Set "%~3=Light White"
IF %~1==7 Set "%~2=0" && Set "%~3=Black"
IF %~1==8 Set "%~2=1" && Set "%~3=Blue"
IF %~1==9 Set "%~2=2" && Set "%~3=Green"
IF %~1==10 Set "%~2=3" && Set "%~3=Aqua"
IF %~1==11 Set "%~2=4" && Set "%~3=Red"
IF %~1==12 Set "%~2=5" && Set "%~3=Purple"
IF %~1==13 Set "%~2=6" && Set "%~3=Yellow"
IF %~1==14 Set "%~2=7" && Set "%~3=White"
IF %~1==15 Set "%~2=8" && Set "%~3=Grey"
IF %~1==16 Set "%~2=9" && Set "%~3=light Blue"
exit /b 0
REM - Colorize function. To use:
REM - CALL :Colorize colorcodes "String in quotes"
REM - Function works by creating a temporary file named using the string and Printing it Colored with FINDSTR
REM - Note: Cannot use strings with characters reserved against use in filenames. Strips trailing Spaces.
Color Function Used from Jebs answer here. Other, Improved methods can be found there.
:Colorize
IF NOT EXIST "%TEMP%\colorize" md "%TEMP%\colorize"
PUSHD %TEMP%\colorize
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
POPD
goto :eof
There's many, many different ways of displaying information, It's just a matter of choosing the means.