diff --git a/bin/miaou-bash b/bin/miaou-bash index 8e0e8ce..153c3d6 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -39,7 +39,6 @@ function on_return { if [[ "${BASH_COMMAND}" == 'return '* ]]; then code=$(echo "${BASH_COMMAND}" | cut -d' ' -f2) if [[ -n "$code" ]] && [[ "$code" -ne 0 ]]; then - trap - DEBUG >&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: return $code from ${FUNCNAME[1]}" fi fi @@ -49,6 +48,7 @@ function on_exit { code=${1:-0} if [[ $code -gt 0 ]]; then + stack_lines=("${BASH_LINENO[@]}") stack_functions=("${FUNCNAME[@]}") stack_sources=("${BASH_SOURCE[@]}") @@ -91,7 +91,7 @@ function on_exit { failure_payload="${BASH_REMATCH[2]}" fi last_error="${BASH_SOURCE[1]}:${BASH_LINENO[0]} subshell term $code" - printf "\r" + printf "\r" # useful! kill -USR1 $$ else failure_type='UNKNOWN' @@ -192,7 +192,7 @@ function on_exit { } function miaou_debug { - is_true "${MIAOU_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true + is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "*********** DEBUG: $*" || true } function ansi_block_continuation { @@ -204,24 +204,22 @@ function ansi_block_continuation { } function ansi_block_error { - BG=RED FG=BLACK + BG=RED PADDING=2 - local content detail exit_code content=$(style_ansi "$1") content=$(style_padding "$content") detail="$2" - [[ -n "$detail" ]] && detail=$(BG=BLACK FG=WHITE style_padding "$2") + [[ -n "$detail" ]] && detail=$(BG=BLACK FG=WHITE PADDING_LEFT=4 style_padding "$2") - exit_code=$(FG=CYAN style_ansi " $3") - printf "\r" + exit_code=$(FG=CYAN style_ansi "$3") + builtin echo -en "\r" BLOCK_CONTINUATION_COL=5 style_block "$content$detail$exit_code" ansi_reset - FG=RED style_ansi " ║" - echo + FG=RED style_ansi " ║" && builtin echo } function ansi_traces { @@ -243,22 +241,19 @@ function ansi_traces { function dump_failure { declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash" dump_stderr true + + miaou_debug "---error box ${failure_type:-} ---" if [[ ${failure_type} == 'SUBSHELL SOURCE NOT FOUND' ]]; then : else - miaou_debug '---error---' - if [[ $failure_type == 'SUBSHELL ERROR' ]]; then - >&4 echo -e "${failure_payload}" - else - >&4 ansi_block_error "$failure_type" "$failure_payload" "$code" - fi - miaou_debug '---end of error---' + >&4 ansi_block_error "$failure_type" "$failure_payload" "$code" fi + miaou_debug '---end of error box---' miaou_debug '---stacktrace---' >&4 ansi_traces stack_sources stack_lines stack_functions - miaou_debug '---end of stacktrace---' + cleanup } diff --git a/lib/ansi.bash b/lib/ansi.bash index b512dc3..5e4af6d 100644 --- a/lib/ansi.bash +++ b/lib/ansi.bash @@ -26,14 +26,14 @@ FG_COLORS[GRAY]='\e[90m' FG_COLORS[MAGENTA]='\e[95m' declare -A BG_COLORS -BG_COLORS["BLACK"]='\e[40m' -BG_COLORS["RED"]='\e[41m' -BG_COLORS["GREEN"]='\e[42m' -BG_COLORS["YELLOW"]='\e[43m' -BG_COLORS["BLUE"]='\e[44m' -BG_COLORS["PURPLE"]='\e[45m' -BG_COLORS["CYAN"]='\e[46m' -BG_COLORS["WHITE"]='\e[47m' +BG_COLORS[BLACK]='\e[40m' +BG_COLORS[RED]='\e[41m' +BG_COLORS[GREEN]='\e[42m' +BG_COLORS[YELLOW]='\e[43m' +BG_COLORS[BLUE]='\e[44m' +BG_COLORS[PURPLE]='\e[45m' +BG_COLORS[CYAN]='\e[46m' +BG_COLORS[WHITE]='\e[47m' # BG_COLORS["GRAY"]='\e[90m' # BG_COLORS["MAGENTA"]='\e[95m' @@ -59,7 +59,6 @@ function style_padding { style_ansi "$left" style_ansi "$1" - # builtin echo -n "$1" right=$(for _ in $(seq 1 "${padding_right}"); do builtin echo -n ' '; done) style_ansi "$right" @@ -75,9 +74,7 @@ function _style_variant { function _style_bg { if [[ -n "$1" ]]; then - [[ -v BG_COLORS[$1] ]] && echo "${BG_COLORS[$1]}" && return - >&2 echo "unknown BG value: $1" && return 1 - # false + [[ -v BG_COLORS[$1] ]] && echo "${BG_COLORS[$1]}" || >&2 echo "unknown BG value: $1" fi } @@ -93,6 +90,7 @@ function style_ansi { function style_block { local content length top bottom i + content=$(style_padding "$1") length=$(ansi_length "$content") diff --git a/test/stub/ansi_error.bash b/test/stub/ansi_error.bash index c4a3bf4..812b465 100755 --- a/test/stub/ansi_error.bash +++ b/test/stub/ansi_error.bash @@ -14,9 +14,7 @@ stack_functions=('f2' 'f1' '
') # tput rc # FG=RED style_ansi "\t║\n" # } -function strip_ansi { - echo "$1" | sed -E 's/\x1b\[[0-9;]*[a-zA-Z]//g' -} + function ansi_block_error { BG=RED FG=BLACK @@ -62,10 +60,5 @@ declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash" echo START -output=$(BG=RED style_ansi "╔") -output=$(strip_ansi "$output") -echo "$output" -# echo "$output" | cat -v - -# echo -n "standard flow:" && show_error +echo -n "standard flow:" && show_error # echo -n "starting subshell: $(show_error)"