summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/grid.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2018-07-11 06:51:39 +0000
committernicm <nicm@openbsd.org>2018-07-11 06:51:39 +0000
commit91c2caa42aea33db5f1bcab2260546b915fac461 (patch)
treeac1745b83cce0d0b4bd99055f2ce60965f60c284 /usr.bin/tmux/grid.c
parentimplement media type detection and forcing of link speed, lightly tested (diff)
downloadwireguard-openbsd-91c2caa42aea33db5f1bcab2260546b915fac461.tar.xz
wireguard-openbsd-91c2caa42aea33db5f1bcab2260546b915fac461.zip
Helper function to shorten history.
Diffstat (limited to 'usr.bin/tmux/grid.c')
-rw-r--r--usr.bin/tmux/grid.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/usr.bin/tmux/grid.c b/usr.bin/tmux/grid.c
index d82317eae85..ec78d1e78f4 100644
--- a/usr.bin/tmux/grid.c
+++ b/usr.bin/tmux/grid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grid.c,v 1.85 2018/07/11 06:43:45 nicm Exp $ */
+/* $OpenBSD: grid.c,v 1.86 2018/07/11 06:51:39 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -286,6 +286,15 @@ grid_compare(struct grid *ga, struct grid *gb)
return (0);
}
+/* Trim lines from the history. */
+static void
+grid_trim_history(struct grid *gd, u_int ny)
+{
+ grid_free_lines(gd, 0, ny);
+ memmove(&gd->linedata[0], &gd->linedata[ny],
+ (gd->hsize + gd->sy - ny) * (sizeof *gd->linedata));
+}
+
/*
* Collect lines from the history if at the limit. Free the top (oldest) 10%
* and shift up.
@@ -308,9 +317,7 @@ grid_collect_history(struct grid *gd)
* Free the lines from 0 to ny then move the remaining lines over
* them.
*/
- grid_free_lines(gd, 0, ny);
- memmove(&gd->linedata[0], &gd->linedata[ny],
- (gd->hsize + gd->sy - ny) * (sizeof *gd->linedata));
+ grid_trim_history(gd, ny);
gd->hsize -= ny;
if (gd->hscrolled > gd->hsize)
@@ -340,9 +347,7 @@ grid_scroll_history(struct grid *gd, u_int bg)
void
grid_clear_history(struct grid *gd)
{
- grid_free_lines(gd, 0, gd->hsize);
- memmove(&gd->linedata[0], &gd->linedata[gd->hsize],
- gd->sy * (sizeof *gd->linedata));
+ grid_trim_history(gd, gd->hsize);
gd->hscrolled = 0;
gd->hsize = 0;