0

我有这个荧光笔

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)

在此处输入图像描述

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

4

1 回答 1

0

您是否希望您输入的文本在您键入时突出显示?

Rich没有这种能力。您可能需要查看 prompt_toolkit 。

于 2021-07-06T21:05:22.820 回答