smarter ansi_error
This commit is contained in:
+37
-27
@@ -1,21 +1,19 @@
|
||||
#!/usr/bin/env miaou-bash
|
||||
|
||||
. "$MIAOU_BASH_DIR/lib/ansi.bash"
|
||||
|
||||
CODE=118
|
||||
TYPE='SUBSHELL TERM'
|
||||
PAYLOAD='blabla'
|
||||
code=118
|
||||
failure_type='SUBSHELL TERM'
|
||||
failure_payload='blabla'
|
||||
stack_sources=('file.bash' './lib/utility.bash' 'file.bash')
|
||||
stack_lines=(18 56 12)
|
||||
stack_functions=('f2' 'f1' '<main>')
|
||||
|
||||
function ansi_block_continuation {
|
||||
tput sc
|
||||
tput cuu 1
|
||||
BG=RED FG=BLACK style_ansi "\t╦"
|
||||
tput rc
|
||||
FG=RED style_ansi "\t║\n"
|
||||
}
|
||||
# function ansi_block_continuation {
|
||||
# tput sc
|
||||
# tput cuu 1
|
||||
# BG=RED FG=BLACK style_ansi "\t╦"
|
||||
# tput rc
|
||||
# FG=RED style_ansi "\t║\n"
|
||||
# }
|
||||
|
||||
function ansi_block_error {
|
||||
BG=RED
|
||||
@@ -24,30 +22,42 @@ function ansi_block_error {
|
||||
|
||||
local content detail exit_code
|
||||
|
||||
content=$(style_ansi "${TYPE}")
|
||||
content=$(style_ansi "$1")
|
||||
content=$(style_padding "$content")
|
||||
detail=$(BG=BLACK style_padding "${PAYLOAD}")
|
||||
exit_code=$(FG=WHITE style_ansi " ${CODE}")
|
||||
style_block "$content$detail$exit_code"
|
||||
|
||||
detail=$(BG=BLACK style_padding "$2")
|
||||
exit_code=$(FG=CYAN style_ansi " $3")
|
||||
BLOCK_CONTINUATION_COL=5 style_block "$content$detail$exit_code"
|
||||
ansi_reset
|
||||
FG=RED style_ansi " ║"
|
||||
echo
|
||||
}
|
||||
|
||||
function ansi_traces {
|
||||
local optional location
|
||||
|
||||
local optional location sources lines functions
|
||||
declare -n sources=$1
|
||||
declare -n lines=$2
|
||||
declare -n functions=$3
|
||||
optional=false
|
||||
for i in "${!stack_sources[@]}"; do
|
||||
FG=RED style_ansi "\t╟─⟶"
|
||||
location="${stack_sources[$i]}:${stack_lines[$i]}"
|
||||
for i in "${!sources[@]}"; do
|
||||
FG=RED style_ansi " ╟─⟶"
|
||||
location=$(printf "%40s" "${sources[$i]}:${lines[$i]}")
|
||||
is_true "$optional" &&
|
||||
location=$(FG=GRAY STYLE=ITALIC style_ansi "\t$location") || # FIXME: \t should not be required!
|
||||
location=$(FG=GRAY STYLE=ITALIC style_ansi "$location") ||
|
||||
location=$(STYLE=ITALIC style_ansi "$location")
|
||||
printf "%40s\t%s\n" "${location}" "${stack_functions[$i]}"
|
||||
builtin echo "${location} ${functions[$i]}"
|
||||
optional=true
|
||||
done
|
||||
}
|
||||
|
||||
ansi_block_error
|
||||
ansi_block_continuation
|
||||
ansi_traces
|
||||
function show_error {
|
||||
>&2 printf '\r'
|
||||
>&2 ansi_block_error "$failure_type" "$failure_payload" "$code"
|
||||
>&2 ansi_traces stack_sources stack_lines stack_functions
|
||||
# [[ -p /dev/stdout ]] && kill -TERM $$
|
||||
}
|
||||
|
||||
declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
|
||||
|
||||
echo START
|
||||
# echo -n "standard flow:" && show_error
|
||||
echo -n "starting subshell: $(show_error)"
|
||||
|
||||
@@ -7,6 +7,10 @@ readonly BASEDIR
|
||||
|
||||
# SCENARII
|
||||
|
||||
function do_subshell_false {
|
||||
result=$(false)
|
||||
}
|
||||
|
||||
function do_subshell_term {
|
||||
# grep nope nope
|
||||
echo "found=$(command_not_found)"
|
||||
|
||||
Reference in New Issue
Block a user