Skip to content

ANSI colours and formatting not applied to Questionary prompt title #449

@kotazzz

Description

@kotazzz

Question

I am unable to apply ANSI colour codes or Rich formatting to the title of a Questionary prompt. While option titles accept ANSI/Rich styling correctly, passing a formatted FormattedText to the message parameter of questionary.select() has no effect.

What have you already tried?

Rich → PromptToolkit conversion

from prompt_toolkit.formatted_text import to_formatted_text, ANSI

def _rich_to_prompt_toolkit(self, text: str) -> FormattedText:
    with self.console.capture() as cap:
        self.console.print(text)
    return to_formatted_text(ANSI(cap.get()))

# Option titles work:
choices = [
    questionary.Choice(self._rich_to_prompt_toolkit("[cyan]Option"), value="opt")
]
# But title does not:
formatted_title = self._rich_to_prompt_toolkit("[red]Test")
questionary.select(formatted_title, choices, qmark="", instruction=" ").ask()

– The FormattedText object is created, but its styling is ignored for the prompt message.

Any pointers on how to inject ANSI/Rich styles into the prompt title itself would be greatly appreciated.

Please see GitHub Issue #107 in the Questionary repository for a nearly identical report, which—despite several work‑arounds—remains unresolved

Read the documentation

  • I have checked to ensure that my question is not answered by the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions