ansi_error
This commit is contained in:
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env miaou-bash
|
||||
|
||||
. "$MIAOU_BASH_DIR/lib/ansi.bash"
|
||||
|
||||
TYPE='SUBSHELL TERM'
|
||||
PAYLOAD='blabla'
|
||||
stack_sources=('file.bash' './lib/utility.bash' 'file.bash')
|
||||
stack_lines=(18 56 12)
|
||||
stack_functions=('f2' 'f1' '<main>')
|
||||
|
||||
function dump_failure {
|
||||
BG=RED
|
||||
FG=BLACK
|
||||
PADDING=2
|
||||
|
||||
content=$(style_ansi "${TYPE}")
|
||||
content=$(style_padding "$content")
|
||||
detail=$(BG=BLACK style_padding "${PAYLOAD}")
|
||||
style_block "$content$detail"
|
||||
|
||||
ansi_reset
|
||||
}
|
||||
|
||||
function dump_traces {
|
||||
local optional location
|
||||
# block continuation
|
||||
tput sc
|
||||
tput cuu 1
|
||||
BG=RED FG=BLACK style_ansi "\t╦"
|
||||
tput rc
|
||||
|
||||
FG=RED style_ansi "\t║\n"
|
||||
|
||||
optional=false
|
||||
for i in "${!stack_sources[@]}"; do
|
||||
FG=RED style_ansi "\t╟─⟶"
|
||||
location="${stack_sources[$i]}:${stack_lines[$i]}"
|
||||
is_true "$optional" &&
|
||||
location=$(FG=GRAY STYLE=ITALIC style_ansi "\t$location") || # FIXME: \t should not be required!
|
||||
location=$(STYLE=ITALIC style_ansi "$location")
|
||||
printf "%40s\t%s\n" "${location}" "${stack_functions[$i]}"
|
||||
optional=true
|
||||
done
|
||||
}
|
||||
|
||||
dump_failure
|
||||
dump_traces
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env miaou-bash
|
||||
|
||||
PREFIX_NESTED="__nested__"
|
||||
INSPECT_SIMPLE='-> '
|
||||
INSPECT_NESTED='=> '
|
||||
INSPECT_END='~~~~'
|
||||
|
||||
function array_new {
|
||||
ref_name="$1"
|
||||
shift
|
||||
[[ -v nested_count ]] && ((nested_count++)) || nested_count=1
|
||||
nested_name="${PREFIX_NESTED}$nested_count"
|
||||
declare -ga "$nested_name"
|
||||
declare -gn "$ref_name"="$nested_name"
|
||||
local -n internal="$nested_name"
|
||||
internal+=("$@")
|
||||
}
|
||||
|
||||
function array_inspect {
|
||||
local ref prefix i
|
||||
declare -n ref="$1"
|
||||
prefix="${2:-}"
|
||||
echo "${prefix}array '$1' contains ${#ref[@]} elements"
|
||||
for i in "${ref[@]}"; do
|
||||
if [[ -R $i ]]; then
|
||||
array_inspect "$i" "${prefix}${INSPECT_NESTED}"
|
||||
else
|
||||
echo "${prefix}${INSPECT_SIMPLE}${i}"
|
||||
fi
|
||||
done
|
||||
echo "${prefix}${INSPECT_END}"
|
||||
}
|
||||
|
||||
# initialization
|
||||
array_new mine1 'Albert Dupontel' 20
|
||||
array_new mine2 'Bob Sinclar' 24
|
||||
array_new mine3 'Conrad Ademayor' 31 true
|
||||
array_new nested mine1 mine2 mine3
|
||||
array_inspect nested
|
||||
|
||||
# change values
|
||||
mine1+=(false)
|
||||
mine3[1]=$((mine3[1] + 8))
|
||||
mine3[2]=false
|
||||
array_inspect nested
|
||||
|
||||
# nested twice
|
||||
declare -n other="${nested[1]:?}" # ':?' fix shellcheck issue
|
||||
array_inspect other
|
||||
array_new mine4 'Darryl' 30
|
||||
other+=(mine4)
|
||||
array_inspect nested
|
||||
|
||||
# CAN'T PREVENT LOOP!
|
||||
# other+=(nested)
|
||||
# array_inspect nested
|
||||
Reference in New Issue
Block a user