Expose wcwidth to the python api
This commit is contained in:
parent
a527cc88f3
commit
348cdf5d5d
@ -1246,6 +1246,16 @@ screen_url_range(Screen *self, uint32_t *data) {
|
|||||||
#define WRAP1E(name, defval, ...) static PyObject* name(Screen *self, PyObject *args) { unsigned int v=defval; if(!PyArg_ParseTuple(args, "|I", &v)) return NULL; screen_##name(self, v, __VA_ARGS__); Py_RETURN_NONE; }
|
#define WRAP1E(name, defval, ...) static PyObject* name(Screen *self, PyObject *args) { unsigned int v=defval; if(!PyArg_ParseTuple(args, "|I", &v)) return NULL; screen_##name(self, v, __VA_ARGS__); Py_RETURN_NONE; }
|
||||||
#define WRAP2(name, defval1, defval2) static PyObject* name(Screen *self, PyObject *args) { unsigned int a=defval1, b=defval2; if(!PyArg_ParseTuple(args, "|II", &a, &b)) return NULL; screen_##name(self, a, b); Py_RETURN_NONE; }
|
#define WRAP2(name, defval1, defval2) static PyObject* name(Screen *self, PyObject *args) { unsigned int a=defval1, b=defval2; if(!PyArg_ParseTuple(args, "|II", &a, &b)) return NULL; screen_##name(self, a, b); Py_RETURN_NONE; }
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
screen_wcswidth(Screen UNUSED *self, PyObject *str) {
|
||||||
|
if (PyUnicode_READY(str) != 0) return NULL;
|
||||||
|
int kind = PyUnicode_KIND(str);
|
||||||
|
void *data = PyUnicode_DATA(str);
|
||||||
|
Py_ssize_t len = PyUnicode_GET_LENGTH(str), ans = 0, i;
|
||||||
|
for (i = 0; i < len; i++) ans += wcwidth_impl(PyUnicode_READ(kind, data, i));
|
||||||
|
return PyLong_FromSsize_t(ans);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
line(Screen *self, PyObject *val) {
|
line(Screen *self, PyObject *val) {
|
||||||
unsigned long y = PyLong_AsUnsignedLong(val);
|
unsigned long y = PyLong_AsUnsignedLong(val);
|
||||||
@ -1551,6 +1561,7 @@ static PyMethodDef methods[] = {
|
|||||||
MND(cursor_down, METH_VARARGS)
|
MND(cursor_down, METH_VARARGS)
|
||||||
MND(cursor_down1, METH_VARARGS)
|
MND(cursor_down1, METH_VARARGS)
|
||||||
MND(cursor_forward, METH_VARARGS)
|
MND(cursor_forward, METH_VARARGS)
|
||||||
|
{"wcswidth", (PyCFunction)screen_wcswidth, METH_O, ""},
|
||||||
{"index", (PyCFunction)xxx_index, METH_VARARGS, ""},
|
{"index", (PyCFunction)xxx_index, METH_VARARGS, ""},
|
||||||
MND(tab, METH_NOARGS)
|
MND(tab, METH_NOARGS)
|
||||||
MND(backspace, METH_NOARGS)
|
MND(backspace, METH_NOARGS)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user