From fe2c6aa0ac1a1a586aab93ed5038d7fd5c2907bc Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 30 Jul 2026 18:53:41 +0400 Subject: [PATCH] colored hint message --- bin/miaou-bash | 19 ++++++++++++++++++- test/miaou-bash.test.bash | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bin/miaou-bash b/bin/miaou-bash index 65f944c..3c99b84 100755 --- a/bin/miaou-bash +++ b/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 '' diff --git a/test/miaou-bash.test.bash b/test/miaou-bash.test.bash index cc50e57..5cf5a1b 100755 --- a/test/miaou-bash.test.bash +++ b/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))