Add an action to the `clear_terminal` function to scroll the screen contents into the scrollback buffer

Now if you want to map a key combination that will both scroll the
current screen contents into the scrollback buffer and clear the screen,
you can do something like:

map ctrl+l combine : clear_terminal scroll active : send_text normal,application \x0c

Fixes #1113
This commit is contained in:
Kovid Goyal
2018-11-03 14:18:09 +05:30
parent a958cabf01
commit fc3bd2d15f
4 changed files with 23 additions and 2 deletions

View File

@@ -1128,6 +1128,15 @@ screen_insert_lines(Screen *self, unsigned int count) {
}
}
void
screen_scroll_until_empty(Screen *self) {
unsigned int num_lines_to_scroll = MIN(self->margin_bottom, self->cursor->y + 1);
index_type y = self->cursor->y;
self->cursor->y = self->margin_bottom;
while (num_lines_to_scroll--) screen_index(self);
self->cursor->y = y;
}
void
screen_delete_lines(Screen *self, unsigned int count) {
unsigned int top = self->margin_top, bottom = self->margin_bottom;
@@ -1864,6 +1873,7 @@ is_using_alternate_linebuf(Screen *self, PyObject *a UNUSED) {
WRAP1E(cursor_back, 1, -1)
WRAP1B(erase_in_line, 0)
WRAP1B(erase_in_display, 0)
WRAP0(scroll_until_empty)
#define MODE_GETSET(name, uname) \
static PyObject* name##_get(Screen *self, void UNUSED *closure) { PyObject *ans = self->modes.m##uname ? Py_True : Py_False; Py_INCREF(ans); return ans; } \
@@ -2170,6 +2180,7 @@ static PyMethodDef methods[] = {
MND(cursor_back, METH_VARARGS)
MND(erase_in_line, METH_VARARGS)
MND(erase_in_display, METH_VARARGS)
MND(scroll_until_empty, METH_NOARGS)
METHOD(current_char_width, METH_NOARGS)
MND(insert_lines, METH_VARARGS)
MND(delete_lines, METH_VARARGS)