prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.37k stars 716 forks source link

Using "Rich" for formatted text. #1346

Open jonathanslenders opened 3 years ago

jonathanslenders commented 3 years ago

Look into support for the "Rich" library for definition of formatted text: https://github.com/willmcgugan/rich

daddycocoaman commented 3 years ago

This would be dope. I've managed to get a mostly working output using Rich with something like:

from io import StringIO
from prompt_toolkit.formatted_text import ANSI
from prompt_toolkit.widgets import Label
from rich.console import Console

console = Console(file=StringIO, force_terminal=True, color_system="truecolor")

# Making a Label
console.print("[bold red]Here is a label!", justify="center")
label = Label(text=console.file.getvalue())
nadapez commented 2 years ago

Cool. I would subclass StringIO to make printing automatically update label text.