Skip to content

Commit

Permalink
major styling improvements (progress #74)
Browse files Browse the repository at this point in the history
- 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
balupton committed Nov 11, 2021
1 parent c5dbe1d commit f8ede3b
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 154 deletions.
1 change: 1 addition & 0 deletions commands/ask
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2164,SC1091
source "$DOROTHY/sources/tty.bash"
source "$DOROTHY/sources/strict.bash"

Expand Down
76 changes: 70 additions & 6 deletions commands/echo-color
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,37 @@ background_intense_gray="$background_intense_white"
background_intense_grey="$background_intense_white"

# modes
reset=$'\e[0m' # tput sgr0
bold=$'\e[1m' # tput bold
dim=$'\e[2m' # tput dim
underline=$'\e[4m' # tput sgr 0 1
blink=$'\e[5m' # tput blink
invert=$'\e[7m' # tput rev
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
reset=$'\e[0m' # tput sgr0
bold=$'\e[1m' # tput bold
dim=$'\e[2m' # tput dim
italic=$'\e[3m' #
underline=$'\e[4m' # tput sgr 0 1
blink=$'\e[5m' # tput blink
invert=$'\e[7m' # tput rev
conceal=$'\e[8m' #
strike=$'\e[9m' # not widely supported
double_underline=$'\e[21m' #
disable_intensity=$'\e[22m' #
disable_italic=$'\e[23m' #
disable_underline=$'\e[24m' #
disable_blink=$'\e[25m' #
disable_invert=$'\e[27m' #
disable_conceal=$'\e[28m' #
reveal="$disable_conceal" #
disable_strike=$'\e[29m' #
disable_foreground_color=$'\e[39m' #
disable_background_color=$'\e[49m' #
framed=$'\e[51m' # not widely supported
circled=$'\e[52m' # not widely supported
overlined=$'\e[53m' # not widely supported
disable_framed_and_circled=$'\e[54m' #
disable_overlined=$'\e[55m' #

# modes that aren't implemented by operating systems
# blink_fast=$'\e[6m'

# styles
h1="${invert}"
e1="${background_red}${intense_white}"
#g1="${background_green}${intense_white}"
Expand All @@ -151,6 +176,45 @@ e3="${h3}${red}"
header="${bold}${underline}"
error="${background_intense_red}${intense_white}"

# don't use these, as too noisey
#
#
#

# level 1 wrappers
oh1="${reset}${h1}${reset}"
ch1="${reset}${h1} ⏲ ┐${reset}"
og1="${reset}${g1}${reset}"
cg1="${reset}${g1} ✅ ┘${reset}"
oe1="${reset}${e1}${reset}"
ce1="${reset}${e1}${reset}"

# level 2 wrappers
oh2="${reset}${bold}${reset}"
ch2="${reset}${bold}${reset}"
og2="${reset}${bold}${green}${reset}"
cg2="${reset}${bold}${green}${reset}"
oe2="${reset}${bold}${red}${reset}"
ce2="${reset}${bold}${red}${reset}"

# level 3 wrappers
oh3="${reset}${reset}"
ch3="${reset}${reset}"
og3="${reset}${green}${reset}"
cg3="${reset}${green}${reset}"
oe3="${reset}${red}${reset}"
ce3="${reset}${red}${reset}"

# element wrappers
oe="${reset}${dim}${bold}< ${reset}"
ce="${reset}${dim}${bold} >${reset}"
oes="${reset}${dim}${bold}</ ${reset}"
ces="${reset}${dim}${bold} />${reset}"

# the resets allow these to work:
# echo-color --oh1 --h1='Setup Python' --ch1 $'\n' --og1 --g1='Setup Python' --cg1
# echo-color --oes --h3="this should not be dim" --ce "$status"

# helper
function colorize() {
local style="$1"
Expand Down
9 changes: 9 additions & 0 deletions commands/echo-indent
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
87 changes: 87 additions & 0 deletions commands/eval-collapse
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
2 changes: 1 addition & 1 deletion commands/setup-node
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2164
# shellcheck disable=SC2164,SC1091
source "$DOROTHY/sources/strict.bash"

# setup-environment-commands provides: NVM_DIR
Expand Down

0 comments on commit f8ede3b

Please sign in to comment.