What is curses?¶
Curses.ncursesversion¶ A named tuple containing the three components of the ncurses library version: major, minor, and patch. All values are integers. The components can also be accessed by name, so curses.ncursesversion0 is equivalent to curses.ncursesversion.major and so on. Availability: if the ncurses library is used. For Fedora Linux: If you are using Fedora 22 Linux or the newer versions, you can use the dnf command to install the ncurses library, type: $ sudo dnf install ncurses-devel. Outputs: root@fedora26-osetc # dnf install ncurses-devel Last metadata expiration check: 1:36:24 ago on Fri 21 Jul 2017 09:01:19 AM EDT.
The curses library supplies a terminal-independent screen-painting andkeyboard-handling facility for text-based terminals; such terminalsinclude VT100s, the Linux console, and the simulated terminal providedby various programs. Display terminals support various control codesto perform common operations such as moving the cursor, scrolling thescreen, and erasing areas. Different terminals use widely differingcodes, and often have their own minor quirks.
Ncurses Library Windows
In a world of graphical displays, one might ask “why bother”? It’strue that character-cell display terminals are an obsolete technology,but there are niches in which being able to do fancy things with themare still valuable. One niche is on small-footprint or embeddedUnixes that don’t run an X server. Another is tools such as OSinstallers and kernel configurators that may have to run before anygraphical support is available.
The curses library provides fairly basic functionality, providing theprogrammer with an abstraction of a display containing multiplenon-overlapping windows of text. The contents of a window can bechanged in various ways—adding text, erasing it, changing itsappearance—and the curses library will figure out what control codesneed to be sent to the terminal to produce the right output. cursesdoesn’t provide many user-interface concepts such as buttons, checkboxes,or dialogs; if you need such features, consider a user interface library such asUrwid.
The curses library was originally written for BSD Unix; the later System Vversions of Unix from AT&T added many enhancements and new functions. BSD cursesis no longer maintained, having been replaced by ncurses, which is anopen-source implementation of the AT&T interface. If you’re using anopen-source Unix such as Linux or FreeBSD, your system almost certainly usesncurses. Since most current commercial Unix versions are based on System Vcode, all the functions described here will probably be available. The olderversions of curses carried by some proprietary Unixes may not supporteverything, though.
The Windows version of Python doesn’t include the
curses
module. A ported version called UniCurses is available. You couldalso try the Console modulewritten by Fredrik Lundh, which doesn’tuse the same API as curses but provides cursor-addressable text outputand full support for mouse and keyboard input.The Python curses module¶
Ncurses Library Documentation
The Python module is a fairly simple wrapper over the C functions provided bycurses; if you’re already familiar with curses programming in C, it’s reallyeasy to transfer that knowledge to Python. The biggest difference is that thePython interface makes things simpler by merging different C functions such as
addstr()
, mvaddstr()
, and mvwaddstr()
into a singleaddstr()
method. You’ll see this covered in moredetail later.No Curses Or Ncurses Library On This System
This HOWTO is an introduction to writing text-mode programs with cursesand Python. It doesn’t attempt to be a complete guide to the curses API; forthat, see the Python library guide’s section on ncurses, and the C manual pagesfor ncurses. It will, however, give you the basic ideas.