aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-02-14 00:02:30 -0800
committerKaz Kylheku <kaz@kylheku.com>2025-02-14 00:02:30 -0800
commitab3719742a7a62b810679b9ef91e42d8c2477135 (patch)
tree1cbbf9bb278830424d67141a4129e56f98e9ad66
parent62c92629b40ea907c5cc6f69001e2fecdfa66b88 (diff)
downloadbasta-ab3719742a7a62b810679b9ef91e42d8c2477135.tar.gz
basta-ab3719742a7a62b810679b9ef91e42d8c2477135.tar.bz2
basta-ab3719742a7a62b810679b9ef91e42d8c2477135.zip
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.
-rw-r--r--basta.sh37
1 files 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}>&-