summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/grid.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2013-02-05 11:09:00 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2013-02-05 11:09:00 +0000
commit7cd8ab6cfacbee8d6601302f1bda468a6acd83f0 (patch)
tree3460ff7f5407a4e2dcb7ef34b9237892d4da6f24 /usr.bin/tmux/grid.c
parent2a0ead63be18af9221cd2ba903800152bc178a77 (diff)
Automatically reflow wrapped lines when a pane is resized, requested by
many over the years and finally implemented by Richard Woodbury.
Diffstat (limited to 'usr.bin/tmux/grid.c')
-rw-r--r--usr.bin/tmux/grid.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/usr.bin/tmux/grid.c b/usr.bin/tmux/grid.c
index 48f5a0074ac..626a2694038 100644
--- a/usr.bin/tmux/grid.c
+++ b/usr.bin/tmux/grid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grid.c,v 1.21 2013/01/18 02:16:21 nicm Exp $ */
+/* $OpenBSD: grid.c,v 1.22 2013/02/05 11:08:59 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -460,3 +460,44 @@ grid_duplicate_lines(
dy++;
}
}
+
+/*
+ * Reflow lines from src grid into dst grid based on width sx. Returns number
+ * of lines fewer in the visible area, or zero.
+ */
+u_int
+grid_reflow(struct grid *dst, const struct grid *src, u_int sx)
+{
+ u_int px, py, line, cell;
+ int previous_wrapped;
+ struct grid_line *gl;
+
+ px = py = 0;
+ previous_wrapped = 1;
+ for (line = 0; line < src->sy + src->hsize; line++) {
+ gl = src->linedata + line;
+ if (!previous_wrapped) {
+ px = 0;
+ py++;
+ if (py >= dst->hsize + dst->sy)
+ grid_scroll_history(dst);
+ }
+ for (cell = 0; cell < gl->cellsize; cell++) {
+ if (px == sx) {
+ dst->linedata[py].flags |= GRID_LINE_WRAPPED;
+ px = 0;
+ py++;
+ if (py >= dst->hsize + dst->sy)
+ grid_scroll_history(dst);
+ }
+ grid_set_cell(dst, px, py, gl->celldata + cell);
+ px++;
+ }
+ previous_wrapped = gl->flags & GRID_LINE_WRAPPED;
+ }
+ py++; /* account for final line, which never wraps */
+
+ if (py > src->sy)
+ return (0);
+ return (src->sy - py);
+}