diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-02-10 10:25:13 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-02-10 10:25:13 -0800 |
commit | 02620a07969b078b86cb6a034ef574fee37104a7 (patch) | |
tree | f07907c56cd99b455e48653e47f3ccb4b56cc08d | |
parent | 0a62c283a13c2f911ea660ce736ed522cde3c1b9 (diff) | |
download | basta-02620a07969b078b86cb6a034ef574fee37104a7.tar.gz basta-02620a07969b078b86cb6a034ef574fee37104a7.tar.bz2 basta-02620a07969b078b86cb6a034ef574fee37104a7.zip |
Don't interrogate terminal too often in basta.check_cursor.
- We take advantage of the $EPOCHSECONDS variable available in
newer Bash to get the current time. We don't perform the
cursor position or resize check in basta.check_cursor if
it has been done in the last 5 seconds, in addition to
continuing to avoid it if there is buffered TTY input.
-rw-r--r-- | basta.sh | 39 |
1 files changed, 30 insertions, 9 deletions
@@ -5,6 +5,7 @@ basta_old_cmdno=${basta_old_cmdno-0} basta_old_lines=${basta_old_lines-0} basta_old_cols=${basta_old_cols-0} +basta_last_check_epoch=${basta_last_check_epoch-0} basta_scroll_lines=${basta_scroll_lines-0} basta_prev_reserved_rows=${basta_prev_reserved_rows-} @@ -58,6 +59,20 @@ basta.get_cur_line() printf "%s\n" "$2" } +if [ $EPOCHSECONDS ] ; then + basta.epoch() + { + local -n intovar=$1 + intovar=$EPOCHSECONDS + } +else + basta.epoch() + { + local -n intovar=$1 + intovar=$(date +%s) + } +fi + basta.update_status() { local pwd=$PWD @@ -97,18 +112,24 @@ basta.update_status() basta.check_cursor() { if ! read -t 0; then - local exit=$? - local curln=$(basta.get_cur_line) - local realrows + local now + basta.epoch now - if [ $curln ] && [ $curln -gt $basta_scroll_lines ]; then - printf $'\e[%s;1H' $basta_scroll_lines - fi + if [ $((now - 5)) -ge $basta_last_check_epoch ] ; then + local exit=$? + local curln=$(basta.get_cur_line) + local realrows - basta.query_terminal_lines realrows + if [ $curln ] && [ $curln -gt $basta_scroll_lines ]; then + printf $'\e[%s;1H' $basta_scroll_lines + fi - [ $LINES -eq $((realrows - $basta_prev_reserved_rows - 1)) ] - return $? + basta_last_check_epoch=$now + + basta.query_terminal_lines realrows + [ $LINES -eq $((realrows - $basta_prev_reserved_rows - 1)) ] + return $? + fi fi return 0 |