Skip to main content

Curses-like terminal wrapper, with colored strings!

Project description

[![Build Status](https://travis-ci.org/thomasballinger/curtsies.svg?branch=master)](https://travis-ci.org/thomasballinger/curtsies)
[![Documentation Status](https://readthedocs.org/projects/curtsies/badge/?version=latest)](https://readthedocs.org/projects/curtsies/?badge=latest)
![Curtsies Logo](http://ballingt.com/assets/curtsiestitle.png)

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

```python
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](http://curtsies.readthedocs.org/en/latest/)

Primer
------

[FmtStr](http://curtsies.readthedocs.org/en/latest/FmtStr.html) objects are strings formatted with
colors and styles displayable in a terminal with [ANSI escape sequences](http://en.wikipedia.org/wiki/ANSI_escape_code>`_).

(the import statement shown below is outdated)
![fmtstr example screenshot](http://i.imgur.com/7lFaxsz.png)

[FSArray](http://curtsies.readthedocs.org/en/latest/FSArray.html) 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)
![fsarray example screenshot](http://i.imgur.com/rvTRPv1.png)

Such grids of characters can be rendered to the terminal in alternate screen mode
(no history, like `Vim`, `top` etc.) by [FullscreenWindow](http://curtsies.readthedocs.org/en/latest/window.html#curtsies.window.FullscreenWindow) objects
or normal history-preserving screen by [CursorAwareWindow](http://curtsies.readthedocs.org/en/latest/window.html#curtsies.window.CursorAwareWindow) objects.
User keyboard input events like pressing the up arrow key are detected by an
[Input](http://curtsies.readthedocs.org/en/latest/input.html) object.

Examples
--------

* [Tic-Tac-Toe](/examples/tictactoeexample.py)

![screenshot](http://i.imgur.com/AucB55B.png)

* [Avoid the X's game](/examples/gameexample.py)

![screenshot](http://i.imgur.com/nv1RQd3.png)

* [Bpython-curtsies uses curtsies](http://ballingt.com/2013/12/21/bpython-curtsies.html)

[![ScreenShot](http://i.imgur.com/r7rZiBS.png)](http://www.youtube.com/watch?v=lwbpC4IJlyA)

* [More examples](/examples)

About
-----

* [Curtsies Documentation](http://curtsies.readthedocs.org/en/latest/)
* Curtsies was written to for [bpython-curtsies](http://ballingt.com/2013/12/21/bpython-curtsies.html)
* `#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](http://curtsies.readthedocs.org/en/latest/FmtStr.html#rationale)!

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

Uploaded Source

Built Distribution

curtsies-0.2.3-py2.py3-none-any.whl (29.7 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for curtsies-0.2.3.tar.gz
Algorithm Hash digest
SHA256 5da88a67472ada96de3be2a9da4210080c7e4b2c1afc4c97075b3f51755e0dc4
MD5 60d2da7850f9a3fdc14ceb18a050559b
BLAKE2b-256 e37a9ee8a2a2ae8554c38fefd9ea922da0e42a955571150ce0916850606ee511

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for curtsies-0.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 40fd66b2dc8ad4216f8bb3cb8cc10972137c697ec1a58271c7537e047dfd0077
MD5 4f29e9d9472fb79968892168e526ee5d
BLAKE2b-256 007483854007b35a76b3d92457d4fb41987d6c5d81df0195a159a8f48990896b

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