From ab3719742a7a62b810679b9ef91e42d8c2477135 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 14 Feb 2025 00:02:30 -0800 Subject: Share logic between prepare_term and fullscreen_alt. * basta.sh (basta.ensure_bottom_margin): New function, factored off from basta.prepare_term. (basta.prepare_term): Code for ensuring that screen contents move out of status-sized bottom area now moved into basta.ensure_bottom_margin. (basta.fullscreen_alt): Complex logic involving knowing the current line, moving the cursor to the bottom, and scrolling a certain nummber of lines removed. Replaced with call to basta.ensure_bottom_margin. --- basta.sh | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/basta.sh b/basta.sh index 5707e0e..4f6c032 100644 --- a/basta.sh +++ b/basta.sh @@ -36,6 +36,18 @@ basta.query_termios_lines_cols() colsvar=$2 } +basta.ensure_bottom_margin() +{ + local i + local realrows=$1 + + printf $'\e7\e[1;%sr\e8' $realrows + for (( i = 0; i <= basta_prev_reserved_rows; i++ )); do + printf $'\n' + done + printf $'\e[%sA' $i +} + basta.prepare_term() { local realrows @@ -47,11 +59,7 @@ basta.prepare_term() if [ -z "$basta_prev_reserved_rows" ] ; then basta_prev_reserved_rows=${#LC_basta_status[@]} - printf $'\e7\e[1;%sr\e8' $realrows - for (( i = 0; i <= basta_prev_reserved_rows; i++ )); do - printf $'\n' - done - printf $'\e[%sA' $i + basta.ensure_bottom_margin $realrows fi LINES=$((realrows - $basta_prev_reserved_rows - 1)) @@ -359,23 +367,8 @@ basta.fullscreen_alt() { basta_deferred_intr=WINCH LINES=$realrows command "$@" || exit=$? - local scrolls_needed=$((basta_prev_reserved_rows + 1)) - - if basta.query_terminal_lines realrows >&$ttyfd <&$ttyfd && - basta.get_cur_line curline >&$ttyfd <&$ttyfd - then - : $(( scrolls_needed -= realrows - curline )) - fi - - if [ $scrolls_needed -gt 0 ] ; then - printf $'\e[%s;1H' $realrows >&$ttyfd - - for (( i = 0 ; i < scrolls_needed; i++ )) ; do - printf $'\n' >&$ttyfd - done - - printf $'\e[%sA' $(( basta_prev_reserved_rows + 1 )) >&$ttyfd - fi + basta.query_terminal_lines realrows >&$ttyfd <&$ttyfd && + basta.ensure_bottom_margin $realrows >&$ttyfd exec {ttyfd}>&- -- cgit v1.2.3