bpython / curtsies

Curses-like terminal wrapper with a display based on compositing 2d arrays of text.
MIT License
228 stars 52 forks source link

Documentation Status Curtsies Logo

Curtsies is a Python 3.6+ compatible library for interacting with the terminal. This is what using (nearly every feature of) curtsies looks like:

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)

Paste it in a something.py file and try it out!

Installation: pip install curtsies

Documentation

Primer

FmtStr objects are strings formatted with colors and styles displayable in a terminal with ANSI escape sequences.

FSArray objects contain multiple such strings with each formatted string on its own row, and FSArray objects can be superimposed on each other to build complex grids of colored and styled characters through composition.

(the import statement shown below is outdated)

Such grids of characters can be rendered to the terminal in alternate screen mode (no history, like Vim, top etc.) by FullscreenWindow objects or normal history-preserving screen by CursorAwareWindow objects. User keyboard input events like pressing the up arrow key are detected by an Input object.

Examples

About