aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-08-27 01:02:35 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-08-27 01:02:35 -0700
commit0399d1d0ea06875a0691cf3dee89de7a69e6bdf2 (patch)
tree05b8e3e64f46ae9df6037827e714c4d3c815bb50
parent8599f6e9f9883bce871c48c2da34f67a48074185 (diff)
downloadbasta-0399d1d0ea06875a0691cf3dee89de7a69e6bdf2.tar.gz
basta-0399d1d0ea06875a0691cf3dee89de7a69e6bdf2.tar.bz2
basta-0399d1d0ea06875a0691cf3dee89de7a69e6bdf2.zip
Calculate real terminal size when resize detected.
Basta should not trust that a changed value of LINES reflects the terminal size. In cases when LINES is set to a bad value, it leaves the display in a bad state: wrong scrolling region, wrong status line position. As a test, try a command like "LINES=3; stty rows $LINES". Before this change, Basta will react and move the status line to the third line, setting up a two-line scrolling region. With this change, Basta isn't fooled; it asks the terminal. - New function basta.calc_current_size interrogates the terminal to get the size, just like basta.calc_prev_preserved does. The function sets up LINES and stty rows to the discovered terminal size. - basta.prepare_term calls this function the second and subsequent time it is called.
-rw-r--r--basta.sh11
1 files changed, 11 insertions, 0 deletions
diff --git a/basta.sh b/basta.sh
index 8b7ad38..07b268f 100644
--- a/basta.sh
+++ b/basta.sh
@@ -18,11 +18,22 @@ basta.calc_prev_reserved()
basta_prev_reserved_rows=$((realrows - LINES))
}
+basta.calc_current_size()
+{
+ local esc=$(printf "\033")
+ printf "${esc}7$esc[999;999H"
+ LINES=$(basta.get_cur_line)
+ printf "${esc}8"
+ stty rows $LINES
+}
+
basta.prepare_term()
{
if [ -z "$basta_prev_reserved_rows" ] ; then
basta.calc_prev_reserved
printf "\n\033[A"
+ else
+ basta.calc_current_size
fi
basta_scroll_lines=$((LINES - 1))