Skip to main content

Terminal UI library with differential rendering

Project description

pig-tui

PyPI version Python

Terminal UI library with rich formatting and interactive components.

Features

  • 🎨 Rich Formatting: Colors, styles, markdown rendering
  • 💬 Chat Interface: Ready-to-use chat UI components
  • Streaming Support: Real-time text streaming
  • 🎯 Interactive Input: Advanced prompt with autocomplete
  • 📊 Progress Indicators: Spinners, progress bars
  • 🔄 Differential Rendering: Efficient screen updates

Installation

pip install pig-tui

Quick Start

Simple Chat Interface

from pig_tui import ChatUI

# Create chat UI
chat = ChatUI(title="My AI Assistant")

# Display messages
chat.user("Hello!")
chat.assistant("Hi! How can I help you?")

# Stream response
with chat.assistant_stream() as stream:
    for chunk in generate_response():
        stream.write(chunk)

Markdown Rendering

from pig_tui import Console

console = Console()
console.markdown("""
# Hello World

This is **bold** and this is *italic*.

- Item 1
- Item 2

\`\`\`python
def hello():
    print("Hello!")
\`\`\`
""")

Progress Indicators

from pig_tui import Progress, Spinner

# Progress bar
with Progress() as progress:
    task = progress.add_task("Processing...", total=100)
    for i in range(100):
        progress.update(task, advance=1)

# Spinner
with Spinner("Loading...") as spinner:
    do_long_task()

Interactive Input

from pig_tui import Prompt

prompt = Prompt()

# Simple input
name = prompt.ask("What's your name?")

# With validation
age = prompt.ask("Your age?", validate=lambda x: x.isdigit())

# With autocomplete
color = prompt.ask(
    "Favorite color?",
    choices=["red", "blue", "green"]
)

Components

ChatUI

Full-featured chat interface:

from pig_tui import ChatUI

chat = ChatUI(
    title="Assistant",
    theme="dark",  # or "light"
    show_timestamps=True,
)

# User message
chat.user("Hello")

# Assistant message
chat.assistant("Hi there!")

# System message
chat.system("Model: gpt-4")

# Stream assistant response
with chat.assistant_stream() as stream:
    stream.write("Streaming ")
    stream.write("response...")

# Error message
chat.error("Something went wrong")

Console

Rich console output:

from pig_tui import Console

console = Console()

# Print with style
console.print("Hello", style="bold blue")

# Markdown
console.markdown("# Title")

# JSON pretty print
console.json({"key": "value"})

# Code syntax highlighting
console.code('print("hello")', language="python")

# Table
from rich.table import Table
table = Table()
table.add_column("Name")
table.add_column("Value")
table.add_row("foo", "bar")
console.print(table)

Prompt

Interactive prompts:

from pig_tui import Prompt

prompt = Prompt()

# Text input
name = prompt.ask("Name:")

# Password
password = prompt.ask("Password:", password=True)

# Confirm
confirmed = prompt.confirm("Continue?")

# Choice
option = prompt.choice("Select:", ["A", "B", "C"])

# Multiple choice
selected = prompt.multi_choice("Select multiple:", ["A", "B", "C"])

Theming

from pig_tui import ChatUI, Theme

# Custom theme
theme = Theme(
    user_color="cyan",
    assistant_color="green",
    system_color="yellow",
    error_color="red",
)

chat = ChatUI(theme=theme)

Examples

See examples/tui/ directory:

  • chat_demo.py - Chat interface demo
  • streaming_demo.py - Streaming text demo
  • prompt_demo.py - Interactive prompts
  • progress_demo.py - Progress indicators

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pig_tui-0.1.1.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pig_tui-0.1.1-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file pig_tui-0.1.1.tar.gz.

File metadata

  • Download URL: pig_tui-0.1.1.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for pig_tui-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7b78b13f8ee0729be81c63ed1a5992a0bf388248238d35ca11a10800712ff4da
MD5 e2df1dad6d110467db39bc721beeb9de
BLAKE2b-256 aa63a0d289d479c66a93ec099c8c7bf6f9c2d9303a15aaf958ddbe7b73acf01a

See more details on using hashes here.

File details

Details for the file pig_tui-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pig_tui-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for pig_tui-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e265f307ec71b0481cc76f9e126e8dad00dfc89631da8d3bacce26d65351ea2c
MD5 d2644c9a4157c79fe8c5e66b6ec3960b
BLAKE2b-256 b9ce272c93e21887d2eeac3c7f98ee97b350d614bda46d6b97f49ec03eee137e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page