diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-02-14 09:59:59 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-02-14 09:59:59 -0800 |
commit | 82edc56b096ad21103551eaad899e217915c9fe3 (patch) | |
tree | 50ad36f3008a084b2204cdccf954b10b85a2e2d2 | |
parent | ab3719742a7a62b810679b9ef91e42d8c2477135 (diff) | |
download | basta-82edc56b096ad21103551eaad899e217915c9fe3.tar.gz basta-82edc56b096ad21103551eaad899e217915c9fe3.tar.bz2 basta-82edc56b096ad21103551eaad899e217915c9fe3.zip |
Simplify fullscreen to one function.
* basta.sh (badsta.fullscreen); Merges functionality of
basta.fullscreen_alt. When -s is not specified,
clears to end of screen, and calls
basta.ensure_bottom_margin. When calling this function,
we use the current value of $LINES rather than
recalculating realrows, removing one interaction to the
terminal. Since we are in full screen mode, we can
trust that $LINES is tracking the size.
When -s is specified, we don't clear to end of screen
or call basta.ensure_bottom_margin. Also we don't
need to provoke WINCH handling.
(basta.fullscreen_alt): Function removed.
* README.md: Documentation trimmed and revised.
-rw-r--r-- | README.md | 53 | ||||
-rw-r--r-- | basta.sh | 50 |
2 files changed, 24 insertions, 79 deletions
@@ -98,50 +98,23 @@ the full screen. Create `basta.fullscreen <program>` alias for each program that is to use the full terminal. -The `basta.fullscreen` function works well with programs such as editors -that use the full screen, and do not generate TTY-like output that scrolls the -terminal. Some such programs save and restore the terminal screen. -These work very well with `basta.fullscreen`. - -Programs that do not save and restore the terminal screen, or which generate -some log messages before or after restoring the terminal screen, may cause a -small cosmetic problem, like the Bash prompt appearing over top of a line of -output from the program. For the former category, full-screen programs -which don't save and restore the terminal, one possible fix for the cosmetic -issue is to use the `-s` (save and restore) option of `basta.fullscreen`, -which saves and restores the terminal contents around the invocation of -the program. For instance, many versions of the `top` utility are like this, -and can be handled using: +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 +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: ::text alias top='basta.fullscreen -s top' -Now the `top` command restores the terminal upon quitting. - -Programs which generate arbitrary scrolling output can be operated in full -screen mode the function `basta.fullscreen_alt`. Almost any program, including -non-interactive batch programs, can be run in full screen with this function. -This function clears the screen and switches to the full scrolling area -prior to running the program. Then when the program terminates, it checks -the cursor position. The cursor position is assumed to be where the program -produced its last line of output. The terminal is scrolled so that this -last line of output is above the status area, which Basta then displays -once again, and configures the scrolling region above it. - -Note for `git` users: though the `less` pager used by `git` normally saves -and restores the terminal by default, `git` runs it in such a way that it does -not do this: `git` adds some arguments to `less`. To fix the behavior, add a -`[core]` configuration section to your `~/.gitconfig` file (if necessary) and -then add the following `pager =` line to that section: - - ::text - [core] # add if necessary - pager = less -+Xn -+F - -Even with this setting, it is recommended to use `alias -git='basta.fullscreen_alt git'` because `git` does not always use the pager; -under some invocations, `git` behaves as noninteractive program -which produces TTY-like scrolling output. +Now the `top` command restores the terminal upon quitting. Note that +with the above alias, it becomes impossible to see the output of `top -h` on +the terminal; the terminal is quickly restored after `top -h` produces output, +making it look as if no output had been produced. ## Environment @@ -312,15 +312,17 @@ basta.fullscreen() { fi local realrows=$(( LINES + basta_prev_reserved_rows + 1 )) - local exit= + local curline + local i + local exit=0 local saveint=$(trap -p INT) local saveterm= local ttyfd - exec {ttyfd}<>/dev/tty - trap : INT + exec {ttyfd}<>/dev/tty + if [ "$1" == "-s" ] ; then shift saveterm=y @@ -329,46 +331,16 @@ basta.fullscreen() { printf $'\e7\e[1;%sr\e8' $realrows >&$ttyfd stty rows $realrows <&$ttyfd - basta_deferred_intr=WINCH - LINES=$realrows command "$@" - exit=$? - - [ $saveterm ] && printf $'\e[?1049l' >&$ttyfd - - exec {ttyfd}>&- - - eval "$saveint" - - return $exit -} - -basta.fullscreen_alt() { - if [ -n "$COMP_WORDS" ]; 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 - - exec {ttyfd}<>/dev/tty - - printf $'\e7\e[1;%sr\e8' $realrows >&$ttyfd - stty rows $realrows <&$ttyfd - printf $'\e[J' >&$ttyfd + [ $saveterm ] || printf $'\e[J' >&$ttyfd && basta_deferred_intr=WINCH - basta_deferred_intr=WINCH LINES=$realrows command "$@" || exit=$? - basta.query_terminal_lines realrows >&$ttyfd <&$ttyfd && - basta.ensure_bottom_margin $realrows >&$ttyfd + if [ $saveterm ] ; then + printf $'\e[?1049l' >&$ttyfd + else + basta.ensure_bottom_margin $LINES >&$ttyfd + fi exec {ttyfd}>&- |