如何在rich.prompt.prompt中突出显示

2024-09-28 19:05:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个荧光灯

from rich.console import Console
import rich.prompt
from rich.highlighter import RegexHighlighter
from rich.theme import Theme


class Highlighter(RegexHighlighter):
    base_style = "help."
    highlights = [r"(?P<cmd>!help\b)", r"(?P<cmd2>\'|\"[\w]+\"|\')"]

theme = Theme({"help.cmd": "bold magenta", "help.cmd2": "bold green"})
console = Console(highlighter=Highlighter(), theme=theme)

如果我执行类似console.print()的操作,它会提供自定义高亮显示,但不会为rich.prompt.Prompt.ask()提供自定义高亮显示

prompt = rich.prompt.Prompt(console=console)
text = prompt.ask("\'Enter text\'\n")
console.print(text)

enter image description here

我怎样才能得到rich.prompt.Prompt.ask()的荧光灯


Tags: textfromimporthelpthemeprompthighlighterconsole