Sujet : Re: How to Add ANSI Color to User Response
De : list1 (at) *nospam* tompassin.net (Thomas Passin)
Groupes : comp.lang.pythonDate : 11. Apr 2024, 01:01:51
Autres entêtes
Message-ID : <mailman.95.1712816224.3468.python-list@python.org>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 4/10/2024 6:41 PM, Alan Gauld via Python-list wrote:
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
Curses is a C module, and there is a Python interface to it. Jython would have to find an equivalent Java library. Still, isn't the case that the terminal color output commands are pretty standard? They could just be stuck into the output string. Doing more fancy things, like moving the cursor arbitrarily, probably differ but the OP just mentioned colors.