aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-01 17:20:21 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-01 17:20:21 +0000
commit24395cf4cd2bd058ad194a8ba08c25d4b9c4d2a7 (patch)
tree794d72f4da4d093cb13b65a12ebf196a86105510 /terminal.c
parentrender: use actual grid size when re-allocating grid buffer (diff)
scrolling: implement partial scrolling
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c68
1 files changed, 45 insertions, 23 deletions
diff --git a/terminal.c b/terminal.c
index 0bd38915..c6129953 100644
--- a/terminal.c
+++ b/terminal.c
@@ -86,6 +86,7 @@ damage_adjust_after_scroll(struct terminal *term, enum damage_type damage_type,
struct scroll_region region, int lines)
{
tll_foreach(term->grid->damage, it) {
+#if 0
if (it->item.range.start < term->grid->offset) {
int end = it->item.range.start + it->item.range.length;
if (end >= term->grid->offset) {
@@ -95,6 +96,12 @@ damage_adjust_after_scroll(struct terminal *term, enum damage_type damage_type,
tll_remove(term->grid->damage, it);
}
}
+#endif
+
+ int start = it->item.range.start;
+ int end = start + it->item.range.length;
+
+ if (start -
}
}
#endif
@@ -190,37 +197,52 @@ void
term_scroll_partial(struct terminal *term, struct scroll_region region, int rows)
{
LOG_DBG("scroll: %d rows", rows);
- if (rows >= region.end - region.start) {
- assert(false && "untested");
- return;
- }
-#if 0
- int cell_dst = (region.start + 0) * term->cols;
- int cell_src = (region.start + rows) * term->cols;
- int cell_count = (region.end - region.start - rows) * term->cols;
+ if (region.start > 0) {
+ /* TODO: check if it's worth memoving the scroll area instead,
+ * under certain circumstances */
- LOG_DBG("moving %d lines from row %d to row %d", cell_count / term->cols,
- cell_src / term->cols, cell_dst / term->cols);
+ grid_memmove(term->grid, rows * term->cols, 0, region.start * term->cols);
- const int bytes = cell_count * sizeof(term->grid->cells[0]);
- memmove(
- &term->grid->cells[cell_dst], &term->grid->cells[cell_src],
- bytes);
+ tll_foreach(term->grid->damage, it) {
+ int start = it->item.range.start - term->grid->offset;
+ int end = start + it->item.range.length;
- memset(&term->grid->cells[(region.end - rows) * term->cols], 0,
- rows * term->cols * sizeof(term->grid->cells[0]));
+ if (start < region.start) {
+ assert(end <= region.start);
+ it->item.range.start += rows * term->cols;
+ }
+ }
+ }
- term_damage_scroll(term, DAMAGE_SCROLL, region, rows);
-#else
- /* TODO */
- assert(region.start == 0 && region.end == term->rows);
- assert(rows < term->rows);
+ if (region.end < term->rows) {
+ /* Copy scrolled-up bottom region to new bottom region */
+ grid_memmove(
+ term->grid,
+ (region.end + rows) * term->cols,
+ region.end * term->cols,
+ (term->rows - region.end) * term->cols);
+
+ tll_foreach(term->grid->damage, it) {
+ int start = it->item.range.start - term->grid->offset;
+ int end = start + it->item.range.length;
+ if (end > region.end) {
+ assert(start >= region.end);
+ it->item.range.start += rows * term->cols;
+ }
+ }
+ }
+
+ /* Offset grid origin */
term->grid->offset += rows * term->cols;
- grid_memset(term->grid, (region.end - rows) * term->cols, 0, rows * term->cols);
+
+ /* Clear scrolled-in lines */
+ grid_memset(
+ term->grid,
+ max(0, region.end - rows) * term->cols, 0, rows * term->cols);
+
term_damage_scroll(term, DAMAGE_SCROLL, region, rows);
-#endif
}
void