On Sun, Sep 26, 2010 at 02:22:50AM -0400, Niki Yoshiuchi wrote: > I would absolutely love to see text reflowing but I think that would be > pretty difficult with the way that text is currently handled by dvtm.
Yeah probably isn't trivial to implement, but to be honest I don't really need it. $EDITOR or $PAGER takes care of that. Anyway patches welcome. > By the way, there is a small bug (feature?) in my patch. It will sometimes > show old bits of text after a resize, since the extra buffer space hasn't > been zeroed. I would say that's a bug. See the attached patch for a possible solution (I haven't had the time to really test it so far though). Please test and report back. Thanks, Marc -- Marc Andre Tanner >< http://www.brain-dump.org/ >< GPG key: CF7D56C0
>From aec819970f5db8e3b09a9da552f4464400fd784f Mon Sep 17 00:00:00 2001 From: Marc Andre Tanner <m...@brain-dump.org> Date: Fri, 1 Oct 2010 17:29:38 +0200 Subject: [PATCH] Buffer text on window resize Keep the content around if the window is made smaller so we can restore it later. This uses more memory but reduces the number of allocations. Based on a patch from Niki Yoshiuchi. Signed-off-by: Marc Andre Tanner <m...@brain-dump.org> --- madtty.c | 23 ++++++++++++++--------- 1 files changed, 14 insertions(+), 9 deletions(-) diff --git a/madtty.c b/madtty.c index c3249da..d59ad52 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; @@ -293,6 +293,7 @@ static void fill_scroll_buf(madtty_t *t, int s) static void cursor_line_down(madtty_t *t) { + t_row_set(t->curs_row, t->cols, t->maxcols - t->cols, 0); t->curs_row++; if (t->curs_row < t->scroll_bot) return; @@ -993,6 +994,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 +1060,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 +1068,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,15 +1079,19 @@ 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) { + madtty_dirty(t); t->cols = cols; } while (t->rows < rows) { - lines[t->rows].text = (wchar_t *)calloc(sizeof(wchar_t), cols); - lines[t->rows].attr = (uint16_t *)calloc(sizeof(uint16_t), cols); - lines[t->rows].fg = calloc(sizeof(short), cols); - lines[t->rows].bg = calloc(sizeof(short), cols); - t_row_set(lines + t->rows, 0, t->cols, 0); + lines[t->rows].text = (wchar_t *)calloc(sizeof(wchar_t), t->maxcols); + lines[t->rows].attr = (uint16_t *)calloc(sizeof(uint16_t), t->maxcols); + lines[t->rows].fg = calloc(sizeof(short), t->maxcols); + lines[t->rows].bg = calloc(sizeof(short), t->maxcols); + t_row_set(lines + t->rows, 0, t->maxcols, 0); t->rows++; } -- 1.6.5