Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Style Option for Variables #252

Open
Wulf-Steppen opened this issue Sep 16, 2022 · 2 comments
Open

Add Style Option for Variables #252

Wulf-Steppen opened this issue Sep 16, 2022 · 2 comments
Labels
Enhancement New feature or request

Comments

@Wulf-Steppen
Copy link

Wulf-Steppen commented Sep 16, 2022

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.

@Wulf-Steppen Wulf-Steppen added the Enhancement New feature or request label Sep 16, 2022
@WilliamStam
Copy link

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)

@WilliamStam
Copy link

WilliamStam commented Jan 24, 2023

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",
)]

image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants