Skip to main content

Terminal UI library with differential rendering

Project description

pig-tui

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.0.1.tar.gz (9.3 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.0.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pig_tui-0.0.1.tar.gz
Algorithm Hash digest
SHA256 92c6dc40704272877962ce20f65d1b9511c9e81f39f10eaae504e6bed4698ce0
MD5 0ced191667b05ee4e23807830ca89e08
BLAKE2b-256 e893aff44be63063c57d41f7dfeefab3e4fdf1fc196d9b78a16b0c28f0204db5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pig_tui-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e0660fe25855e2f28ee4d5e9cc424a38fd0e47e46819e4a6774b570e638066d
MD5 ed85783d255260e6285c05c0c8af024e
BLAKE2b-256 ad174da0ab5237decf9a22f11a643231a9e37a81750cff34dbdd6a6e007070f8

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