aboutsummaryrefslogtreecommitdiff
path: root/grid.c
diff options
context:
space:
mode:
authorThomas Adam <thomas.adam@smoothwall.net>2013-02-07 12:08:55 +0000
committerThomas Adam <thomas.adam@smoothwall.net>2013-02-07 12:08:55 +0000
commit64da762c15ddf0930baa1f8e4fc2b41515a64e3a (patch)
treecd2a953395962c7f2e7265d16722508a80606372 /grid.c
parentfe00607816308953209cb85ab92a586c1f344cde (diff)
parent8903c1f167839569b7514508b38988aa6486575c (diff)
downloadrtmux-64da762c15ddf0930baa1f8e4fc2b41515a64e3a.tar.gz
rtmux-64da762c15ddf0930baa1f8e4fc2b41515a64e3a.tar.bz2
rtmux-64da762c15ddf0930baa1f8e4fc2b41515a64e3a.zip
Merge branch 'obsd-master'
Diffstat (limited to 'grid.c')
-rw-r--r--grid.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/grid.c b/grid.c
index 05d62737..aabf66cb 100644
--- a/grid.c
+++ b/grid.c
@@ -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);
+}