libAnsiScreen
libAnsiScreen is a character-cell rendering library that treats ANSI as a serialization format, not as a rendering model.
Instead of relying on terminal state, cursor tricks, or partial redraw side effects, libAnsiScreen maintains an explicit in-memory screen buffer composed of cells—each with a character, foreground color, background color, and attributes. ANSI escape sequences are parsed into this buffer, and optimized ANSI output is generated from it.
This design makes terminal rendering deterministic, composable, and portable.
Motivation
ANSI terminals were designed for teletypes, not modern interfaces.
Cursor movement is expensive. Partial redraws are fragile. Terminal emulators vary wildly in behavior. Anyone who has tried to build a game, UI, or compositor using raw ANSI has eventually discovered the same truth:
You need a real screen model.
libAnsiScreen exists to provide that model.
Core Concepts
Screen Buffer
At the heart of libAnsiScreen is a 2D screen buffer with an explicit width and height. Each cell contains:
- a character
- a foreground color (internally stored as RGB)
- a background color (internally stored as RGB)
- optional attributes (bold, underline, inverse, etc.)
The buffer is the single source of truth. No terminal state is assumed.
ANSI as Input and Output
ANSI escape sequences are supported in two directions:
-
Import: ANSI streams can be parsed into the buffer, starting at any
(x, y)coordinate. Cursor movement, color changes, and erase commands mutate the buffer—not the terminal. -
Export: The buffer can be rendered back to ANSI using different strategies, such as:
- full-frame scanline output (no cursor positioning)
- diff-based output with cost-aware cursor movement
This makes ANSI deterministic, replayable, and testable.
Truecolor Internals
Internally, all colors are stored as up to 24-bit RGB.
This allows libAnsiScreen to:
- correctly parse truecolor ANSI (
38;2/48;2) - downsample deterministically to:
- 256-color ANSI
- 16-color ANSI
- 8-color ANSI
- monochrome
- apply perceptual quantization and dithering policies
ANSI color depth becomes an output choice, not a limitation.
Intended Use Cases
libAnsiScreen is designed to be a foundational rendering layer for:
- BBS software (e.g. Synchronet external programs)
- terminal games
- ANSI art tools and compositors
- image-to-ANSI pipelines
- terminal UI experiments
- offline ANSI processing and optimization
It is not a full terminal emulator. Input modes, keyboard mapping, mouse tracking, and device queries are intentionally out of scope.
Design Philosophy
- Deterministic: Same input buffer → same output ANSI
- Explicit: No hidden terminal state
- Composable: Multiple sources can render into the same buffer
- Cost-aware: Rendering strategies can be chosen based on byte cost
- Portable: Works across terminals, SSH, telnet, and BBS environments
Project Status
libAnsiScreen is under active development.
The core buffer model, ANSI parsing, and rendering strategies are being designed with correctness and long-term reuse in mind. The public API is not yet frozen.
Usage & API
from libansiscreen.screen import Screen
from libansiscreen.color.rgb import Color
# Create screen buffer
screen = Screen(width=40)
screen.set_foreground(Color(0, 255, 128))
screen.put_text("Hello, libAnsiScreen!")
# Render to ANSI escape sequence string
print(screen.emit())
For detailed guides and reference:
License
MIT License. See LICENSE for details.
Metadata
Release files for libAnsiScreen 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| libansiscreen-0.2.0.tar.gz | 55.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| libansiscreen-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 106.2 kB
Release files / libansiscreen-0.2.0.tar.gz
| Download URL | libansiscreen-0.2.0.tar.gz |
|---|---|
| Size | 55.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
78fcad492ff5f1dfe1aa7cda95e300ab1f6731a00d6ada54519d15ba77e8fc85
|
|
BLAKE2b-256 checksum How to use checksums |
2fe2256a28a5e48e12eb37678c8c5fb6321f95342bddfa707fa5e6df7a700495
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / libansiscreen-0.2.0-py3-none-any.whl
| Download URL | libansiscreen-0.2.0-py3-none-any.whl |
|---|---|
| Size | 50.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
80c41a8c1b7b4b43a7aed3761d3a0c8359dce7a90a43263a9d082a4d7fe1d35f
|
|
BLAKE2b-256 checksum How to use checksums |
3307c0da5cfbe83975dbd5fa8932e7860ea8714788dad597ce6ed200a14f996c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|