-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvements to clearing, and resolve setup-util(-bash) edge case
- brew-installed: support --quiet argument, return exit status 46 if brew is not installed - echo-quote: support --double and --single arguments - echo-revolving-door: remove some outdated implementation comments - fs-rm: note when trash is not available - setup-util: - output to /dev/tty if supported and appropriate - if uninstalling/upgrading the currently executing bash, output a warning - redo the clearing functionality to implement modern conventions and support a wide range of edge cases, such as when installer outputs more than LINES, or when clear is not available, or when the installer needs interaction - don't remove non-xdg-bins when upgrading as that causes issues with homebrew if the homebrew-intalled bin was removed but homebrew still thinks it is installed - setup-util-bash: detections and workarounds if trying to uninstall/upgrade the currently executing bash - add an `echo-revolving-screen` command that unfortunately doesn't work properly and I don't know why - styles.bash: change clear screen to use `\e[J` instead of `\e[2J` for reasoning documented inside the file
- Loading branch information
Showing
8 changed files
with
305 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/usr/bin/env bash | ||
|
||
function echo_revolving_screen() ( | ||
source "$DOROTHY/sources/bash.bash" | ||
|
||
# ===================================== | ||
# Arguments | ||
|
||
function help { | ||
cat <<-EOF >/dev/stderr | ||
ABOUT: | ||
Continously clear the output of a command, showing only the latest output, then clearing it upon completion. | ||
USAGE: | ||
(echo-lines -- 1 2; sleep 2; echo-lines -- 3 4; sleep 2) | echo-revolving-door [...options] | ||
# outputs 2, then waits, then outputs 4, then waits, then clears | ||
OPTIONS: | ||
--columns=<columns> | ||
The number of columns to display. If not provided, the terminal's columns will be used. If the terminal's columns cannot be determined, or if <= 0, then the full line will be displayed. | ||
EOF | ||
if test "$#" -ne 0; then | ||
echo-error "$@" | ||
fi | ||
return 22 # EINVAL 22 Invalid argument | ||
} | ||
|
||
# process | ||
local item option_lines='' option_columns='' | ||
while test "$#" -ne 0; do | ||
item="$1" | ||
shift | ||
case "$item" in | ||
'--help' | '-h') help ;; | ||
'--lines='*) option_lines="${item#*=}" ;; | ||
'--columns='*) option_columns="${item#*=}" ;; | ||
'--'*) help "An unrecognised flag was provided: $item" ;; | ||
*) help "An unrecognised argument was provided: $item" ;; | ||
esac | ||
done | ||
|
||
# determine columns | ||
if test -z "$option_lines" -o -z "$option_columns"; then | ||
local terminal_size=() | ||
mapfile -t terminal_size < <(get-terminal-lines-and-columns || :) | ||
if test "${#terminal_size[@]}" -eq 2; then | ||
if test -z "$option_lines"; then | ||
option_lines="${terminal_size[0]}" | ||
fi | ||
if test -z "$option_columns"; then | ||
option_columns="${terminal_size[1]}" | ||
fi | ||
fi | ||
fi | ||
|
||
# ===================================== | ||
# Action | ||
|
||
if test -z "$option_lines" -o -z "$option_columns" || test "$option_lines" -le 0 -o "$option_columns" -le 0; then | ||
cat | ||
else | ||
local terminal_device_file clear_screen | ||
terminal_device_file="$(get-terminal-device-file)" | ||
clear_screen=$'\e[H\e[J' | ||
|
||
local input total_lines=0 status wrapped lines=0 | ||
while IFS='' read -r input || test -n "$input"; do | ||
eval_capture --statusvar=status --outputvar=wrapped \ | ||
-- gfold --width="$option_columns" <<<"$input" | ||
#-- echo-wrap --width="$option_columns" -- "$input" | ||
if test "$status" -ne 0; then | ||
echo-error "$wrapped" | ||
return "$status" | ||
fi | ||
# count lines | ||
lines="$(echo-count-lines -- "$wrapped")" | ||
total_lines="$((total_lines + lines))" | ||
if test "$total_lines" -ge "$option_lines"; then | ||
if test "$lines" -ge "$option_lines"; then | ||
# this line is very long and wraps across all lines of our screen, this is an edge case | ||
# use a coreutil to trim the excess lines | ||
__print_lines "${clear_screen}${wrapped}" | head -n "$option_lines" | ||
else | ||
# clear the screen | ||
__print_lines "${clear_screen}${wrapped}" >"$terminal_device_file" | ||
fi | ||
total_lines="$lines" | ||
else | ||
# print the wrapped output | ||
__print_lines "$wrapped" >"$terminal_device_file" | ||
fi | ||
done | ||
# we are now done, so clear wrapped | ||
# echo-clear-lines --count="$lines" >"$terminal_device_file" | ||
__print_string "${clear_screen}" >"$terminal_device_file" | ||
fi | ||
) | ||
|
||
# fire if invoked standalone | ||
if test "$0" = "${BASH_SOURCE[0]}"; then | ||
echo_revolving_screen "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.