Curses-like terminal wrapper, with colored strings!
Project description
Curtsies is a Python 2.7 & 3.4+ compatible 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
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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file curtsies-0.3.1.tar.gz
.
File metadata
- Download URL: curtsies-0.3.1.tar.gz
- Upload date:
- Size: 47.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2c913a8113c4382e1a221679f2338139b112839deb16c00ee873e57a4b33bd4 |
|
MD5 | 60b63928812df3297856bcd53278071b |
|
BLAKE2b-256 | 5a81acd15a63392c25d78ba94f528f66e86093d72e0fb618b573743aa4efdccc |
File details
Details for the file curtsies-0.3.1-py2.py3-none-any.whl
.
File metadata
- Download URL: curtsies-0.3.1-py2.py3-none-any.whl
- Upload date:
- Size: 32.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9169d734323a1356e7563b1ca0bff3c5358c1b1dcce52506a9d4d8ab8a8f5604 |
|
MD5 | 8699d039c27432717c08ce853775c4be |
|
BLAKE2b-256 | b7d6f3e8ff9e7cae11bc3c441d58c945963afa3755eeccceb51c4046dceb891c |