diff --git a/kitty/history.c b/kitty/history.c index 508ae2fac..7a43eda57 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -208,7 +208,7 @@ static PyObject* as_text(HistoryBuf *self, PyObject *args) { Line l = {.xnum=self->xnum}; #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 } diff --git a/kitty/line-buf.c b/kitty/line-buf.c index 6b6699b41..38f4940a8 100644 --- a/kitty/line-buf.c +++ b/kitty/line-buf.c @@ -414,7 +414,7 @@ get_line(LineBuf *self, index_type y) { static PyObject* 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); } diff --git a/kitty/lineops.h b/kitty/lineops.h index ec93cc7a8..b2a238a28 100644 --- a/kitty/lineops.h +++ b/kitty/lineops.h @@ -81,14 +81,15 @@ void historybuf_refresh_sprite_positions(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; \ - int as_ansi = 0; \ - if (!PyArg_ParseTuple(args, "O|p", &callback, &as_ansi)) return NULL; \ + int as_ansi = 0, insert_wrap_markers = 0; \ + if (!PyArg_ParseTuple(args, "O|pp", &callback, &as_ansi, &insert_wrap_markers)) return NULL; \ PyObject *ret = NULL, *t = NULL; \ Py_UCS4 *buf = NULL; \ 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) { \ buf = malloc(sizeof(Py_UCS4) * columns * 100); \ if (buf == NULL) { PyErr_NoMemory(); goto end; } \ @@ -109,9 +110,14 @@ void historybuf_clear(HistoryBuf *self); if (t == NULL) goto end; \ ret = PyObject_CallFunctionObjArgs(callback, t, NULL); \ 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: \ - Py_CLEAR(nl); free(buf); \ + Py_CLEAR(nl); Py_CLEAR(cr); free(buf); \ if (PyErr_Occurred()) return NULL; \ Py_RETURN_NONE; \ } diff --git a/kitty/screen.c b/kitty/screen.c index bb5ad1c80..2e9471dba 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1462,12 +1462,12 @@ screen_open_url(Screen *self) { static PyObject* 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* 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*