Skip to content

Commit e7d5302

Browse files
author
nicm
committed
Helper function to shorten history.
1 parent 0351902 commit e7d5302

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

grid.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ grid_compare(struct grid *ga, struct grid *gb)
286286
return (0);
287287
}
288288

289+
/* Trim lines from the history. */
290+
static void
291+
grid_trim_history(struct grid *gd, u_int ny)
292+
{
293+
grid_free_lines(gd, 0, ny);
294+
memmove(&gd->linedata[0], &gd->linedata[ny],
295+
(gd->hsize + gd->sy - ny) * (sizeof *gd->linedata));
296+
}
297+
289298
/*
290299
* Collect lines from the history if at the limit. Free the top (oldest) 10%
291300
* and shift up.
@@ -308,9 +317,7 @@ grid_collect_history(struct grid *gd)
308317
* Free the lines from 0 to ny then move the remaining lines over
309318
* them.
310319
*/
311-
grid_free_lines(gd, 0, ny);
312-
memmove(&gd->linedata[0], &gd->linedata[ny],
313-
(gd->hsize + gd->sy - ny) * (sizeof *gd->linedata));
320+
grid_trim_history(gd, ny);
314321

315322
gd->hsize -= ny;
316323
if (gd->hscrolled > gd->hsize)
@@ -340,9 +347,7 @@ grid_scroll_history(struct grid *gd, u_int bg)
340347
void
341348
grid_clear_history(struct grid *gd)
342349
{
343-
grid_free_lines(gd, 0, gd->hsize);
344-
memmove(&gd->linedata[0], &gd->linedata[gd->hsize],
345-
gd->sy * (sizeof *gd->linedata));
350+
grid_trim_history(gd, gd->hsize);
346351

347352
gd->hscrolled = 0;
348353
gd->hsize = 0;

0 commit comments

Comments
 (0)