Colour code TEXT in a batch file!

Page 1 of 2 12 LastLast

  1. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
       #1

    Colour code TEXT in a batch file!


    Good afternoon,

    I have written a batch file which works great!
    However, I would like to colour several pieces of text within the batch file.
    I have spent a LONG time researching this on Google and I am almost there.

    This is what I have at the top of the code...

    Code:
    @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"
    )
    This is what I have as an example that I want to colour red [which it does]...

    Code:
    call :ColorText 0c "     IMPORTANT - Numbers 2 blah blah."
    call :ColorText 0c "                    If you blah blah!" & set /p ".= " < nul
    echo.
    This is what I have as the :ColorText code...

    Code:
    :ColorText
    rem echo off
    <nul set /p ".=%DEL%" > "%~2"
    findstr /v /a:%1 /R "^$" "%~2" nul
    del "%~2" > nul 2>&1
    GOTO :EOF
    The questions I have are...

    [1] If I put a colon [:] after Important, is doesn't work, hence the dash [-]?
    [2] Why will it not show the exclamation [!] at the end of the line although it is there?
    [3] Why will it not show the full stop [.] at the end of the line although it is there?
    [4] Is there a way to split the call :ColorText 0c " IMPORTANT - Numbers 2 blah blah." over two lines so it makes it esaier to read and also lines up in the script with the code below it. I tried several options, all to no avail!
    [5] As you see from the middle piece of code, the Numbers 2 and If you are not lined up, but they are in the consol!
    [6] Why doesn't it put a blank row after even though there is a echo. after the text to be coloured, but it does if I use & set /p ".= " < nul end & echo..
    [7] It will also not accept forward slash [/]!

    Thanks in advance.
    Last edited by Paul Black; 27 Apr 2019 at 10:28.
      My Computer


  2. Posts : 3,785
    win 8 32 bit
       #2

    Does color 2 work


    0 = Black 8 = Gray 1 = Blue 9 = Light Blue 2 = Green A = Light Green 3 = Aqua B = Light Aqua 4 = Red C = Light Red 5 = Purple D = Light Purple 6 = Yellow E = Light Yellow 7 = White F = Bright White
      My Computer


  3. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
    Thread Starter
       #3

    Hi samuria, thanks for the reply,

    samuria said:
    Does color 2 work

    0 = Black 8 = Gray 1 = Blue 9 = Light Blue 2 = Green A = Light Green 3 = Aqua B = Light Aqua 4 = Red C = Light Red 5 = Purple D = Light Purple 6 = Yellow E = Light Yellow 7 = White F = Bright White
    The colour is not the problem!

    I think it is the parameters that are stopping what I have posted in the numbered comments/questions!
      My Computer


  4. Posts : 31,249
    Windows 11 Pro x64 [Latest Release and Release Preview]
       #4

    Paul, the Command line DOS language used to write batch files has a number of "protected" or System Characters. There are ways to get around these limitations

    Take a look here as a starting point to future research Batch files - Escape Characters also check the left menu for good tips and suggestions for Batch scripting

    You may also find a specific editor better for writing code than Notepad Notepad++ is an old one Notepad++ v7.6.6 - Current Version that can be setup to format code and comments to show more clearly

    EDIT

    Batch Editor download | SourceForge.net is an opensource specific Batch File Editor
      My Computers


  5. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
    Thread Starter
       #5

    Hi Barman58, thanks for the reply, it is appreciated!

    Barman58 said:
    Paul, the Command line DOS language used to write batch files has a number of "protected" or System Characters. There are ways to get around these limitations.
    I have had a quick look at the batch link you posted but I need to look at it in more detail.

    I only have about a dozen lines of text that I actually want to colour. The thing is, I need exclamation [!], colon [:] and full stop [.] to be accepted within the colour parameters because they are included in the lines of text which are at present after the echo. It is harder to achieve this than I thought it would be.
      My Computer


  6. Posts : 31,249
    Windows 11 Pro x64 [Latest Release and Release Preview]
       #6

    You could try a single quote as a delimiter either end of the text string that should designate everything between the quotes as a part of the text or maybe use the ASCII code for the symbols with a delimiter - you may need to use one of the modifiers mentioned in the link -

    I wish I could remember how exactly I wrote the Batch Files back in the 80's - used to produce menus for old pre-windows systems to allow the typists to access various programs, without needing to remember the names
      My Computers


  7. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
    Thread Starter
       #7

    Hi Barman58,

    Barman58 said:
    You could try a single quote as a delimiter either end of the text string that should designate everything between the quotes as a part of the text or maybe use the ASCII code for the symbols with a delimiter - you may need to use one of the modifiers mentioned in the link.
    Thanks again for the reply.

    I have tried numerous combinations of characters etc to try and get this working. I just can't seem to get the correct delimiter!
    I will look at the link again later and do some more investigating!
    I could live with just getting the full stop to work at the end of the sentences!
      My Computer


  8. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
    Thread Starter
       #8

    Hi everyone,

    I am still no nearer to resolving this!
    Has anyone got any other ideas please?

    Thanks in advance.
      My Computer


  9. Posts : 16,149
    7 X64
       #9

    As far as I know, what you are trying to do isn't natively supported.Unless you want to use some kind of software add on, you are wasting your time.
      My Computers


  10. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
    Thread Starter
       #10

    Hi SIW2,

    SIW2 said:
    As far as I know, what you are trying to do isn't natively supported. Unless you want to use some kind of software add on, you are wasting your time.
    OK, thanks SIW2, that is good enough for me. It is not important but it would have been nice! I don't want to use some kind of software add on so I will mark this thread as solved.
    Thanks again .
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 01:03.
Find Us