turned chomp! into an rstrip! in process_line(). Fixed 1.8.7 compat

for `read_between_lines` function commands.rb. Removed before/after
hook output text (too spammy). Fixed file-mode completion, so it works
straight away. CHanged 'pry' rake task to 'binding.pry' instead of
just 'pry' so that context is given.
This commit is contained in:
John Mair 2011-04-08 13:06:39 +12:00
parent 0e1e5524b3
commit 3c271ff712
6 changed files with 33 additions and 31 deletions

View File

@ -36,7 +36,7 @@ end
desc "run pry"
task :pry do
require "#{direc}/lib/pry.rb"
Pry.start
binding.pry
end
desc "show pry version"

View File

@ -123,7 +123,7 @@ class Pry
command "gem-cd", "Change working directory to specified gem's directory." do |gem_name|
require 'rubygems'
gem_spec = Gem.source_index.find_name(gem_name).first
next output.put("Gem `#{gem_name}` not found.") if !gem_spec
next output.puts("Gem `#{gem_name}` not found.") if !gem_spec
Dir.chdir(File.expand_path(gem_spec.full_gem_path))
end
@ -149,6 +149,8 @@ class Pry
else
Pry.active_instance.prompt = Pry::FILE_PROMPT
Pry.active_instance.custom_completions = Pry::FILE_COMPLETIONS
Readline.completion_proc = Pry::InputCompleter.build_completion_proc target,
Pry.active_instance.instance_eval(&Pry::FILE_COMPLETIONS)
end
end
@ -426,20 +428,13 @@ Shows local and instance variables by default.
CodeRay.scan(contents, language_detected).term
end
read_between_the_lines = lambda do |file_name, start_line, end_line, with_line_numbers|
read_between_the_lines = lambda do |file_name, start_line, end_line|
content = File.read(File.expand_path(file_name))
if with_line_numbers
lines = content.each_line.map.with_index { |line, idx| "#{idx + 1}: #{line}" }
else
lines = content.each_line.to_a
end
lines[start_line..end_line].join
content.each_line.to_a[start_line..end_line].join
end
add_line_numbers = lambda do |lines, start_line|
lines.each_line.map.with_index do |line, idx|
lines.each_line.each_with_index.map do |line, idx|
adjusted_index = idx + start_line
if Pry.color
cindex = CodeRay.scan("#{adjusted_index}", :ruby).term
@ -475,7 +470,7 @@ e.g: cat-file hello.rb
end_line = line.to_i - 1
end
opts.on("-t", "--type TYPE", "The specific file type for syntax higlighting.") do |type|
opts.on("-t", "--type TYPE", "The specific file type for syntax higlighting (e.g ruby, python, cpp, java)") do |type|
file_type = type.to_sym
end
@ -494,7 +489,7 @@ e.g: cat-file hello.rb
next
end
contents = read_between_the_lines.call(file_name, start_line, end_line, false)
contents = read_between_the_lines.call(file_name, start_line, end_line)
if Pry.color
contents = syntax_highlight_by_file_type_or_specified.call(contents, file_name, file_type)

View File

@ -4,7 +4,7 @@ class Pry
DEFAULT_HOOKS = {
:before_session => proc do |out, target|
out.puts "Beginning Pry session for #{Pry.view_clip(target.eval('self'))}"
# out.puts "Beginning Pry session for #{Pry.view_clip(target.eval('self'))}"
# ensure we're actually in a method
meth_name = target.eval('__method__')
@ -16,6 +16,6 @@ class Pry
end
end,
:after_session => proc { |out, target| out.puts "Ending Pry session for #{Pry.view_clip(target.eval('self'))}" }
# :after_session => proc { |out, target| out.puts "Ending Pry session for #{Pry.view_clip(target.eval('self'))}" }
}
end

View File

@ -142,6 +142,7 @@ class Pry
def rep(target=TOPLEVEL_BINDING)
target = Pry.binding_for(target)
result = re(target)
print.call output, result if !@suppress_output
end
@ -235,7 +236,7 @@ class Pry
# @param [String] eval_string The cumulative lines of input.
# @target [Binding] target The target of the Pry session.
def process_line(val, eval_string, target)
val.chomp!
val.rstrip!
Pry.cmd_ret_value = @command_processor.process_commands(val, eval_string, target)
if Pry.cmd_ret_value

View File

@ -70,15 +70,17 @@ describe Pry do
o.instance_variable_get(:@x).should == 10
end
it 'should execute start session and end session hooks' do
input = InputTester.new("exit")
str_output = StringIO.new
o = Object.new
# # this is now deprecated
# it 'should execute start session and end session hooks' do
# next
# input = InputTester.new("exit")
# str_output = StringIO.new
# o = Object.new
pry_tester = Pry.start(o, :input => input, :output => str_output)
str_output.string.should =~ /Beginning.*#{o}/
str_output.string.should =~ /Ending.*#{o}/
end
# pry_tester = Pry.start(o, :input => input, :output => str_output)
# str_output.string.should =~ /Beginning.*#{o}/
# str_output.string.should =~ /Ending.*#{o}/
# end
end
describe "test loading rc files" do
@ -514,23 +516,26 @@ describe Pry do
str_output = StringIO.new
Pry.new(:print => proc {}, :input => InputTester.new("v"),
:output => str_output, :commands => Command4).rep("john")
str_output.string.chomp.should == "john"
str_output.string.rstrip.should == "john"
Object.remove_const(:Command3)
Object.remove_const(:Command4)
end
it 'should import commands from another command object' do
class Command3 < Pry::CommandBase
Object.remove_const(:Command77) if Object.const_defined?(:Command77)
class Command77 < Pry::CommandBase
import_from Pry::Commands, "status", "jump-to"
end
str_output = StringIO.new
Pry.new(:print => proc {}, :input => InputTester.new("status"),
:output => str_output, :commands => Command3).rep("john")
:output => str_output, :commands => Command77).rep("john")
str_output.string.should =~ /Status:/
Object.remove_const(:Command3)
Object.remove_const(:Command77)
end
it 'should delete some inherited commands when using delete method' do
@ -569,11 +574,11 @@ describe Pry do
str_output = StringIO.new
Pry.new(:input => InputTester.new("jump-to"), :output => str_output, :commands => Command3).rep
str_output.string.chomp.should == "jump-to the music"
str_output.string.rstrip.should == "jump-to the music"
str_output = StringIO.new
Pry.new(:input => InputTester.new("help"), :output => str_output, :commands => Command3).rep
str_output.string.chomp.should == "help to the music"
str_output.string.rstrip.should == "help to the music"
Object.remove_const(:Command3)

View File

@ -35,6 +35,7 @@ class Pry
# null output class - doesn't write anywwhere.
class NullOutput
def self.puts(*) end
def self.string(*) end
end
end