Lines Matching full:gd
189 grid_get_line(struct grid *gd, u_int line)
191 return (&gd->linedata[line]);
196 grid_adjust_lines(struct grid *gd, u_int lines)
198 gd->linedata = xreallocarray(gd->linedata, lines, sizeof *gd->linedata);
203 grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)
205 struct grid_line *gl = &gd->linedata[py];
225 grid_check_y(struct grid *gd, const char *from, u_int py)
227 if (py >= gd->hsize + gd->sy) {
276 grid_free_line(struct grid *gd, u_int py)
278 free(gd->linedata[py].celldata);
279 gd->linedata[py].celldata = NULL;
280 free(gd->linedata[py].extddata);
281 gd->linedata[py].extddata = NULL;
286 grid_free_lines(struct grid *gd, u_int py, u_int ny)
291 grid_free_line(gd, yy);
298 struct grid *gd;
300 gd = xmalloc(sizeof *gd);
301 gd->sx = sx;
302 gd->sy = sy;
305 gd->flags = GRID_HISTORY;
307 gd->flags = 0;
309 gd->hscrolled = 0;
310 gd->hsize = 0;
311 gd->hlimit = hlimit;
313 if (gd->sy != 0)
314 gd->linedata = xcalloc(gd->sy, sizeof *gd->linedata);
316 gd->linedata = NULL;
318 return (gd);
323 grid_destroy(struct grid *gd)
325 grid_free_lines(gd, 0, gd->hsize + gd->sy);
327 free(gd->linedata);
329 free(gd);
361 grid_trim_history(struct grid *gd, u_int ny)
363 grid_free_lines(gd, 0, ny);
364 memmove(&gd->linedata[0], &gd->linedata[ny],
365 (gd->hsize + gd->sy - ny) * (sizeof *gd->linedata));
373 grid_collect_history(struct grid *gd)
377 if (gd->hsize == 0 || gd->hsize < gd->hlimit)
380 ny = gd->hlimit / 10;
383 if (ny > gd->hsize)
384 ny = gd->hsize;
390 grid_trim_history(gd, ny);
392 gd->hsize -= ny;
393 if (gd->hscrolled > gd->hsize)
394 gd->hscrolled = gd->hsize;
399 grid_remove_history(struct grid *gd, u_int ny)
403 if (ny > gd->hsize)
406 grid_free_line(gd, gd->hsize + gd->sy - 1 - yy);
407 gd->hsize -= ny;
415 grid_scroll_history(struct grid *gd, u_int bg)
419 yy = gd->hsize + gd->sy;
420 gd->linedata = xreallocarray(gd->linedata, yy + 1,
421 sizeof *gd->linedata);
422 grid_empty_line(gd, yy, bg);
424 gd->hscrolled++;
425 grid_compact_line(&gd->linedata[gd->hsize]);
426 gd->linedata[gd->hsize].time = current_time;
427 gd->hsize++;
432 grid_clear_history(struct grid *gd)
434 grid_trim_history(gd, gd->hsize);
436 gd->hscrolled = 0;
437 gd->hsize = 0;
439 gd->linedata = xreallocarray(gd->linedata, gd->sy,
440 sizeof *gd->linedata);
445 grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower, u_int bg)
451 yy = gd->hsize + gd->sy;
452 gd->linedata = xreallocarray(gd->linedata, yy + 1,
453 sizeof *gd->linedata);
456 gl_history = &gd->linedata[gd->hsize];
457 memmove(gl_history + 1, gl_history, gd->sy * sizeof *gl_history);
461 gl_upper = &gd->linedata[upper];
470 grid_empty_line(gd, lower, bg);
473 gd->hscrolled++;
474 gd->hsize++;
479 grid_expand_line(struct grid *gd, u_int py, u_int sx, u_int bg)
484 gl = &gd->linedata[py];
488 if (sx < gd->sx / 4)
489 sx = gd->sx / 4;
490 else if (sx < gd->sx / 2)
491 sx = gd->sx / 2;
492 else if (gd->sx > sx)
493 sx = gd->sx;
497 grid_clear_cell(gd, xx, py, bg);
503 grid_empty_line(struct grid *gd, u_int py, u_int bg)
505 memset(&gd->linedata[py], 0, sizeof gd->linedata[py]);
507 grid_expand_line(gd, py, gd->sx, bg);
512 grid_peek_line(struct grid *gd, u_int py)
514 if (grid_check_y(gd, __func__, py) != 0)
516 return (&gd->linedata[py]);
561 grid_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc)
563 if (grid_check_y(gd, __func__, py) != 0 ||
564 px >= gd->linedata[py].cellsize)
567 grid_get_cell1(&gd->linedata[py], px, gc);
572 grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
577 if (grid_check_y(gd, __func__, py) != 0)
580 grid_expand_line(gd, py, px + 1, 8);
582 gl = &gd->linedata[py];
595 grid_set_padding(struct grid *gd, u_int px, u_int py)
597 grid_set_cell(gd, px, py, &grid_padding_cell);
602 grid_set_cells(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc,
610 if (grid_check_y(gd, __func__, py) != 0)
613 grid_expand_line(gd, py, px + slen, 8);
615 gl = &gd->linedata[py];
631 grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg)
639 if (px == 0 && nx == gd->sx) {
640 grid_clear_lines(gd, py, ny, bg);
644 if (grid_check_y(gd, __func__, py) != 0)
646 if (grid_check_y(gd, __func__, py + ny - 1) != 0)
650 gl = &gd->linedata[yy];
652 sx = gd->sx;
663 grid_expand_line(gd, yy, px + ox, 8); /* default bg first */
665 grid_clear_cell(gd, xx, yy, bg);
671 grid_clear_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
678 if (grid_check_y(gd, __func__, py) != 0)
680 if (grid_check_y(gd, __func__, py + ny - 1) != 0)
684 grid_free_line(gd, yy);
685 grid_empty_line(gd, yy, bg);
688 gd->linedata[py - 1].flags &= ~GRID_LINE_WRAPPED;
693 grid_move_lines(struct grid *gd, u_int dy, u_int py, u_int ny, u_int bg)
700 if (grid_check_y(gd, __func__, py) != 0)
702 if (grid_check_y(gd, __func__, py + ny - 1) != 0)
704 if (grid_check_y(gd, __func__, dy) != 0)
706 if (grid_check_y(gd, __func__, dy + ny - 1) != 0)
713 grid_free_line(gd, yy);
716 gd->linedata[dy - 1].flags &= ~GRID_LINE_WRAPPED;
718 memmove(&gd->linedata[dy], &gd->linedata[py],
719 ny * (sizeof *gd->linedata));
727 grid_empty_line(gd, yy, bg);
730 gd->linedata[py - 1].flags &= ~GRID_LINE_WRAPPED;
735 grid_move_cells(struct grid *gd, u_int dx, u_int px, u_int py, u_int nx,
744 if (grid_check_y(gd, __func__, py) != 0)
746 gl = &gd->linedata[py];
748 grid_expand_line(gd, py, px + nx, 8);
749 grid_expand_line(gd, py, dx + nx, 8);
759 grid_clear_cell(gd, xx, py, bg);
1062 grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
1083 gl = grid_peek_line(gd, py);
1091 grid_get_cell(gd, xx, py, &gc);
1204 grid_reflow_add(struct grid *gd, u_int n)
1207 u_int sy = gd->sy + n;
1209 gd->linedata = xreallocarray(gd->linedata, sy, sizeof *gd->linedata);
1210 gl = &gd->linedata[gd->sy];
1212 gd->sy = sy;
1218 grid_reflow_move(struct grid *gd, struct grid_line *from)
1222 to = grid_reflow_add(gd, 1);
1230 grid_reflow_join(struct grid *target, struct grid *gd, u_int sx, u_int yy,
1244 gl = grid_reflow_move(target, &gd->linedata[yy]);
1260 if (yy + 1 + lines == gd->hsize + gd->sy)
1265 if (~gd->linedata[line].flags & GRID_LINE_WRAPPED)
1267 if (gd->linedata[line].cellused == 0) {
1279 grid_get_cell1(&gd->linedata[line], 0, &gc);
1287 from = &gd->linedata[line];
1316 grid_move_cells(gd, 0, want, yy + lines, left, 8);
1324 free(gd->linedata[i].celldata);
1325 free(gd->linedata[i].extddata);
1326 grid_reflow_dead(&gd->linedata[i]);
1330 if (gd->hscrolled > to + lines)
1331 gd->hscrolled -= lines;
1332 else if (gd->hscrolled > to)
1333 gd->hscrolled = to;
1338 grid_reflow_split(struct grid *target, struct grid *gd, u_int sx, u_int yy,
1341 struct grid_line *gl = &gd->linedata[yy], *first;
1393 if (yy <= gd->hscrolled)
1394 gd->hscrolled += lines - 1;
1401 grid_reflow_join(target, gd, sx, yy, width, 1);
1406 grid_reflow(struct grid *gd, u_int sx)
1417 target = grid_create(gd->sx, 0, 0);
1422 for (yy = 0; yy < gd->hsize + gd->sy; yy++) {
1423 gl = &gd->linedata[yy];
1462 grid_reflow_split(target, gd, sx, yy, at);
1471 grid_reflow_join(target, gd, sx, yy, width, 0);
1479 if (target->sy < gd->sy)
1480 grid_reflow_add(target, gd->sy - target->sy);
1481 gd->hsize = target->sy - gd->sy;
1482 if (gd->hscrolled > gd->hsize)
1483 gd->hscrolled = gd->hsize;
1484 free(gd->linedata);
1485 gd->linedata = target->linedata;
1491 grid_wrap_position(struct grid *gd, u_int px, u_int py, u_int *wx, u_int *wy)
1496 if (gd->linedata[yy].flags & GRID_LINE_WRAPPED)
1497 ax += gd->linedata[yy].cellused;
1503 if (px >= gd->linedata[yy].cellused)
1513 grid_unwrap_position(struct grid *gd, u_int *px, u_int *py, u_int wx, u_int wy)
1517 for (yy = 0; yy < gd->hsize + gd->sy - 1; yy++) {
1520 if (~gd->linedata[yy].flags & GRID_LINE_WRAPPED)
1529 while (gd->linedata[yy].flags & GRID_LINE_WRAPPED)
1531 wx = gd->linedata[yy].cellused;
1533 while (gd->linedata[yy].flags & GRID_LINE_WRAPPED) {
1534 if (wx < gd->linedata[yy].cellused)
1536 wx -= gd->linedata[yy].cellused;
1546 grid_line_length(struct grid *gd, u_int py)
1551 px = grid_get_line(gd, py)->cellsize;
1552 if (px > gd->sx)
1553 px = gd->sx;
1555 grid_get_cell(gd, px - 1, py, &gc);
1567 grid_in_set(struct grid *gd, u_int px, u_int py, const char *set)
1572 grid_get_cell(gd, px, py, &gc);
1577 grid_get_cell(gd, --pxx, py, &tmp_gc);