Jinxed Terminal Library

1.4.0 · active · verified Wed Apr 15

Jinxed is an implementation of a subset of the Python curses library, providing pure Python implementations of terminfo functions such as `tigetstr()` and `tparm()`. It also offers convenience methods for working with Windows terminals. Initially developed to support the Blessed library on Windows, Jinxed is designed to work across all platforms.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `jinxed` to retrieve and apply terminfo capabilities like moving the cursor. It fetches terminal capabilities using `tigetstr` and then uses `tparm` to instantiate parameterized strings, which are then written to the console.

import os
from jinxed.terminfo import tigetstr, tparm

def main():
    # Get the terminal type from environment, default to 'xterm'
    term_type = os.environ.get('TERM', 'xterm')
    print(f"Using terminal type: {term_type}")

    # Get the 'cursor up' capability string
    cursor_up_cap = tigetstr('cuu1')
    if cursor_up_cap:
        print(f"'cursor up' capability: {cursor_up_cap!r}")
    else:
        print("'cursor up' capability not found for this terminal.")

    # Get and apply a parameterized capability, e.g., 'cursor address' (cup)
    # This moves the cursor to a specific row and column (0-indexed)
    cursor_address_cap = tigetstr('cup')
    if cursor_address_cap:
        # Move cursor to row 5, column 10 (0-indexed)
        # Note: tparm parameters are often 1-indexed in terminfo, but curses/jinxed often maps to 0-indexed.
        # Actual behavior may depend on specific terminal and capability.
        control_sequence = tparm(cursor_address_cap, 5, 10)
        if control_sequence:
            print(f"Moving cursor to (5,10): {control_sequence!r}")
            os.write(1, control_sequence) # Write directly to stdout's file descriptor
            os.write(1, b'Hello!\n')
    else:
        print("'cursor address' capability not found.")

if __name__ == '__main__':
    main()

view raw JSON →