From bcd111d203f9e421b43e4e31fc750b0515b10d61 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 9 Jul 2019 16:26:36 +0200 Subject: wip: initial scroll back support Can scroll up and down, and stops when the beginning/end of history is reached. However, it probably breaks when the entire scrollback buffer has been filled - we need to detect when the view has wrapped around to the current terminal offset. The detection of when we've reached the bottom of the history is also flawed, and only works when we overshoot the bottom with at least a page. Resizing the windows while in a view most likely doesn't work. The view will not detect a wrapped around scrollback buffer. I.e. if the user has scrolled back, and is stationary at a view, but there is still output being produced. Then eventually the scrollback buffer will wrap around. In this case, the correct thing to do is make the view start following the beginning of the history. Right now it doesn't, meaning once the scrollback buffer wraps around, you'll start seeing command output... --- terminal.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 1cf15cfb..56ac6cee 100644 --- a/terminal.c +++ b/terminal.c @@ -152,11 +152,18 @@ term_scroll_partial(struct terminal *term, struct scroll_region region, int rows grid_swap_row(term->grid, i, i + rows); /* Offset grid origin */ + bool view_follows = term->grid->view == term->grid->offset; term->grid->offset += rows; term->grid->offset %= term->grid->num_rows; - for (int r = max(region.end - rows, 0); r < region.end; r++) - erase_line(term, grid_row(term->grid, r)); + if (view_follows) + term->grid->view = term->grid->offset; + + for (int r = max(region.end - rows, 0); r < region.end; r++) { + struct row *row = grid_row(term->grid, r); + erase_line(term, row); + row->initialized = true; + } term_damage_scroll(term, DAMAGE_SCROLL, region, rows); term->grid->cur_row = grid_row(term->grid, term->cursor.row); @@ -174,9 +181,14 @@ term_scroll_reverse_partial(struct terminal *term, { assert(rows < term->rows && "unimplemented"); + bool view_follows = term->grid->view == term->grid->offset; + term->grid->offset += term->grid->num_rows - rows; term->grid->offset %= term->grid->num_rows; + if (view_follows) + term->grid->view = term->grid->offset; + /* Bottom non-scrolling region */ for (int i = region.end + rows; i < term->rows + rows; i++) grid_swap_row(term->grid, i, i - rows); -- cgit v1.3 From 8a65d52b215dfe1288a6dfc650b0b38acbc4434f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 10 Jul 2019 14:32:40 +0200 Subject: terminal: add term_damage_view() This ensures everything *visible* (i.e. maybe scrolled back content) is re-rendered. --- terminal.c | 7 +++++++ terminal.h | 1 + 2 files changed, 8 insertions(+) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 56ac6cee..8804140b 100644 --- a/terminal.c +++ b/terminal.c @@ -21,6 +21,13 @@ term_damage_all(struct terminal *term) grid_row(term->grid, i)->dirty = true; } +void +term_damage_view(struct terminal *term) +{ + for (int i = 0; i < term->rows; i++) + grid_row_in_view(term->grid, i)->dirty = true; +} + void term_damage_scroll(struct terminal *term, enum damage_type damage_type, struct scroll_region region, int lines) diff --git a/terminal.h b/terminal.h index 35a1fae7..7d379229 100644 --- a/terminal.h +++ b/terminal.h @@ -250,6 +250,7 @@ struct terminal { }; void term_damage_all(struct terminal *term); +void term_damage_view(struct terminal *term); void term_damage_scroll( struct terminal *term, enum damage_type damage_type, struct scroll_region region, int lines); -- cgit v1.3