aboutsummaryrefslogtreecommitdiffstats
path: root/eval_error.c
diff options
context:
space:
mode:
authorsorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-29 11:14:23 +0000
committersorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-29 11:14:23 +0000
commitb5e0ca4730cb4bfe1466a2e51eeed422bae20296 (patch)
treebac95f8dc673e1475a03b59eaefb7c2833e0f966 /eval_error.c
parentb8d15b7e470fe6889daae9e8ff8cf6541f789a59 (diff)
downloadruby-b5e0ca4730cb4bfe1466a2e51eeed422bae20296.tar.gz
Log exception with bold and underline for TTYs
Print error message in bold/underlined text if STDERR is unchanged and a tty. [Feature #14160] [experimental] Screenshot: https://img.sorah.jp/s/2017-11-29_1711_xj2fu.png git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval_error.c')
-rw-r--r--eval_error.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/eval_error.c b/eval_error.c
index e8a1691036..4c79bf044e 100644
--- a/eval_error.c
+++ b/eval_error.c
@@ -73,8 +73,11 @@ error_print(rb_execution_context_t *ec)
}
static void
-print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg)
+print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, int colored)
{
+ static const char underline[] = "\033[4;1m";
+ static const char bold[] = "\033[1m";
+ static const char reset[] = "\033[m";
const char *einfo = "";
long elen = 0;
VALUE mesg;
@@ -89,13 +92,16 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg)
warn_print(": ");
}
+ if (colored) warn_print(bold);
+
if (!NIL_P(emesg)) {
einfo = RSTRING_PTR(emesg);
- elen = RSTRING_LEN(emesg);
+ elen = RSTRING_LEN(emesg);
}
}
if (eclass == rb_eRuntimeError && elen == 0) {
+ if (colored) warn_print(underline);
warn_print("unhandled exception\n");
}
else {
@@ -103,6 +109,7 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg)
epath = rb_class_name(eclass);
if (elen == 0) {
+ if (colored) warn_print(underline);
warn_print_str(epath);
warn_print("\n");
}
@@ -119,7 +126,10 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg)
warn_print_str(tail ? rb_str_subseq(emesg, 0, len) : emesg);
if (epath) {
warn_print(" (");
- warn_print_str(epath);
+ if (colored) warn_print(underline);
+ warn_print_str(epath);
+ if (colored) warn_print(reset);
+ if (colored) warn_print(bold);
warn_print(")\n");
}
if (tail) {
@@ -128,6 +138,7 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg)
if (tail ? einfo[elen-1] != '\n' : !epath) warn_print2("\n", 1);
}
}
+ if (colored) warn_print(reset);
}
static void
@@ -192,12 +203,12 @@ rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo)
}
}
if (rb_stderr_tty_p()) {
- warn_print("Traceback (most recent call last):\n");
+ warn_print("\033[1mTraceback \033[m(most recent call last):\n");
print_backtrace(eclass, errat, TRUE);
- print_errinfo(eclass, errat, emesg);
+ print_errinfo(eclass, errat, emesg, TRUE);
}
else {
- print_errinfo(eclass, errat, emesg);
+ print_errinfo(eclass, errat, emesg, FALSE);
print_backtrace(eclass, errat, FALSE);
}
error: