Curtsies: Curses-like Terminal Wrapper
Curtsies is a Python library designed for interactive terminal applications, offering full-screen window management, user input handling, and formatted text rendering with colors and styles. It enables developers to create dynamic terminal interfaces like text editors or games. The current version is 0.4.3, and it has a moderate release cadence, with recent updates focusing on Python version compatibility and minor feature enhancements.
Warnings
- breaking Python 3.7, 3.8, and 3.9 are no longer supported. Users on these Python versions must upgrade to Python 3.10 or newer, or stick to an older curtsies version.
- breaking Curtsies switched its backend from `curses` to `blessed` in version 0.4.0. While largely compatible, subtle behavioral changes or reliance on `curses`-specific features might break existing code.
- breaking Python 3.6 support was dropped in version 0.4.0. Users on Python 3.6 must upgrade or use an older `curtsies` version.
- gotcha Application crashes can leave the terminal in a 'messed up' state (e.g., no echo, strange characters). This is common for `curses`-like libraries.
- gotcha The `Input` class can return keypresses named differently depending on the `keynames` parameter. The default 'curtsies' might differ from 'curses' or 'plain', leading to unexpected input handling if not explicitly specified.
Install
-
pip install curtsies
Imports
- FullscreenWindow
from curtsies import FullscreenWindow
- Input
from curtsies import Input
- FSArray
from curtsies import FSArray
- fmtfuncs
from curtsies.fmtfuncs import red, bold, on_blue
Quickstart
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)