aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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