Curtsies: Curses-like Terminal Wrapper

0.4.3 · active · verified Wed Apr 15

Curtsies is a Python library designed for interactive terminal applications, offering full-screen window management, user input handling, and formatted text rendering with colors and styles. It enables developers to create dynamic terminal interfaces like text editors or games. The current version is 0.4.3, and it has a moderate release cadence, with recent updates focusing on Python version compatibility and minor feature enhancements.

Warnings

Install

Imports

Quickstart

This example initializes a full-screen terminal window, displays an instruction message, and then continuously captures user input. Pressing the escape key exits the application. Pressing space clears the screen, and other key presses are rendered randomly on the screen with different colors. This demonstrates basic window management, formatted text, and input handling.

import random
import sys
from curtsies import FullscreenWindow, Input, FSArray
from curtsies.fmtfuncs import red, bold, green, on_blue, yellow

print(yellow('This prints normally, not to the alternate screen'))

with FullscreenWindow() as window:
    a = FSArray(window.height, window.width)
    msg = red(on_blue(bold('Press escape to exit, space to clear.')))
    a[0:1, 0:msg.width] = [msg]
    window.render_to_terminal(a)

    with Input() as input_generator:
        for c in input_generator:
            if c == '<ESC>':
                break
            elif c == '<SPACE>':
                a = FSArray(window.height, window.width)
            else:
                s = repr(c)
                row = random.choice(range(window.height))
                column = random.choice(range(window.width - len(s)))
                color = random.choice([red, green, on_blue, yellow])
                a[row, column:column + len(s)] = [color(s)]
            window.render_to_terminal(a)

view raw JSON →