aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-06-24 19:12:44 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-06-24 19:12:44 +0000
commitf4b8f00255eb4e5d1e7b5e989d8dd48f34716c46 (patch)
treee02fd903654fb06a6665ecec1016d7e8926dc7b7
parentda8401d8bee19d9f5394ddef0c7905b6a8ac9932 (diff)
downloadrtmux-f4b8f00255eb4e5d1e7b5e989d8dd48f34716c46.tar.gz
rtmux-f4b8f00255eb4e5d1e7b5e989d8dd48f34716c46.tar.bz2
rtmux-f4b8f00255eb4e5d1e7b5e989d8dd48f34716c46.zip
Change to match xterm's resizing behaviour, including pushing lines into the
history from the top when reducing vertical size and pulling them again when increasing size. ok todd sthen
-rw-r--r--screen.c80
1 files changed, 47 insertions, 33 deletions
diff --git a/screen.c b/screen.c
index 5c689c8a..a79a7d42 100644
--- a/screen.c
+++ b/screen.c
@@ -169,38 +169,42 @@ void
screen_resize_y(struct screen *s, u_int sy)
{
struct grid *gd = s->grid;
- u_int oy, yy, ny;
+ u_int needed, available, oldy, i;
if (sy == 0)
fatalx("zero size");
+ oldy = screen_size_y(s);
+
+ /*
+ * When resizing:
+ *
+ * If the height is decreasing, delete lines from the bottom until
+ * hitting the cursor, then push lines from the top into the history.
+ *
+ * When increasing, pull as many lines as possible from the history to
+ * the top, then fill the remaining with blanks at the bottom.
+ */
/* Size decreasing. */
- if (sy < screen_size_y(s)) {
- oy = screen_size_y(s);
-
- if (s->cy != 0) {
- /*
- * The cursor is not at the start. Try to remove as
- * many lines as possible from the top. (Up to the
- * cursor line.)
- */
- ny = s->cy;
- if (ny > oy - sy)
- ny = oy - sy;
-
- grid_view_delete_lines(gd, 0, ny);
-
- s->cy -= ny;
- oy -= ny;
+ if (sy < oldy) {
+ needed = oldy - sy;
+
+ /* Delete as many lines as possible from the bottom. */
+ available = oldy - 1 - s->cy;
+ if (available > 0) {
+ if (available > needed)
+ available = needed;
+ grid_view_delete_lines(gd, oldy - available, available);
}
+ needed -= available;
- if (sy < oy) {
- /* Remove any remaining lines from the bottom. */
- grid_view_delete_lines(gd, sy, oy - sy);
- if (s->cy >= sy)
- s->cy = sy - 1;
- }
- }
+ /*
+ * Now just increase the history size to take over the lines
+ * which are left. XXX Should apply history limit?
+ */
+ gd->hsize += needed;
+ s->cy -= needed;
+ }
/* Resize line arrays. */
gd->size = xrealloc(gd->size, gd->hsize + sy, sizeof *gd->size);
@@ -209,18 +213,28 @@ screen_resize_y(struct screen *s, u_int sy)
gd->udata = xrealloc(gd->udata, gd->hsize + sy, sizeof *gd->udata);
/* Size increasing. */
- if (sy > screen_size_y(s)) {
- oy = screen_size_y(s);
- for (yy = gd->hsize + oy; yy < gd->hsize + sy; yy++) {
- gd->size[yy] = 0;
- gd->data[yy] = NULL;
- gd->usize[yy] = 0;
- gd->udata[yy] = NULL;
+ if (sy > oldy) {
+ needed = sy - oldy;
+
+ /* Try to pull as much as possible out of the history. */
+ available = gd->hsize;
+ if (available > 0) {
+ if (available > needed)
+ available = needed;
+ gd->hsize -= available;
+ s->cy += available;
+ }
+ needed -= available;
+
+ /* Then fill the rest in with blanks. */
+ for (i = gd->hsize + sy - needed; i < gd->hsize + sy; i++) {
+ gd->size[i] = gd->usize[i] = 0;
+ gd->data[i] = gd->udata[i] = NULL;
}
}
+ /* Set the new size, and reset the scroll region. */
gd->sy = sy;
-
s->rupper = 0;
s->rlower = screen_size_y(s) - 1;
}