aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-08-05 19:58:05 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-08-05 19:58:05 -0700
commitd5871904a4f13c9db63ebb06f2369d801b6893d9 (patch)
treefbfd2d9a8dda0af8ebf1e5db6195ecb9186abcc9
parented0cfd2b48aee480556f3a7dd49b7f24ec2bfceb (diff)
downloadbasta-d5871904a4f13c9db63ebb06f2369d801b6893d9.tar.gz
basta-d5871904a4f13c9db63ebb06f2369d801b6893d9.tar.bz2
basta-d5871904a4f13c9db63ebb06f2369d801b6893d9.zip
Detect existing status line and clean up on exit.
- On startup, determine how many bottom rows of the terminal are already reserved by something, and remember this value. - When resizing, observe this value; set the scrolling region such that we protect the existing one. - When terminating, restore the protection to the original one found, or else reset the scrolling region. Also bump up the stty rows again; don't leave it trimmed.
-rw-r--r--basta.sh32
1 files changed, 30 insertions, 2 deletions
diff --git a/basta.sh b/basta.sh
index 9c8c932..01b7447 100644
--- a/basta.sh
+++ b/basta.sh
@@ -4,10 +4,22 @@ old_cmdno=${old_cmdno-0}
old_lines=${old_lines-0}
old_cols=${old_cols-0}
+existing_reserved_rows=${existing_reserved_rows-}
+
+calc_existing_rows()
+{
+ local esc=$(printf "\033")
+ printf "${esc}7$esc[999;999H"
+ local realrows=$(get_current_line)
+ printf "${esc}8"
+ existing_reserved_rows=$((realrows - LINES))
+}
+
prepare_terminal()
{
- stty rows $((LINES - 1))
- printf "\n\033[1A"
+ [ -n "$existing_reserved_rows" ] || calc_existing_rows
+ stty rows $((LINES - existing_reserved-rows - 1))
+ printf "\n\033[A"
old_lines=$LINES
old_cols=$COLUMNS
}
@@ -76,6 +88,20 @@ update_status_timer()
done
}
+release_status()
+{
+ local esc=$(printf "\033")
+ local newlines=$((LINES + 1))
+
+ if [ $existing_reserved_rows ] && [ $existing_reserved_rows -gt 0 ] ; then
+ printf "$esc[1;%sr" $((newlines - existing_reserved_rows))
+ else
+ printf "$esc[1r"
+ fi
+
+ stty rows $newlines
+}
+
PROMPT_COMMAND='update_status_line'
if ! [ $update_status_alarm ] ; then
@@ -85,6 +111,8 @@ if ! [ $update_status_alarm ] ; then
disown $!
fi
+trap release_status EXIT
+
# Copyright 2023
# Kaz Kylheku <kaz@kylheku.com>
# Vancouver, Canada