How to Add ANSI Color to User Response
David
bouncingcats at gmail.com
Wed Apr 10 22:24:59 EDT 2024
On Wed, 10 Apr 2024 at 18:51, WordWeaver Evangelist via Python-list
<python-list at python.org> 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 where the conditions
> are, so that the color of the user’s input is of a color of my choosing,
> instead of just white?
Hi Bill,
Here's a tutorial:
https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
Note the sentence: "once you print out the special code enabling a color,
the color persists forever until someone else prints out the code for
a different color, or prints out the Reset code to disable it."
Here's a more detailed specification:
https://en.wikipedia.org/wiki/ANSI_escape_code
And here's a conversation:
http://mywiki.wooledge.org/BashFAQ/037
(see the first sentence, and then under the heading "Discussion")
that might help you decide whether this approach will satisy your need in
your particular circumstances of operating system, Python version, and
terminal settings.
More information about the Python-list
mailing list