Skip to main content

A simple, light weight (under 27k), and 'No Dependencies' (except in linux but has auto fallbacks) terminal interface that abstracts complex ansi codes into a tilemap with 3 bit rgb support for charecter fore/background.

Project description

PyTermint

This is a cross-platform terminal abstraction that converts a tile map to a non-flickering terminal output with 3 bit rgb support using escape codes. It also has significant amounts of input automation for things like typing and movement. It clocks in at just under 27k bytes (k is 1024) (uncompressed, It goes down to 16k just with windows file compression) and has no significant dependencies outside of the Python Standard Library (other than evdev for linux input but it handles the lack of this automatically). While ~27k bytes sounds like a lot this is boiler plate not in your project which means a full colored snake game comes in at around 2.2k bytes. It also has a large amount of graphics macros for things like drawing a window, a line, a rectangle or a text_box. Through gplot() the horozontal and vertical resolution are doubled into a 1bpp bitmap with 2x2 pixel 3bpp rgb attribute coloring. The array is edited and read through screen[y][x].


  • Install with "pip install PyTermint"
  • Import as "import PyTerm"
  • Create a init() function that takes screen and returns the inital state of the tile map (a list of lists addresable as arr[y][x] or [y0 [x0, x1, x2...], y1 [x0, x1, x2...]...]), a dictionary holding all variables that should persist after the end of a frame and a optional command string
  • Create a tick() command that takes as inputs tick(screen, vars, keys). Screen is an array, vars is the dict you initialized in init and keys which is a set of every key thats pressed
  • Call the run(tick_func, init_func)

import PyTerm as pt
from PyTerm import clear, blit, color, TILE_SET, HEIGHT, WIDTH, pressed

def init(screen):
    return (screen, {
        'text': '', 
        'cpos': (0, 0),  
    })

def tick(screen, v, keys):
    pt.clear(screen, pt.color(0, bg=1)) 
    pt.handle_input(v, keys)
    if "alt" in keys and "q" in keys: return "quit"
    pt.blit(screen, pt.str_to_arr(v["text"], pt.color(0)), 0, 0)
    # Cursor rendering
    x, y = v['cpos']
    if pt.inside(screen, (x, y)):
        screen[y][x] = pt.color(8, fg=1, bg=2)

if __name__ == "__main__":
    pt.run(tick, init, False)
  • A small text editor for PyTerm

GitHub Home page link

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

pytermint-0.0.4.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

pytermint-0.0.4-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file pytermint-0.0.4.tar.gz.

File metadata

  • Download URL: pytermint-0.0.4.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pytermint-0.0.4.tar.gz
Algorithm Hash digest
SHA256 28c16a4a8f283ae5002596395ade34ee1247d17fb107e0d90bb576b204f458fe
MD5 b15f78530459cee34d7df2284ff47d9a
BLAKE2b-256 5bcec91dd9d20ee07a8a57dd59192e9c484751c1495b5494e8cdfd0977fa3938

See more details on using hashes here.

File details

Details for the file pytermint-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pytermint-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pytermint-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9755f73ce2d2e8578cef5dd780134f7509d0947b62185d88ad9356ad3ea7e83e
MD5 3236961ef1281b286a5a917ff736a145
BLAKE2b-256 5d59d53eb29f244ebab587bcde80bc0da283e9daf3d24ae58be58539c90d1143

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