Style¶
Each InquirerPy
prompt contains several components which you can
customise the style.
Customising Style¶
See also
Checkout Default Style for all available style classes to customise.
Classic Syntax (PyInquirer)¶
Tip
InquirerPy
also supports style customisation via ENV variables. Checkout ENV documentation.
The entry point function prompt has a parameter style
which you can use to apply custom styling using dict
.
from InquirerPy import prompt
result = prompt(
{"message": "Confirm order?", "type": "confirm", "default": False},
style={"questionmark": "#ff9d00 bold"},
vi_mode=True,
style_override=False,
)
The parameter style_override
can be used to remove all Default Style. Value is True
by default.
from InquirerPy import prompt
result = prompt(
{"message": "Confirm order?", "type": "confirm", "default": False},
style={"questionmark": "#ff9d00 bold"},
vi_mode=True,
style_override=True,
)
Alternate Syntax¶
When using the Alternate Syntax, each prompt class requires a InquirerPyStyle
instance instead of a dictionary. You can get
this object by using get_style()
.
- InquirerPy.utils.get_style(style=None, style_override=True)[source]
Obtain an
InquirerPyStyle
instance which can be consumed by the style parameter in prompts.Tip
This function supports ENV variables.
For all the color ENV variable names, refer to the ENV documentation.
Note
If no style is provided, then a default theme based on one dark color palette is applied.
Note
Priority: style parameter -> ENV variable -> default style
- Parameters
style (Optional[Dict[str, str]]) – The dictionary of style classes and their colors, If nothing is passed, the style will be resolved to the Default Style.
style_override (bool) – A boolean to determine if the supplied style parameter should be merged with the Default Style or override them. By default, the supplied style will overwrite the Default Style.
- Returns
An instance of
InquirerPyStyle
.- Return type
Examples
>>> from InquirerPy import get_style >>> from InquirerPy import inquirer >>> style = get_style({"questionmark": "#ffffff", "answer": "#000000"}, style_override=False) >>> result = inquirer.confirm(message="Confirm?", style=style).execute()
Default Style¶
Note
The default style is based on onedark color palette.
Checkout Components to see how the following styles are applied to each prompt
.
{
"questionmark": "#e5c07b",
"answermark": "#e5c07b",
"answer": "#61afef",
"input": "#98c379",
"question": "",
"answered_question": "",
"instruction": "#abb2bf",
"long_instruction": "#abb2bf",
"pointer": "#61afef",
"checkbox": "#98c379",
"separator": "",
"skipped": "#5c6370",
"validator": "",
"marker": "#e5c07b",
"fuzzy_prompt": "#c678dd",
"fuzzy_info": "#abb2bf",
"fuzzy_border": "#4b5263",
"fuzzy_match": "#c678dd",
"spinner_pattern": "#e5c07b",
"spinner_text": "",
}
Color Syntax¶
Applying basic style.
{
"questionmark": "blue"
}
Coloring both foreground and background.
{
"questionmark": "fg:#e5c07b bg:#ffffff"
}
Adding additional styles to text.
{
"questionmark": "fg:#e5c07b bg:#ffffff underline bold"
}
Available Options¶
Colors¶
ANSI color palette:
ansired
Named color:
red
Hexadecimal notation:
#ffffff
Text¶
underline
italic
bold
reverse
hidden
blink
Negative Variants¶
noblink
nobold
nounderline
noreverse
nohidden
noitalic
Support¶
The styling functionality leverages prompt_toolkit.
For more reference of the styling options, visit prompt_toolkit
documentation.
The colors and styling support will be limited by the terminal and font and experience may vary between different environments. Avoid
adding styles such as italic
since lots of font or terminal doesn’t support it.
Components¶