pythoncursespython-cursesrich

How to integrate Rich with Python curses?


I'm thinking of creating a CLI app using python curses and rich libraries. As curses requires addstr method to print text to string, I'm unable to print using rich. Is it possible to integrate these two libraries?

Following codes don't work accordingly!!

import curses
from curses import wrapper
from rich.console import Console
console = Console()
with console.capture() as capture:
    console.print("[bold red]Hello[/] World")
str_output = capture.get()

def main(stdscr):
    stdscr.clear()
    stdscr.addstr(str_output)
    stdscr.refresh()
    stdscr.getch()

wrapper(main)

Solution

  • Author of Rich here. Rich and Curses probably aren't going to work well in combination. However you could look in to Textual which is a TUI framework I'm working on that uses Rich under the hood.