I have a batch script that can display two or more colors of text on the same line in the command prompt. (below)
@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
echo say the name of the colors, don't read
call :ColorText 0a "blue"
call :ColorText 0C "green"
call :ColorText 0b "red"
echo(
call :ColorText 19 "yellow"
call :ColorText 2F "black"
call :ColorText 4e "white"
pause
goto :eof
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
however that text must be entered in the script before-hand by editing the batch file with notepad. i’d like to be able to just open the command prompt and type something like:
cecho /blue hello world!
or
cecho blue "hello world!"
or something simple where i can supply the color (preferably as a string not a color code) and text (with or without quotations).
I don’t know if this is of any use to you but it is possible to save this part of the script:
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
(from “:ColorText” to the end of the script)
and save it as “ColorText.bat” in “C:\windows\system32”. Then in the other half of the script, everywhere you see:
call :ColorText
Change it to:
call ColorText
(Omit the colons)
And save that script as colors.bat in “C:\windows\system32”. Then open the command prompt and type “colors”. This is how i want it to function; no additional commands, setup scripts, file paths; just a simple one or two word function with all that messy code going on in the background (out of sight). However the above idea still won’t let me specify my own text or color from the command prompt…. any ideas?
EDIT: Take 3
Create the folder
C:\Utilities. Add this folder to your Path environment variable so Windows looks there for additional scripts and commands.Do not mess these next steps up!
;C:\Utilities, including the semi-colon. Do not remove any other text.Breathe easy again.
Take the script following the
:ColorTextlabel and save it toC:\Utilities\cecho.bat. Put an@in front ofecho offto preventecho offfrom appearing during the script.CEcho.bat
Now you can use this command from any command line or script. Usage:
Edit: In response to your comment:
You can use words for colours by inserting the following lines and replacing the
FindStrline:Now you can type:
Note that the color word is case sensitive.