Character-cell rendering engine with ANSI import/export
Project description
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
Coming soon.
This section will document:
- the
ScreenandCellAPIs - ANSI import and export interfaces
- rendering strategies and cost models
- image and palette integration
License
MIT License. See LICENSE for details.
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 libansiscreen-0.1.0.tar.gz.
File metadata
- Download URL: libansiscreen-0.1.0.tar.gz
- Upload date:
- Size: 30.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19fbfd3d3c47c892ef33ed5de7e00392aa79abaab373597922a1b1519017b54e
|
|
| MD5 |
ef80a200fa123f2fc01c1c1f6d20e02f
|
|
| BLAKE2b-256 |
64afb06fe040d936039021f2dedd380f4bc66b22480fbc19d92a7e906ad7bd18
|
File details
Details for the file libansiscreen-0.1.0-py3-none-any.whl.
File metadata
- Download URL: libansiscreen-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37ff7c2ec8796c9070ada1536e5d5efc8259681827b86a40d68baeca846ca308
|
|
| MD5 |
2c03559880c7e3f3217ee63f7b249928
|
|
| BLAKE2b-256 |
a45a316881e10699a1670e6fd41c8f424914967707e0f10534609ddee6931bf1
|