"Serving" an UI with Rich? #4033
-
|
Hi, I have an app that has a global When I run that locally or with tmux, I can attach and see the Do you think of any way to "serve" the UI, so I could attach to it on demand? Thank you for any ideas. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
For anyone wondering, a way to do it is to just serve the rich console on a unix/tcp socket # server.py
import socket
from rich.console import Console
from rich.live import Live
from rich.table import Table
from io import TextIOWrapper
import time
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('127.0.0.1', 10905))
server.listen(1)
conn, addr = server.accept()
file = conn.makefile(mode='wb', buffering=0)
console = Console(file=TextIOWrapper(file, write_through=True), width=40, force_terminal=True)
# rich.live example
table = Table()
table.add_column("Row ID")
table.add_column("Description")
table.add_column("Level")
with Live(table, console=console, refresh_per_second=4): # update 4 times a second to feel fluid
for row in range(12):
time.sleep(0.4) # arbitrary delay
# update the renderable internally
table.add_row(f"{row}", f"description {row}", "[red]ERROR")simple client with socat socat - TCP4:127.0.0.1:10905 |
Beta Was this translation helpful? Give feedback.
For anyone wondering, a way to do it is to just serve the rich console on a unix/tcp socket