Skip to main content

A modern, elegant CLI framework for building AI chat applications

Project description

SilanTui

A Modern Terminal UI Framework for Python

Build beautiful, interactive command-line applications with ease. SilanTui provides powerful UI components, command management, and extensibility - no AI required (but AI integration is optional and easy).

Author: Silan Hu
License: MIT

๐ŸŒ Internationalization (i18n)

SilanTui supports multiple languages out of the box:

from silantui.i18n import set_language, t

# Set language
set_language('zh')  # Chinese
set_language('en')  # English (default)
set_language('es')  # Spanish
set_language('fr')  # French
set_language('ja')  # Japanese

# Use translations
print(t('welcome'))      # Outputs in current language
print(t('success'))      # Translated success message
print(t('command.help')) # Translated command help

See examples/i18n_demo.py for a complete example.

๐ŸŽฏ What is SilanTui?

SilanTui is a UI-first CLI framework that makes it simple to create professional terminal applications. Think of it as a toolkit for building TUIs (Text User Interfaces) with:

  • Beautiful, Rich-based components
  • Intuitive command systems
  • Flexible layouts and displays
  • Easy customization

AI integration is just one of many possible use cases.

โœจ Core Features

๐ŸŽจ UI Components

  • ModernLogger - Advanced logging with colors, progress bars, and formatting
  • UIBuilder - Fluent API for Panels, Tables, Menus, Forms, and Layouts
  • ChatDisplay - Fixed-bottom input with scrollable content
  • LiveDisplay - Real-time updating layouts without flicker

๐ŸŽฎ Command System

  • 3 Ways to Register - Decorators, Builders, or Quick functions
  • Command Categories - Organize commands by function
  • Aliases Support - Create shortcuts for any command
  • Help Generation - Automatic help text and documentation

๐Ÿ”ง Extensibility

  • Custom Themes - Define your own color schemes
  • Plugin Architecture - Easy to extend and customize
  • Session Management - Save/load application state
  • Configuration - Flexible config system

๐Ÿค– Optional AI Integration

  • Universal AI Client - Works with OpenAI, Anthropic, Ollama, or any compatible API
  • Custom BaseURL - Point to any API endpoint
  • Streaming Support - Real-time response display
  • Markdown Rendering - Beautiful AI response formatting

๐Ÿ“ฆ Installation

pip install silantui

Or from source:

git clone https://github.com/yourusername/silantui.git
cd silantui
pip install -e .

๐Ÿš€ Quick Start

Example 1: Simple Dashboard

from silantui import ModernLogger, UIBuilder

logger = ModernLogger(name="dashboard")
ui = UIBuilder(console=logger.console)

# Create a beautiful table
ui.table("User Data") \
    .add_column("Name", style="cyan") \
    .add_column("Status", style="green") \
    .add_row("Alice", "Active") \
    .add_row("Bob", "Inactive") \
    .show()

# Create an info panel
ui.panel("Welcome", "This is your dashboard!") \
    .border("cyan") \
    .show()

Example 2: Interactive Menu

from silantui import UIBuilder

ui = UIBuilder()

choice = ui.menu("Main Menu") \
    .add_item("1", "Start", description="Start the application") \
    .add_item("2", "Settings", description="Configure options") \
    .add_separator() \
    .add_item("3", "Exit") \
    .show()

print(f"You selected: {choice}")

Example 3: Custom Commands

from silantui import CommandRegistry, ModernLogger

registry = CommandRegistry()
logger = ModernLogger(name="app")

@registry.command("greet", description="Say hello", aliases=["hi"])
def greet_command(app, args):
    logger.success(f"Hello, {args}!")

@registry.command("stats", description="Show statistics")
def stats_command(app, args):
    logger.info("Statistics: ...")

# Execute commands
registry.execute("greet", None, "World")
registry.show_help(logger.console)

Example 4: AI Chat (Optional)

from silantui import LiveChatDisplay
from silantui.integrations.universal_client import UniversalAIClient

# Works with OpenAI, Ollama, or any compatible API
client = UniversalAIClient(
    api_key="your-key",
    base_url="http://localhost:11434/v1",  # Optional: use local Ollama
    model="llama2"
)

display = LiveChatDisplay()
display.start()

# Add messages
display.add_user_message("Hello!")

