diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-03-18 23:53:05 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-03-18 23:53:05 -0700 |
commit | bc74bf497cb004eb0bc77dd6925818c5db063178 (patch) | |
tree | a46db5cb0aee3ab12265d6a0f14942b56628cdc5 | |
parent | 5757c92613f66caa6d6215a5d089e9efdd4ecf32 (diff) | |
download | basta-bc74bf497cb004eb0bc77dd6925818c5db063178.tar.gz basta-bc74bf497cb004eb0bc77dd6925818c5db063178.tar.bz2 basta-bc74bf497cb004eb0bc77dd6925818c5db063178.zip |
fullscreen: don't fullscreen if stdout is not a tty.
* basta.sh (basta.fullscreen): Separate option parsing
from side effects an do it earlier. Recognize a new -f
option, separately or clumped with -s. If -f is not
supplied and standard output is not a TTY, then
just execute the command and return, without doing
full screen.
* README.md: Documented -f option.
-rw-r--r-- | README.md | 26 | ||||
-rw-r--r-- | basta.sh | 30 |
2 files changed, 44 insertions, 12 deletions
@@ -98,15 +98,25 @@ the full screen. Create `basta.fullscreen <program>` alias for each program that is to use the full terminal. -The `basta.fullscreen` function takes a single option, `-s`. If that -is specified, then then Basta will save and restore the terminal around -the invocation of the program. This should only be used for full-screen +The `basta.fullscreen` function takes two options, `-f` and `-s`. +They can be used together, and may be specified separately in any order +or clumped as `-fs` or `-sf`. + +The `-f` option will force full screen mode even if the function's +standard output is redirected such that it is not a terminal. +By default, if standard output is redirected, `basta.fullscreen` +just executes the specified command without preparing full screen mode. +The default behavior is sensible; it prevents a race condition between +`basta.fullscreen` coming out of fullscreen mode and restoring the status line, +and a subsequent pipeline element still running, concurrently producing output +to the terminal, resulting in a messed-up display. + +If the `-s` option is used, then then Basta will save and restore the terminal +around the invocation of the program. This should only be used for full-screen programs that don't output any messages outside of their full-screen paradigm, -which should persist in the terminal window. - -The `top` utility is a good target for this. Some versions of `top` do not -save and restore the screen, with with `basta.fullscreen -s top` we -get that behavior: +which should persist in the terminal window. The `top` utility is a good +target for this. Some versions of `top` do not save and restore the screen, +with with `basta.fullscreen -s top` we get that behavior: ::text alias top='basta.fullscreen -s top' @@ -313,22 +313,44 @@ basta.fullscreen() local exit=0 local saveint=$(trap -p INT) local saveterm= + local force= local ttyfd + while true; do + case $1 in + ( -s ) + saveterm=y + ;; + ( -f ) + force=y + ;; + ( -sf | -fs ) + saveterm=y + force=y + ;; + ( * ) + break + ;; + esac + shift + done + + if ! [ -t 1 ] && ! [ $force ] ; then + eval command $args + return $? + fi + trap : INT exec {ttyfd}<>/dev/tty - if [ "$1" == "-s" ] ; then - shift - saveterm=y + if [ $saveterm ] ; then printf $'\e[?1049h' >&$ttyfd else basta_deferred_intr=WINCH printf $'\e[J' >&$ttyfd fi - printf $'\e7\e[1;%sr\e8' $realrows >&$ttyfd stty rows $realrows <&$ttyfd |