generates text from generators and provides as grid
Project description
ViewText
Declarative text grid layouts from structured data
ViewText is a lightweight Python library for building dynamic text-based grid layouts. It provides a simple, declarative way to map structured data to formatted text output through a flexible registry and layout system.
Features
- Field Registry: Register data getters that extract values from context objects
- Formatter System: Built-in formatters for text, numbers, prices, dates, and relative times
- Layout Engine: TOML-based layout definitions that map fields to grid positions
- Extensible: Easy to add custom fields and formatters for domain-specific needs
Use Cases
- Terminal/CLI dashboards
- E-ink/LCD displays
- Text-based data visualization
- Any scenario requiring structured text layouts
Quick Example
from viewtext import LayoutEngine, LayoutLoader, FieldRegistry
# Define your field registry
registry = FieldRegistry()
registry.register("temperature", lambda ctx: ctx["temp"])
# Load layout from TOML
loader = LayoutLoader("layouts.toml")
layout = loader.get_layout("weather")
# Build grid output
engine = LayoutEngine()
lines = engine.build_line_str(layout, {"temp": 72})
Installation
pip install viewtext
Command Line Interface
Viewtext includes a CLI for inspecting and testing layouts:
# Show all available layouts
viewtext list
# Show specific layout configuration
viewtext show weather
# Show field mappings from config
viewtext fields
# Render a layout with mock data
viewtext render weather
# Show all available formatters
viewtext formatters
# Show configuration info
viewtext info
# Use custom config file (global option)
viewtext -c my_layouts.toml list
viewtext --config examples/layouts.toml show weather
CLI Commands
- list: List all layouts in the configuration file
- show: Display detailed configuration for a specific layout
- fields: Display all field mappings from the configuration file
- render: Render a layout with mock data
- formatters: List all available formatters and their descriptions
- info: Show configuration file information and global formatters
Global Options
- --config, -c: Path to layouts.toml file (can be placed before any command)
License
See LICENSE file in the root directory.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file viewtext-0.1.0.tar.gz.
File metadata
- Download URL: viewtext-0.1.0.tar.gz
- Upload date:
- Size: 34.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7ee47a27a031d0ba25ed696ead94c7c16e86695860d5de7fd23429501619f65
|
|
| MD5 |
36b8a04938936073d1f351bab364e518
|
|
| BLAKE2b-256 |
192ac073d17ffa1238da04fdb832b21097f1b4bd6d005398dd603547e6fc6275
|
File details
Details for the file viewtext-0.1.0-py3-none-any.whl.
File metadata
- Download URL: viewtext-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ce6b81cc36c1b1c31ed24a634185711fc2a5488bffcf8cfb2754b1d70925af1
|
|
| MD5 |
a3a84e516de43df46b3a8ad29b3276fa
|
|
| BLAKE2b-256 |
d5df58154b0fb0bfa6ac4881a990c852cd64612c0bce08e6710976ea131b8377
|