Skip to content

Commit

Permalink
Use premove rather than start of moverect to implement scrollback pus…
Browse files Browse the repository at this point in the history
…h in screen layer
  • Loading branch information
leonerd committed Jul 16, 2024
1 parent 3cb1c9c commit c76de09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,25 @@ static void sb_pushline_from_row(VTermScreen *screen, int row)
(screen->callbacks->sb_pushline)(screen->cols, screen->sb_buffer, screen->cbdata);
}

static int moverect_internal(VTermRect dest, VTermRect src, void *user)
static int premove(VTermRect rect, void *user)
{
VTermScreen *screen = user;

if(screen->callbacks && screen->callbacks->sb_pushline &&
dest.start_row == 0 && dest.start_col == 0 && // starts top-left corner
dest.end_col == screen->cols && // full width
rect.start_row == 0 && rect.start_col == 0 && // starts top-left corner
rect.end_col == screen->cols && // full width
screen->buffer == screen->buffers[BUFIDX_PRIMARY]) { // not altscreen
for(int row = 0; row < src.start_row; row++)
for(int row = 0; row < rect.end_row; row++)
sb_pushline_from_row(screen, row);
}

return 1;
}

static int moverect_internal(VTermRect dest, VTermRect src, void *user)
{
VTermScreen *screen = user;

int cols = src.end_col - src.start_col;
int downward = src.start_row - dest.start_row;

Expand Down Expand Up @@ -840,6 +847,7 @@ static int sb_clear(void *user) {
static VTermStateCallbacks state_cbs = {
.putglyph = &putglyph,
.movecursor = &movecursor,
.premove = &premove,
.scrollrect = &scrollrect,
.erase = &erase,
.setpenattr = &setpenattr,
Expand Down Expand Up @@ -884,6 +892,7 @@ static VTermScreen *screen_new(VTerm *vt)
screen->sb_buffer = vterm_allocator_malloc(screen->vt, sizeof(VTermScreenCell) * cols);

vterm_state_set_callbacks(screen->state, &state_cbs, screen);
vterm_state_callbacks_has_premove(screen->state);

return screen;
}
Expand Down
2 changes: 1 addition & 1 deletion t/62screen_damage.test
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ PUSH "\e[25H\r\nABCDE\b\b\b\e[2P\r\n"
sb_pushline 80 =
moverect 1..25,0..80 -> 0..24,0..80
damage 24..25,0..80 = 24<41 42 43 44 45>
sb_pushline 80 =
moverect 24..25,4..80 -> 24..25,2..78
damage 24..25,78..80
sb_pushline 80 =
DAMAGEFLUSH
moverect 1..25,0..80 -> 0..24,0..80
damage 24..25,0..80
Expand Down

0 comments on commit c76de09

Please sign in to comment.