Skip to main content

Curses-like terminal wrapper, with colored strings!

Project description

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

  • Curtsies Documentation
  • Curtsies was written to for bpython-curtsies
  • #bpython on irc is a good place to talk about Curtsies, but feel free to open an issue if you're having a problem!
  • Thanks to the many contributors!
  • If all you need are colored strings, consider one of these other libraries!

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

curtsies-0.4.2.tar.gz (53.6 kB view details)

Uploaded Source

Built Distribution

curtsies-0.4.2-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file curtsies-0.4.2.tar.gz.

File metadata

  • Download URL: curtsies-0.4.2.tar.gz
  • Upload date:
  • Size: 53.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for curtsies-0.4.2.tar.gz
Algorithm Hash digest
SHA256 6ebe33215bd7c92851a506049c720cca4cf5c192c1665c1d7a98a04c4702760e
MD5 0a4326bc5e0f3c076626419592dfeda2
BLAKE2b-256 53d2ea91db929b5dcded637382235f9f1b7d06ef64b7f2af7fe1be1369e1f0d2

See more details on using hashes here.

File details

Details for the file curtsies-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: curtsies-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for curtsies-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f24d676a8c4711fb9edba1ab7e6134bc52305a222980b3b717bb303f5e94cec6
MD5 185524b89041063afc1c9dca25e8693c
BLAKE2b-256 5eabc4ae7ff01c75001829dfa54da9b25632a8206fa5c9036ea0292096b402d0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page