Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r91589:223ff388e219
Date: 2017-06-12 07:40 +0200
http://bitbucket.org/pypy/pypy/changeset/223ff388e219/
Log: _curses: Implement Window.get_wch() and unget_wch().
These two functions are needed to handle wide Unicode characters,
like CJK and some emoji.
(from linkmauve, last part of PR #535 and the only one that applies
only to py3.5)
diff --git a/lib_pypy/_curses.py b/lib_pypy/_curses.py
--- a/lib_pypy/_curses.py
+++ b/lib_pypy/_curses.py
@@ -403,6 +403,17 @@
raise error("getch requires 0 or 2 arguments")
return val
+ def get_wch(self, *args):
+ wch = ffi.new("int[1]")
+ if len(args) == 0:
+ val = lib.wget_wch(self._win, wch)
+ elif len(args) == 2:
+ val = lib.mvwget_wch(self._win, *args, wch)
+ else:
+ raise error("get_wch requires 0 or 2 arguments")
+ _check_ERR(val, "get_wch"):
+ return wch[0]
+
def getkey(self, *args):
if len(args) == 0:
val = lib.wgetch(self._win)
@@ -1005,6 +1016,11 @@
return _check_ERR(lib.ungetch(_chtype(ch)), "ungetch")
+def unget_wch(ch):
+ _ensure_initialised()
+ return _check_ERR(lib.unget_wch(_chtype(ch)), "unget_wch")
+
+
def use_env(flag):
lib.use_env(flag)
return None
diff --git a/lib_pypy/_curses_build.py b/lib_pypy/_curses_build.py
--- a/lib_pypy/_curses_build.py
+++ b/lib_pypy/_curses_build.py
@@ -70,6 +70,8 @@
typedef unsigned long... chtype;
typedef chtype attr_t;
+typedef int... wint_t;
+
typedef struct
{
short id; /* ID to distinguish multiple devices */
@@ -167,6 +169,8 @@
void filter(void);
int flash(void);
int flushinp(void);
+int wget_wch(WINDOW *, wint_t *);
+int mvwget_wch(WINDOW *, int, int, wint_t *);
chtype getbkgd(WINDOW *);
WINDOW * getwin(FILE *);
int halfdelay(int);
@@ -242,6 +246,7 @@
int touchwin(WINDOW *);
int typeahead(int);
int ungetch(int);
+int unget_wch(const wchar_t);
int untouchwin(WINDOW *);
void use_env(bool);
int waddch(WINDOW *, const chtype);
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit