Different Colours in Batch Files
by Prof. Pickle in Circuits > Computers
42297 Views, 7 Favorites, 0 Comments
Different Colours in Batch Files
Everyone, with the help of g-one, I have created a function that you can install into your windows/system32 folder to get more than one colour in batch files.
Copy and paste the following code and save it as ncol.bat (this is very important that you save it exactly like that).
@echo off
setlocal
if "%~1"=="/?" (
echo.
echo ncol ["Text"] [Colour]
echo.
echo "Text" - The text you want displayed in another colour.
echo Remember that spaces cannot be added if you don't put the text in
echo quotation marks (""^).
echo.
echo Colour - The hexadecimal colour code that you want the text to be changed into.
echo For more information of colour codes, see "color /?"
echo.
exit /b
)
for /f "delims=#" %%i in ('"prompt #$H# &for %%b in (1) do rem"') do set "bs=%%i"
"%~1.@" set /p "=.%bs%%bs%%bs%%bs%"
findstr /p /a:%2 . "*.@"
endlocal
del "*.@"
@echo on
@exit /b
Once that is done, head over to your windows system32 folder and save it in there (C:\Windows\System32)
Read on for instructions...
Copy and paste the following code and save it as ncol.bat (this is very important that you save it exactly like that).
setlocal
if "%~1"=="/?" (
echo.
echo ncol ["Text"] [Colour]
echo.
echo "Text" - The text you want displayed in another colour.
echo Remember that spaces cannot be added if you don't put the text in
echo quotation marks (""^).
echo.
echo Colour - The hexadecimal colour code that you want the text to be changed into.
echo For more information of colour codes, see "color /?"
echo.
exit /b
)
for /f "delims=#" %%i in ('"prompt #$H# &for %%b in (1) do rem"') do set "bs=%%i"
findstr /p /a:%2 . "*.@"
endlocal
del "*.@"
@echo on
@exit /b
Once that is done, head over to your windows system32 folder and save it in there (C:\Windows\System32)
Read on for instructions...
Instructions
Ok, how to use this function.
Firstly, type it in as you would any command "ncol"
The first parameter is the text you want converted.
The second parameter is the colour (must be correspondent to the colour command).
Example:
ncol "Hello" 10
Would output:
Just try it!
Note: If you have spaces, you must use quotation marks ("").
P.S: type in "ncol /?" for more help.
Unfortunately, special characters cannot be converted yet... (~!@#$%^&*()_+=-/,.<>":;'[]\{}|`)
And there is a little glitch with it, but other than that... It's good to go!
--EDIT--
To add more colors onto one line, use the && operator. E.g: ncol "Hello " 12 && ncol "there" 23
would output "Hello " in one color, and "there" in another.
Firstly, type it in as you would any command "ncol"
The first parameter is the text you want converted.
The second parameter is the colour (must be correspondent to the colour command).
Example:
ncol "Hello" 10
Would output:
Hello
Just try it!
Note: If you have spaces, you must use quotation marks ("").
P.S: type in "ncol /?" for more help.
Unfortunately, special characters cannot be converted yet... (~!@#$%^&*()_+=-/,.<>":;'[]\{}|`)
And there is a little glitch with it, but other than that... It's good to go!
--EDIT--
To add more colors onto one line, use the && operator. E.g: ncol "Hello " 12 && ncol "there" 23
would output "Hello " in one color, and "there" in another.