mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Merge branch 'dev' of github.com:banister/pry into dev
This commit is contained in:
commit
f0c73cacab
2 changed files with 15 additions and 14 deletions
|
@ -12,20 +12,22 @@ class Pry
|
||||||
history = Readline::HISTORY.to_a
|
history = Readline::HISTORY.to_a
|
||||||
|
|
||||||
Slop.parse(args) do |opt|
|
Slop.parse(args) do |opt|
|
||||||
opt.banner "Usage: hist [--replay START..END]\n" \
|
opt.banner "Usage: hist [--replay START..END] [--clear] [--grep PATTERN] [--help]\n"
|
||||||
"View and replay history\n" \
|
|
||||||
"e.g hist --replay 2..8"
|
|
||||||
|
|
||||||
opt.on :g, :grep, 'A pattern to match against the history.', true do |pattern|
|
opt.on :g, :grep, 'A pattern to match against the history.', true do |pattern|
|
||||||
|
pattern = Regexp.new pattern
|
||||||
history.pop
|
history.pop
|
||||||
matches = history.grep Regexp.new(pattern)
|
|
||||||
text = add_line_numbers matches.join("\n"), 0
|
history.each_with_index do |element, index|
|
||||||
stagger_output text
|
if element =~ pattern
|
||||||
|
output.puts "#{colorize index}: #{element}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
opt.on :r, :replay, 'The line (or range of lines) to replay.', true, :as => Range do |range|
|
opt.on :r, :replay, 'The line (or range of lines) to replay.', true, :as => Range do |range|
|
||||||
unless opt.grep?
|
unless opt.grep?
|
||||||
actions = history[range].join("\n") + "\n"
|
actions = Array(history[range]).join("\n") + "\n"
|
||||||
Pry.active_instance.input = StringIO.new(actions)
|
Pry.active_instance.input = StringIO.new(actions)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,16 +23,15 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def colorize text
|
||||||
|
Pry.color ? CodeRay.scan(text.to_s, :ruby).term : text
|
||||||
|
end
|
||||||
|
|
||||||
def add_line_numbers(lines, start_line)
|
def add_line_numbers(lines, start_line)
|
||||||
line_array = lines.each_line.to_a
|
line_array = lines.each_line.to_a
|
||||||
line_array.each_with_index.map do |line, idx|
|
line_array.each_with_index.map do |line, idx|
|
||||||
adjusted_index = idx + start_line
|
adjusted_index = idx + start_line
|
||||||
if Pry.color
|
"#{colorize adjusted_index}: #{line}"
|
||||||
cindex = CodeRay.scan("#{adjusted_index}", :ruby).term
|
|
||||||
"#{cindex}: #{line}"
|
|
||||||
else
|
|
||||||
"#{idx}: #{line}"
|
|
||||||
end
|
|
||||||
end.join
|
end.join
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue