diff --git a/kitty/line-buf.c b/kitty/line-buf.c index 7971de19c..8fb0aef8a 100644 --- a/kitty/line-buf.c +++ b/kitty/line-buf.c @@ -14,6 +14,18 @@ clear_chars_to_space(LineBuf* linebuf, index_type y) { for (index_type i = 0; i < linebuf->xnum; i++) chars[i] = (1 << ATTRS_SHIFT) | 32; } +static PyObject* +clear(LineBuf *self) { +#define clear_doc "Clear all lines in this LineBuf" + memset(self->buf, 0, self->block_size * CELL_SIZE); + memset(self->continued_map, 0, self->ynum * sizeof(index_type)); + for (index_type i = 0; i < self->ynum; i++) { + clear_chars_to_space(self, i); + self->line_map[i] = i; + } + Py_RETURN_NONE; +} + static PyObject * new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) { LineBuf *self; @@ -98,6 +110,7 @@ copy_old(LineBuf *self, PyObject *y); static PyMethodDef methods[] = { METHOD(line, METH_O) METHOD(copy_old, METH_O) + METHOD(clear, METH_NOARGS) {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/kitty_tests/datatypes.py b/kitty_tests/datatypes.py index 591bd1d83..2af028314 100644 --- a/kitty_tests/datatypes.py +++ b/kitty_tests/datatypes.py @@ -17,6 +17,8 @@ class TestDataTypes(BaseTest): new = LineBuf(1, 3) new.copy_old(old) self.ae(new.line(0), old.line(1)) + new.clear() + self.ae(str(new.line(0)), ' ' * new.xnum) def test_line(self): lb = LineBuf(2, 3)