UniCurses is a wrapper for Python 2.x/3.x that provides a unified set of Curses functions on all platforms (MS Windows, Linux, and Mac OS X). Pygcurse (pronounced 'pig curse') is a curses library emulator that runs on top of. Provides curses-like features, but it only runs on Windows and not Mac/Linux. Pygcursesrc.zip, 38 KB (Requires Python 2 or 3 and Pygame to.
![]() What is curses?¶
The curses library supplies a terminal-independent screen-painting andkeyboard-handling facility for text-based terminals; such terminals includeVT100s, the Linux console, and the simulated terminal provided by X11 programssuch as xterm and rxvt. Display terminals support various control codes toperform common operations such as moving the cursor, scrolling the screen, anderasing areas. Different terminals use widely differing codes, and often havetheir own minor quirks.
In a world of X displays, one might ask “why bother”? It’s true thatcharacter-cell display terminals are an obsolete technology, but there areniches in which being able to do fancy things with them are still valuable. Oneis on small-footprint or embedded Unixes that don’t carry an X server. Anotheris for tools like OS installers and kernel configurators that may have to runbefore X is available.
The curses library hides all the details of different terminals, and providesthe programmer with an abstraction of a display, containing multiplenon-overlapping windows. The contents of a window can be changed in variousways– adding text, erasing it, changing its appearance–and the curses librarywill automagically figure out what control codes need to be sent to the terminalto produce the right output.
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.
No one has made a Windows port of the curses module. On a Windows platform, trythe Console module written by Fredrik Lundh. The Console module providescursor-addressable text output, plus full support for mouse and keyboard input,and is available from http://effbot.org/zone/console-index.htm.
The Python curses module¶![]()
Thy 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 asaddstr(), mvaddstr(), mvwaddstr(), into a singleaddstr() method. You’ll see this covered in more detail later.
This HOWTO is simply 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.
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |