Browse Source

colored hint message

main
pvincent 2 weeks ago
parent
commit
fe2c6aa0ac
  1. 19
      bin/miaou-bash
  2. 2
      test/miaou-bash.test.bash

19
bin/miaou-bash

@ -370,14 +370,31 @@ function dump_stacktrace {
for i in "${!error_source[@]}"; do
tty_ansi FG_MAGENTA
echo -n " ╟──▷"
[[ $i -gt 0 ]] && tty_ansi FG_GRAY
tty_ansi STYLE_ITALIC
source="${error_source[$i]}"
lineno="${error_lineno[$i]}"
funcname="${error_funcname[$i]}"
local hint regex='(^.*) \(hint: (.*)\)$'
if [[ "$funcname" =~ $regex ]]; then
hint="${BASH_REMATCH[2]}"
funcname="${BASH_REMATCH[1]} (hint: "
else
unset hint
[[ $i -gt 0 ]] && tty_ansi FG_GRAY
fi
printf "%40s:%.4s" "$source" "$lineno"
tty_ansi RESET
printf " \t%s" "$funcname"
if [[ -v hint ]]; then
tty_ansi FG_YELLOW
printf "$hint"
tty_ansi RESET
printf ')'
fi
echo
done
miaou_debug '</stacktrace>'

2
test/miaou-bash.test.bash

@ -63,7 +63,7 @@ fail_type exit EXIT
fail_type command_not_found COMMAND_NOT_FOUND
fail_type source_not_found SOURCE_NOT_FOUND
fail_type file_not_found FILE_NOT_FOUND
fail_type child_error CHILD_ERROR '(hint: prefer source than child process)'
fail_type child_error CHILD_ERROR 'prefer source than child process'
failed=${#failures[@]}
success=$((test_count - failed))

Loading…
Cancel
Save