-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major styling improvements (progress #74)
- move out `act` from `setup-util` into `echo-collapse` which can be run as a command, or sourced - added segment open and close styles to `echo-color` - redid `setup-python` to use these new styling abilities - disabled some irrelevant shellcheck issues in the headers of some files - added `echo-indent`, it isn't used yet, but perhaps could be one day Signed-off-by: Benjamin Lupton <b@lupton.cc>
- Loading branch information
Showing
7 changed files
with
329 additions
and
154 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck disable=SC2164,SC1091,SC1090 | ||
source "$DOROTHY/sources/strict.bash" | ||
|
||
# @todo this adds a trailing newline, and I can't figure out why | ||
|
||
while read -r line || test -n "$line"; do | ||
echo "${1-}${line}" | ||
done </dev/stdin |
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,87 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck disable=SC2164,SC1091 | ||
source "$DOROTHY/sources/strict.bash" | ||
|
||
# helper | ||
function eval_collapse() { | ||
# prepare | ||
local ec=0 status='' log | ||
log="$(mktemp)" | ||
|
||
# options | ||
mapfile -t options < <(echo-before-separator "$@") | ||
QUIET="$(get-flag-value quiet --missing="${QUIET-}" -- "${options[@]}" | echo-affirmative || get-flag-value verbose --missing="${VERBOSE-}" -- "$@" | echo-non-affirmative || :)" | ||
option_pending="$(get-flag-value pending -- "${options[@]}")" | ||
option_success="$(get-flag-value success -- "${options[@]}")" | ||
option_failure="$(get-flag-value failure -- "${options[@]}")" | ||
mapfile -t args < <(echo-after-separator "$@") | ||
|
||
# footer | ||
function eval_collapse_footer() { | ||
if test "$ec" -eq 0; then | ||
if test -n "$option_success"; then | ||
echo "$option_success" | ||
fi | ||
else | ||
if test -n "$option_failure"; then | ||
echo "$option_failure" | ||
fi | ||
fi | ||
} | ||
trap eval_collapse_footer RETURN | ||
|
||
# header | ||
if test -n "$option_pending"; then | ||
echo "$option_pending" | ||
fi | ||
echo-color --oe --h3="${args[*]}" --ce | ||
|
||
# command | ||
ec=0 && ("${args[@]}" 2>&1 | tee "$log" | echo-revolving-door) || ec="$?" | ||
if test "$ec" -eq 0; then | ||
# unless QUIET=no (verbose mode) then | ||
# hide header (the revolving door already hid the command output) | ||
# and return | ||
if test "$QUIET" != 'no'; then | ||
# hide headers | ||
if test -n "$option_pending"; then | ||
echo-clear-line | ||
fi | ||
echo-clear-line | ||
# return | ||
return "$ec" | ||
fi | ||
# success status | ||
status="$(echo-color -n --g3="[$ec]")" | ||
else | ||
# failure status | ||
status="$(echo-color -n --e3="[$ec]")" | ||
fi | ||
|
||
# did the command output anything? | ||
if test -z "$(cat "$log")"; then | ||
# if not, hide header | ||
if test -n "$option_pending"; then | ||
echo-clear-line | ||
fi | ||
echo-clear-line | ||
# and output header footer combo | ||
echo-color --oe --h3="${args[*]}" --ces "$status" | ||
else | ||
# if it did | ||
# then output its results (if error) | ||
if test "$ec" -ne 0; then | ||
cat "$log" | ||
fi | ||
# then output footer | ||
echo-color --oes --h3="${args[*]}" --ce "$status" | ||
fi | ||
|
||
# done | ||
return "$ec" | ||
} | ||
|
||
# fire if invoked standalone | ||
if test "$0" = "${BASH_SOURCE[0]}"; then | ||
eval_collapse "$@" | ||
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
Oops, something went wrong.