[issue17700] Update Curses HOWTO for 3.4

New submission from A.M. Kuchling: Here's a patch updating the Curses HOWTO for 3.4 that can be applied to the default branch. Changes: * curses.wrapper.wrapper is now just curses.wrapper * Mention window.encoding and its effect on Unicode. * Describe getkey() as well as getch() * Improve some examples. * Use 4-space indentation. * Add links to urwid, an alternate UI library. * Various edits & rewording. ---------- assignee: docs@python components: Documentation files: update-curses-howto.txt messages: 186599 nosy: akuchling, docs@python priority: normal severity: normal stage: patch review status: open title: Update Curses HOWTO for 3.4 type: enhancement Added file: http://bugs.python.org/file29783/update-curses-howto.txt _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

Éric Araujo added the comment: Do the changes (e.g. curses.wrapper new name) not apply to 3.3? ---------- nosy: +eric.araujo versions: +Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

A.M. Kuchling added the comment: Updated version of the patch: * Correct the errors reported in the review. * Restore 3-space indents. * Mention the LINES and COLS variables. * Add more links to the final section. I believe everything in the howto also applies to 3.3; it would be fine if you want to apply it to the 3.3 branch as well. ---------- Added file: http://bugs.python.org/file29790/update-curses-howto.txt _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- nosy: +ezio.melotti versions: +Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

A.M. Kuchling added the comment: Updated version of the patch, applying many changes suggested by merwok: * use ~curses.funcname notation for links. * use 3-hyphen em-dash * minor fixes to various examples * rewrap long paragraphs (this makes the diff larger -- sorry!) ---------- Added file: http://bugs.python.org/file30071/update-curses-howto.txt _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

STINNER Victor added the comment: window.get_wch() and curses.unget_wch(ch) should be used instead of window.getch() and curses.ungetch(ch), when available. They work much better with non-ASCII characters. ---------- nosy: +haypo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

A.M. Kuchling added the comment: Victor: I would like to add a section about using Unicode characters with curses, but found little material about doing that in either Python or the underlying C API. Do you have any suggested references or example code that I could look at? (It's probably better to commit the current patch if it's suitable, and commit the wide-character changes in a separate patch once they're ready.) ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

A.M. Kuchling added the comment: I've just verified that I still have commit access to the repo, so unless someone has any further suggested changes to the patch, I'll go ahead and commit it to trunk. Should I also commit it to the 3.3 branch? Victor: I'm willing to improve the HOWTO's discussion of Unicode/wide characters if you can point me at some references. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

Ezio Melotti added the comment: Patch LGTM. You should commit it to 3.3 and then merge it with default (unless the patch contains parts that are specific to 3.4). ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

Roundup Robot added the comment: New changeset 1fa70b797973 by Andrew Kuchling in branch '3.3': #17700: update the curses HOWTO for 3.x http://hg.python.org/cpython/rev/1fa70b797973 New changeset 70f530161b9b by Andrew Kuchling in branch 'default': #17700: merge with 3.3 http://hg.python.org/cpython/rev/70f530161b9b ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

A.M. Kuchling added the comment: Applied to 3.3 and 3.4. I'll leave this issue open for a week so that Victor can comment on Unicode/wide-characters. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

STINNER Victor added the comment:
Applied to 3.3 and 3.4. I'll leave this issue open for a week so that Victor can comment on Unicode/wide-characters.
I don't know (n)curses, but I tried to improve the curses module of Python. I added an encoding attribute which is the locale encoding by default, so it should work without special configuration. But it's good to know what the default encoding is. (It was UTF-8 on older Python 3 release, maybe in Python < 3.3.) I also added functions like unget_wch() and get_wch(). The problem is that unget_wch() and get_wch() are not always available, it depends on the platform. If I remember correctly, it depends if libreadline is linked to libncursesw (and not libncurses). Ah yes, and the Python curses modules uses Unicode versions of C curses functions if available. It is still possible to use thes bytes versions if you pass bytes strings. For example: * window.addstr("abc"): use *add_wstr() functions if available, *addstr() otherwise * window.addstr(b"abc"): always use *addstr() functions I don't know enough the C libncursesw library to write an HOWTO or something like that. I just would like to say that you should prefer get_wch() over getch() if get_wch() is available. But I don't understand exactly how curses behave with control characters ("keys"?) like "up" or "left". ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________

A.M. Kuchling added the comment: I can't make sense of unget_wch. I used this test program: -------- import curses def main(stdscr): stdscr.addstr(0,0, "Key") stdscr.refresh() curses.ungetch(0x0149) while True: ch = stdscr.get_wch() stdscr.addstr(1,1, repr(ch) + ' ') if ch == 'q': break curses.wrapper(main) -------- If I use curses.unget_wch(chr(0x0149)), the following get_wch() call returns -119, not 0x149. The whole area of wide character support in curses is just a mystery, and I don't know how to resolve my questions. I'll close this item, since I have nothing further to add to the curses howto. ---------- resolution: -> fixed stage: patch review -> committed/rejected status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17700> _______________________________________
participants (5)
-
A.M. Kuchling
-
Ezio Melotti
-
Roundup Robot
-
STINNER Victor
-
Éric Araujo