Skip to main content

Curses-like terminal wrapper, with colored strings!

Project description

Build Status Documentation Status Curtsies Logo

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

from __future__ import unicode_literals # convenient for Python 2
import random

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:
    with Input() as input_generator:
        msg = red(on_blue(bold('Press escape to exit')))
        a = FSArray(window.height, window.width)
        a[0:1, 0:msg.width] = [msg]
        for c in input_generator:
            if c == '<ESC>':
                break
            elif c == '<SPACE>':
                a = FSArray(window.height, window.width)
            else:
                s = repr(c).decode()
                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.

(the import statement shown below is outdated)

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

image3

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.2.11.tar.gz (46.7 kB view details)

Uploaded Source

Built Distribution

curtsies-0.2.11-py2.py3-none-any.whl (32.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: curtsies-0.2.11.tar.gz
  • Upload date:
  • Size: 46.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for curtsies-0.2.11.tar.gz
Algorithm Hash digest
SHA256 ec4639df654357944c201abd0d791d9dfd3ac27ce4f90ba1c2991aaf07af92ee
MD5 fe1944b9dd078c7d5d8a93c10ad7413d
BLAKE2b-256 e74ffb0cdd66abfbffd2788384accbf7896d717f70b62edf7556e2468ab87d07

See more details on using hashes here.

File details

Details for the file curtsies-0.2.11-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for curtsies-0.2.11-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8af7b0df83270a8d53c972b3436b7ac7813ffca27e6301c53b788372e3d862c2
MD5 5623081d32e348cfd02866a564a5d921
BLAKE2b-256 33d3d3473b5f082d0fe910614882d9eb0bddd4a045c319dba72f9f023ec192bb

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