term: define scrollback expansion helper functions

These functions do the following:

 - Determine whether adding the given number of lines
   would overflow the terminal's scrollback
 - Determine whether whether the terminal should expand
   its scrollback capacity in order to hold the requested
   number of new rows, taking user configuration into account.
 - Expand the terminal capacity if necessary and configured to do so.
This commit is contained in:
Matheus Afonso Martins Moreira 2024-04-07 11:21:24 -03:00
parent 3818cbd93c
commit 800b7c423a

View file

@ -2783,6 +2783,29 @@ selection_on_bottom_region(const struct terminal *term,
selection_on_rows(term, region.end, term->rows - 1);
}
bool
term_would_overflow_scrollback(struct terminal *term, int new_rows)
{
return term->grid->offset + new_rows >= term->grid->num_rows;
}
bool term_should_expand_scrollback(struct terminal *term, int new_rows)
{
bool would_overflow = term_would_overflow_scrollback(term, new_rows);
return term->unlimited_scrollback && would_overflow;
}
bool
term_expand_scrollback_capacity_if_needed(struct terminal *term, int new_rows)
{
if (term_should_expand_scrollback(term, new_rows)) {
grid_expand_capacity(term->grid, new_rows, term->render.scrollback_lines);
return true;
}
return false;
}
void
term_scroll_partial(struct terminal *term, struct scroll_region region, int rows)
{