[前][次][番号順一覧][スレッド一覧]

ruby-changes:48818

From: sorah <ko1@a...>
Date: Wed, 29 Nov 2017 20:14:28 +0900 (JST)
Subject: [ruby-changes:48818] sorah:r60935 (trunk): Log exception with bold and underline for TTYs

sorah	2017-11-29 20:14:23 +0900 (Wed, 29 Nov 2017)

  New Revision: 60935

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60935

  Log:
    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

  Modified files:
    trunk/NEWS
    trunk/eval_error.c
Index: eval_error.c
===================================================================
--- eval_error.c	(revision 60934)
+++ eval_error.c	(revision 60935)
@@ -73,8 +73,11 @@ error_print(rb_execution_context_t *ec) https://github.com/ruby/ruby/blob/trunk/eval_error.c#L73
 }
 
 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 https://github.com/ruby/ruby/blob/trunk/eval_error.c#L92
 	    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 https://github.com/ruby/ruby/blob/trunk/eval_error.c#L109
 
 	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 https://github.com/ruby/ruby/blob/trunk/eval_error.c#L126
 	    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 https://github.com/ruby/ruby/blob/trunk/eval_error.c#L138
 	    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 https://github.com/ruby/ruby/blob/trunk/eval_error.c#L203
 	}
     }
     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:
Index: NEWS
===================================================================
--- NEWS	(revision 60934)
+++ NEWS	(revision 60935)
@@ -284,6 +284,9 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L284
 * Print backtrace and error message in reverse order if STDERR is unchanged and a tty.
   [Feature #8661] [experimental]
 
+* Print error message in bold/underlined text if STDERR is unchanged and a tty.
+  [Feature #14160] [experimental]
+
 * configure option --with-ext now mandates its arguments.  So for
   instance if you run ./configure --with-ext=openssl,+ then the
   openssl library is guaranteed compiled, otherwise the build fails

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]