Add examples in readme, fix in types hint.
Change of license: GPLv2 to LGPLv3.
Initial commit.
A collection of snippets to work more comfortably and pythonic with curses
.
To get started, install the library with pip
:
git clone https://git.sr.ht/~tim-ats-d/more-curses
cd More-curses
pip install .
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)
True
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
attr = (A_REVERSE, A_ALTCHARSET)
@text_attributes(*attr)
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))
win.refresh()
Feel free to contribute your own snippets.
Distributed under the LGPL-3.0 license. See license for more information.