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

ruby-changes:50939

From: nobu <ko1@a...>
Date: Sat, 14 Apr 2018 03:11:27 +0900 (JST)
Subject: [ruby-changes:50939] nobu:r63146 (trunk): irb.rb: backtrace order

nobu	2018-04-14 03:11:22 +0900 (Sat, 14 Apr 2018)

  New Revision: 63146

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

  Log:
    irb.rb: backtrace order
    
    * lib/irb.rb (handle_exception): show backtrace from the topmost
      if stdout is not a tty.

  Modified files:
    trunk/lib/irb.rb
Index: lib/irb.rb
===================================================================
--- lib/irb.rb	(revision 63145)
+++ lib/irb.rb	(revision 63146)
@@ -511,6 +511,12 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L511
         irb_bug = false
       end
 
+      if STDOUT.tty?
+        attr = ATTR_TTY
+        print "#{attr[1]}Traceback#{attr[]} (most recent call last):\n"
+      else
+        attr = ATTR_PLAIN
+      end
       messages = []
       lasts = []
       levels = 0
@@ -518,7 +524,12 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L524
         count = 0
         exc.backtrace.each do |m|
           m = @context.workspace.filter_backtrace(m) or next unless irb_bug
-          m = sprintf("%9d: from %s", (count += 1), m)
+          count += 1
+          if attr == ATTR_TTY
+            m = sprintf("%9d: from %s", count, m)
+          else
+            m = "\tfrom #{m}"
+          end
           if messages.size < @context.back_trace_limit
             messages.push(m)
           elsif lasts.size < @context.back_trace_limit
@@ -527,16 +538,23 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L538
           end
         end
       end
-      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
+      if attr == ATTR_TTY
+        unless lasts.empty?
+          puts lasts.reverse
+          printf "... %d levels...\n", levels if levels > 0
+        end
+        puts messages.reverse
+      end
+      m = exc.to_s.split(/\n/)
+      print "#{attr[1]}#{exc.class} (#{attr[4]}#{m.shift}#{attr[0, 1]})#{attr[]}\n"
+      puts m.map {|s| "#{attr[1]}#{s}#{attr[]}\n"}
+      if attr == ATTR_PLAIN
+        puts messages
+        unless lasts.empty?
+          puts lasts
+          printf "... %d levels...\n", levels if levels > 0
+        end
       end
-      puts messages.reverse
-      messages = exc.to_s.split(/\n/)
-      print "#{attr[1]}#{exc.class} (#{attr[4]}#{messages.shift}#{attr[0, 1]})#{attr[]}\n"
-      puts messages.map {|s| "#{attr[1]}#{s}#{attr[]}\n"}
       print "Maybe IRB bug!\n" if irb_bug
     end
 

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

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