Sujet : Re: How to Add ANSI Color to User Response
De : learn2program (at) *nospam* gmail.com (Alan Gauld)
Groupes : comp.lang.pythonDate : 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:
'\n[1;33mYour 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 GAuthor of the Learn to Program web sitehttp://www.alan-g.me.uk/http://www.amazon.com/author/alan_gauldFollow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos