diff --git a/madtty.c b/madtty.c index d97813d..b5ba032 100644 --- a/madtty.c +++ b/madtty.c @@ -103,7 +103,7 @@ struct madtty_t { unsigned bell : 1; /* geometry */ - int rows, cols; + int rows, cols, maxcols; unsigned curattrs; short curfg, curbg; @@ -993,6 +993,7 @@ madtty_t *madtty_create(int rows, int cols, int scroll_buf_sz) /* record dimensions */ t->rows = rows; t->cols = cols; + t->maxcols = cols; /* default mode is replace */ t->insert = false; @@ -1058,7 +1059,7 @@ void madtty_resize(madtty_t *t, int rows, int cols) lines = realloc(lines, sizeof(t_row_t) * rows); } - if (t->cols != cols) { + if (t->maxcols < cols) { for (int row = 0; row < t->rows; row++) { lines[row].text = realloc(lines[row].text, sizeof(wchar_t) * cols); lines[row].attr = realloc(lines[row].attr, sizeof(uint16_t) * cols); @@ -1066,8 +1067,7 @@ void madtty_resize(madtty_t *t, int rows, int cols) lines[row].bg = realloc(lines[row].bg, sizeof(short) * cols); if (t->cols < cols) t_row_set(lines + row, t->cols, cols - t->cols, 0); - else - lines[row].dirty = true; + lines[row].dirty = true; } t_row_t *sbuf = t->scroll_buf; for (int row = 0; row < t->scroll_buf_sz; row++) { @@ -1078,6 +1078,13 @@ void madtty_resize(madtty_t *t, int rows, int cols) if (t->cols < cols) t_row_set(sbuf + row, t->cols, cols - t->cols, 0); } + t->maxcols = cols; + t->cols = cols; + } + else if(t->cols != cols) { + for (int row = 0; row < t->rows; row++) { + lines[row].dirty = true; + } t->cols = cols; }