diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-08-27 01:02:35 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-08-27 01:02:35 -0700 |
commit | 0399d1d0ea06875a0691cf3dee89de7a69e6bdf2 (patch) | |
tree | 05b8e3e64f46ae9df6037827e714c4d3c815bb50 | |
parent | 8599f6e9f9883bce871c48c2da34f67a48074185 (diff) | |
download | basta-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.sh | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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)) |