1

How can I put 2 different texts of 1 color each? Because when I tried to put, for example // color B to a text and then I put color A to another text, I took color A, which was the code below and the one I took:

CODE:

enter image description here

.BAT:

enter image description here

Giacomo1968
  • 58,727
Ron
  • 19

2 Answers2

1

Use ANSI escape codes, as were used in terminals and printers. There's an excellent demo batch file at GitHub. View it in Notepad++ or other code editor to see special characters, such as ASCII(27), ESC. BTW, add a pause for the last line, or the command prompt showing the output will quickly disappear.

For example, in a .bat file, enter echo ▼[31mRed▼[0m, where the triangle, ▼, is meant to be ESC to see the word in red letters. In Notepad++, that can be entered from the Character Panel (or Windows Character Map or BabelMap:

Notepad++ Character Panel

Note that the string <ESC>[31m sets text after it to red, and <ESC>[0m resets text color to default.

0
@(cls & color 1f & cd. & goto %:^))
                   _______  ______    _______  _______  _______        __   __  ____
                  |       ||    _ |  |       ||       ||       |      |  | |  ||    |
                  |    ___||   | ||  |   _   ||  _____||_     _|      |  |_|  | |   |
                  |   |___ |   |_||_ |  | |  || |_____   |   |        |       | |   |
                  |    ___||    __  ||  |_|  ||_____  |  |   |        |       | |   |
                  |   |    |   |  | ||       | _____| |  |   |         |     |  |   |
                  |___|    |___|  |_||_______||_______|  |___|          |___|   |___|

%:^)
@echo off

for /f skip^=4 %%e in ('echo;prompt $E^|cmd.exe')do set "_$E=%%~e"
title <nul & title %_$E% SuperUser %_$E% Q1826937 & mode con lines=16 cols=104

findstr.exe /e "_ |" "%~f0" & echo/ & pathping 127.1 -n -q 1 -p 1500 >nul 2>nul & color

timeout /t 02 | echo\ %_$e%[0;30;32;40mThis is a sentence with %_$e%[0;1;4;34;40mcolor A%_$e%[0m & echo/
timeout /t 02 | echo/ %_$e%[0;30;32;40mThis is a sentence with %_$e%[0;1;4;31;40mcolor B%_$e%[0m & echo\
timeout /t 02 | echo\ %_$e%[0;30;32;40mThis is a sentence with %_$e%[0;1;4;34;40mcolor A%_$e%[0;30;32;40m and %_$e%[0;1;4;31;40mcolor B%_$e%[0m & echo\

enter image description here


You can get the ESC as a variable if you prefer, so regardless of the text editor, you have options for inserting this type of character and composing your lines following the different color options and formatting, also the limitations relevant to the versions/systems.


Maybe you might also be interested in:
How to clear message sent by echo command

Io-oI
  • 9,237