summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-13 18:11:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-13 18:11:22 +0000
commit282efd1f326c75bfa1368ddd9ea54464a361bd4f (patch)
treef90b582bc41b20dbf64a5536c9e86739e5f91bae
parenta90e24268c1a6d05827ec157f3f5edb569f0aaf7 (diff)
irb.rb: backtrace order
* lib/irb.rb (handle_exception): show backtrace from the topmost if stdout is not a tty. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--lib/irb.rb38
1 files changed, 28 insertions, 10 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index 30874cd..16c03e9 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -511,6 +511,12 @@ module IRB
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
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
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