From df2b87308b1187a9840b9bd8d56d4c54b35dc63a Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 18 Nov 2013 21:41:30 +0100 Subject: [PATCH] add termpty_screen_swap() to simplify code --- src/bin/termpty.c | 36 +++++++++++++++++++++++++++--------- src/bin/termpty.h | 2 +- src/bin/termptyesc.c | 14 ++------------ 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/bin/termpty.c b/src/bin/termpty.c index a8586f3f..03a6413a 100644 --- a/src/bin/termpty.c +++ b/src/bin/termpty.c @@ -1484,20 +1484,38 @@ termpty_cell_copy(Termpty *ty, Termcell *src, Termcell *dst, int n) } } -void -termpty_cell_swap(Termpty *ty EINA_UNUSED, Termcell *src, Termcell *dst, int n) +static void +_swap_line(Termpty *ty, Termcell *cells, Termcell *cells2) { - int i; - Termcell t; - - for (i = 0; i < n; i++) + int x; + Termcell c; + + for (x = 0; x < ty->w; x++) { - t = dst[i]; - dst[i] = src[i]; - src[i] = t; + c = cells[x]; + cells[x] = cells2[x]; + cells2[x] = c; } } +void +termpty_screen_swap(Termpty *ty) +{ + int y; + + for (y = 0; y < ty->h; y++) + { + _swap_line(ty, + &(TERMPTY_SCREEN(ty, 0, y)), + &ty->screen2[y * ty->w]); + } + ty->circular_offset = 0; + ty->altbuf = !ty->altbuf; + + if (ty->cb.cancel_sel.func) + ty->cb.cancel_sel.func(ty->cb.cancel_sel.data); +} + void termpty_cell_fill(Termpty *ty, Termcell *src, Termcell *dst, int n) { diff --git a/src/bin/termpty.h b/src/bin/termpty.h index 6f3b1d2e..208c8fb4 100644 --- a/src/bin/termpty.h +++ b/src/bin/termpty.h @@ -225,9 +225,9 @@ void termpty_block_chid_update(Termpty *ty, Termblock *blk); Termblock *termpty_block_chid_get(Termpty *ty, const char *chid); void termpty_cell_copy(Termpty *ty, Termcell *src, Termcell *dst, int n); -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); +void termpty_screen_swap(Termpty *ty); ssize_t termpty_line_length(const Termcell *cells, ssize_t nb_cells); diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c index bd7daee8..ff66d2cb 100644 --- a/src/bin/termptyesc.c +++ b/src/bin/termptyesc.c @@ -626,8 +626,6 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce) arg = _csi_arg_get(&b); if (b) { - int size; - // complete-ish list here: // http://ttssh2.sourceforge.jp/manual/en/about/ctrlseq.html switch (arg) @@ -830,7 +828,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce) { // if we are looking at alt buf now, // clear main buf before we swap it back - // into the sreen2 save (so save is + // into the screen2 save (so save is // clear) _termpty_clear_all(ty); // _termpty_cursor_copy(&(ty->swap), &(ty->state)); @@ -841,16 +839,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce) // _termpty_cursor_copy(&(ty->state), &(ty->swap)); ty->swap = ty->state; } - size = ty->w * ty->h; // swap screen content now - for (i = 0; i < size; i++) - termpty_cell_swap(ty, - &(ty->screen[(i + ty->circular_offset * ty->w) % size]), - &(ty->screen2[i]), - 1); - ty->altbuf = !ty->altbuf; - if (ty->cb.cancel_sel.func) - ty->cb.cancel_sel.func(ty->cb.cancel_sel.data); + termpty_screen_swap(ty); break; case 1048: if (mode)