From 852400f03992c9cb316b3c08e9a6f2d474b45a03 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sun, 17 Mar 2013 19:27:20 +0100 Subject: [PATCH] reflow: correctly set line length when pushing to backscroll --- src/bin/termpty.c | 4 ++-- src/bin/termpty.h | 2 ++ src/bin/termptyops.c | 11 ++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/bin/termpty.c b/src/bin/termpty.c index a297e3ff..68406d13 100644 --- a/src/bin/termpty.c +++ b/src/bin/termpty.c @@ -469,7 +469,7 @@ termpty_write(Termpty *ty, const char *input, int len) if (write(ty->fd, input, len) < 0) ERR("write %s", strerror(errno)); } -ssize_t _line_length(const Termcell *cells, ssize_t nb_cells) +ssize_t termpty_line_length(const Termcell *cells, ssize_t nb_cells) { ssize_t len = nb_cells; @@ -616,7 +616,7 @@ expand_screen: { ssize_t cur_line_length; - cur_line_length = _line_length(&OLD_SCREEN(0, old_y), old_w); + cur_line_length = termpty_line_length(&OLD_SCREEN(0, old_y), old_w); if (rewrapping) { if (new_ts) diff --git a/src/bin/termpty.h b/src/bin/termpty.h index 9510d611..b6840f1a 100644 --- a/src/bin/termpty.h +++ b/src/bin/termpty.h @@ -184,6 +184,8 @@ void termpty_cell_swap(Termpty *ty, Termcell *src, Termcell *dst, int n); void termpty_cell_fill(Termpty *ty, Termcell *src, Termcell *dst, int n); void termpty_cell_codepoint_att_fill(Termpty *ty, int codepoint, Termatt att, Termcell *dst, int n); +ssize_t termpty_line_length(const Termcell *cells, ssize_t nb_cells); + extern int _termpty_log_dom; #define TERMPTY_SCREEN(Tpty, X, Y) \ diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c index 11151134..140767f6 100644 --- a/src/bin/termptyops.c +++ b/src/bin/termptyops.c @@ -32,11 +32,16 @@ static void _text_save_top(Termpty *ty) { Termsave *ts; + Termcell *cells; + ssize_t w; if (ty->backmax <= 0) return; - ts = calloc(1, sizeof(Termsave) + ((ty->w - 1) * sizeof(Termcell))); - ts->w = ty->w; - _termpty_text_copy(ty, &(TERMPTY_SCREEN(ty, 0, 0)), ts->cell, ty->w); + + cells = &(TERMPTY_SCREEN(ty, 0, 0)); + w = termpty_line_length(cells, ty->w); + ts = calloc(1, sizeof(Termsave) + ((w - 1) * sizeof(Termcell))); + ts->w = w; + _termpty_text_copy(ty, cells, ts->cell, w); if (!ty->back) ty->back = calloc(1, sizeof(Termsave *) * ty->backmax); if (ty->back[ty->backpos]) {