changing colors in python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GujuBoy

    #1

    changing colors in python

    i have a ansi.py file that i use in LINUX to change the text color to
    STDOUT when i use the "print" function...but when i move this ansi.py
    file over the windows...it does not work

    is there a version of ansi.py i can use for windows/linux....

    please help

  • Kane

    #2
    Re: changing colors in python

    To convert ansi escape sequences into text colors you need a terminal
    that understands what you are doing. Linux does this by default; dos
    and windows do not. You need to have an extra program in memory. The
    conventional approach is the "ANSI.SYS" driver which probably still
    ships with Windows (link below).

    I've included a link to nansi.com but haven't used it with any windows
    version > 3.1. If memory serves it is significantly faster.




    Comment

    • jay graves

      #3
      Re: changing colors in python

      AFAIK, the cmd.exe program on Win2K/XP doesn't support ANSI escape
      sequences. There are various other options on windows but they
      probably won't work on Linux.




      Comment

      • Cappy2112

        #4
        Re: changing colors in python

        if you are talking about writing text console program only , for
        Windows, then just use the color command- but you will need a handle to
        that console window-

        C:\>help color
        Sets the default console foreground and background colors.

        COLOR [attr]

        attr Specifies color attribute of console output

        Color attributes are specified by TWO hex digits -- the first
        corresponds to the background; the second the foreground. Each digit
        can be any of the following values:

        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

        If no argument is given, this command restores the color to what it was
        when CMD.EXE started. This value either comes from the current console
        window, the /T command line switch or from the DefaultColor registry
        value.
        Press any key to continue . . .

        Comment

        • Claudio Grondi

          #5
          Re: changing colors in python

          The readline module (used e.g. in IPython)
          http://sourceforge.net/project/showf...group_id=82407
          provides the Console.py
          script and in my own version of it, the (extended)
          Console() class supports any ANSI escape
          sequences of the form ESC[#m and ESC[#,#m ,
          making it possible to set any by console supported
          text and background colors.
          Finde deine Wunsch-Domain mit nur wenigen Klicks. ✓ Günstige Preise ✓ SSL-Zertifikat & ✓ 100 % deutsche Server bei freenet Mail


          Replace the Console.py of the readline
          module with my extended version and run
          it as main script to see the coloured output
          looking into the code to see how it comes.

          Claudio
          The official home of the Python Programming Language



          "GujuBoy" <dirgesh@gmail. com> schrieb im Newsbeitrag
          news:1113511856 .510914.103960@ z14g2000cwz.goo glegroups.com.. .[color=blue]
          > i have a ansi.py file that i use in LINUX to change the text color to
          > STDOUT when i use the "print" function...but when i move this ansi.py
          > file over the windows...it does not work
          >
          > is there a version of ansi.py i can use for windows/linux....
          >
          > please help
          >[/color]


          Comment

          Working...