Fix pre-allocation of the full history buffer

Also map negative scrollback numbers to (effectively) infinite
scrollback.
This commit is contained in:
Kovid Goyal 2018-09-06 21:06:31 +05:30
parent 9fd50a6ac0
commit d4d63506e1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 15 additions and 8 deletions

View File

@ -305,9 +305,19 @@ o('cursor_stop_blinking_after', 15.0, option_type=positive_float)
g('scrollback') # {{{
o('scrollback_lines', 2000, option_type=positive_int, long_text=_('''
def scrollback_lines(x):
x = int(x)
if x < 0:
x = 2 ** 32 - 1
return x
o('scrollback_lines', 2000, option_type=scrollback_lines, long_text=_('''
Number of lines of history to keep in memory for scrolling back. Memory is allocated
on demand.'''))
on demand. Negative numbers are (effectively) infinite scrollback. Note that using
very large scrollback is not recommended a it can slow down resizing of the terminal
and also use large amounts of RAM.'''))
o('scrollback_pager', 'less --chop-long-lines --RAW-CONTROL-CHARS +INPUT_LINE_NUMBER', option_type=to_cmdline, long_text=_('''
Program with which to view scrollback in a new window. The scrollback buffer is

View File

@ -61,7 +61,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
if (!PyArg_ParseTuple(args, "II", &ynum, &xnum)) return NULL;
if (xnum * ynum == 0) {
if (xnum == 0 || ynum == 0) {
PyErr_SetString(PyExc_ValueError, "Cannot create an empty history buffer");
return NULL;
}
@ -74,9 +74,6 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
add_segment(self);
self->line = alloc_line();
self->line->xnum = xnum;
for(index_type y = 0; y < self->ynum; y++) {
clear_chars_in_line(cpu_lineptr(self, y), gpu_lineptr(self, y), self->xnum, BLANK_CHAR);
}
}
return (PyObject*)self;
@ -164,7 +161,7 @@ line(HistoryBuf *self, PyObject *val) {
static PyObject*
__str__(HistoryBuf *self) {
PyObject *lines = PyTuple_New(self->ynum);
PyObject *lines = PyTuple_New(self->count);
if (lines == NULL) return PyErr_NoMemory();
for (index_type i = 0; i < self->count; i++) {
init_line(self, index_of(self, i), self->line);
@ -225,7 +222,7 @@ static PyObject*
dirty_lines(HistoryBuf *self, PyObject *a UNUSED) {
#define dirty_lines_doc "dirty_lines() -> Line numbers of all lines that have dirty text."
PyObject *ans = PyList_New(0);
for (index_type i = 0; i < self->ynum; i++) {
for (index_type i = 0; i < self->count; i++) {
if (*attrptr(self, i) & TEXT_DIRTY_MASK) {
PyList_Append(ans, PyLong_FromUnsignedLong(i));
}