From 800b7c423ac9514872fc2aebfde2d6458bb4bfcf Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 7 Apr 2024 11:21:24 -0300 Subject: [PATCH] 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. --- terminal.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/terminal.c b/terminal.c index be1661af..8bd154af 100644 --- a/terminal.c +++ b/terminal.c @@ -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) {