You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I show the default value and other helpful information in the nice_title which is not passed through to the underlying response. This works brilliantly - I'd just like to be able to add some formatting to this.
Manual ANSI codes
I've tried manually adding ANSI codes to the string, or using libraries like rich but they are escaped and don't work:
myval ^[[1;3;31m(False)^[[0m
Where I would like:
myval (False)
..with (False) in bold-red text in this example.
Prompt toolkit
I dug around in the Questionary codebase a little and found that the title attribute is of class FormattedText, which is defined here:
# This is a cut-down version of `prompt_toolkit.formatted_text.AnyFormattedText`
# which does not exist in v2 of prompt_toolkit
FormattedText=Union[
str,
List[Tuple[str, str]],
List[Tuple[str, str, Callable[[Any], None]]],
None,
]
I feel like this is maybe getting close to something I could use, but I pretty much hit a wall at that point. I tried a bit of trial and error with passing lists of strings with stuff like class:selected but succeeded only in breaking stuff. Also I want to format only a partial section of the string so I'm not sure that this would work.
Any tips or pointers on how I might be able to achieve this?
Many thanks in advance,
Phil
The text was updated successfully, but these errors were encountered:
Hi there,
Is it possible to give colours and formatting using ANSI codes to a questionary prompt title?
I am using the following code to generate prompts:
I show the default value and other helpful information in the
nice_title
which is not passed through to the underlying response. This works brilliantly - I'd just like to be able to add some formatting to this.Manual ANSI codes
I've tried manually adding ANSI codes to the string, or using libraries like
rich
but they are escaped and don't work:Where I would like:
..with
(False)
in bold-red text in this example.Prompt toolkit
I dug around in the Questionary codebase a little and found that the
title
attribute is of classFormattedText
, which is defined here:questionary/questionary/prompts/common.py
Lines 23 to 30 in 11ceb8e
I feel like this is maybe getting close to something I could use, but I pretty much hit a wall at that point. I tried a bit of trial and error with passing lists of strings with stuff like
class:selected
but succeeded only in breaking stuff. Also I want to format only a partial section of the string so I'm not sure that this would work.Any tips or pointers on how I might be able to achieve this?
Many thanks in advance,
Phil
The text was updated successfully, but these errors were encountered: