Move implementation of screen_line() into C
This commit is contained in:
parent
4ae3abb3cb
commit
b8c34c3ee2
@ -301,13 +301,7 @@ class CharGrid:
|
||||
|
||||
def screen_line(self, y):
|
||||
' Return the Line object corresponding to the yth line on the rendered screen '
|
||||
if y >= 0 and y < self.screen.lines:
|
||||
if self.scrolled_by:
|
||||
if y < self.scrolled_by:
|
||||
return self.screen.historybuf.line(self.scrolled_by - 1 - y)
|
||||
return self.screen.line(y - self.scrolled_by)
|
||||
else:
|
||||
return self.screen.line(y)
|
||||
return self.screen.visual_line(y, self.scrolled_by)
|
||||
|
||||
def multi_click(self, count, x, y):
|
||||
x, y = self.cell_for_pos(x, y)
|
||||
|
||||
@ -1078,6 +1078,25 @@ line(Screen *self, PyObject *val) {
|
||||
return (PyObject*) self->linebuf->line;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
visual_line(Screen *self, PyObject *args) {
|
||||
// The line corresponding to the yth visual line, taking into account scrolling
|
||||
unsigned int y, scrolled_by;
|
||||
if (!PyArg_ParseTuple(args, "II", &y, &scrolled_by)) return NULL;
|
||||
if (y >= self->lines) { Py_RETURN_NONE; }
|
||||
if (scrolled_by) {
|
||||
if (y < scrolled_by) {
|
||||
historybuf_init_line(self->historybuf, scrolled_by - 1 - y, self->historybuf->line);
|
||||
Py_INCREF(self->historybuf->line);
|
||||
return (PyObject*) self->historybuf->line;
|
||||
}
|
||||
y -= scrolled_by;
|
||||
}
|
||||
linebuf_init_line(self->linebuf, y);
|
||||
Py_INCREF(self->linebuf->line);
|
||||
return (PyObject*) self->linebuf->line;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
draw(Screen *self, PyObject *src) {
|
||||
if (!PyUnicode_Check(src)) { PyErr_SetString(PyExc_TypeError, "A unicode string is required"); return NULL; }
|
||||
@ -1271,6 +1290,7 @@ COUNT_WRAP(cursor_forward)
|
||||
|
||||
static PyMethodDef methods[] = {
|
||||
MND(line, METH_O)
|
||||
MND(visual_line, METH_VARARGS)
|
||||
MND(draw, METH_O)
|
||||
MND(cursor_position, METH_VARARGS)
|
||||
MND(set_mode, METH_VARARGS)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user