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

ruby-changes:49318

From: nobu <ko1@a...>
Date: Sun, 24 Dec 2017 11:26:27 +0900 (JST)
Subject: [ruby-changes:49318] nobu:r61435 (trunk): lib/irb.rb: highlight exceptions

nobu	2017-12-24 11:26:22 +0900 (Sun, 24 Dec 2017)

  New Revision: 61435

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

  Log:
    lib/irb.rb: highlight exceptions

  Modified files:
    trunk/lib/irb.rb
Index: lib/irb.rb
===================================================================
--- lib/irb.rb	(revision 61434)
+++ lib/irb.rb	(revision 61435)
@@ -520,13 +520,14 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L520
                 end
               end
             end
-            print "Traceback (most recent call last):\n"
+            attr = STDOUT.tty? ? ATTR_TTY : ATTR_PLAIN
+            print "#{attr[1]}Traceback#{attr[]} (most recent call last):\n"
             unless lasts.empty?
               puts lasts.reverse
               printf "... %d levels...\n", levels if levels > 0
             end
             puts messages.reverse
-            print exc.class, ": ", exc, "\n"
+            print "#{attr[1]}#{exc.class} (#{attr[4]}#{exc}#{attr[0, 1]})#{attr[]}\n"
             print "Maybe IRB bug!\n" if irb_bug
           end
         end
@@ -674,6 +675,11 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L675
       end
       format("#<%s: %s>", self.class, ary.join(", "))
     end
+
+    ATTR_TTY = "\e[%sm"
+    def ATTR_TTY.[](*a) self % a.join(";"); end
+    ATTR_PLAIN = ""
+    def ATTR_PLAIN.[](*) self; end
   end
 
   def @CONF.inspect

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

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