【问题标题】:How to highlight in rich.prompt.Prompt如何在rich.prompt.Prompt 中突出显示
【发布时间】:2021-09-17 10:41:32
【问题描述】:

我有这个荧光笔

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() 的荧光笔

【问题讨论】:

    标签: python highlight rich


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-03-18
      • 2018-06-05
      • 2019-03-16
      • 2013-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-24
      • 1970-01-01
      相关资源
      最近更新 更多