# Stream AI response
display.start_assistant_message()
for chunk in client.chat_stream("Hello!"):
    display.append_streaming(chunk)
display.finish_assistant_message()

display.stop()

๐Ÿ“š Complete Examples

SilanTui includes full-featured example applications:

1. Dashboard App

python examples/dashboard_app.py

Real-time data dashboard with live monitoring, charts, and statistics.

2. Task Manager

python examples/task_manager.py

Complete task management application with persistence, filtering, and statistics.

3. AI Chat (Optional)

# With OpenAI
export OPENAI_API_KEY=your-key
python examples/ai_chat_app.py

# With Ollama (local)
python examples/ai_chat_app.py --preset ollama --model llama2

# With custom API
python examples/ai_chat_app.py --base-url http://your-api.com/v1 --model your-model

๐ŸŽฌ Showcase

Interactive Chat Interface

SilanTui provides a beautiful, modern chat interface with real-time streaming, alternate screen mode, and smooth animations:

Chat Demo 1 Clean, minimalist chat interface with streaming responses

Chat Demo 2 Real-time message streaming with metadata display

Chat Demo 3 Full conversation flow with markdown rendering

Features demonstrated:

  • ๐ŸŽจ Alternate screen mode for isolated UI experience
  • โšก Real-time streaming with frame merging
  • ๐Ÿ“ Markdown rendering for formatted responses
  • ๐ŸŽฏ Bottom-aligned chat with scrollable history
  • ๐Ÿ’ฌ Fixed input area with IME support
  • โฑ๏ธ Response timing and metadata display

๐ŸŽจ UI Components Guide

Tables

from silantui import UIBuilder

ui = UIBuilder()

table = ui.table("User List")
table.add_column("ID", style="cyan", width=5)
table.add_column("Name", style="green")
table.add_column("Email", style="yellow")

table.add_row("1", "Alice", "alice@example.com")
table.add_row("2", "Bob", "bob@example.com")

table.show()

Panels

panel = ui.panel("Title", "Content here") \
    .border("cyan") \
    .padding((2, 4)) \
    .expand(True) \
    .build()

Forms

results = ui.form("User Settings") \
    .add_field("name", "Name", required=True) \
    .add_field("age", "Age", field_type="int") \
    .add_field("theme", "Theme", field_type="choice",
              choices=["light", "dark"]) \
    .show()

Layouts

layout = ui.layout("root") \
    .split_column("header", "main", "footer") \
    .update("header", "Header Content") \
    .update("main", "Main Content") \
    .update("footer", "Footer Content") \
    .show()

Live Display

from silantui import LiveChatDisplay

display = LiveChatDisplay()
display.start()

display.add_user_message("Hello!")
display.start_assistant_message()
display.append_streaming("Response...")
display.finish_assistant_message()

display.stop()

๐ŸŽฏ Command System

Method 1: Decorator (Recommended)

from silantui import CommandRegistry

registry = CommandRegistry()

@registry.command(
    "deploy",
    description="Deploy application",
    aliases=["d"],
    category="Operations",
    requires_args=True
)
def deploy_command(app, args):
    print(f"Deploying to {args}...")

Method 2: Builder Pattern

from silantui import CommandBuilder

cmd = CommandBuilder("backup") \
    .description("Backup data") \
    .aliases(["bk"]) \
    .category("Operations") \
    .handler(lambda app, args: print("Backing up...")) \
    .build()

registry.register(cmd)

Method 3: Quick Register

from silantui import quick_command

quick_command(
    registry,
    "status",
    lambda app, args: print("Status: OK"),
    description="Show status",
    aliases=["st"]
)

๐Ÿค– AI Integration (Optional)

SilanTui supports multiple AI providers through a universal client:

OpenAI

from silantui.integrations.universal_client import UniversalAIClient

client = UniversalAIClient(
    api_key="sk-...",
    model="gpt-4"
)

Ollama (Local)

client = UniversalAIClient(
    api_key="ollama",
    base_url="http://localhost:11434/v1",
    model="llama2"
)

Azure OpenAI

client = UniversalAIClient(
    api_key="your-key",
    base_url="https://YOUR_RESOURCE.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT",
    model="gpt-4"
)

Any Custom API

