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:
  '\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

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.

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to