Quick example of ncurses in Python! GitHub Gist: instantly share code, notes, and snippets. Quick example of ncurses in Python! GitHub Gist: instantly share code, notes, and snippets. Thank you for the example @qguv For some reason, every time I try any python curses example (both Putty and xterm) the terminal gets corrupted after i exit. This document is intended to be an 'All in One' guide for programming with ncurses and its sister libraries. We graduate from a simple 'Hello World' program to more complex form manipulation. No prior experience in ncurses is assumed. Send comments to this address.
- On Windows, you need to install one special Python package, windows-curses available on PyPI to add support. # Needed in Windows only python -m pip install windows-curses You can verify everything works by running a Python interpreter and attempting to import curses. If you do not get any errors, you are in good shape.
- Curses.endwin curses.initscr Actually I'd expect to see curses.refresh here - but that may be a quirk of the python code. In general, ncurses passes a KEYRESIZE via the getch call that the application (such as python) should process. If it's not reading from getch, ncurses' repainting/resizing won't happen.
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 as
addstr()
, 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.
C# Ncurses
Latest version Last released:
Support for the standard curses module on Windows
Project description
Adds support for the standard Python
curses
module on Windows. Based onthese wheels. Uses thePDCurses curses implementation.The wheels are built from this GitHubrepository.
PDCurses is compiled with wide character support, meaning
get_wch()
isavailable. UTF-8 is forced as the encoding.Starting from windows-curses 2.0, in the name of pragmatism, these wheels (butnot Gohlke's) include a hack to make resizing work for applications developedagainst ncurses without Python code changes: Whenever
getch()
, getkey()
, orget_wch()
return KEY_RESIZE
, resize_term(0, 0)
is called automatically.This gives behavior similar to the automatic SIGWINCH
handling in ncurses(see PDCurses' resize_term()
documentation). Thiscommitimplements the hack.To add the same hack in Python code (which is harmless, and needed if you wantresizing to work with older windows-curses versions or with Gohlke's wheels),call
curses.resize_term(0, 0)
after receiving KEY_RESIZE
, and ignore anycurses.error
exceptions. ncurses reliably fails and does nothing forresize_term(0, 0)
, so this is safe on *nix.Please tell me if the
resize_term(0, 0)
hackery causes you any trouble.Release historyRelease notifications
2.0.1
2.0
1.1
1.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size windows_curses-2.0.1-cp27-cp27m-win32.whl (54.7 kB) | File type Wheel | Python version cp27 | Upload date | Hashes |
Filename, size windows_curses-2.0.1-cp27-cp27m-win_amd64.whl (62.9 kB) | File type Wheel | Python version cp27 | Upload date | Hashes |
Filename, size windows_curses-2.0.1-cp35-cp35m-win32.whl (60.6 kB) | File type Wheel | Python version cp35 | Upload date | Hashes |
Filename, size windows_curses-2.0.1-cp35-cp35m-win_amd64.whl (70.1 kB) | File type Wheel | Python version cp35 | Upload date | Hashes |
Filename, size windows_curses-2.0.1-cp36-cp36m-win32.whl (69.2 kB) | File type Wheel | Python version cp36 | Upload date | Hashes |
Filename, size windows_curses-2.0.1-cp36-cp36m-win_amd64.whl (77.9 kB) | File type Wheel | Python version cp36 | Upload date | Hashes |
Filename, size windows_curses-2.0.1-cp37-cp37m-win32.whl (69.2 kB) | File type Wheel | Python version cp37 | Upload date | Hashes |
Filename, size windows_curses-2.0.1-cp37-cp37m-win_amd64.whl (77.9 kB) | File type Wheel | Python version cp37 | Upload date | Hashes |
Filename, size windows_curses-2.0.1-cp38-cp38m-win32.whl (84.4 kB) | File type Wheel | Python version cp38 | Upload date | Hashes |
Filename, size windows_curses-2.0.1-cp38-cp38m-win_amd64.whl (96.5 kB) | File type Wheel | Python version cp38 | Upload date | Hashes |
Hashes for windows_curses-2.0.1-cp27-cp27m-win32.whl
Algorithm | Hash digest |
---|---|
SHA256 | 735ccc1f5d0806f4f670d6517c7aa80e844ca24c9f766f4075f895acccfbebea |
MD5 | d0fef22de9dd58f7d417dcd068c75964 |
BLAKE2-256 | e8378ac53053f32b4dbb293c82e4298259b9f3027cda37a293eabef0be613fd0 |
Hashes for windows_curses-2.0.1-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest |
---|---|
SHA256 | 5dfa38206025891f08f2f37aaf78596cfffdd5108f2032450658e5d4a04cf047 |
MD5 | 1a4a1d3b95398433681eaba8d37e61d9 |
BLAKE2-256 | b7c360e24b747c692702fa0748526d9fb001d3cc2384a9c2b9748d8ca9556b69 |
Hashes for windows_curses-2.0.1-cp35-cp35m-win32.whl
Algorithm | Hash digest |
---|---|
SHA256 | d3f7ec03ba643fd8aea06ca4466f63ad5e0acedf021670224a3aaddffe5336dd |
MD5 | 6fde7a0e7bb9d795e8300dd506123db0 |
BLAKE2-256 | c1e0c0e82643b7bbb80bbbfe903af58f11d5c65db991b86e76acb3a733c078b6 |
Hashes for windows_curses-2.0.1-cp35-cp35m-win_amd64.whl
Python Ncurses Windows 11
Algorithm | Hash digest |
---|---|
SHA256 | b9457c3ed1571787dc3835d3bf67dc07a493829d78714757cc63b517133d4a34 |
MD5 | b200f8d86c81f993f7f68887c863e479 |
BLAKE2-256 | 33504d7e286cbb1bc7c819839d6af22a134f698968fab3d3ada8f9d405eacd3f |
Hashes for windows_curses-2.0.1-cp36-cp36m-win32.whl
Algorithm | Hash digest |
---|---|
SHA256 | 6b362a2114da068d5127a0c0400423103c163f1d28bc7436350742cdd472e5eb |
MD5 | 750e63da64c3a6fa58a8dc0ea933b510 |
BLAKE2-256 | e06a13d9ed484e6d4ca4c88316dae46ceca6ed386d63be7eab4f50409be9e459 |
Hashes for windows_curses-2.0.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest |
---|---|
SHA256 | dc1d3d314c5b9580b57b5f1e24fd9dc48a306cc6b280182da432cbe05255e0fc |
MD5 | 26a9ce1771cce3fcfddbaf9a376212bc |
BLAKE2-256 | e48debaf1d97e4dc5194ef02b84ef124edf7017a833db1b315aded396656260f |
Hashes for windows_curses-2.0.1-cp37-cp37m-win32.whl
Algorithm | Hash digest |
---|---|
SHA256 | ece30053b5340a51c8f1cac4eeaf75bd7faa451c453cd07ef7fda7a9fba17adb |
MD5 | 3997e6dfc46be68422aefe69001edabd |
BLAKE2-256 | 2f40ae87b59723e0f1f617de414ee4baf5acc8f8f9854f3df080cfe509b2152c |
Hashes for windows_curses-2.0.1-cp37-cp37m-win_amd64.whl
Python Ncurses Windows Download
Algorithm | Hash digest |
---|---|
SHA256 | e531de5731201583eaf3a5e15a956bd1221e0447479ceed12aab50573757cb33 |
MD5 | 9985c91bdb553cd235cfc0c2eef14c2c |
BLAKE2-256 | c765ab6acc2a48956e8ae57ad460eca69cfb5ce85cc768a728f5634b693f0d0c |
Python Curses Windows
CloseHashes for windows_curses-2.0.1-cp38-cp38m-win32.whl
Algorithm | Hash digest |
---|---|
SHA256 | cc454f0acd911fb7c187bf672353ef4774930f38fc9d0da14cbe79f03296393c |
MD5 | e65ffaddda5c8ddb0afdb92b4d34d32c |
BLAKE2-256 | 44f57614a7448bc02ad00e088492c227027805e3759d6994cdf39c57244d333c |
Hashes for windows_curses-2.0.1-cp38-cp38m-win_amd64.whl
Algorithm | Hash digest |
---|---|
SHA256 | d6c1b3de905767abe08bacb34465ac63f5ad9b49d301994717639403b9c9337e |
MD5 | 6fbe69553106b26aaf2e9f397a8c1838 |
BLAKE2-256 | 0582feafb99e8990c06280a1371a2c9dbe93837bd94d04d523dc690b12886905 |