LineBuf.set_continued

This commit is contained in:
Kovid Goyal 2016-11-04 22:41:35 +05:30
parent 7687e75de4
commit 20b5534c71
3 changed files with 28 additions and 2 deletions

View File

@ -114,6 +114,26 @@ set_attribute(LineBuf *self, PyObject *args) {
Py_RETURN_NONE;
}
static PyObject*
set_continued(LineBuf *self, PyObject *args) {
#define set_continued_doc "set_continued(y, val) -> Set the continued values for the specified line."
unsigned int y;
int val;
if (!PyArg_ParseTuple(args, "Ip", &y, &val)) return NULL;
if (y >= self->ynum) { PyErr_SetString(PyExc_ValueError, "Out of bounds."); return NULL; }
self->continued_map[y] = val & 1;
Py_RETURN_NONE;
}
static PyObject*
is_continued(LineBuf *self, PyObject *val) {
#define is_continued_doc "is_continued(y) -> Whether the line y is continued or not"
unsigned long y = PyLong_AsUnsignedLong(val);
if (y >= self->ynum) { PyErr_SetString(PyExc_ValueError, "Out of bounds."); return NULL; }
if (self->continued_map[y]) { Py_RETURN_TRUE; }
Py_RETURN_FALSE;
}
// Boilerplate {{{
static PyObject*
@ -125,6 +145,8 @@ static PyMethodDef methods[] = {
METHOD(copy_old, METH_O)
METHOD(clear, METH_NOARGS)
METHOD(set_attribute, METH_VARARGS)
METHOD(set_continued, METH_VARARGS)
METHOD(is_continued, METH_O)
{NULL, NULL, 0, NULL} /* Sentinel */
};

View File

@ -357,7 +357,7 @@ class Screen:
if mo.DECAWM in self.mode:
self.carriage_return()
self.linefeed()
self.linebuf[self.cursor.y].continued = True
self.linebuf.set_continued(self.cursor.y, True)
space_left_in_line = self.columns
else:
space_left_in_line = 1
@ -365,7 +365,7 @@ class Screen:
pos = len(data) - 1
self.cursor.x = self.columns - 1
write_sz = min(len_left, space_left_in_line)
line = self.linebuf[self.cursor.y]
line = self.linebuf.line(self.cursor.y)
if do_insert:
line.right_shift(self.cursor.x, write_sz)
line.set_text(data, pos, write_sz, self.cursor)

View File

@ -25,6 +25,10 @@ class TestDataTypes(BaseTest):
c = old.line(y).cursor_from(x)
self.assertFalse(c.reverse)
self.assertTrue(c.bold)
self.assertFalse(old.is_continued(0))
old.set_continued(0, True)
self.assertTrue(old.is_continued(0))
self.assertFalse(old.is_continued(1))
def test_line(self):
lb = LineBuf(2, 3)