Skip to main content

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 Screen and Cell APIs
  • 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

libansiscreen-0.1.2.tar.gz (30.9 kB view details)

Uploaded Source

Built Distribution

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

libansiscreen-0.1.2-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file libansiscreen-0.1.2.tar.gz.

File metadata

  • Download URL: libansiscreen-0.1.2.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for libansiscreen-0.1.2.tar.gz
Algorithm Hash digest
SHA256 79e3bb057bcce5bc890413211ab1df58143b6253e6a2f2024356d3f58054b947
MD5 e6b1afe307a0197671079a3c1911edb5
BLAKE2b-256 3739bbf52718957c14191241a82c41e06daf6a090d2bb6b8fc476afdef1ca126

See more details on using hashes here.

File details

Details for the file libansiscreen-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: libansiscreen-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for libansiscreen-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 45639cdb3c17d0effe3dd21438613e21733a0a82bc58ed2a9f489274cbc942d9
MD5 68e1d31986299c72dbbd149c3cb8def7
BLAKE2b-256 8c9026d52ec4d13df953074689e6c0d39847d8264da597eaa833dd845facd97e

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