~tim-ats-d/more-curses

A set of functions to work more comfortably with curses in Python.
Add examples in readme, fix in types hint.
Change of license: GPLv2 to LGPLv3.
Initial commit.

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~tim-ats-d/more-curses
read/write
git@git.sr.ht:~tim-ats-d/more-curses

You can also use your local clone with git send-email.

#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 .

#Requirements

  • Python 3.8+

#Examples

#Typing annotations

Several typing annotations are provide by More-curses:

from more_curses import CursesTextAttr, CursesKey, CursesWin

#Attributes

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

#Colors

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")

#Inputs

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()

#Contributing

Feel free to contribute your own snippets.

#License

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