Wire up historybuf_rewrap

This commit is contained in:
Kovid Goyal 2016-11-20 22:27:01 +05:30
parent 5dccb91996
commit 05c6e7733c
2 changed files with 10 additions and 0 deletions

View File

@ -321,6 +321,7 @@ void linebuf_set_attribute(LineBuf *, unsigned int , unsigned int );
void linebuf_rewrap(LineBuf *self, LineBuf *other, int *cursor_y_out, HistoryBuf *);
bool historybuf_resize(HistoryBuf *self, index_type lines);
void historybuf_add_line(HistoryBuf *self, const Line *line);
void historybuf_rewrap(HistoryBuf *self, HistoryBuf *other);
void screen_restore_cursor(Screen *);
void screen_save_cursor(Screen *);

View File

@ -63,6 +63,12 @@ void screen_reset(Screen *self) {
screen_change_default_color(self, BG, 0);
tracker_update_screen(self->change_tracker);
}
static inline HistoryBuf* realloc_hb(HistoryBuf *old, unsigned int lines, unsigned int columns) {
HistoryBuf *ans = alloc_historybuf(lines, columns);
if (ans == NULL) { PyErr_NoMemory(); return NULL; }
historybuf_rewrap(old, ans);
return ans;
}
static inline LineBuf* realloc_lb(LineBuf *old, unsigned int lines, unsigned int columns, int *cursor_y, HistoryBuf *hb) {
LineBuf *ans = alloc_linebuf(lines, columns);
@ -76,6 +82,9 @@ static bool screen_resize(Screen *self, unsigned int lines, unsigned int columns
bool is_main = self->linebuf == self->main_linebuf;
int cursor_y = -1;
HistoryBuf *nh = realloc_hb(self->historybuf, lines, columns);
if (nh == NULL) return false;
Py_CLEAR(self->historybuf); self->historybuf = nh;
LineBuf *n = realloc_lb(self->main_linebuf, lines, columns, &cursor_y, self->historybuf);
if (n == NULL) return false;
Py_CLEAR(self->main_linebuf); self->main_linebuf = n;