Add Style Option for Variables
Describe the problem
Right now we can only, from what I can find, format a handful of questionary options and they apply to entire questionary prompt. Which often contains dynamic variables from elsewhere in the script.
Describe the solution
I'd like to highlight these variables with a custom styling so they standout amongst the rest of the text. Example: You ask a question where a previous answer needs to be inserted. I'd like to highlight this answer/variable:
custom_styled_variable = Style([("question, """)("variable", fg_color)]) highlight_me = questionary.text("What do you want highlighted in the next question").ask() questionary.text(f"This is an example of {highlight_me}", style= 'custom_styled_variable')
Alternatives considered
Anything existing that already accomplishes this. I wasn't able to find it in documentation.
im currently looking into how to do this as well.
after much searching i found this: https://questionary.readthedocs.io/en/stable/pages/advanced.html#themes-styling
specificaly this part
import questionary
from questionary import Choice, Style
custom_style_fancy = questionary.Style([
("highlighted", "bold"), # style for a token which should appear highlighted
])
choices = [Choice(title=[("class:text", "order a "),
("class:highlighted", "big pizza")])]
questionary.select(
"What do you want to do?",
choices=choices,
style=custom_style_fancy).ask()
notice the choices
choices = [Choice(title=[("class:text", "order a "),
("class:highlighted", "big pizza")])]
so im guessing the other prompts would work the same? still trying to get it to work my side tho in my implementation of a menu system so results may vary. (ive tried many things already but this looks like it might just work)
well.. it works.. wow - and im totaly dumb for not having realized what im reading over and over again.
# setup the "token" styles
custom_style_fancy = questionary.Style([
("bullet", "bold red"),
("key", "bold green"),
("description", "blue"),
])
# add the token styles to the question
action = questionary.select(
"",
choices=choices,
default=selected_choice,
style=custom_style_fancy
).ask()
# add tuples to the choice's title (the title must be a list of tuples for this)
choices = [questionary.Choice(
title=[('class:bullet', '> '), ('class:key', 'root '), ('class:description', 'More Testing')],
value="root",
)]

altho im not sure if it helps you tho... since it says
title to change how an option is displayed in questionary.select and questionary.checkbox.