1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

cat --ex now movies through backtrace with each invocation (keeps state)

This commit is contained in:
John Mair 2011-09-14 05:39:48 +12:00
parent 019245bf10
commit 21287630d5
2 changed files with 12 additions and 5 deletions

View file

@ -49,16 +49,22 @@ class Pry
end_line = line - 1
end
opt.on :ex, "Show a window of N lines either side of the last exception (defaults to 5).", :optional => true, :as => Integer do |bt_index_str|
opt.on :ex, "Show a window of N lines either side of the last exception (defaults to 5).", :optional => true, :as => Integer do |bt_index_arg|
window_size = Pry.config.exception_window_size || 5
bt_index = bt_index_str.to_i
ex = _pry_.last_exception
next if !ex
if bt_index_arg
bt_index = bt_index_arg
else
bt_index = ex.bt_index
end
ex.bt_index = (bt_index + 1) % ex.backtrace.size
ex_file, ex_line = ex.bt_source_location_for(bt_index)
start_line = (ex_line - 1) - window_size
start_line = start_line < 0 ? 0 : start_line
end_line = (ex_line - 1) + window_size
if is_core_rbx_path?(ex_file)
if ex_file && is_core_rbx_path?(ex_file)
file_name = rbx_convert_path_to_full(ex_file)
else
file_name = ex_file

View file

@ -346,14 +346,15 @@ class Pry
# @param [Binding] target The binding to set `_ex_` on.
def set_last_exception(ex, target)
class << ex
attr_accessor :file, :line
attr_accessor :file, :line, :bt_index
def bt_source_location_for(index)
backtrace[index] =~ /(.*):(\d+)/
[$1, $2.to_i]
end
end
ex.file, ex.line = ex.bt_source_location_for(0)#_btw_index#$1, $2.to_i
ex.bt_index = 0
ex.file, ex.line = ex.bt_source_location_for(0)
@last_result_is_exception = true
@output_array << ex