Skip to main content

termpixels

the terminal as a character-cell matrix

Build Status Code Coverage

Get it

This project is on PyPI.

Alternatively, clone this repository and pip install -e . in the root directory.

Requires Python 3, and no dependencies*!

* Requires pytest to run tests

Purpose

Creating programs that run inside of terminals seems convoluted. The goal of termpixels is to abstract the terminal into a 2D array of "pixels", or character cells, which each contain a single text character, a foreground color, and a background color. termpixels allows you to modify the screen contents anywhere, at any time, and then handles updating the terminal automatically, as well as simplifying complicated terminal input processing.

Ultimately, this project seeks to make the terminal more accessible and more fun.

Limitations

There are lots of great libraries for coloring terminal output. This one is designed for full-screen applications that completely control the contents of the screen. That means that it, e.g., automatically saves and clears the screen, resets the cursor position, and accepts input in cbreak mode.

It's not the best solution for simply printing colored text, though you can do that if you want.

Demo

Demo gif

from termpixels import App, Color
from time import time
from math import sin

class FunTextApp(App):
    def on_frame(self):
        self.screen.clear()                           # remove everything from the screen
        text = "Hello world, from termpixels!"

        for i, c in enumerate(text):
            f = i / len(text)
            color = Color.hsl(f + time(), 1, 0.5)     # create a color from a hue value
            x = self.screen.w // 2 - len(text) // 2   # horizontally center the text
            offset = sin(time() * 3 + f * 5) * 2      # some arbitrary math
            y = round(self.screen.h / 2 + offset)     # vertical center with an offset
            self.screen.print(c, x + i, y, fg=color)  # draw the text to the screen buffer

        self.screen.update()                          # commit the changes to the screen

if __name__ == "__main__":
    FunTextApp().start()

More demos

Features

  • Unix (and Mac) terminal feature detection with terminfo (via Python curses)
  • Windows support through Win32 Console API
  • Terminal (re)size detection
  • Asynchronous input
    • Keyboard input with support for special keys like arrows, function keys, escape, etc.
    • Mouse click, scroll and move input in terminals supporting xterm mouse
  • 16, 256, and true color output (with detection for best supported mode)
  • Display the cursor anywhere (or hide it!)
  • Preserves the state of the user's terminal using alternate screen buffer.
  • Rudimentary support for fullwidth characters.
  • No reliance on ncurses except for terminfo lookup
  • 100% Python
  • and more

Inspiration

Metadata

Release files for termpixels 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for termpixels 0.0.11
File Size Uploaded
termpixels-0.0.11.tar.gz 21.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for termpixels 0.0.11
File Interpreter ABI Platform
termpixels-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 46.7 kB

Release files / termpixels-0.0.11.tar.gz

Download URL termpixels-0.0.11.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
872bfc74f12a9cba4110f708d73afa85d5ee319264b810d44fd7910760804317
BLAKE2b-256 checksum
How to use checksums
f750c425db5364a9307a430415ead69ad12ba15b2402fc8bf04fe9028f33e97c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.7.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.4

Release files / termpixels-0.0.11-py3-none-any.whl

Download URL termpixels-0.0.11-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcd8cef6ee45539537d50696fad885d0ff1a1dd5047799948b297d4ebfec7c0c
BLAKE2b-256 checksum
How to use checksums
d69abc2d69e937c918634f1ccf8ae85ef9318535bf2894ed4232d210d276e0d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.7.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

1 release file

0.0.5

1 release file

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page