client = UniversalAIClient(
    api_key="your-key",
    base_url="https://your-api.com/v1",
    model="your-model"
)

๐ŸŽจ Custom Themes

from silantui import UITheme, UIBuilder

theme = UITheme(
    primary="magenta",
    secondary="cyan",
    success="bright_green",
    warning="bright_yellow",
    error="bright_red"
)

ui = UIBuilder(theme=theme)

๐Ÿ“– Documentation

๐ŸŽฏ Use Cases

SilanTui is perfect for:

  • System Administration Tools - Server management, monitoring dashboards
  • Development Tools - Build tools, deployment scripts, code generators
  • Data Processing - ETL pipelines, data analysis tools
  • Interactive Applications - Games, tutorials, wizards
  • AI Applications - Chatbots, code assistants, content generators (optional)

๐Ÿ—๏ธ Architecture

SilanTui Framework
โ”œโ”€โ”€ Core UI Components
โ”‚   โ”œโ”€โ”€ ModernLogger      # Logging & output
โ”‚   โ”œโ”€โ”€ UIBuilder         # Component builder
โ”‚   โ”œโ”€โ”€ ChatDisplay       # Chat interface
โ”‚   โ””โ”€โ”€ LiveDisplay       # Real-time updates
โ”‚
โ”œโ”€โ”€ Command System
โ”‚   โ”œโ”€โ”€ CommandRegistry   # Command management
โ”‚   โ”œโ”€โ”€ CommandBuilder    # Fluent command API
โ”‚   โ””โ”€โ”€ CommandManager    # Alias management
โ”‚
โ”œโ”€โ”€ Optional Features
โ”‚   โ”œโ”€โ”€ AI Client         # Universal AI integration
โ”‚   โ”œโ”€โ”€ SessionManager    # State persistence
โ”‚   โ””โ”€โ”€ ThemeSystem       # Color customization
โ”‚
โ””โ”€โ”€ Examples
    โ”œโ”€โ”€ Dashboard         # Data visualization
    โ”œโ”€โ”€ Task Manager      # CRUD application
    โ””โ”€โ”€ AI Chat           # Optional AI app

๐Ÿค Contributing

Contributions are welcome! SilanTui is designed to be a general-purpose UI framework.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

MIT License - see LICENSE

Copyright (c) 2024 Silan Hu

๐Ÿ‘ค Author

Silan Hu

๐Ÿ™ Acknowledgments

  • Built with Rich by Will McGugan
  • Inspired by modern TUI frameworks
  • ASCII art by pyfiglet

๐Ÿ—บ๏ธ Roadmap

  • Core UI components (Tables, Panels, Menus, Forms)
  • Command system with multiple registration methods
  • Live display with fixed layouts
  • Internationalization (i18n) support
  • Optional AI integration with multiple providers
  • More UI components (charts, graphs, trees)
  • Plugin system
  • Advanced configuration management
  • Testing utilities and examples
  • Documentation site
  • More example applications
  • Performance optimizations

Build beautiful CLI applications with ease! ๐Ÿš€

pip install silantui

Made with โค๏ธ by Silan Hu

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

silantui-0.1.0.tar.gz (61.2 kB view details)

Uploaded Source

Built Distribution

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

silantui-0.1.0-py3-none-any.whl (46.8 kB view details)

Uploaded Python 3

File details

Details for the file silantui-0.1.0.tar.gz.

File metadata

  • Download URL: silantui-0.1.0.tar.gz
  • Upload date:
  • Size: 61.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for silantui-0.1.0.tar.gz
Algorithm Hash digest
SHA256 36ef8c756ddd447b075d0257910335e4bb28a0e854d7b512e40b0dbb4b27106c
MD5 34489a3658265929279e2d4d7f33c83f
BLAKE2b-256 36165f6f047b680de41160e9bbb8e71bf069a902f357991416189bc06cf78a52

See more details on using hashes here.

File details

Details for the file silantui-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: silantui-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 46.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for silantui-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 721f6984ba0df37d087b1f5f8750d43ac88fabe86c77946f5e7a36c98546824d
MD5 50e044601930fff7d1b9e463af186205
BLAKE2b-256 39adaa613d74df6ebc652e6be8a286dd7f1ad5a237abf55c09c41de2bc827fcb

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