diff options
Diffstat (limited to 'grid.c')
-rw-r--r-- | grid.c | 71 |
1 files changed, 45 insertions, 26 deletions
@@ -48,8 +48,6 @@ static const struct grid_cell_entry grid_cleared_entry = { GRID_FLAG_CLEARED, { .data = { 0, 8, 8, ' ' } } }; -static void grid_empty_line(struct grid *, u_int, u_int); - /* Store cell in entry. */ static void grid_store_cell(struct grid_cell_entry *gce, const struct grid_cell *gc, @@ -213,19 +211,28 @@ grid_check_y(struct grid *gd, const char *from, u_int py) return (0); } -/* Compare grid cells. Return 1 if equal, 0 if not. */ +/* Check if two styles are (visibly) the same. */ int -grid_cells_equal(const struct grid_cell *gca, const struct grid_cell *gcb) +grid_cells_look_equal(const struct grid_cell *gc1, const struct grid_cell *gc2) { - if (gca->fg != gcb->fg || gca->bg != gcb->bg) + if (gc1->fg != gc2->fg || gc1->bg != gc2->bg) return (0); - if (gca->attr != gcb->attr || gca->flags != gcb->flags) + if (gc1->attr != gc2->attr || gc1->flags != gc2->flags) return (0); - if (gca->data.width != gcb->data.width) + return (1); +} + +/* Compare grid cells. Return 1 if equal, 0 if not. */ +int +grid_cells_equal(const struct grid_cell *gc1, const struct grid_cell *gc2) +{ + if (!grid_cells_look_equal(gc1, gc2)) return (0); - if (gca->data.size != gcb->data.size) + if (gc1->data.width != gc2->data.width) return (0); - return (memcmp(gca->data.data, gcb->data.data, gca->data.size) == 0); + if (gc1->data.size != gc2->data.size) + return (0); + return (memcmp(gc1->data.data, gc2->data.data, gc1->data.size) == 0); } /* Free one line. */ @@ -258,7 +265,10 @@ grid_create(u_int sx, u_int sy, u_int hlimit) gd->sx = sx; gd->sy = sy; - gd->flags = GRID_HISTORY; + if (hlimit != 0) + gd->flags = GRID_HISTORY; + else + gd->flags = 0; gd->hscrolled = 0; gd->hsize = 0; @@ -348,6 +358,19 @@ grid_collect_history(struct grid *gd) gd->hscrolled = gd->hsize; } +/* Remove lines from the bottom of the history. */ +void +grid_remove_history(struct grid *gd, u_int ny) +{ + u_int yy; + + if (ny > gd->hsize) + return; + for (yy = 0; yy < ny; yy++) + grid_free_line(gd, gd->hsize + gd->sy - 1 - yy); + gd->hsize -= ny; +} + /* * Scroll the entire visible screen, moving one line into the history. Just * allocate a new line at the bottom and move the history size indicator. @@ -438,7 +461,7 @@ grid_expand_line(struct grid *gd, u_int py, u_int sx, u_int bg) } /* Empty a line and set background colour if needed. */ -static void +void grid_empty_line(struct grid *gd, u_int py, u_int bg) { memset(&gd->linedata[py], 0, sizeof gd->linedata[py]); @@ -755,15 +778,15 @@ grid_string_cells_bg(const struct grid_cell *gc, int *values) case 8: values[n++] = 49; break; - case 100: - case 101: - case 102: - case 103: - case 104: - case 105: - case 106: - case 107: - values[n++] = gc->bg - 10; + case 90: + case 91: + case 92: + case 93: + case 94: + case 95: + case 96: + case 97: + values[n++] = gc->bg + 10; break; } } @@ -1327,17 +1350,13 @@ grid_wrap_position(struct grid *gd, u_int px, u_int py, u_int *wx, u_int *wy) void grid_unwrap_position(struct grid *gd, u_int *px, u_int *py, u_int wx, u_int wy) { - u_int yy, ax = 0, ay = 0; + u_int yy, ay = 0; for (yy = 0; yy < gd->hsize + gd->sy - 1; yy++) { if (ay == wy) break; - if (gd->linedata[yy].flags & GRID_LINE_WRAPPED) - ax += gd->linedata[yy].cellused; - else { - ax = 0; + if (~gd->linedata[yy].flags & GRID_LINE_WRAPPED) ay++; - } } /* |