aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-02-13 20:20:21 +0000
committerKaz Kylheku <kaz@kylheku.com>2025-02-13 20:20:21 +0000
commit6827538fbf6f9646535b76c2450aa66576cb27a4 (patch)
tree32e35079cb96cfbc707c6ce3d8ab8540afafc41e
parent3eacc704680ae8a17bdb5076f12db41d3770f122 (diff)
downloadbasta-6827538fbf6f9646535b76c2450aa66576cb27a4.tar.gz
basta-6827538fbf6f9646535b76c2450aa66576cb27a4.tar.bz2
basta-6827538fbf6f9646535b76c2450aa66576cb27a4.zip
Use /dev/tty rather than disabling fullscreen.
In the full screen functions, our strategy of disabling fullscreen mode when standard input or output are redirected is suboptimal. What we should be doing is opening /dev/tty and doing our terminal interactions with that, and not care that standard input and output are redirected. * basta.sh (basta.fullscreen, basta.fullscreen_alt): Remove the check for stdin and stdout not being a terminal, which runs the command without fullscreen mode. Open /dev/tty for reading and writing, retaining the file descriptor in the ttyfd variable. Redirect all tty interactions to this ttyfd descriptor.
-rw-r--r--basta.sh40
1 files changed, 20 insertions, 20 deletions
diff --git a/basta.sh b/basta.sh
index 4e92022..f402653 100644
--- a/basta.sh
+++ b/basta.sh
@@ -290,31 +290,31 @@ basta.import_array()
# Public API functions
basta.fullscreen() {
- if ! [ -t 0 -a -t 1 ] ; then
- command "$@"
- return $?
- fi
-
local realrows=$(( LINES + basta_prev_reserved_rows + 1 ))
local exit=
local saveint=$(trap -p INT)
local saveterm=
+ local ttyfd
+
+ exec {ttyfd}<>/dev/tty
trap : INT
if [ "$1" == "-s" ] ; then
shift
saveterm=y
- printf $'\e[?1049h'
+ printf $'\e[?1049h' >&$ttyfd
fi
- printf $'\e7\e[1;%sr\e8' $realrows
- stty rows $realrows
+ printf $'\e7\e[1;%sr\e8' $realrows >&$ttyfd
+ stty rows $realrows <&$ttyfd
basta_deferred_intr=WINCH
LINES=$realrows command "$@"
exit=$?
- [ $saveterm ] && printf $'\e[?1049l'
+ [ $saveterm ] && printf $'\e[?1049l' >&$ttyfd
+
+ exec {ttyfd}>&-
eval "$saveint"
@@ -322,23 +322,21 @@ basta.fullscreen() {
}
basta.fullscreen_alt() {
- if ! [ -t 0 -a -t 1 ] ; then
- command "$@"
- return $?
- fi
-
local realrows=$(( LINES + basta_prev_reserved_rows + 1 ))
local curline
local i
local exit=0
local saveint=$(trap -p INT)
+ local ttyfd
trap : INT
- printf $'\e7\e[1;%sr\e8' $realrows
- stty rows $realrows
+ exec {ttyfd}<>/dev/tty
- printf $'\e[J'
+ printf $'\e7\e[1;%sr\e8' $realrows >&$ttyfd
+ stty rows $realrows <&$ttyfd
+
+ printf $'\e[J' >&$ttyfd
basta_deferred_intr=WINCH
LINES=$realrows command "$@" || exit=$?
@@ -348,13 +346,15 @@ basta.fullscreen_alt() {
if [ $curline -ge $(( realrows - basta_prev_reserved_rows )) ] ; then
local scrolls_needed=$(( curline - realrows + basta_prev_reserved_rows ))
- printf $'\e[%s;1H' $realrows
+ printf $'\e[%s;1H' $realrows >&$ttyfd
for (( i = 0 ; i < scrolls_needed; i++ )) ; do
- printf $'\n'
+ printf $'\n' >&$ttyfd
done
- printf $'\n\e[%sA' $(( basta_prev_reserved_rows + 1 ))
+ printf $'\n\e[%sA' $(( basta_prev_reserved_rows + 1 )) >&$ttyfd
fi
+ exec {ttyfd}>&-
+
eval "$saveint"
return $exit