2

I am a newbie here on this website and I would like to ask you how to apply multiple colors by line (or column maybe?) in CMD. Feel free to edit the codes below, I would also like the color of the words to be similar like the classic Google Chrome colors.

cls
@echo off
color 0a
echo.
echo.
echo.
echo                                                                                                      ,,
echo                                                         .g8"""bgd                                  `7MM
echo                                                        .dP'    `M                                    MM
echo                                                        dm'      `    ,pW"Wq.    ,pW"Wq.    .P"Ybmmm  MM   .gP"Ya
echo                                                        MM           6W'   `Wb  6W'   `Wb  :MI  I8    MM  ,M'   Yb
echo                                                        MM.   `7MMF' 8M     MB  8M     MB   Wmmmp"    MM  8M""""""
echo                                                        `Mb     MM   YA.   ,A9  YA.   ,A9  8M         MM  YM.    .
echo                                                         `"bmmmdPY    `Ybmd9'    `Ybmd9'    YMMMMMb .JMML. `Mbmmd'
echo                                                                                           6'    dP
echo                                                                                            Ybmmmd'
echo.
echo.
echo.
pause>nul
Stephan
  • 47,723
  • 10
  • 50
  • 81
CMD.EXE
  • 23
  • 4
  • 1
    [choose one](https://stackoverflow.com/search?q=%5Bbatch-file%5D+different+colors+in+one+line) – Stephan Aug 06 '20 at 12:44
  • If you want a color function that still works across older versions of Windows you can use [Color function](https://www.dostips.com/forum/viewtopic.php?t=4881). Most of the native solutions make use of the `FINDSTR` commands ability to color its output. – Squashman Aug 06 '20 at 13:29

2 Answers2

5

Here is a one way, you'll have to figure out the color refs yourself though, I just added these colors as examples:

@echo off
for /F %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a"
cls
echo(
echo(
echo(
echo                                                                                             %ESC%[90m,,%ESC%[0m
echo                                                %ESC%[91m.g8"""bgd%ESC%[0m                                  %ESC%[90m`7MM%ESC%[0m
echo                                                %ESC%[91m.dP'    `M%ESC%[0m                                    %ESC%[90mMM%ESC%[0m
echo                                                %ESC%[91mdm'      `%ESC%[0m    %ESC%[92m,pW"Wq.    ,pW"Wq.%ESC%[0m    %ESC%[90m.P"Ybmmm  MM   .gP"Ya%ESC%[0m
echo                                                %ESC%[91mMM%ESC%[0m           %ESC%[92m6W'   `Wb  6W'   `Wb%ESC%[0m  %ESC%[90m:MI  I8    MM  ,M'   Yb%ESC%[0m
echo                                                %ESC%[91mMM.   `7MMF'%ESC%[0m %ESC%[92m8M     MB  8M     MB%ESC%[0m   %ESC%[90mWmmmp"    MM  8M""""""%ESC%[0m
echo                                                %ESC%[91m`Mb     MM%ESC%[0m   %ESC%[92mYA.   ,A9  YA.   ,A9%ESC%[0m  %ESC%[90m8M         MM  YM.    .%ESC%[0m
echo                                                %ESC%[91m`"bmmmdPY%ESC%[0m    %ESC%[92m`Ybmd9'    `Ybmd9'%ESC%[0m    %ESC%[90mYMMMMMb .JMML. `Mbmmd'%ESC%[0m
echo                                                                                   %ESC%[90m6'    dP%ESC%[0m
echo                                                                                    %ESC%[90mYbmmmd'%ESC%[0m
echo(
echo(
echo(
pause>nul

Result: enter image description here

EDIT

Here is a reference to the ansi color escape codes.

Gerhard
  • 18,114
  • 5
  • 20
  • 38
2

Here's a somewhat neater looking version of the ANSI escape code method, already suggested by Gerhard.

@Echo Off
SetLocal EnableExtensions
For /F %%G In ('Echo Prompt $E ^| "%__AppDir__%cmd.exe"') Do Set "ESC=%%G"
ClS
Echo=
Echo=
Echo=
Echo                             %ESC%[92m                                                ,,
Echo                             %ESC%[94m  .g8"""bgd  %ESC%[92m                                 `7MM
Echo                             %ESC%[94m .dP'    `M  %ESC%[92m                                   MM
Echo                             %ESC%[94m dm'      `  %ESC%[91m  ,pW"Wq.  %ESC%[93m  ,pW"Wq. %ESC%[94m  .P"Ybmmm %ESC%[92m   MM  %ESC%[91m  .gP"Ya
Echo                             %ESC%[94m MM          %ESC%[91m 6W'   `Wb %ESC%[93m 6W'   `Wb%ESC%[94m :MI  I8   %ESC%[92m   MM  %ESC%[91m ,M'   Yb
Echo                             %ESC%[94m MM.   `7MMF'%ESC%[91m 8M     MB %ESC%[93m 8M     MB%ESC%[94m  Wmmmp"   %ESC%[92m   MM  %ESC%[91m 8M""""""
Echo                             %ESC%[94m `Mb     MM  %ESC%[91m YA.   ,A9 %ESC%[93m YA.   ,A9%ESC%[94m 8M        %ESC%[92m   MM  %ESC%[91m YM.    .
Echo                             %ESC%[94m  `"bmmmdPY  %ESC%[91m  `Ybmd9'  %ESC%[93m  `Ybmd9' %ESC%[94m  YMMMMMb  %ESC%[92m .JMML.%ESC%[91m  `Mbmmd'
Echo                             %ESC%[94m                                   6'    dP
Echo                                                                 Ybmmmd' %ESC%[0m
Echo=
Echo=
Echo=
Pause 1> NUL

You could even mess around with it to put it into a bright white box, for instance:

@Echo Off
SetLocal EnableExtensions
For %%# In (BG FG)Do Set "%%#="
For /F %%# In ('%__AppDir__%WindowsPowerShell\v1.0\powershell.exe -NoP ^
    "$Console=(Get-Host).UI.RawUI;Switch($Console.BackgroundColor," ^
    "$Console.ForegroundColor){'Black'{40}'DarkBlue'{44}'DarkGreen'{42}" ^
    "'DarkCyan'{46}'DarkRed'{41}'DarkMagenta'{45}'DarkYellow'{43}'Gray'{47}" ^
    "'DarkGray'{100}'Blue'{104}'Green'{102}'Cyan'{106}'Red'{101}" ^
    "'Magenta'{105}'Yellow'{103}'White'{107}}" 2^>NUL')Do If Not Defined BG (
    Set "BG=%%#")Else Set "FG=%%#"
For /F %%G In ('Echo Prompt $E ^| "%__AppDir__%cmd.exe"') Do Set "ESC=%%G"
ClS
Echo=
Echo=
Echo=
Echo                             %ESC%[92;107m                                                ,,            %ESC%[%FG%;%BG%m
Echo                             %ESC%[94;107m  .g8"""bgd  %ESC%[92m                                 `7MM            %ESC%[%FG%;%BG%m
Echo                             %ESC%[94;107m .dP'    `M  %ESC%[92m                                   MM            %ESC%[%FG%;%BG%m
Echo                             %ESC%[94;107m dm'      `  %ESC%[91m  ,pW"Wq.  %ESC%[93m  ,pW"Wq. %ESC%[94m  .P"Ybmmm %ESC%[92m   MM  %ESC%[91m  .gP"Ya  %ESC%[%FG%;%BG%m
Echo                             %ESC%[94;107m MM          %ESC%[91m 6W'   `Wb %ESC%[93m 6W'   `Wb%ESC%[94m :MI  I8   %ESC%[92m   MM  %ESC%[91m ,M'   Yb %ESC%[%FG%;%BG%m
Echo                             %ESC%[94;107m MM.   `7MMF'%ESC%[91m 8M     MB %ESC%[93m 8M     MB%ESC%[94m  Wmmmp"   %ESC%[92m   MM  %ESC%[91m 8M"""""" %ESC%[%FG%;%BG%m
Echo                             %ESC%[94;107m `Mb     MM  %ESC%[91m YA.   ,A9 %ESC%[93m YA.   ,A9%ESC%[94m 8M        %ESC%[92m   MM  %ESC%[91m YM.    . %ESC%[%FG%;%BG%m
Echo                             %ESC%[94;107m  `"bmmmdPY  %ESC%[91m  `Ybmd9'  %ESC%[93m  `Ybmd9' %ESC%[94m  YMMMMMb  %ESC%[92m .JMML.%ESC%[91m  `Mbmmd' %ESC%[%FG%;%BG%m
Echo                             %ESC%[94;107m                                   6'    dP                   %ESC%[%FG%;%BG%m
Echo                             %ESC%[94;107m                                    Ybmmmd'                   %ESC%[%FG%;%BG%m
Echo=
Echo=
Echo=
Pause 1> NUL
GoTo :EOF

This above method leverages to determine, and create variables using the current console foreground and background colors. This ensures that they are reset correctly after the color changed image lines have been processed. (Of course the script writer could just define known colors, right from the outset)

I will add however, that the command line is supposed to be for typing commands and reading text output, not for displaying unnecessary childish images and colors. If you want a GUI, build a GUI program, not a console one.

Compo
  • 30,301
  • 4
  • 20
  • 32
  • Yeah, for the very reason _"..not for displaying unnecessary childish images and colors"_ I did not still format the code to look neat, I just could not find the inspiration :) – Gerhard Aug 06 '20 at 15:20
  • Obviously this example is just for fun/learning, but I hope you aren't implying that using colors in "real" command line applications is *always* unnecessary/childish. – 0x5453 Aug 06 '20 at 15:20
  • it works perfectly, thank you Mr. Compo! – CMD.EXE Aug 06 '20 at 15:23
  • @CMD.EXE you can mark the answer as correct by selecting the grey tick mark to the left of the question, if you feel it suited your requirements. – Gerhard Aug 06 '20 at 15:52
  • @Gerhard, I agree that there was no need for you to extend your example for the purposes of answering the question itself. I only expanded upon it really, to make clear that it is not necessary to use `%ESC%[0m` after each color sequence; thus making the building of the 'graphic' even more difficult due to obfuscation. **0x5453**, my comment does not imply anything, it makes an absolute statement. If you, or others interpret it otherwise, the implication is made by you or them, not by me. – Compo Aug 06 '20 at 15:56
  • Yeah, I hear you and agree. – Gerhard Aug 06 '20 at 16:13