Re: How to Add ANSI Color to User Response

Liste des GroupesRevenir à cl python 
Sujet : Re: How to Add ANSI Color to User Response
De : learn2program (at) *nospam* gmail.com (Alan Gauld)
Groupes : comp.lang.python
Date : 10. Apr 2024, 23:41:23
Autres entêtes
Message-ID : <mailman.90.1712788887.3468.python-list@python.org>
References : 1 2
User-Agent : Mozilla Thunderbird
On 10/04/2024 19:50, WordWeaver Evangelist via Python-list wrote:

I have a simple question. I use the following textPrompt in some of my Jython modules:
 '\nYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, forceUppercase=True)
Is there a way to add an ANSI color code to the end

Normally, for any kind of fancy terminal work, I'd say use curses.
But I suspect Jython may not support curses?

On the offchance it does do curses it would look like:

import curses

def main(scr):
   if curses.has_colors():  # check the terminal supports color
      curses.start_color().  # init the color system
      curses.init_pair(1,curses.COLOR_YELLOW,curses.COLOR_BLUE)

      # Now start adding text coloring as desired...
      scr.addstr(0,0,"This string is yellow and blue",
                 curses.color_pair(1))

      scr.refresh().  # make it visible
   else: scr.addstr("Sorry, no colors available")

curses.wrapper(main)

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



Date Sujet#  Auteur
11 Apr 24 o Re: How to Add ANSI Color to User Response1Alan Gauld

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal