mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 03:01:57 +02:00
Cleanup the as_text_generic macro
Also allow adding a \r at the end of each visual line
This commit is contained in:
@@ -208,7 +208,7 @@ static PyObject*
|
|||||||
as_text(HistoryBuf *self, PyObject *args) {
|
as_text(HistoryBuf *self, PyObject *args) {
|
||||||
Line l = {.xnum=self->xnum};
|
Line l = {.xnum=self->xnum};
|
||||||
#define gl(self, y) get_line(self, y, &l);
|
#define gl(self, y) get_line(self, y, &l);
|
||||||
as_text_generic(args, self, gl, self->count, self->xnum, callback, as_ansi);
|
as_text_generic(args, self, gl, self->count, self->xnum);
|
||||||
#undef gl
|
#undef gl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -414,7 +414,7 @@ get_line(LineBuf *self, index_type y) {
|
|||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
as_text(LineBuf *self, PyObject *args) {
|
as_text(LineBuf *self, PyObject *args) {
|
||||||
as_text_generic(args, self, get_line, self->ynum, self->xnum, callback, as_ansi);
|
as_text_generic(args, self, get_line, self->ynum, self->xnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -81,14 +81,15 @@ void historybuf_refresh_sprite_positions(HistoryBuf *self);
|
|||||||
void historybuf_clear(HistoryBuf *self);
|
void historybuf_clear(HistoryBuf *self);
|
||||||
|
|
||||||
|
|
||||||
#define as_text_generic(args, container, get_line, lines, columns, callback, as_ansi) { \
|
#define as_text_generic(args, container, get_line, lines, columns) { \
|
||||||
PyObject *callback; \
|
PyObject *callback; \
|
||||||
int as_ansi = 0; \
|
int as_ansi = 0, insert_wrap_markers = 0; \
|
||||||
if (!PyArg_ParseTuple(args, "O|p", &callback, &as_ansi)) return NULL; \
|
if (!PyArg_ParseTuple(args, "O|pp", &callback, &as_ansi, &insert_wrap_markers)) return NULL; \
|
||||||
PyObject *ret = NULL, *t = NULL; \
|
PyObject *ret = NULL, *t = NULL; \
|
||||||
Py_UCS4 *buf = NULL; \
|
Py_UCS4 *buf = NULL; \
|
||||||
PyObject *nl = PyUnicode_FromString("\n"); \
|
PyObject *nl = PyUnicode_FromString("\n"); \
|
||||||
if (nl == NULL) goto end; \
|
PyObject *cr = PyUnicode_FromString("\r"); \
|
||||||
|
if (nl == NULL || cr == NULL) goto end; \
|
||||||
if (as_ansi) { \
|
if (as_ansi) { \
|
||||||
buf = malloc(sizeof(Py_UCS4) * columns * 100); \
|
buf = malloc(sizeof(Py_UCS4) * columns * 100); \
|
||||||
if (buf == NULL) { PyErr_NoMemory(); goto end; } \
|
if (buf == NULL) { PyErr_NoMemory(); goto end; } \
|
||||||
@@ -109,9 +110,14 @@ void historybuf_clear(HistoryBuf *self);
|
|||||||
if (t == NULL) goto end; \
|
if (t == NULL) goto end; \
|
||||||
ret = PyObject_CallFunctionObjArgs(callback, t, NULL); \
|
ret = PyObject_CallFunctionObjArgs(callback, t, NULL); \
|
||||||
Py_DECREF(t); if (ret == NULL) goto end; Py_DECREF(ret); \
|
Py_DECREF(t); if (ret == NULL) goto end; Py_DECREF(ret); \
|
||||||
|
if (insert_wrap_markers) { \
|
||||||
|
ret = PyObject_CallFunctionObjArgs(callback, cr, NULL); \
|
||||||
|
if (ret == NULL) goto end; \
|
||||||
|
Py_CLEAR(ret); \
|
||||||
|
}\
|
||||||
} \
|
} \
|
||||||
end: \
|
end: \
|
||||||
Py_CLEAR(nl); free(buf); \
|
Py_CLEAR(nl); Py_CLEAR(cr); free(buf); \
|
||||||
if (PyErr_Occurred()) return NULL; \
|
if (PyErr_Occurred()) return NULL; \
|
||||||
Py_RETURN_NONE; \
|
Py_RETURN_NONE; \
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1462,12 +1462,12 @@ screen_open_url(Screen *self) {
|
|||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
as_text(Screen *self, PyObject *args) {
|
as_text(Screen *self, PyObject *args) {
|
||||||
as_text_generic(args, self, visual_line_, self->lines, self->columns, callback, as_ansi);
|
as_text_generic(args, self, visual_line_, self->lines, self->columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
as_text_non_visual(Screen *self, PyObject *args) {
|
as_text_non_visual(Screen *self, PyObject *args) {
|
||||||
as_text_generic(args, self, range_line_, self->lines, self->columns, callback, as_ansi);
|
as_text_generic(args, self, range_line_, self->lines, self->columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
|||||||
Reference in New Issue
Block a user