A set of functions to work more comfortably with curses in Python.

c8bd00b Add examples in readme, fix in types hint.

1 year, 7 days ago

614a069 Change of license: GPLv2 to LGPLv3.

1 year, 13 days ago

#More curses

A collection of snippets to work more comfortably and pythonic with curses.

#Getting started

To get started, install the library with pip:

git clone https://git.sr.ht/~tim-ats-d/more-curses
cd More-curses
pip install .


  • Python 3.8+


#Typing annotations

Several typing annotations are provide by More-curses:

from more_curses import CursesTextAttr, CursesKey, CursesWin


Combinations of attribute of any iterable:

>>> from curses import A_BOLD, A_REVERSE
>>> from more_curses import combine_attr
>>> combine_attr([A_BOLD, A_REVERSE]) == (A_BOLD | A_REVERSE)


More-curses provides a context manager to improve readability.

Without More-curses:

from curses import A_BOLD, A_ITALIC

def func(win)
    win.attron(A_BOLD, A_ITALIC)
    win.addstr(0, 0, "foobar")
    win.attroff(A_BOLD, A_ITALIC)

With More-curses:

from curses import A_BOLD, A_ITALIC

from more_curses import TextAttributes

def func(win):
    with TextAttributes(win, A_BOLD, A_ITALIC):
        win.addstr(0, 0, "foobar")

Also exist as a decorator:

from curses import A_ALTCHARSET, A_REVERSE

from more_curses import text_attributes


def greeting(win):
    win.addstr(0, 0, "Hello")


Hide the obtaining of keyboard inputs by a classical iteration mechanism:

from more_curses import iterkey

keys = iterkey(win, ["q"], method="getch")

for key in keys:
    win.addstr(0, 0, str(key))


Feel free to contribute your own snippets.


Distributed under the LGPL-3.0 license. See license for more information.