aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-02-13 22:12:49 -0800
committerKaz Kylheku <kaz@kylheku.com>2025-02-13 22:12:49 -0800
commit318f71bad51d0fe977a4101cbf764f70de4e5777 (patch)
tree126c40cc5910e539c35d18c649e6de4bbc6d0d39
parentd0ed623631bcf9abd293e88b8a057b304fe3001c (diff)
downloadbasta-318f71bad51d0fe977a4101cbf764f70de4e5777.tar.gz
basta-318f71bad51d0fe977a4101cbf764f70de4e5777.tar.bz2
basta-318f71bad51d0fe977a4101cbf764f70de4e5777.zip
Return and check status from get_cur_line.
From time to time get_cur_line doesn't fetch a value due to a timeout or, more likely, interference from TTY input. We have to check those situations so as not to try to calculate with a bad value or pass it to stty or whatever. * basta.sh (basta.query_terminal_lines): Propagate status now returned by get_cur_line. (basta.prepare_term): Skip logic and return failure if query_terminal_lines failed, since realrows contains garbage. (basta.get_cur_line): Return success if value obtained is a string of one or more decimal digits. (basta.check_cursor): Improve error checking. (basta.fullscreen_alt): Error checks.
-rw-r--r--basta.sh23
1 files changed, 14 insertions, 9 deletions
diff --git a/basta.sh b/basta.sh
index 44c5a71..9acaa89 100644
--- a/basta.sh
+++ b/basta.sh
@@ -17,11 +17,14 @@ basta_deferred_intr=${basta_deferred_intr-}
basta.query_terminal_lines()
{
local -n intovar=$1
+ local result
local curline
printf $'\e7\e[999;999H'
basta.get_cur_line curline
+ result=$?
printf $'\e8'
intovar=$curline
+ return $result
}
basta.query_termios_lines_cols()
@@ -37,7 +40,10 @@ basta.query_termios_lines_cols()
basta.prepare_term()
{
local realrows
- basta.query_terminal_lines realrows
+
+ if ! basta.query_terminal_lines realrows; then
+ return 1
+ fi
if [ -z "$basta_prev_reserved_rows" ] ; then
basta_prev_reserved_rows=${#LC_basta_status[@]}
@@ -61,6 +67,7 @@ basta.get_cur_line()
local IFS="[;"
set -- $response
intovar=$2
+ [[ "$intovar" =~ ^[0-9]+$ ]]
}
if [ $EPOCHSECONDS ] ; then
@@ -142,15 +149,13 @@ basta.check_cursor()
local curln
local realrows
- basta.get_cur_line curln
-
- if [ $curln ] && [ $curln -gt $basta_scroll_lines ]; then
+ if basta.get_cur_line curln && [ $curln -gt $basta_scroll_lines ]; then
printf $'\e[%s;1H' $basta_scroll_lines
fi
basta_last_check_epoch=$now
- basta.query_terminal_lines realrows
+ basta.query_terminal_lines realrows &&
[ $LINES -eq $((realrows - $basta_prev_reserved_rows - 1)) ]
return $?
fi
@@ -351,10 +356,10 @@ basta.fullscreen_alt() {
basta_deferred_intr=WINCH
LINES=$realrows command "$@" || exit=$?
- basta.query_terminal_lines realrows >&$ttyfd <&$ttyfd
- basta.get_cur_line curline >&$ttyfd <&$ttyfd
-
- if [ $curline -ge $(( realrows - basta_prev_reserved_rows )) ] ; then
+ if basta.query_terminal_lines realrows >&$ttyfd <&$ttyfd &&
+ basta.get_cur_line curline >&$ttyfd <&$ttyfd &&
+ [ $curline -ge $(( realrows - basta_prev_reserved_rows )) ]
+ then
local scrolls_needed=$(( curline - realrows + basta_prev_reserved_rows ))
printf $'\e[%s;1H' $realrows >&$ttyfd
for (( i = 0 ; i < scrolls_needed; i++ )) ; do