summaryrefslogtreecommitdiffstats
path: root/Modules/_cursesmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-08-14 11:00:27 (GMT)
committerGitHub <noreply@github.com>2019-08-14 11:00:27 (GMT)
commit7eef81ee766c8df23e522b4e46a930cc1d360ad7 (patch)
tree3770f8be34f25a3a1f99f35f0b05c717efcba642 /Modules/_cursesmodule.c
parent15b6d0a712c08557a605f49034f8ad392985144c (diff)
downloadcpython-7eef81ee766c8df23e522b4e46a930cc1d360ad7.zip
cpython-7eef81ee766c8df23e522b4e46a930cc1d360ad7.tar.gz
cpython-7eef81ee766c8df23e522b4e46a930cc1d360ad7.tar.bz2
bpo-37738: Fix curses addch(str, color_pair) (GH-15071) (GH-15273)
Fix the implementation of curses addch(str, color_pair): pass the color pair to setcchar(), instead of always passing 0 as the color pair. (cherry picked from commit 077af8c2c93dd71086e2c5e5ff1e634b6da8f214)
Diffstat (limited to 'Modules/_cursesmodule.c')
-rw-r--r--Modules/_cursesmodule.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 45decf9..b0be6bb 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -178,6 +178,18 @@ static char *screen_encoding = NULL;
/* Utility Functions */
+static inline int
+color_pair_to_attr(short color_number)
+{
+ return ((int)color_number << 8);
+}
+
+static inline short
+attr_to_color_pair(int attr)
+{
+ return (short)((attr & A_COLOR) >> 8);
+}
+
/*
* Check the return code from a curses function and return None
* or raise an exception as appropriate. These are exported using the
@@ -614,7 +626,7 @@ curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y,
if (type == 2) {
funcname = "add_wch";
wstr[1] = L'\0';
- setcchar(&wcval, wstr, attr, 0, NULL);
+ setcchar(&wcval, wstr, attr, attr_to_color_pair(attr), NULL);
if (coordinates_group)
rtn = mvwadd_wch(cwself->win,y,x, &wcval);
else {
@@ -2204,7 +2216,7 @@ PyCurses_color_pair(PyObject *self, PyObject *args)
PyCursesInitialisedColor;
if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL;
- return PyLong_FromLong((long) (n << 8));
+ return PyLong_FromLong(color_pair_to_attr(n));
}
static PyObject *
@@ -2802,7 +2814,7 @@ PyCurses_pair_number(PyObject *self, PyObject *args)
return NULL;
}
- return PyLong_FromLong((long) ((n & A_COLOR) >> 8));
+ return PyLong_FromLong(attr_to_color_pair(n));
}
static PyObject *