diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-09-15 15:14:10 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-09-15 15:14:10 +0000 |
commit | 553a033acd979a450a93109308fd265b2753b86d (patch) | |
tree | 4ae47ada2bfee5508bf6536935df9edd09499cf9 /usr.bin | |
parent | 855d89da1259857648f3ba9af55c7a58a97e7231 (diff) |
Stick line length to what is actually used (removing an optimization that
allowed it to be bigger), and use clear line/EOL sequences rather than spaces
in copy/scroll mode.
This fixes xterm copy/paste from tmux which treats trailing spaces differently
from clearing a line with the escape sequences. Reported by martynas@.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/grid.c | 26 | ||||
-rw-r--r-- | usr.bin/tmux/screen-write.c | 45 |
2 files changed, 42 insertions, 29 deletions
diff --git a/usr.bin/tmux/grid.c b/usr.bin/tmux/grid.c index 25f6acb0f56..0e6b00797e9 100644 --- a/usr.bin/tmux/grid.c +++ b/usr.bin/tmux/grid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grid.c,v 1.13 2009/08/21 07:29:37 nicm Exp $ */ +/* $OpenBSD: grid.c,v 1.14 2009/09/15 15:14:09 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -189,22 +189,15 @@ grid_scroll_line(struct grid *gd) /* Expand line to fit to cell. */ void -grid_expand_line(struct grid *gd, u_int py, u_int wantx) +grid_expand_line(struct grid *gd, u_int py, u_int sx) { struct grid_line *gl; - u_int xx, sx; + u_int xx; gl = &gd->linedata[py]; - if (wantx <= gl->cellsize) + if (sx <= gl->cellsize) return; - if (gl->cellsize > gd->sx / 2) - sx = gd->sx; - else { - sx = gl->cellsize + 1; - while (sx < wantx) - sx *= 2; - } gl->celldata = xrealloc(gl->celldata, sx, sizeof *gl->celldata); for (xx = gl->cellsize; xx < sx; xx++) grid_put_cell(gd, xx, py, &grid_default_cell); @@ -307,10 +300,7 @@ grid_set_utf8( grid_put_utf8(gd, px, py, gc); } -/* - * Clear area. Note this is different from a fill as it just omits unallocated - * cells. - */ +/* Clear area. */ void grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny) { @@ -336,6 +326,12 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny) return; for (yy = py; yy < py + ny; yy++) { + if (px >= gd->linedata[yy].cellsize) + continue; + if (px + nx >= gd->linedata[yy].cellsize) { + gd->linedata[yy].cellsize = px; + continue; + } for (xx = px; xx < px + nx; xx++) { if (xx >= gd->linedata[yy].cellsize) break; diff --git a/usr.bin/tmux/screen-write.c b/usr.bin/tmux/screen-write.c index c04e596e9ef..7b6ff1e72b5 100644 --- a/usr.bin/tmux/screen-write.c +++ b/usr.bin/tmux/screen-write.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-write.c,v 1.25 2009/09/10 17:16:24 nicm Exp $ */ +/* $OpenBSD: screen-write.c,v 1.26 2009/09/15 15:14:09 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -371,25 +371,42 @@ screen_write_copy(struct screen_write_ctx *ctx, struct grid_line *gl; const struct grid_cell *gc; u_char *udata; - u_int xx, yy, cx, cy; + u_int xx, yy, cx, cy, ax, bx; cx = s->cx; cy = s->cy; for (yy = py; yy < py + ny; yy++) { gl = &gd->linedata[yy]; - for (xx = px; xx < px + nx; xx++) { - udata = NULL; - - if (xx >= gl->cellsize || yy >= gd->hsize + gd->sy) - gc = &grid_default_cell; - else { - gc = &gl->celldata[xx]; - if (gc->flags & GRID_FLAG_UTF8) - udata = gl->utf8data[xx].data; + if (yy < gd->hsize + gd->sy) { + /* + * Find start and end position and copy between + * them. Limit to the real end of the line then use a + * clear EOL only if copying to the end, otherwise + * could overwrite whatever is there already. + */ + if (px > gl->cellsize) + ax = gl->cellsize; + else + ax = px; + if (px + nx == gd->sx && px + nx > gl->cellsize) + bx = gl->cellsize; + else + bx = px + nx; + for (xx = ax; xx < bx; xx++) { + udata = NULL; + if (xx >= gl->cellsize) + gc = &grid_default_cell; + else { + gc = &gl->celldata[xx]; + if (gc->flags & GRID_FLAG_UTF8) + udata = gl->utf8data[xx].data; + } + screen_write_cell(ctx, gc, udata); } - - screen_write_cell(ctx, gc, udata); - } + if (px + nx == gd->sx && px + nx > gl->cellsize) + screen_write_clearendofline(ctx); + } else + screen_write_clearline(ctx); cy++; screen_write_cursormove(ctx, cx, cy); } |