From c03c03cc11ca59dd8e93e769297f99aaf0826652 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 24 Dec 2017 02:26:22 +0000 Subject: lib/irb.rb: highlight exceptions git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/irb.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/irb.rb b/lib/irb.rb index 183ad813ee..ff793dcd64 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -520,13 +520,14 @@ module IRB 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 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 -- cgit v1.2.3