diff --git a/kitty/history.c b/kitty/history.c index e11c51a80..7b0fcf7b6 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -136,10 +136,14 @@ push(HistoryBuf *self, PyObject *args) { } // Boilerplate {{{ +static PyObject* rewrap(HistoryBuf *self, PyObject *args); +#define rewrap_doc "" + static PyMethodDef methods[] = { METHOD(change_num_of_lines, METH_O) METHOD(line, METH_O) METHOD(push, METH_VARARGS) + METHOD(rewrap, METH_VARARGS) {NULL, NULL, 0, NULL} /* Sentinel */ }; @@ -196,4 +200,10 @@ void historybuf_rewrap(HistoryBuf *self, HistoryBuf *other) { if (self->count > 0) rewrap_inner(self, other, self->count, NULL); } - +static PyObject* +rewrap(HistoryBuf *self, PyObject *args) { + HistoryBuf *other; + if (!PyArg_ParseTuple(args, "O!", &HistoryBuf_Type, &other)) return NULL; + historybuf_rewrap(self, other); + Py_RETURN_NONE; +} diff --git a/kitty_tests/datatypes.py b/kitty_tests/datatypes.py index 36ec9dd75..1856bedde 100644 --- a/kitty_tests/datatypes.py +++ b/kitty_tests/datatypes.py @@ -310,3 +310,21 @@ class TestDataTypes(BaseTest): hb.push(lb.line(2)) self.ae(str(hb.line(0)), '2' * hb.xnum) self.ae(str(hb.line(4)), '1' * hb.xnum) + + # rewrap + hb = filled_history_buf(5, 5) + hb2 = HistoryBuf(hb.ynum, hb.xnum) + hb.rewrap(hb2) + for i in range(hb.ynum): + self.ae(hb2.line(i), hb.line(i)) + hb2 = HistoryBuf(8, 5) + hb.rewrap(hb2) + for i in range(hb.ynum): + self.ae(hb2.line(i), hb.line(i)) + for i in range(hb.ynum, hb2.ynum): + with self.assertRaises(IndexError): + hb2.line(i) + hb2 = HistoryBuf(3, 5) + hb.rewrap(hb2) + for i in range(hb2.ynum): + self.ae(hb2.line(i), hb.line(i))