kazhala / InquirerPy

:snake: Python port of Inquirer.js (A collection of common interactive command-line user interfaces)
https://inquirerpy.readthedocs.io
MIT License
357 stars 19 forks source link

Dynamic change color choice name #41

Open arossert opened 2 years ago

arossert commented 2 years ago

I'm using the fuzzy prompt to list EC2 instances, the choices are a list of Choice with a value and name, the name is in this format

<instance name> | <running/stopped>

I want that the running/stopped will be in green/red colors, is it possible to change the color of the line based on the status? Also is it possible to only change this specific part of the string to a different color? I looked at color_print but couldn't find a way using it.

kazhala commented 2 years ago

Hi @arossert ,

As of the current release, this feature does not exist yet. Thanks for raising it, I'll include this in the next release.

For changing a specific part of the string, it won't happen for Choice (it'll only for the entire choice), but for color_print, you essentially have to break your characters into multiple tuples. E.g. printing hello world

color_print(formatted_text=[("blue", "hel"), ("red", "lo"), ("", " "), ("green", "wor"), ("yellow", "ld")])

Thanks, Kevin

arossert commented 2 years ago

@kazhala thanks for the quick response. even changing the whole choice text will be good, I did tried to look at how fuzzy prompt color part of the text in a different color as you search (it mark the found characters in pink) but I got lost ☺️