Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Multiple Colours.  (Read 6753 times)

0 Members and 1 Guest are viewing this topic.

Jacob

    Topic Starter


    Hopeful

    Thanked: 1
    • Experience: Expert
    • OS: Windows XP
    Multiple Colours.
    « on: November 02, 2008, 09:04:51 AM »
    I have always wondered, if it is possible to display multiple colours within MS-DOS.
    I know perl can do this (I think). But then if a 3rd party ran the file, without perl installed, would it work?
    Any help or information is greatly appreciated.

    Problem Solved:
    Thanks ALAN and Dias.
    http://www.computerhope.com/forum/index.php?action=dlattach;topic=69701.0;attach=6821
    « Last Edit: November 06, 2008, 02:37:05 PM by Jacob »

    ALAN_BR



      Hopeful

      Thanked: 5
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: Multiple Colours.
      « Reply #1 on: November 02, 2008, 09:40:09 AM »
      Hi

      See http://www.computerhope.com/ansisys.htm

      ANSI ESC code sequences change the colour attributes quite nicely, with great versatility.

      Years ago I had two project folders
      C:\some\thing\or\other\etc
      G:\some\thing\or\other\etc

      My work in progress was on C:, and my server based backup archive was on G:.
      Since both sets of folder names were identical, I sometimes got confused as to whether I was about to update the archive with today's work, or whether I was about to wipe-out today's work !!!

      I achieved a perfect solution - I modified the usual $P$G prompt with an extra ANSI escape code sequence that altered the colour attributes depending upon which Drive I was aiming at.

      Regards
      Alan

      Jacob

        Topic Starter


        Hopeful

        Thanked: 1
        • Experience: Expert
        • OS: Windows XP
        Re: Multiple Colours.
        « Reply #2 on: November 02, 2008, 09:47:34 AM »
        I've taken a look, so what would I need to type. To display
        echo red (as red.)
        and
        echo white (as white.)
        as an example.

        Thanks for your response.

        diablo416



          Hopeful
          • Experience: Beginner
          • OS: Unknown
          Re: Multiple Colours.
          « Reply #3 on: November 02, 2008, 03:46:14 PM »
          just find windows.ini i think it is in your system folder and add a line that says , DEVICEHIGH=ANSI.SYS
          thats if ansi.sys is in the root folder otherwise include the path too


          you can google ansi sequences , it doesnt work in vista i dont think

          color 08 &echo k&pause>nul &color 0F &echo k&pause>nul &color 0D &echo k&Pause>nul

          @echo off
          set top=0
          :top
          set /a top=%top%+1
          if "%top%"=="1" Color 0F
          if "%top%"=="1" Color 08
          if "%top%"=="1" Color 0D
          if "%top%"=="1" Color 02
          if "%top%"=="4" Exit
          CLS&ECHO Message.
          Goto Top


          those are some other ideas

          Jacob

            Topic Starter


            Hopeful

            Thanked: 1
            • Experience: Expert
            • OS: Windows XP
            Re: Multiple Colours.
            « Reply #4 on: November 04, 2008, 01:41:18 PM »
            I'm struggling on how to even set up ansi.sys. to work.
            As I don't know anything about it.
            I need somebody with good knowledge to please explain it well on everything I have to do.

            My OS is windows XP.

            And by multiple I mean say on the same screen:
            echo hello this is red.
            echo hello this is blue.
            echo hello this is cyan.
            Without having to reload, so that each line has a separate colour, or each word.

            ALAN_BR



              Hopeful

              Thanked: 5
              • Computer: Specs
              • Experience: Experienced
              • OS: Windows 7
              Re: Multiple Colours.
              « Reply #5 on: November 04, 2008, 02:08:30 PM »
              Jacob

              Sorry to abandon you after starting you down this road !!!

              I last used ansi.sys about 3 years ago, and it was 10 years ago when I last configured Windows 95 to activate ansi.sys.  I forget all the details

              If you search on this site for "ansi.sys" there are 6 results.
              The link I previously quoted shows that Windows 95/98 uses
              device=c:\windows\command\ansi.sys
              and says the syntax is
              Device=[drive:][path]ANSI.SYS [/x] [/k] [/r]

              In my Windows XP Home edition, SP3, I can find c:\windows\system32\ansi.sys,
              so I guess it is still supported.
              Unfortunately "Device /?" is not a recognised command,
              therefore "Device=c:\windows\system32\ansi.sys" will probably not work
              ( I never actually tried that because if it did do something it would be unpredictable.)

              Another link to look at is http://www.computerhope.com/issues/ch000361.htm
              This is specific to Windows ME, but it gives a link for ANSI.COM at
              http://www.pcmag.com/article2/0,1759,1556221,00.asp
              which says it works on "Platforms: DOS or equivalent".
              With luck it might do what you need, and if it is not compatible the worst that can happen is a refresher course on reinstalling Windows !!!

              Alternatively, for a safer life, wait for Diablo who probably has a 2 line fix for you

              Regards
              Alan

              Dias de verano

              • Guest
              Re: Multiple Colours.
              « Reply #6 on: November 05, 2008, 12:49:33 AM »
              device=c:\windows\command\ansi.sys
              and says the syntax is
              Device=[drive:][path]ANSI.SYS [/x] [/k] [/r]

              You don't get ansi support in NT family command prompt under cmd.exe. But it is available under command.com. This may or may not be good news!

              "Device= ... " lines are not commands you can type at the prompt, or include in a batch, they are config lines that you put into DOS files such as config.sys.

              1. Edit or create a config.nt file in "c:\windows\system32" folder.
              2. Add the line: device=c:\windows\system32\ansi.sys

              Now when you start the (real) MS-DOS prompt ansi.sys will be loaded.


              Jacob

                Topic Starter


                Hopeful

                Thanked: 1
                • Experience: Expert
                • OS: Windows XP
                Re: Multiple Colours.
                « Reply #7 on: November 05, 2008, 09:06:01 AM »
                Thanks both of you, but Dias I adopted your approach and I think it has worked.
                I still need an answer to the second part of my question.
                Quote
                echo hello this is red.
                echo hello this is blue.
                echo hello this is cyan.
                Without having to reload, so that each line has a separate colour, or each word.
                Thanks to both of you so far, you are great.


                ALAN_BR



                  Hopeful

                  Thanked: 5
                  • Computer: Specs
                  • Experience: Experienced
                  • OS: Windows 7
                  Re: Multiple Colours.
                  « Reply #8 on: November 05, 2008, 09:43:26 AM »
                  Hi

                  I will implement the solution by Dias, but I have other things to do first.

                  I cannot test this yet, but search for "ESC[Ps;...;Psm" on
                  http://www.computerhope.com/ansisys.htm
                  This is followed by a list of arguments to control colours etc.

                  I think you will get red text on a blue background with
                  echo ESC[Ps;31,44;Psm hello this is red

                  NB what is shown as ESC actually represents the Escape character, value 0x1B or decimal 27, which can by created by typing 27 whilst holding down the ALT key.

                  Regards
                  Alan

                  Jacob

                    Topic Starter


                    Hopeful

                    Thanked: 1
                    • Experience: Expert
                    • OS: Windows XP
                    Re: Multiple Colours.
                    « Reply #9 on: November 05, 2008, 09:49:02 AM »
                    That does not work, It just echo's.
                    ESC[Ps;31,44;Psm hello this is red

                    ALAN_BR



                      Hopeful

                      Thanked: 5
                      • Computer: Specs
                      • Experience: Experienced
                      • OS: Windows 7
                      Re: Multiple Colours.
                      « Reply #10 on: November 05, 2008, 10:03:08 AM »
                      Hi

                      I suspect you typed
                      "echo ESC[Ps;31,44;Psm hello this is red"

                      and what is needed is
                      "echo ←[Ps;31,44;Psm hello this is red"

                      NB "←" is what appears on my screen when I release the ALT key, after I have held the ALT key down whilst typing the digits "2" then "7".

                      I get ← with NUMLOCK active and typing 27 on the number pad of my USB keyboard.
                      The USB keyboard gives me nothing at all if I use the row of numbers under the Function keys.

                      Instead of ← I get • by using the same row of numbers on the built in keyboard of my laptop.  I guess it is yet another of those weird codepage and Windows things that just are - I don't know why !!!

                      Regards
                      Alan

                      Jacob

                        Topic Starter


                        Hopeful

                        Thanked: 1
                        • Experience: Expert
                        • OS: Windows XP
                        Re: Multiple Colours.
                        « Reply #11 on: November 05, 2008, 10:10:33 AM »
                         ←or • do not work.
                        Do I need to type this on the command line or in a batch file?
                        I can also not save ← in a bat file.

                        ALAN_BR



                          Hopeful

                          Thanked: 5
                          • Computer: Specs
                          • Experience: Experienced
                          • OS: Windows 7
                          Re: Multiple Colours.
                          « Reply #12 on: November 05, 2008, 11:01:23 AM »
                          If you have a hex editor, what you need is a character sequence which starts
                          65 63 58 6f 20 1B 5b 50 73  i.e. characters
                          e   c   h   o        ←  [   P   s    etc. etc.

                          where ← is the special character I see when I release ALT key after typing 2 7 with the key down.
                          That is how I think I remember creating the ESC code using Windows 98.
                          Today using XP I just cannot get the value 0x1B.   It gives me other strange values instead, and using Notepad in any mode other than ANSI just makes things worse.

                          Sorry, I will have to think so more

                          Regards
                          Alan

                          Jacob

                            Topic Starter


                            Hopeful

                            Thanked: 1
                            • Experience: Expert
                            • OS: Windows XP
                            Re: Multiple Colours.
                            « Reply #13 on: November 05, 2008, 11:04:07 AM »
                            No worries, thanks for helping me some more.
                            Let me know if you find any solution.

                            ALAN_BR



                              Hopeful

                              Thanked: 5
                              • Computer: Specs
                              • Experience: Experienced
                              • OS: Windows 7
                              Re: Multiple Colours.
                              « Reply #14 on: November 05, 2008, 01:33:18 PM »
                              Hi

                              Notepad is giving me the same level of aggravation as the servers here !!!

                              I normally use a free download dual pane replacement for Windows Explorer available from
                              http://www.zabkat.com/

                              The package includes Editor2, with which I created this code.
                              It seems to paste on this forum, but just in case I have also attached it as colour3.txt
                              ( I believe *.cmd files get rejected ).

                              Code: [Select]
                              echo s;31,44;Psm hello this is red
                              Regards
                              Alan


                              [Saving space - attachment deleted by admin]