Skip to content

Commit a4a7c3c

Browse files
committed
Merge branch 'obsd-master'
2 parents 6f26980 + e7d5302 commit a4a7c3c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

grid.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,14 @@ grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
145145
return (gcp);
146146
}
147147

148+
/* Get line data. */
148149
struct grid_line *
149150
grid_get_line(struct grid *gd, u_int line)
150151
{
151152
return (&gd->linedata[line]);
152153
}
153154

155+
/* Adjust number of lines. */
154156
void
155157
grid_adjust_lines(struct grid *gd, u_int lines)
156158
{
@@ -284,6 +286,15 @@ grid_compare(struct grid *ga, struct grid *gb)
284286
return (0);
285287
}
286288

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+
287298
/*
288299
* Collect lines from the history if at the limit. Free the top (oldest) 10%
289300
* and shift up.
@@ -306,9 +317,7 @@ grid_collect_history(struct grid *gd)
306317
* Free the lines from 0 to ny then move the remaining lines over
307318
* them.
308319
*/
309-
grid_free_lines(gd, 0, ny);
310-
memmove(&gd->linedata[0], &gd->linedata[ny],
311-
(gd->hsize + gd->sy - ny) * (sizeof *gd->linedata));
320+
grid_trim_history(gd, ny);
312321

313322
gd->hsize -= ny;
314323
if (gd->hscrolled > gd->hsize)
@@ -338,9 +347,7 @@ grid_scroll_history(struct grid *gd, u_int bg)
338347
void
339348
grid_clear_history(struct grid *gd)
340349
{
341-
grid_free_lines(gd, 0, gd->hsize);
342-
memmove(&gd->linedata[0], &gd->linedata[gd->hsize],
343-
gd->sy * (sizeof *gd->linedata));
350+
grid_trim_history(gd, gd->hsize);
344351

345352
gd->hscrolled = 0;
346353
gd->hsize = 0;

0 commit comments

Comments
 (0)