Issue #15785: Modify window.get_wch() API of the curses module: return a

character for most keys, and an integer for special keys, instead of always
returning an integer. So it is now possible to distinguish special keys like
keypad keys.
This commit is contained in:
Victor Stinner 2012-08-29 01:40:57 +02:00
parent 4e07a8c9aa
commit 1d39cde50c
4 changed files with 20 additions and 13 deletions

View file

@ -267,8 +267,7 @@ def test_issue6243(stdscr):
def test_unget_wch(stdscr):
if not hasattr(curses, 'unget_wch'):
return
import locale
encoding = locale.getpreferredencoding()
encoding = stdscr.encoding
for ch in ('a', '\xe9', '\u20ac', '\U0010FFFF'):
try:
ch.encode(encoding)
@ -277,18 +276,17 @@ def test_unget_wch(stdscr):
try:
curses.unget_wch(ch)
except Exception as err:
raise Exception("unget_wch(%a) failed with locale encoding %s: %s"
% (ch, encoding, err))
raise Exception("unget_wch(%a) failed with encoding %s: %s"
% (ch, stdscr.encoding, err))
read = stdscr.get_wch()
read = chr(read)
if read != ch:
raise AssertionError("%r != %r" % (read, ch))
code = ord(ch)
curses.unget_wch(code)
read = stdscr.get_wch()
if read != code:
raise AssertionError("%r != %r" % (read, code))
if read != ch:
raise AssertionError("%r != %r" % (read, ch))
def test_issue10570():
b = curses.tparm(curses.tigetstr("cup"), 5, 3)